EDIT: added first fix provided by @jakub
Cargo.toml
[package]
name = "rust_test"
version = "0.1.0"
edition = '2021'
[dependencies]
ring = "0.16.20"
Dockerfile
FROM rust:latest
RUN rustup target add x86_64-unknown-linux-musl
RUN apt -y update
RUN apt install -y musl-tools musl-dev
ADD . ./
ENV RUSTFLAGS='-C linker=musl-gcc'
ENV CC_x86_64-unknown-linux-musl=musl-gcc
RUN cargo build --target x86_64-unknown-linux-musl --manifest-path ring_test/Cargo.toml
Failure
#11 33.09 error: failed to run custom build command for `ring v0.16.20`
#11 33.09 --- stderr
#10 32.89 running "musl-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-I" "include" "-Wall" "-Wextra" "-pedantic" "-pedantic-errors" "-Wall" "-Wextra" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-fno-strict-aliasing" "-fvisibility=hidden" "-fstack-protector" "-g3" "-U_FORTIFY_SOURCE" "-DNDEBUG" "-c" "-o/target/x86_64-unknown-linux-musl/debug/build/ring-aa1b6608fcc0aa5d/out/aesni-x86_64-elf.o" "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/pregenerated/aesni-x86_64-elf.S"
#10 32.89 cc1: error: unrecognized command-line option '-m64'
#10 32.89 thread 'main' panicked at 'execution failed', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/ring-0.16.20/build.rs:656:9
#10 32.89 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Just in case it matters, Docker is running on an M1 Max.
Note: This also fails when cross-compiling directly from the Mac host and skipping Docker entirely via: cargo build --target x86_64-unknown-linux-musl
Solution proposed here doesn't work: Apple M1 to Linux x86_64: unrecognized command-line option '-m64'