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

Tracking Issue for -Z link-native-libraries #134948

Open
2 of 4 tasks
jieyouxu opened this issue Dec 31, 2024 · 1 comment
Open
2 of 4 tasks

Tracking Issue for -Z link-native-libraries #134948

jieyouxu opened this issue Dec 31, 2024 · 1 comment
Labels
A-CLI Area: Command-line interface (CLI) to the compiler A-linkage Area: linking into static, shared libraries and binaries C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jieyouxu
Copy link
Member

jieyouxu commented Dec 31, 2024

This is a tracking issue for the unstable rustc flag -Z link-native-libraries.

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.

Steps

Unresolved Questions

  • What does this unstable rustc flag -Z link-native-libraries do, exactly?
  • How does it relate to the stable #[link] attribute?
  • What does this mean for the #[link] attribute (which is a stable attribute)?
  • How does this unstable flag relate to -Z link-directives?

    Seems fine to me. Perhaps we should proactively remove the other Zlink-native-libraries flag as a "failed experiment"?

    I think we still need -Zlink-native-libraries to deal with prebuilt rlibs - ie, the sysroot libraries.
    Implement -Zlink-directives=yes/no #107675 (comment)

Implementation history

Related links

@jieyouxu jieyouxu added A-CLI Area: Command-line interface (CLI) to the compiler A-linkage Area: linking into static, shared libraries and binaries C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 31, 2024
@ChrisDenton
Copy link
Member

So link-native-libraries=no is interesting. It appears to entirely disable passing native libraries to the linker. And unlike other flags, it has a global effect. So if we have #[link(name = "something")] in the precompiled std then usually there's no way to stop something being passed to the linker. However, with this flag it is possible (at the cost of having to manually add back everything else). The effect is useful for build systems that want complete control of linking.

Personally, if we ever stabilize something like this, I'd want it to be a bit more fine grained. So you could remove or replace individual native libraries as well as removing everything. You can kinda do a rename today with -l oldname:newname. But that effect is local to the crate and only allows renaming and not removing.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 31, 2024
Windows: Enable issue 70093 link tests

Tracking issue for `-Z link-native-libraries`: rust-lang#134948
Tracking issue for `-Z link-directives`: rust-lang#134947

`-Zlink-native-libraries=no` and `-Zlink-directives=no` *should* work on Windows, at least for msvc. The fly in ointment is that `default-linker-libraries` doesn't. On unixy platforms rustc calls another compiler which in turn calls the linker along with the default libraries. On MSVC rustc calls the linker directly therefore it would need to be the one to implement `default-linker-libraries`. Except it doesn't so we workaround that in the test by using `-C link-arg` to talk to the linker.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 31, 2024
Rollup merge of rust-lang#134918 - ChrisDenton:issue-70093, r=jieyouxu

Windows: Enable issue 70093 link tests

Tracking issue for `-Z link-native-libraries`: rust-lang#134948
Tracking issue for `-Z link-directives`: rust-lang#134947

`-Zlink-native-libraries=no` and `-Zlink-directives=no` *should* work on Windows, at least for msvc. The fly in ointment is that `default-linker-libraries` doesn't. On unixy platforms rustc calls another compiler which in turn calls the linker along with the default libraries. On MSVC rustc calls the linker directly therefore it would need to be the one to implement `default-linker-libraries`. Except it doesn't so we workaround that in the test by using `-C link-arg` to talk to the linker.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CLI Area: Command-line interface (CLI) to the compiler A-linkage Area: linking into static, shared libraries and binaries C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants