-
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
Inform the msvc linker about local and upstream native libraries #84264
Conversation
This gives downstream crates the ability to override upstream native libraries
r? @varkor (rust-highfive has picked a reviewer for you, use r? to override) |
Still didn't get to reviewing this in detail, but I'm generally skeptical about introducing more linker-specific behavior. We have more generic Rust mechanisms for doing things like you've mentioned. |
I'm having trouble finding the documentation for this. Can it be used to disable only a single library?
That is indeed an option. Though it is awkward to override dependencies. In any case, my goal here is not for Rust to introduce more linker specific behaviour. I simply think that Rust linking behaviour should be implemented in a similar way to MSVC C++ libraries when using the MSVC toolchain (if it makes sense to do so). So for this Rust code: #[link(name="library")]
extern {} The MSVC C++ equivalent is: #pragma comment(lib, "library") I think they should try to behave the same way, so long as it still fits Rust's semantics. This is especially useful in a mixed Rust/C++ code base. Especially so that standard tooling can be used. |
I think the short version is that I'm not trying to change or add features to Rust. I'm trying to get Rust to integrate better with MSVC tooling. |
(That said, we don't necessarily have to keep such analogy. Yes,
Adding
No, I think what we should do is to support an empty (Right now you can override a library into nothing with some dirty workaround like |
☔ The latest upstream changes (presumably #84982) made this pull request unmergeable. Please resolve the merge conflicts. |
Ok, I need to think about this some more. Here's a powershell session that I think highlights one of the issues I'm trying to resolve. It creates a library and a binary, both with native imports, then tries to override the native libraries when building the binary.
The other issue (which you've touched on) is that I can also remove any native library so long as Rust doesn't explicitly import it. For example, The advantage of using |
Hmm, I assumed this is a bug, but looks like the original RFC (https://github.com/rust-lang/rfcs/blob/master/text/1717-dllimport.md#library-name-and-kind-variance) tells that overrides indeed work only for the current crate. I'd like to try making |
Ok. I'll close this now as any outstanding issues can be revisited once more linking features have been implemented. |
This gives downstream crates the ability to override upstream native libraries.
In the MSVC linker there are two ways to specify a library:
/DEFAULTLIB:
The first way cannot be overridden, except by a library that appears earlier on the command line. There is no way to remove such a library. On the other hand, using
/DEFAULTLIB:
allows overriding or removing a library using/NODEFAULTLIB:
. Thus using/DEFAULTLIB:
for upstream native libraries grants more control over linking. This is especially useful for overriding standard library imports which isn't as easy to patch as third party crates. It is also consistent with the behaviour of Visual C++'s#pragma comment(lib, "libname")
. Such consistency is useful in mixed Rust/C++ code bases.This PR does effectively de-prioritise upstream libraries but crate local libraries were always favoured.