linker: Move native library search from linker to rustc#138753
linker: Move native library search from linker to rustc#138753petrochenkov wants to merge 3 commits intorust-lang:mainfrom
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.
| } 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.
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.
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.
Ok, can you mention that Meson and CMake do this in the comment?
There was a problem hiding this comment.
FYI: There is a relevant issue about Windows static lib naming here: #114013 (could be outdated, I don't know if things changed in rustc since).
|
☔ 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.
In practice this doesn't change anything for current built-in targets
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
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
+verbatimmodifier even on targets with linkers not supporting it natively.This closes #132264 in particular.
If this is supported for dynamic libraries as well (which is nontrivial), this may also allow us to not pass
-Loptions 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
+verbatimand library naming fallback on Windows, if they are missing.