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

rustc: implement -C link-arg #36574

Merged
merged 2 commits into from
Sep 27, 2016
Merged

rustc: implement -C link-arg #36574

merged 2 commits into from
Sep 27, 2016

Conversation

japaric
Copy link
Member

@japaric japaric commented Sep 19, 2016

this flag lets you pass a single argument to the linker but can be
used repeatedly. For example, instead of using:

rustc -C link-args='-l bar' (..)

you could write

rustc -C link-arg='-l' -C link-arg='bar' (..)

This new flag can be used with RUSTFLAGS where -C link-args has
problems with "nested" spaces:

RUSTFLAGS='-C link-args="-Tlayout.ld -nostartfiles"'

This passes three arguments to rustc: -C link-args="-Tlayout.ld and
-nostartfiles" to rustc. That's not what we meant. But this does
what we want:

RUSTFLAGS='-C link-arg=-Tlayout.ld -C link-arg=-nostartfiles`

cc rust-lang/rfcs#1509

r? @alexcrichton
cc @Zoxc

This needs a test. Any suggestion?

this flag lets you pass a _single_ argument to the linker but can be
used _repeatedly_. For example, instead of using:

```
rustc -C link-args='-l bar' (..)
```

you could write

```
rustc -C link-arg='-l' -C link-arg='bar' (..)
```

This new flag can be used with RUSTFLAGS where `-C link-args` has
problems with "nested" spaces:

```
RUSTFLAGS='-C link-args="-Tlayout.ld -nostartfiles"'
```

This passes three arguments to rustc: `-C` `link-args="-Tlayout.ld` and
`-nostartfiles"` to `rustc`. That's not what we meant. But this does
what we want:

```
RUSTFLAGS='-C link-arg=-Tlayout.ld -C link-arg=-nostartfiles`
```

cc rust-lang/rfcs#1509
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@japaric
Copy link
Member Author

japaric commented Sep 19, 2016

This needs a test. Any suggestion?

Added a simple test of using -C link-arg twice.

@retep998
Copy link
Member

Can -Clink-arg be combined with -Clink-args? And will -Clink-args continue to support only being passed once?

@japaric
Copy link
Member Author

japaric commented Sep 19, 2016

Can -Clink-arg be combined with -Clink-args?

Yes, both sources get merged.

And will -Clink-args continue to support only being passed once?

This PR doesn't touch -Clink-args.

@jethrogb
Copy link
Contributor

Could you add the attribute counterpart #[link_arg] as well?

@japaric
Copy link
Member Author

japaric commented Sep 23, 2016

@jethrogb That I'm not sure about. The docs discourage using #[link_args] and @alexcrichton said:

This is an intentional design decision of #![link_args], and is one of the reasons it's not generally suitable for passing linker arguments. This "feature" has basically always been slated for deprecation/removal.

@alexcrichton alexcrichton added the relnotes Marks issues that should be documented in the release notes of the next release. label Sep 26, 2016
@alexcrichton
Copy link
Member

@bors: r+

Thanks @japaric!

@bors
Copy link
Contributor

bors commented Sep 26, 2016

📌 Commit 2f71fa7 has been approved by alexcrichton

sophiajt pushed a commit to sophiajt/rust that referenced this pull request Sep 27, 2016
rustc: implement -C link-arg

this flag lets you pass a _single_ argument to the linker but can be
used _repeatedly_. For example, instead of using:

```
rustc -C link-args='-l bar' (..)
```

you could write

```
rustc -C link-arg='-l' -C link-arg='bar' (..)
```

This new flag can be used with RUSTFLAGS where `-C link-args` has
problems with "nested" spaces:

```
RUSTFLAGS='-C link-args="-Tlayout.ld -nostartfiles"'
```

This passes three arguments to rustc: `-C` `link-args="-Tlayout.ld` and
`-nostartfiles"` to `rustc`. That's not what we meant. But this does
what we want:

```
RUSTFLAGS='-C link-arg=-Tlayout.ld -C link-arg=-nostartfiles`
```

cc rust-lang/rfcs#1509

r? @alexcrichton
cc @Zoxc

This needs a test. Any suggestion?
bors added a commit that referenced this pull request Sep 27, 2016
@bors bors merged commit 2f71fa7 into rust-lang:master Sep 27, 2016
@japaric japaric deleted the link-arg branch September 28, 2016 16:16
lrascao added a commit to lrascao/rebar3_cargo that referenced this pull request Jan 16, 2021
After rust-lang/rust/pull/36574 has been merged the latest Rust
version 1.49 breaks the linking of dynamic libs in MacOS. These
changes ensure that the extra link args are applied only at the
dynamic lib generation linking step.
belltoy pushed a commit to belltoy/rebar3_cargo that referenced this pull request Aug 17, 2021
After rust-lang/rust/pull/36574 has been merged the latest Rust
version 1.49 breaks the linking of dynamic libs in MacOS. These
changes ensure that the extra link args are applied only at the
dynamic lib generation linking step.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants