GitHub Actions workflow for cross-compilation to Intel / ARM64 on Mac and Linux?

So I am about to do a deep dive on GitHub Actions market place for this but TL;DR: I want to share a repo of mine with a group of people and do releases and have GitHub Actions produce binaries for:

  • aarch64 Mac
  • x86_64 Mac
  • aarch64 Linux
  • x86_64 Linux

...and link them on the releases page.

Does anyone have a complete YAML file handy? I'll find my way through eventually but hey, why not ask for a shortcut if somebody is willing to link to it.

(Everything else failing, I can also produce a Docker Compose recipe that spins up 4 containers that build the binaries, and then upload those to the GitHub releases page (not sure if that's possible but will check) and stop there.)

Thank you.

The linked repository seems to fit your request...

The flow creates and publishes binaries for Linux, macOS, and Windows. Albeit just for the amd64 architecture and with no versioning.

1 Like

It's a start. I'll try it. Thank you!

1 Like

I'm just starting researching something similar - my requirements are a bit soft but essentially: run tests, build binaries, & create a github release. I think it would ideally use Cross as that gives it a chance of being easy to keep up to date. Would quite like to also generate release notes (ideally from issues closed since last release).

A quick search here was my first action so I mean "just starting" very literally. I don't have anything to contribute yet. But if you find much out there that's already useful, I'd be grateful if you could report back here.

1 Like

If you're using GitHub to build what purpose does cross-rs serve? Just use a target architecture machine to build natively.

1 Like

Maybe none - I haven't used Github Actions before so have a bit of research to do. I was just familiar with cross-rs from doing manual/local builds.

1 Like

You can't built to all targets natively. For example, wasm requires cross compilation.

1 Like

No doubt.

I assumed the topic was still confined to the targets listed in the subject.

I tried to tackle local cross-compilation and mostly succeeded but couldn't manage to produce x86_64 Linux binaries (musl, so statically linked) no matter what I tried. I know about trust and cross but figured my first priority should be to have the Actions in place that create a new release and produce cross-compiled binaries, and not try and emulate part of that on my machine. For now at least.

1 Like

I've been experimenting a bit with GitHub - rust-build/rust-build.action: Automate publishing Rust build artifacts for GitHub releases through GitHub Actions. It seems useful for my purposes (which are pretty limited, for a project which is my first semi-real Rust attempt). This doesn't handle ARM targets so won't be directly useful for you @dimitarvp, but perhaps you could build on it with cross or an added Docker-based action?

I notice the build script therein has an option to minify binaries, which uses strip and upx. I don't think I want to trust anything messing with the compiler outputs (at least not without a really serious need), but just out of interest, does anyone know what the implications of these tools might be for Rust binaries?

I've used strip and upx just fine, zero issues. Also cargo will do strip for you if you configure it so so you don't even need to call it manually.

For local development I often use GitHub - casey/just: 🤖 Just a command runner with a few handy small recipes like e.g. invoke clippy or package up a final release binary (with upx compressing it at the end) when I want to do some performance testing. Pretty cool and easy stuff.

Not like the half-arsed "programming language" shoved in YAML that we have to learn in order to do basic activities in GitHub. sighs

1 Like

Yes from just an initial couple of hours with gh actions yesterday, I'm already in despair and will never complain about Rust build times again. The push-trigger-browse cycle is to edit-compile-run as the latter is to a decent REPL. I was hopeful when I came across GitHub - nektos/act: Run your GitHub Actions locally 🚀, but found the docker images to be missing too much compared to the live github runners to be useful for my purposes.

Are you caching your Rust builds?


Definitely will, now that I know that GitHub Actions is not much different than many other container-based CI/CD solutions.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.