-
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
Statically link against glibc #65447
Comments
The reddit thread mentions libm. And another source of speedups might be the malloc implementation (glibc 2.26 introduced thread-local caches). One can already use custom global allocators, maybe it would make sense to link a custom libm too? |
First blocker is the license. Glibc is licensed under LGPL, it has dynamic linking exception so one can freely link dynamically to it. Static linking doesn't fall under this exception. I'm not a lawyer but I think Rust would have to be licensed as (L)GPL to fit it. Another thing is glibc doesn't really support static linking, sure it works well for small software but bites you when you need more of it's features. |
(Obviously not a lawyer but), I'm pretty sure that as long as the code it is linked against is (L)GPLed, it should work. |
https://www.gnu.org/licenses/gpl-faq.html#LGPLStaticVsDynamic Also as long as the program it is linked against is licensed under a GPL compatible license, it is allowed. The MIT license, is compatible. All this information can be confirmed by looking at the above link. You can even link proprietary code against LGPL if you provide the object files. |
|
@haraldh The former should be doable. The latter is a tradeoff that people will need to understand if they statically link glibc, and it's something they already have to deal with if they use |
Implementation instructions:
|
See the comment above. |
@petrochenkov Thanks! |
I have this successfully working; just waiting on a release of the libc crate containing rust-lang/libc#1899 . |
…henkov Support static linking with glibc and target-feature=+crt-static With this change, it's possible to build on a linux-gnu target and pass RUSTFLAGS='-C target-feature=+crt-static' or the equivalent via a `.cargo/config.toml` file, and get a statically linked executable. Update to libc 0.2.78, which adds support for static linking with glibc. Add `crt_static_respected` to the `linux_base` target spec. Update `android_base` and `linux_musl_base` accordingly. Avoid enabling crt_static_respected on Android platforms, since that hasn't been tested. Closes rust-lang#65447.
Reasons for:
FROM scratch
. example using muslIt is possible to link glibc statically as demonstrated here.
From what I can tell, on the user facing side, this would be enable using
-C target-feature=+crt-static
as described in the reference.The text was updated successfully, but these errors were encountered: