Hi there!
I'd like to create a cross platform CLI tool / daemon that I would like to also be able to have running on OpenWRT routers.
I've managed to compile a hello world (with only the std println macro) using cross-rs + podman, but sadly that binary doesn't run on my target device, instead printing:
-ash: /path/file: not found
Reading linux - ELF file exists in /usr/bin but turns out "-ash: file: not found" - Stack Overflow made me believe the reason is incompatible libc versions between build and runtime environments.
My runtime has this libc version:
$ opkg list-installed | grep libc
libc - 1.2.3-4
That package contains only one file with two symbolic links pointing onto itself:
$ opkg files libc
Package libc (1.2.3-4) is installed on root and has the following files:
/lib/libc.so
/lib/ld-musl-powerpc-sf.so.1
/usr/bin/ldd
How can I get a compatible build environment? Is that "musl" in there a hint that I should use a target architecture with "musl" suffix?
My next try:
cargo +nightly build -Z build-std=std --release --target powerpc-unknown-linux-musl
failed with:
error[E0463]: can't find crate for panic_abort
next try:
cargo +nightly build -Z build-std=std,panic_abort --release --target powerpc-unknown-linux-musl
failure:
error: linking with `cc` failed: exit status: 1
|
= note: LC_ALL="C" PATH="/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/self-contained:/home/user/.rustup/toolchains/esp/riscv32-esp-elf/esp-12.2.0_20230208/riscv32-esp-elf/bin:/home/user/.rustup/toolchains/esp/xtensa-esp32s2-elf/esp-12.2.0_20230208/xtensa-esp32s2-elf/bin:/home/user/.rustup/toolchains/esp/xtensa-esp32s3-elf/esp-12.2.0_20230208/xtensa-esp32s3-elf/bin:/home/user/.rustup/toolchains/esp/xtensa-esp32-elf/esp-12.2.0_20230208/xtensa-esp32-elf/bin:/home/user/bin:/home/user/.cargo/bin:/opt/flutter/bin:/opt/android-sdk/tools/bin:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-sdk/cmdline-tools/latest/bin:/opt/flutter/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/lib/rustup/bin" VSLANG="1033" "cc" "-m32" "crt1.o" "crti.o" "crtbegin.o" "/tmp/rustcdu8X2U/symbols.o" "/home/user/Development/git/project/target/powerpc-unknown-linux-musl/release/deps/rust_p2p_chat-361aa1a14a2e669f.rust_p2p_chat.2fc1f9e84b3f03e1-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/home/user/Development/git/project/target/powerpc-unknown-linux-musl/release/deps" "-L" "/home/user/Development/git/project/target/release/deps" "-L" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/powerpc-unknown-linux-musl/lib" "-Wl,-Bstatic" "-lunwind" "-lc" "/home/user/Development/git/project/target/powerpc-unknown-linux-musl/release/deps/libcompiler_builtins-af938bdf6febe714.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-nostartfiles" "-L" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/powerpc-unknown-linux-musl/lib" "-L" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/powerpc-unknown-linux-musl/lib/self-contained" "-o" "/home/user/Development/git/project/target/powerpc-unknown-linux-musl/release/deps/rust_p2p_chat-361aa1a14a2e669f" "-Wl,--gc-sections" "-static" "-no-pie" "-Wl,-z,relro,-z,now" "-Wl,--strip-all" "-nodefaultlibs" "crtend.o" "crtn.o"
= note: /usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: cannot find crtbegin.o: No such file or directory
/usr/bin/ld: /home/user/Development/git/project/target/powerpc-unknown-linux-musl/release/deps/rust_p2p_chat-361aa1a14a2e669f.rust_p2p_chat.2fc1f9e84b3f03e1-cgu.0.rcgu.o: relocations in generic ELF (EM: 20)
I've installed the package musl
on my system (=a x86_64 Manjaro linux box) which did contain the files /usr/lib/musl/lib/crt1.o
& /usr/lib/musl/lib/crti.o
(unsure where crtbegin.o
should come from) but that didn't change the latest error messages. Unsure if that's because /usr/lib/musl/lib/
is not on the library search path or if powerpc specific versions of those files need to be available somewhere..
I found a quite good explanation of the options for compiling for older libc versions here:
rust, glibc, rust-cargo
Since my final goal is to get this build done using Gitlab CI (and since I dislike static linking because I need to optimize for size) the 3rd option with a docker image would be the one I prefer.
So now I need to find or learn how to create a docker image that enables building rust with libc version 1.2.3