You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rustc should prefer statically linking native dependencies with unspecified kind if crt-static is enabled #71647
A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
The main goal of +crt-static (at least on non-Windows targets) is to produce self-contained statically linked executables.
With this goal in mind rustc switches linking of 1) Rust crates and 2) libc to static if possible. (The libc part is done in the libraries through lazy cfgs though.)
However, for native dependencies with unspecified kind rustc will still prefer the dynamic version of the library if both are available.
Unfortunately, doing this is not entirely trivial because -Bstatic -lmylib won't just prefer the static version (e.g. libmylib.a), it will require it.
So we need to check for the existence of libmylib.a first (in which directories exactly?) and then pass -l:libmylib.a instead of -lmylib if it exists.
@smaeul
I do not agree with what alexcrichton said #55566, it's mostly a "it mostly works, so don't touch it because you may break something" position motivated by lack of resources and people ready to take responsibilities for this work on the Rust side.
We can at least make an experiment (possibly using crater, possibly landing this on nightly and reverting) and verify what actually breaks in practice.
I fear crater will likely have a pretty poor coverage as far as linkage is concerned as its environment won't generally have anything but the most common libraries installed on the system (and the "native" libraries built in build.rs are already almost universally statically linked).
A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
petrochenkov commentedon Apr 28, 2020
If #39998 is accepted as the way to go by default when
crt-staticis enabled (on non-Windows platforms), then we can just use-Bstatic.smaeul commentedon May 2, 2020
This was discussed at length in #55566, where I was told that
NativeUnknownmeans dynamic, and changing the semantics of#[link]was unacceptable.petrochenkov commentedon May 10, 2020
Some history in links: #71586 (comment)
petrochenkov commentedon May 10, 2020
@smaeul
I do not agree with what alexcrichton said #55566, it's mostly a "it mostly works, so don't touch it because you may break something" position motivated by lack of resources and people ready to take responsibilities for this work on the Rust side.
We can at least make an experiment (possibly using crater, possibly landing this on nightly and reverting) and verify what actually breaks in practice.
nagisa commentedon Mar 8, 2021
I fear crater will likely have a pretty poor coverage as far as linkage is concerned as its environment won't generally have anything but the most common libraries installed on the system (and the "native" libraries built in
build.rsare already almost universally statically linked).polarathene commentedon Mar 2, 2024
Was this not resolved with #111698 ?