forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable link-arg link kind inside of #[link] attribute
- Implement link-arg as an attribute - Apply suggestions from review - Co-authored-by: Vadim Petrochenkov <[email protected]> - Add unstable book entry
- Loading branch information
1 parent
1670ff6
commit f7617c1
Showing
19 changed files
with
114 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -934,6 +934,7 @@ symbols! { | |
likely, | ||
line, | ||
link, | ||
link_arg_attribute, | ||
link_args, | ||
link_cfg, | ||
link_llvm_intrinsics, | ||
|
21 changes: 21 additions & 0 deletions
21
src/doc/unstable-book/src/language-features/link-arg-attribute.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# `link_arg_attribute` | ||
|
||
The tracking issue for this feature is: [#99427] | ||
|
||
------ | ||
|
||
The `link_arg_attribute` feature allows passing arguments into the linker | ||
from inside of the source code. Order is preserved for link attributes as | ||
they were defined on a single extern block: | ||
|
||
```rust,no_run | ||
#![feature(link_arg_attribute)] | ||
#[link(kind = "link-arg", name = "--start-group")] | ||
#[link(kind = "static", name = "c")] | ||
#[link(kind = "static", name = "gcc")] | ||
#[link(kind = "link-arg", name = "--end-group")] | ||
extern "C" {} | ||
``` | ||
|
||
[#99427]: https://github.com/rust-lang/rust/issues/99427 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#![feature(link_arg_attribute)] | ||
|
||
#[link(kind = "static", name = "l1")] | ||
#[cfg_attr(feature = "verbatim", link(kind = "link-arg", name = "a1", modifiers = "+verbatim"))] | ||
#[cfg_attr(not(feature = "verbatim"), link(kind = "link-arg", name = "a1"))] | ||
#[link(kind = "static", name = "l2")] | ||
#[link(kind = "link-arg", name = "a2")] | ||
#[link(kind = "dylib", name = "d1")] | ||
#[link(kind = "link-arg", name = "a3")] | ||
extern "C" {} | ||
|
||
fn main() {} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/run-make/pass-linker-flags-from-dep/rust_dep_attr.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#![feature(link_arg_attribute)] | ||
|
||
#[link(kind = "static", name = "native_dep_1", modifiers = "-bundle")] | ||
#[link(kind = "link-arg", name = "some_flag")] | ||
#[link(kind = "static", name = "native_dep_2", modifiers = "-bundle")] | ||
extern "C" { | ||
pub fn foo(); | ||
} | ||
|
||
pub fn f() { | ||
unsafe { | ||
foo(); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
include ../tools.mk | ||
|
||
all: | ||
$(RUSTC) rs.rs -Z unstable-options -l static=l1 -l link-arg=a1 -l static=l2 -l link-arg=a2 -l dylib=d1 -l link-arg=a3 --print link-args | $(CGREP) -e 'l1.*a1.*l2.*a2.*d1.*a3' | ||
$(RUSTC) empty.rs -Z unstable-options -l static=l1 -l link-arg=a1 -l static=l2 -l link-arg=a2 -l dylib=d1 -l link-arg=a3 --print link-args | $(CGREP) -e 'l1.*a1.*l2.*a2.*d1.*a3' | ||
$(RUSTC) attribute.rs --print link-args | $(CGREP) -e 'l1.*a1.*l2.*a2.*d1.*a3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![feature(link_arg_attribute)] | ||
|
||
#[link(kind = "static", name = "l1")] | ||
#[link(kind = "link-arg", name = "a1")] | ||
#[link(kind = "static", name = "l2")] | ||
#[link(kind = "link-arg", name = "a2")] | ||
#[link(kind = "dylib", name = "d1")] | ||
#[link(kind = "link-arg", name = "a3")] | ||
extern "C" {} | ||
|
||
fn main() {} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#[link(kind = "link-arg", name = "foo")] | ||
//~^ ERROR link kind `link-arg` is unstable | ||
extern "C" {} | ||
|
||
fn main() {} |
12 changes: 12 additions & 0 deletions
12
tests/ui/feature-gates/feature-gate-link-arg-attribute.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0658]: link kind `link-arg` is unstable | ||
--> $DIR/feature-gate-link-arg-attribute.rs:1:15 | ||
| | ||
LL | #[link(kind = "link-arg", name = "foo")] | ||
| ^^^^^^^^^^ | ||
| | ||
= note: see issue #99427 <https://github.com/rust-lang/rust/issues/99427> for more information | ||
= help: add `#![feature(link_arg_attribute)]` to the crate attributes to enable | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
// link-arg is not supposed to be usable in #[link] attributes | ||
#![feature(link_arg_attribute)] | ||
|
||
// compile-flags: | ||
// error-pattern: error[E0458]: unknown link kind `link-arg`, expected one of: static, dylib, framework, raw-dylib | ||
|
||
#[link(kind = "link-arg")] | ||
#[link(kind = "link-arg", name = "arg", modifiers = "+bundle")] | ||
//~^ ERROR linking modifier `bundle` is only compatible with `static` linking kind | ||
extern "C" {} | ||
|
||
pub fn main() {} |
18 changes: 5 additions & 13 deletions
18
tests/ui/native-library-link-flags/link-arg-from-rs.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,8 @@ | ||
error[E0458]: unknown link kind `link-arg`, expected one of: static, dylib, framework, raw-dylib | ||
--> $DIR/link-arg-from-rs.rs:6:15 | ||
error: linking modifier `bundle` is only compatible with `static` linking kind | ||
--> $DIR/link-arg-from-rs.rs:3:53 | ||
| | ||
LL | #[link(kind = "link-arg")] | ||
| ^^^^^^^^^^ unknown link kind | ||
LL | #[link(kind = "link-arg", name = "arg", modifiers = "+bundle")] | ||
| ^^^^^^^^^ | ||
|
||
error[E0459]: `#[link]` attribute requires a `name = "string"` argument | ||
--> $DIR/link-arg-from-rs.rs:6:1 | ||
| | ||
LL | #[link(kind = "link-arg")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `name` argument | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to 1 previous error | ||
|
||
Some errors have detailed explanations: E0458, E0459. | ||
For more information about an error, try `rustc --explain E0458`. |