You can't add rust targets via apt, and you shouldn't try to get rust from there either. Assuming you're cross-compiling, then rustup target add armv7-unknown-linux-musleabihf should do the trick. If you get linker errors then add
That only works for bare metal targets and for windows. Linux requires gcc or clang as wrapper to tell the linker where libc can be found and several other flags that are necessary. Instead you have to use armv7-linux-musleabihf-gcc or however the gcc executable for this target is called as linker.
Another option would be to use clang, which is a lot easier when cross-compiling, especially for more niche targets. If you go that route, set the linker to "ld.lld" and then build CC=clang cargo build --target arm7-unknown-linux-musleabihf.
Do you have any suggestion as when I am using cargo -v build --release --target armv7-unknown-linux-gnueabihf to build I am getting the following error
Running `rustc --crate-name http_body --edition=2018 /home/abc/.cargo/registry/src/github.com-1ecc6299db9ec823/http-body-0.3.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=b1e3ccb6a23e7840 -C extra-filename=-b1e3ccb6a23e7840 --out-dir /home/abbc/a/target/armv7-unknown-linux-gnueabihf/release/deps --target armv7-unknown-linux-gnueabihf -C linker=arm-linux-gnueabihf-gcc -L dependency=/home/akumar/targetarm/target/armv7-unknown-linux-gnueabihf/release/deps -L dependency=/home/akumar/targetarm/target/release/deps --extern bytes=/home/akumar/targetarm/target/armv7-unknown-linux-gnueabihf/release/deps/libbytes-5318421955a4f8ab.rmeta --extern http=/home/akumar/targetarm/target/armv7-unknown-linux-gnueabihf/release/deps/libhttp-bfe6be4f855d175c.rmeta --cap-lints allow`
error: failed to run custom build command for `libudev-sys v0.1.4`
Caused by:
process didn't exit successfully: `/home/abc/a/target/release/build/libudev-sys-0463db1d4d4cbd4d/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=LIBUDEV_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_armv7-unknown-linux-gnueabihf
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_armv7_unknown_linux_gnueabihf
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONFIG_armv7-unknown-linux-gnueabihf
cargo:rerun-if-env-changed=PKG_CONFIG_armv7_unknown_linux_gnueabihf
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_armv7-unknown-linux-gnueabihf
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_armv7_unknown_linux_gnueabihf
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
--- stderr
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "pkg-config has not been configured to support cross-compilation.\n\nInstall a sysroot for the target platform and configure it via\nPKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a\ncross-compiling wrapper for pkg-config and set it via\nPKG_CONFIG environment variable."', /home/akumar/.cargo/registry/src/github.com-1ecc6299db9ec823/libudev-sys-0.1.4/build.rs:38:41
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
Hi, thank you for your help, can you please suggest which distro support musleabihf, I will try to use that also in addition to using clang as a safe option.
Hi! Thank you for your response. If that is possible how can I install target.armv7-unknown-linux-musleabihf ? Please visit How to install armv7-unknown-linux-musleabihf - #10 by bjorn3 they have suggested that Ubuntu 20.04 does not support it.
If you're doing it for rust, just use rustup target add armv7-unknown-linux-musleabihf. For clang, it should be installed out of the box. For GCC, you'd probably have to build it yourself.
Anyway, I just opened up a Linux VM, and to get a hello world to build for armv7-unknown-linux-musleabihf with clang and rust installed, I had to do three things:
Invoke cargo via CC=clang cargo build --target=armv7-unknown-linux-musleabihf
That should be enough to get most crates built. Crates that depend on C or more platform specific apis might require more effort to get to build, but in that case, it should say in their documentation.