-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
linker: Move native library search from linker to rustc #138753
base: master
Are you sure you want to change the base?
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
This PR modifies cc @jieyouxu Some changes occurred in compiler/rustc_codegen_ssa |
This comment has been minimized.
This comment has been minimized.
For static libraries only, for now. Linker's search by name is still used if rustc's search fails, because linker may search in additional platform-specific directories in addition to directories known to rustc.
In practice this doesn't change anything for current built-in targets
} else if target != unix && sess.target.is_like_msvc { | ||
// On Windows MSVC naming scheme `libfoo.a` is used as a fallback from default `foo.lib`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is correct. To my knowledge, MSVC does not use .a
at all for static libs (unless we/the Rust ecosystem have started doing this somewhere). What probably does use .a
though would be *-windows-gnu
.
This code originated a long time ago, far before MSVC was supported: cb823b0. My hunch is that this probably needs to either be changed to target Windows generally or *-windows-gnu
more specifically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All built-in targets except windows-msvc already have the libname.a
naming scheme in their target specs, so this fallback doesn't apply to them (due to the target != unix
condition). So on windows-gnu in particular the fallback is also not necessary.
unless we/the Rust ecosystem have started doing this somewhere
Meson is using the libname.a
naming scheme on MSVC and CMake now also supports it due to Meson (#123436, https://mesonbuild.com/FAQ.html#why-does-building-my-project-with-msvc-output-static-libraries-called-libfooa, https://gitlab.kitware.com/cmake/cmake/-/issues/23975).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, can you mention that Meson and CMake do this in the comment?
☔ The latest upstream changes (presumably #138956) made this pull request unmergeable. Please resolve the merge conflicts. |
For static libraries only, for now.
Linker's search by name is still used if rustc's search fails, because linker may search in additional platform-specific directories in addition to directories known to rustc.
So we are basically doing something like #123436 for all targets.
This way we provide best effort support for
+verbatim
modifier even on targets with linkers not supporting it natively.If this is supported for dynamic libraries as well (which is nontrivial), this may also allow us to not pass
-L
options to the linker at all, although it may cause some breakage from libraries passed to linker directly, without rustc knowing about it.TODO: Some more tests for
+verbatim
and library naming fallback on Windows, if they are missing.