Adding these 2 environments worked for me:
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc
export CC=aarch64-linux-gnu-gcc
Answer from lu ji on Stack OverflowAdding these 2 environments worked for me:
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc
export CC=aarch64-linux-gnu-gcc
I think you want the aarch64-unknown-linux-musl target; I don't think aarch64-linux-musl-gcc is even a thing.
Try installing the target for your current toolchain:
rustup target add aarch64-unknown-linux-musl
and then building for that source:
cargo build --release --target aarch64-unknown-linux-musl
Also, if you're building for this target from Windows, it's almost undoubtedly easier to do it from WSL2.
Further NB: While I have never built for aarch64, I have tried to build openssl for an x86_64-unknown-linux-musl Alpine target, and I've never gotten it to work. I have no idea what your application is, but if you have trouble building openssl even with the correct target, you might see if you can use rustls instead.
windows subsystem for linux - How to get aarch64 version of musl on Debian for qemu user mode - Unix & Linux Stack Exchange
Can't compile ring with target aarch64-unknown-linux-musl
Cross compilation, Linux, x86_64 host, aarch64 target
Crosscompile aarch64-unknown-linux-GNU to aarch64-unknown-linux-MUSL?
I did read that for cross-compiling from Windows to Linux, you need to supply the rust-lld linker in the Cargo config; but (un?)fortunately my situation does not seem to be that simple.
On Ubuntu, I installed musl and musl-dev. This means that I have aarch64-linux-musl-gcc in my $PATH and should have the required libraries. However, when I try to cargo build --target aarch64-unknown-linux-musl, I see this:
error: failed to run custom build command for `rquickjs-sys v0.6.2`
Caused by:
process didn't exit successfully: `/opt/surrealdb/target/debug/build/rquickjs-sys-f5cc455b87df8099/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-changed=build.rs
cargo:rerun-if-env-changed=CARGO_FEATURE_BINDGEN
cargo:rerun-if-env-changed=CARGO_FEATURE_UPDATE_BINDINGS
cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_BYTECODE
cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_GC
cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_GC_FREE
cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_FREE
cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_LEAKS
cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_MEM
cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_OBJECTS
cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_ATOMS
cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_SHAPES
cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_MODULE_RESOLVE
cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_PROMISE
cargo:rerun-if-env-changed=CARGO_FEATURE_DUMP_READ_OBJECT
Applying patch patches/error_column_number.patch
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/Makefile b/Makefile
|index 0270a6a..1c78547 100644
|--- a/Makefile
|+++ b/Makefile
--------------------------
No file to patch. Skipping patch.
1 out of 1 hunk ignored
patching file cutils.c
patching file cutils.h
patching file quickjs-atom.h
patching file quickjs-opcode.h
patching file quickjs.c
patching file quickjs.h
patching file tests/test_line_column.js
Applying patch patches/get_function_proto.patch
patching file quickjs.c
Hunk #1 succeeded at 2222 (offset 7 lines).
patching file quickjs.h
Applying patch patches/check_stack_overflow.patch
patching file quickjs.c
Hunk #1 succeeded at 1622 (offset 32 lines).
Applying patch patches/infinity_handling.patch
patching file quickjs.c
Hunk #1 succeeded at 10391 (offset 105 lines).
Hunk #2 succeeded at 43407 (offset 317 lines).
Hunk #3 succeeded at 49735 (offset 317 lines).
Bindings for target: aarch64-unknown-linux-gnu
--- stderr
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir:
Found candidate GCC installation: /../lib/gcc/aarch64-linux-gnu/11
Found candidate GCC installation: /../lib/gcc/aarch64-linux-gnu/13
Selected GCC installation: /../lib/gcc/aarch64-linux-gnu/13
Candidate multilib: .;@m64
Selected multilib: .;@m64
ignoring nonexistent directory "/usr/include/clang/18.1.3/include/"
ignoring nonexistent directory "/../lib/gcc/aarch64-linux-gnu/13/../../../../aarch64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/include/aarch64-linux-gnu
/usr/include
End of search list.
/usr/include/stdio.h:34:10: fatal error: 'stddef.h' file not found
thread 'main' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rquickjs-sys-0.6.2/build.rs:351:39:
Unable to generate bindings: ClangDiagnostic("/usr/include/stdio.h:34:10: fatal error: 'stddef.h' file not found\n")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...A few things stand out to me:
It's using Clang instead of the totally available GCC. Do I need to manually specify
cc?stddef.his most definitively included in musl. But, just to make sure, I went to verify:
# dpkg -L musl-dev | grep -i stddef /usr/include/aarch64-linux-musl/stddef.h
Sure enough. Technically, everything should be present. I made sure the target is also installed:
# rustup target list --installed aarch64-unknown-linux-gnu aarch64-unknown-linux-musl
So... what exactly am I missing here?
Thanks and kind regards!