Github Actions cannot compile arm64 rust container

I am attempting to containerize an application, I can compile it on amd64, as well as on an M1 macbook without issue. But when Github Actions builds the container, the arm64 architecture fails to compile one package.

14 automatic builds · r-Techsupport/rts-cms@a00e4f0 (github.com)

: could not compile `syn` (lib)
106.8 
106.8 Caused by:
106.8   process didn't exit successfully: `rustc --crate-name syn --edition=2021 /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/syn-2.0.65/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="clone-impls"' --cfg 'feature="default"' --cfg 'feature="derive"' --cfg 'feature="extra-traits"' --cfg 'feature="full"' --cfg 'feature="parsing"' --cfg 'feature="printing"' --cfg 'feature="proc-macro"' --cfg 'feature="visit-mut"' -C metadata=0ec71765fdbc0b72 -C extra-filename=-0ec71765fdbc0b72 --out-dir /app/backend/target/release/deps -C strip=debuginfo -L dependency=/app/backend/target/release/deps --extern proc_macro2=/app/backend/target/release/deps/libproc_macro2-3e7ab99e5dd418a5.rmeta --extern quote=/app/backend/target/release/deps/libquote-e30613fd547d174f.rmeta --extern unicode_ident=/app/backend/target/release/deps/libunicode_ident-94891640d59accc2.rmeta --cap-lints allow` (signal: 11, SIGSEGV: invalid memory reference)
106.8 warning: build failed, waiting for other jobs to finish...

Does anyone understand why this may be occuring?

1 Like

In my experience, that is on-par for QEMU. I try to avoid that thing to the greatest extent possible. In your case, I believe that means not using buildx.

And, thank you for including details like the link to the build log.

As far as I can tell qemu and buildx are the only way to do this in Github Actions. It would suck if this is a fatal limitation of GHA

To do what? Build a Dockerized version of your application for the ARM64 processor?

Indeed, to build multi-arch containers you need qemu and buildx

Multi-platform image with GitHub Actions | Docker Docs

No, you don't. The alternative is to build native images with a manifest. It's more work but the result is much better.

Unfortunately, I can't provide an example. When I did that sort of thing, the working stuff was not publicly available. I do remember it was not especially difficult; just more work. The goal was Linux (Alpine) for AMD and ARM processors. I think it was just one Docker file with the target processor specified at build. The Docker manifest is just a simple text file that identifies which images are available.

I should have mentioned ... Each native image was built on that platform. The AMD version was built on an AMD machine. The ARM version was built on an ARM machine. That eliminates the headache of trying to cross-compile.

Yeah, that would be another issue. If I could run natively in GHA I would but their platforms are all amd64 from what I have seen

They just released ARM runners 4 days ago lol, but they are not publicly avail yet

Arm64 on GitHub Actions: Powering faster, more efficient build systems - The GitHub Blog

1 Like

I don't know about containers (that doesn't seem like like a rust specific problem), but you can cross compile with Rust without using qemu. This is in fact how GitHub - cross-rs/cross: “Zero setup” cross compilation and “cross testing” of Rust crates works.

So perhaps you could cross compile the binary, then put it in a docker image afterwards if you really need that part. It is likely going to be much faster too, avoiding the emulation overhead.

Also I belive there are other build services you can use together with github if you prefer to build native ARM?

EDIT: There is also GitHub - rust-cross/cargo-zigbuild: Compile Cargo project with zig as linker (I haven't tried it myself)

1 Like

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.