Closed vi closed 3 years ago
Workaround by building staticlib for x86_64-unknown-linux-gnu
with #[no_mangle] pub fn main
, then linking with musl-gcc -static
seems to work and produce slightly a larger, yet comparable-sized helloworld.
$ grep crate-type Cargo.toml
crate-type = ["staticlib"]
$ cat src/lib.rs
#[no_mangle]
pub fn main() -> i32 {
println!("Hello, world!");
0
}
$ cargo build --release -Zbuild-std=panic_abort,std -Zbuild-std-features=panic_immediate_abort --target=x86_64-unknown-linux-gnu
Finished release [optimized] target(s) in 0.04s
$ musl-gcc -static target/x86_64-unknown-linux-gnu/release/libkoo.a -o koo_static
$ strip koo_static
$ file koo_static
koo_static: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
$ ls -lh koo_static
-rwxrwxr-x 1 vi vi 38K Sep 18 01:13 koo_static
$ ./koo_static
Hello, world!
So in theory it should be possible to build std for musl with std-aware-cargo.
@alexcrichton Should the rust-src
component include a copy of the libunwind source from llvm?
Ah yeah since some targets use it we should probably include it. I think it should be safe to include as it's pretty small and I believe it's self-contained.
Posted a fix at https://github.com/rust-lang/rust/pull/77086.
I forgot to close this. Feel free to reopen or open a new issue if it hasn't been resolved.
Usual target works:
But musl don't:
Why
unwind
? I specified that panic aborts. Can all the stack trickery be completely opted out?