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

Implement -Zlink-native-libraries #70095

Merged
merged 1 commit into from
Mar 28, 2020
Merged

Implement -Zlink-native-libraries #70095

merged 1 commit into from
Mar 28, 2020

Conversation

jsgf
Copy link
Contributor

@jsgf jsgf commented Mar 18, 2020

This implements a flag -Zlink-native-libraries=yes/no. If set to true/yes, or unspecified, then
native libraries referenced via #[link] attributes will be put on the linker line (ie, unchanged
behaviour).

If -Zlink-native-libraries=no is specified then rustc will not add the native libraries to the link
line. The assumption is that the outer build system driving the build already knows about the native
libraries and will specify them to the linker directly (for example via -Clink-arg=).

Addresses issue #70093

@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 18, 2020
@jsgf
Copy link
Contributor Author

jsgf commented Mar 18, 2020

cc @cramertj

@eddyb
Copy link
Member

eddyb commented Mar 18, 2020

r? @alexcrichton

@rust-highfive rust-highfive assigned alexcrichton and unassigned eddyb Mar 18, 2020
@Centril
Copy link
Contributor

Centril commented Mar 18, 2020

cc @nagisa

@alexcrichton
Copy link
Member

Sorry I don't have the time nowadays to review PRs like this, would it be possible to find someone else to take over review?

@Centril
Copy link
Contributor

Centril commented Mar 18, 2020

r? @nagisa

@rust-highfive rust-highfive assigned nagisa and unassigned alexcrichton Mar 18, 2020
@nagisa
Copy link
Member

nagisa commented Mar 18, 2020

I have my qualms about the naming of the flag, but since its a -Z I’m fine with it landing as is.

@bors r+

@bors
Copy link
Contributor

bors commented Mar 18, 2020

📌 Commit bb55741 has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 18, 2020
@jsgf
Copy link
Contributor Author

jsgf commented Mar 18, 2020

@nagisa Very happy to consider other names. Did you have any thoughts/suggestions? What don't you like about this name?

@cramertj
Copy link
Member

cc @tmandry @petrhosek

Centril added a commit to Centril/rust that referenced this pull request Mar 19, 2020
Implement -Zlink-native-libraries

This implements a flag `-Zlink-native-libraries=yes/no`. If set to true/yes, or unspecified, then
native libraries referenced via `#[link]` attributes will be put on the linker line (ie, unchanged
behaviour).

If `-Zlink-native-libraries=no` is specified then rustc will not add the native libraries to the link
line. The assumption is that the outer build system driving the build already knows about the native
libraries and will specify them to the linker directly (for example via `-Clink-arg=`).

Addresses issue rust-lang#70093
bors added a commit that referenced this pull request Mar 19, 2020
Rollup of 9 pull requests

Successful merges:

 - #69036 (rustc: don't resolve Instances which would produce malformed shims.)
 - #69443 (tidy: Better license checks.)
 - #69814 (Smaller and more correct generator codegen)
 - #69929 (Regenerate tables for Unicode 13.0.0)
 - #69959 (std: Don't abort process when printing panics in tests)
 - #69969 (unix: Set a guard page at the end of signal stacks)
 - #70005 ([rustdoc] Improve visibility for code blocks warnings)
 - #70088 (Use copy bound in atomic operations to generate simpler MIR)
 - #70095 (Implement -Zlink-native-libraries)

Failed merges:

r? @ghost
@Centril
Copy link
Contributor

Centril commented Mar 19, 2020

Failed in #70130 (comment), @bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 19, 2020
@jsgf
Copy link
Contributor Author

jsgf commented Mar 19, 2020

@Centril I think this is going to be hard to do a true cross-platform test. I'll limit it to Unix-like for now.

@Centril
Copy link
Contributor

Centril commented Mar 19, 2020

(I just paste a standard message whenever I find a PR breaks my rollup...)

You'll want to make this test unix-only then; but I don't recall what the flag is atm.

This implements a flag `-Zlink-native-libraries=yes/no`. If set to true/yes, or unspecified, then
native libraries referenced via `#[link]` attributes will be put on the linker line (ie, unchanged
behaviour).

If `-Zlink-native-libraries=no` is specified then rustc will not add the native libraries to the link
line. The assumption is that the outer build system driving the build already knows about the native
libraries and will specify them to the linker directly (for example via `-Clink-arg=`).

Addresses issue rust-lang#70093
@jsgf
Copy link
Contributor Author

jsgf commented Mar 27, 2020

Updated to add ignore-windows in test.

@tmandry
Copy link
Member

tmandry commented Mar 28, 2020

@bors r=nagisa

@bors
Copy link
Contributor

bors commented Mar 28, 2020

📌 Commit 53c4e0c has been approved by nagisa

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 28, 2020
@petrochenkov
Copy link
Contributor

petrochenkov commented Mar 28, 2020

Hmm, this should help linking to libc statically on platforms where rustc and libc crate disrespect +crt-static (most of them, cc rust-lang/libc#1711). Nice.

@bors
Copy link
Contributor

bors commented Mar 28, 2020

⌛ Testing commit 53c4e0c with merge b76238a...

@bors
Copy link
Contributor

bors commented Mar 28, 2020

☀️ Test successful - checks-azure
Approved by: nagisa
Pushing b76238a to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 28, 2020
@bors bors merged commit b76238a into rust-lang:master Mar 28, 2020
jsgf added a commit to jsgf/rust that referenced this pull request Feb 22, 2023
`-Zlink-directives=no` will ignored `#[link]` directives while compiling a
crate, so nothing is emitted into the crate's metadata.  The assumption is
that the build system already knows about the crate's native dependencies
and can provide them at link time without these directives.

This is another way to address issue # rust-lang#70093, which is currently addressed
by `-Zlink-native-libraries` (implemented in rust-lang#70095). The latter is
implemented at link time, which has the effect of ignoring `#[link]`
in *every* crate. This makes it a very large hammer as it requires all
native dependencies to be known to the build system to be at all usable,
including those in sysroot libraries. I think this means its effectively
unused, and definitely under-used.

Being able to control this on a crate-by-crate basis should make it much
easier to apply when needed.

I'm not sure if we need both mechanisms, but we can decide that later.
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Feb 25, 2023
Implement -Zlink-directives=yes/no

`-Zlink-directives=no` will ignored `#[link]` directives while compiling a crate, so nothing is emitted into the crate's metadata.  The assumption is that the build system already knows about the crate's native dependencies and can provide them at link time without these directives.

This is another way to address issue # rust-lang#70093, which is currently addressed by `-Zlink-native-libraries` (implemented in rust-lang#70095). The latter is implemented at link time, which has the effect of ignoring `#[link]` in *every* crate. This makes it a very large hammer as it requires all native dependencies to be known to the build system to be at all usable, including those in sysroot libraries. I think this means its effectively unused, and definitely under-used.

Being able to control this on a crate-by-crate basis should make it much easier to apply when needed.

I'm not sure if we need both mechanisms, but we can decide that later.

cc `@pcwalton` `@cramertj`
tmandry added a commit to tmandry/rust that referenced this pull request Sep 28, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 28, 2023
Document -Zlink-native-libraries

Originally added in rust-lang#70095.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 28, 2023
Rollup merge of rust-lang#116213 - tmandry:doclnl, r=ehuss

Document -Zlink-native-libraries

Originally added in rust-lang#70095.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants