]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commit
rust: enable fully static linking with TCLIBC=musl
authorSunil Dora <sunilkumar.dora@windriver.com>
Mon, 13 Apr 2026 07:04:57 +0000 (00:04 -0700)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 16 Apr 2026 10:09:38 +0000 (11:09 +0100)
commit75409c60e9e63fdcbb9d4f54130052991362ec08
tree8492cc1e52d866ff5fc99a101419ab5b0c73fcbf
parentefec0447c8e8a6003f00642b33a71ed94fc4ec82
rust: enable fully static linking with TCLIBC=musl

Fixes [YOCTO #16076]

Rust binaries built with TCLIBC=musl and
-C target-feature=+crt-static were still dynamically linked.
Fix this by addressing three issues:

1) Set crt-static-respected in the generated musl target spec
   so rustc honors +crt-static. [1]

2) Add the target sysroot library path to the linker flags so
   libunwind.a can be found.

3) Use LLVM libunwind for musl:
   - GNU libunwind does not provide static libraries in OE
     and lacks required _Unwind_* symbols on some architectures [2]
   - libgcc_eh depends on pthread and cannot be used for fully
     static linking with musl
   - LLVM libunwind provides the required symbols without
     additional dependencies
   Install LLVM libunwind from libcxx and switch libstd-rs
   to depend on libcxx for musl.

Also remove the obsolete DEPENDS:remove:riscv32/riscv64 = "libunwind"
lines added in 2021 when riscv musl support was still being patched.
LLVM libunwind supports both riscv32 and riscv64 - verified locally.
riscv32 support was upstreamed at [3].

Add a selftest to verify that produced binaries are statically linked.

[1] https://github.com/rust-lang/rust/blob/main/compiler/rustc_target/src/spec/mod.rs
[2] https://github.com/libunwind/libunwind/issues/761
[3] https://github.com/llvm/llvm-project/commit/b17d464

Reported-by: Nick Owens <nick.owens@eero.com>
Signed-off-by: Sunil Dora <sunilkumar.dora@windriver.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
meta-selftest/recipes-devtools/rust/rust-static-musl-test/Cargo.lock [new file with mode: 0644]
meta-selftest/recipes-devtools/rust/rust-static-musl-test/Cargo.toml [new file with mode: 0644]
meta-selftest/recipes-devtools/rust/rust-static-musl-test/src/main.rs [new file with mode: 0644]
meta-selftest/recipes-devtools/rust/rust-static-musl-test_0.1.bb [new file with mode: 0644]
meta/classes-recipe/rust-common.bbclass
meta/classes-recipe/rust-target-config.bbclass
meta/lib/oeqa/selftest/cases/rust.py
meta/recipes-devtools/clang/libcxx_git.bb
meta/recipes-devtools/rust/libstd-rs_1.94.1.bb