-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Distribute libc.a as a separate library instead of bundling it into liblibc.rlib on musl and wasi #72274
Comments
If only we could also eliminate |
FWIW It's hard for me personally at least to read comments like "Eliminate the unbundling logic from the compiler (with fire)." and "If only we could also eliminate kind = static with fire..." as semi-attacks on me personally since I originally implemented all of this. I really do feel that much ire about these features is directed personally at me since I've tried to review patches and provide feedback on other designs, and often times things don't work out. I did the best I could with the resources and knowledge I had at the time. I'm sorry if things didn't work out. The general idea here is "things just work". I don't think it really matters how they work, so long as they work. The "thing" here for targets like musl and wasi is "you don't need to install a native toolchain". I think anyone has much of a preference how things works so long as it works. I'm gonna unsubscribe from this issue because I don't think I have much to offer and I'm likely to just get stressed out staying on this. Feel free to cc me if there's a specific question (e.g. about wasi), however. |
@alexcrichton |
I'd also like to apologize for my comment. You've done a lot of fantastic work on Rust over the years, and I don't want any of my comments on specific features to feel like they're directed at you!
|
FWIW, I want to write an RFC for general syntax for linking modifiers for native libraries that would cover things like UPD: Done in rust-lang/rfcs#2951. |
That would also fix #58163 |
List of libraries that need to be shipped with Rust rather than bundled in rlibs:
Additionally:
|
Would this make it easier to decide at build time whether to statically or dynamically link libc, for targets that currently always dynamically link libc? |
@joshtriplett |
@petrochenkov I realize that. I'm more wondering, if we can defer linking against libc until the final link, could we potentially decide at the final link whether to link |
@joshtriplett glibc-based targets don't give it right now, but changing that is a matter of switching a flag in the target spec + adding a couple of |
@joshtriplett To clarify the functional impact of this issue: For the listed targets, in scenarios where we have already decided to link statically using The expectation is that the native toolchain's |
That'd be incredible. I'd be happy to submit the necessary changes, if you can outline what needs doing. I have a need for static glibc-based Rust binaries. |
Is there any follow-up on this issue? |
@mingweishih |
Use link modifiers -bundle on musl and wasi target Implement rust-lang/rust#72274 Fix: - rust-lang/wg-cargo-std-aware#66 - rust-lang/rust#89626 TODO: - [x] Implement rustbuild side change: rust-lang/rust#90527
Use link modifiers -bundle on musl and wasi target Implement rust-lang/rust#72274 Fix: - rust-lang/wg-cargo-std-aware#66 - rust-lang/rust#89626 TODO: - [x] Implement rustbuild side change: rust-lang/rust#90527
Use link modifiers -bundle on musl and wasi target Implement rust-lang/rust#72274 Fix: - rust-lang/wg-cargo-std-aware#66 - rust-lang/rust#89626 TODO: - [x] Implement rustbuild side change: rust-lang/rust#90527
The only thing required for implementing the first item now is bumping libc version used by this repo. |
libc has been updated in #90681. |
The last item ('Eliminate the "unbundling" logic from the compiler') was implemented in #105601, closing. |
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:
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
The text was updated successfully, but these errors were encountered: