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 extra-link-arg #9426

Closed
ehuss opened this issue Apr 28, 2021 · 1 comment
Closed

Tracking Issue for extra-link-arg #9426

ehuss opened this issue Apr 28, 2021 · 1 comment
Labels
A-build-scripts Area: build.rs scripts A-linkage Area: linker issues, dylib, cdylib, shared libraries, so C-tracking-issue Category: A tracking issue for something unstable.

Comments

@ehuss
Copy link
Contributor

ehuss commented Apr 28, 2021

Summary

Implementation: #7811 #8441
Documentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#extra-link-arg

The -Z extra-link-arg flag allows build scripts to issue additional cargo commands to pass custom flags to the linker:

*cargo:rustc-link-arg-bins=FLAG – Passes custom flags to a linker for binaries.
*cargo:rustc-link-arg=FLAG – Passes custom flags to a linker for benchmarks, binaries, cdylib crates, examples, and tests.

Unresolved issues

None at this time.

Future extensions

  • Additional options could be added in the future to pass flags for other targets. These flags should probably mirror cargo's CLI flags, though some cases are a little unclear. For example:
    cargo:rustc-link-arg-bin-NAME=…      # equivalent to --bin=NAME
    cargo:rustc-link-arg-example-NAME=…  # equivalent to --example=NAME
    cargo:rustc-link-arg-bins=…          # equivalent to --bins (NOW IMPLEMENTED)
    cargo:rustc-link-arg-examples=…      # equivalent to --examples
    cargo:rustc-link-arg-test-NAME=…     # equivalent to --test=NAME
    cargo:rustc-link-arg-tests=…         # equivalent to --tests (including unittests)
    cargo:rustc-link-arg-unittests=…     # ??? (not sure what this means)
    cargo:rustc-link-arg-test-LIBNAME=…  # for unittest of lib only?
    cargo:rustc-link-arg-cdylib=…        # for cdylib (ON STABLE AS rustc-cdylib-link-arg)
    cargo:rustc-link-arg-bench-NAME=…    # equivalent to --bench=NAME
    cargo:rustc-link-arg-benches=…       # equivalent to --benches
    cargo:rustc-link-arg=…               # anything linkable? bins,examples,tests,benches,cdylib? (NOW IMPLEMENTED)
    

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.

cc @reitermarkus

@ehuss ehuss added A-linkage Area: linker issues, dylib, cdylib, shared libraries, so A-build-scripts Area: build.rs scripts C-tracking-issue Category: A tracking issue for something unstable. labels Apr 28, 2021
bors added a commit that referenced this issue May 24, 2021
Add `cargo:rustc-link-arg-bin` flag.

This PR implements a `cargo:rustc-link-arg-bin` command to specify per-binary link args from build scripts. This follows the suggestion from the tracking issue #9426.

Syntax is `cargo:rustc-link-arg-bin=BIN_NAME=ARG`

This was previously possible to do using the `#[link_args=".."]` attribute, but it was removed in rust-lang/rust#83820 in favor of the Cargo extra-link-args feature, which can currently not specify different link args for different bins in the same crate. This PR adds back the ability to do that.
bors added a commit that referenced this issue Jun 1, 2021
Add some validation to rustc-link-arg

This adds some validation, so that if a `cargo:rustc-link-arg-*` build script instruction specifies a target that doesn't exist, it will generate an error.  This also changes a parse warning to an error if the `=` is missing from BIN=ARG.

I intentionally did not bother to add the validation to config overrides, as it is a bit trickier to do, and that feature is very rarely used (AFAIK), and I'm uncertain if rustc-link-arg is really useful in that context.

cc #9426
bors added a commit that referenced this issue Jul 26, 2021
Stabilize the rustc-link-arg option

This change removes the unstable option (tracked by #9426) and unconditionally accepts additional linker arguments (as implemented in #7811 and #8441). Documentation is moved from unstable to what appeared to be the correct location.

I am not aware of any significant concerns with the option and it appears consistent with some other existing stable linker options.

Please let me know if this is not the appropriate process or if there is anything that I am missing from the PR.
@ehuss
Copy link
Contributor Author

ehuss commented Aug 3, 2021

Closing as this has now been stabilized via #9557.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-scripts Area: build.rs scripts A-linkage Area: linker issues, dylib, cdylib, shared libraries, so C-tracking-issue Category: A tracking issue for something unstable.
Projects
None yet
Development

No branches or pull requests

1 participant