Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

petrochenkov
Copy link
Contributor

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.

@rustbot
Copy link
Collaborator

rustbot commented Mar 20, 2025

r? @wesleywiser

rustbot has assigned @wesleywiser.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 20, 2025

This PR modifies run-make tests.

cc @jieyouxu

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@rust-log-analyzer

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
Comment on lines +102 to +103
} 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`.
Copy link
Member

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.

Copy link
Contributor Author

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).

Copy link
Member

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?

@bors
Copy link
Contributor

bors commented Mar 26, 2025

☔ The latest upstream changes (presumably #138956) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants