Right now the libc crate links native libc with #[link(kind = "static")] for two targets - musl and wasi.
kind = "static" means that object files from native libc.a are bundled into liblibc.rlib and distributed with rustc toolchain in this form.
Then if user builds something with +crt-static then the bundled object files are used, and if user builds with -crt-static then they are "unbundled" and dynamic linking with libc.so available at user site happens.
Experience with windows-gnu targets (#67429) and porting rust to musl-native targets (#40113) showed that it's strongly preferable to use the native toolchain available at user site to using anything bundled with rustc toolchain, and that includes libc.a as well.
At the same time rustc historically provides more "self-contained" experience for selected targets (windows-gnu, musl, wasm), so we must continue shipping libc.a in some form in case the user doesn't have a native toolchain available.
That we means we need to fall back from using the native toolchain if it's available to using bundled libc.a (and other libraries) if it's not.
Such scheme is already used relatively successfully for windows-gnu, but not for musl and wasi.
So, the plan of the work should be roughly like this:
Once this is done #65760 should become fixed as well.
UPD: libunwind (https://github.com/rust-lang/rust/tree/master/src/libunwind) on musl also bundles libunwind.a, it should probably have the same treatment.
cc @hvenev @gnzlbg @alexcrichton @mati865 @smaeul
Right now the libc crate links native libc with
#[link(kind = "static")]for two targets - musl and wasi.kind = "static"means that object files from native libc.a are bundled into liblibc.rlib and distributed with rustc toolchain in this form.Then if user builds something with
+crt-staticthen the bundled object files are used, and if user builds with-crt-staticthen they are "unbundled" and dynamic linking with libc.so available at user site happens.Experience with windows-gnu targets (#67429) and porting rust to musl-native targets (#40113) showed that it's strongly preferable to use the native toolchain available at user site to using anything bundled with rustc toolchain, and that includes libc.a as well.
At the same time rustc historically provides more "self-contained" experience for selected targets (windows-gnu, musl, wasm), so we must continue shipping libc.a in some form in case the user doesn't have a native toolchain available.
That we means we need to fall back from using the native toolchain if it's available to using bundled libc.a (and other libraries) if it's not.
Such scheme is already used relatively successfully for windows-gnu, but not for musl and wasi.
So, the plan of the work should be roughly like this:
kind = "static-nobundle"instead ofkind = "static"in the libc crate (Don't bundle static libc. libc#1327).Once this is done #65760 should become fixed as well.
UPD: libunwind (https://github.com/rust-lang/rust/tree/master/src/libunwind) on musl also bundles
libunwind.a, it should probably have the same treatment.cc @hvenev @gnzlbg @alexcrichton @mati865 @smaeul