Rollup merge of #104360 - petrochenkov:stabverb, r=TaKO8Ki

Stabilize native library modifier `verbatim`

Stabilization report - https://github.com/rust-lang/rust/pull/104360#issuecomment-1312724787.

cc https://github.com/rust-lang/rust/issues/81490
Closes https://github.com/rust-lang/rust/issues/99425
This commit is contained in:
Dylan DPC 2022-11-28 15:42:09 +05:30 committed by GitHub
commit f33d4094f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 73 additions and 95 deletions

View file

@ -104,6 +104,33 @@ This modifier has no effect when building other targets like executables or dyna
The default for this modifier is `+bundle`.
### Linking modifiers: `verbatim`
This modifier is compatible with all linking kinds.
`+verbatim` means that rustc itself won't add any target-specified library prefixes or suffixes
(like `lib` or `.a`) to the library name, and will try its best to ask for the same thing from the
linker.
For `ld`-like linkers supporting GNU extensions rustc will use the `-l:filename` syntax (note the
colon) when passing the library, so the linker won't add any prefixes or suffixes to it.
See [`-l namespec`](https://sourceware.org/binutils/docs/ld/Options.html) in ld documentation for
more details. \
For linkers not supporting any verbatim modifiers (e.g. `link.exe` or `ld64`) the library name will
be passed as is. So the most reliable cross-platform use scenarios for this option are when no
linker is involved, for example bundling native libraries into rlibs.
`-verbatim` means that rustc will either add a target-specific prefix and suffix to the library
name before passing it to linker, or won't prevent linker from implicitly adding it. \
In case of `raw-dylib` kind in particular `.dll` will be added to the library name on Windows.
The default for this modifier is `-verbatim`.
NOTE: Even with `+verbatim` and `-l:filename` syntax `ld`-like linkers do not typically support
passing absolute paths to libraries. Usually such paths need to be passed as input files without
using any options like `-l`, e.g. `ld /my/absolute/path`. \
`-Clink-arg=/my/absolute/path` can be used for doing this from stable `rustc`.
<a id="option-crate-type"></a>
## `--crate-type`: a list of types of crates for the compiler to emit

View file

@ -1,20 +0,0 @@
# `native_link_modifiers_verbatim`
The tracking issue for this feature is: [#81490]
[#81490]: https://github.com/rust-lang/rust/issues/81490
------------------------
The `native_link_modifiers_verbatim` feature allows you to use the `verbatim` modifier.
`+verbatim` means that rustc itself won't add any target-specified library prefixes or suffixes (like `lib` or `.a`) to the library name, and will try its best to ask for the same thing from the linker.
For `ld`-like linkers rustc will use the `-l:filename` syntax (note the colon) when passing the library, so the linker won't add any prefixes or suffixes as well.
See [`-l namespec`](https://sourceware.org/binutils/docs/ld/Options.html) in ld documentation for more details.
For linkers not supporting any verbatim modifiers (e.g. `link.exe` or `ld64`) the library name will be passed as is.
The default for this modifier is `-verbatim`.
This RFC changes the behavior of `raw-dylib` linking kind specified by [RFC 2627](https://github.com/rust-lang/rfcs/pull/2627). The `.dll` suffix (or other target-specified suffixes for other targets) is now added automatically.
If your DLL doesn't have the `.dll` suffix, it can be specified with `+verbatim`.

View file

@ -6,10 +6,10 @@ include ../../run-make-fulldeps/tools.mk
all:
# Verbatim allows specify precise name.
$(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_some_strange_name.ext
$(RUSTC) main.rs -Zunstable-options -l static:+verbatim=local_some_strange_name.ext
$(RUSTC) main.rs -l static:+verbatim=local_some_strange_name.ext
# With verbatim any other name cannot be used (local).
$(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/liblocal_native_dep.a
$(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_native_dep.a
$(RUSTC) local_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/local_native_dep.lib
$(RUSTC) main.rs -Zunstable-options -l static:+verbatim=local_native_dep 2>&1 | $(CGREP) "local_native_dep"
$(RUSTC) main.rs -l static:+verbatim=local_native_dep 2>&1 | $(CGREP) "local_native_dep"

View file

@ -3,10 +3,10 @@ include ../../run-make-fulldeps/tools.mk
all:
# Verbatim allows specify precise name.
$(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_some_strange_name.ext
$(RUSTC) rust_dep.rs -Zunstable-options -l static:+verbatim=upstream_some_strange_name.ext --crate-type rlib
$(RUSTC) rust_dep.rs -l static:+verbatim=upstream_some_strange_name.ext --crate-type rlib
# With verbatim any other name cannot be used (upstream).
$(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/libupstream_native_dep.a
$(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_native_dep.a
$(RUSTC) upstream_native_dep.rs --crate-type=staticlib -o $(TMPDIR)/upstream_native_dep.lib
$(RUSTC) rust_dep.rs -Zunstable-options -l static:+verbatim=upstream_native_dep --crate-type rlib 2>&1 | $(CGREP) "upstream_native_dep"
$(RUSTC) rust_dep.rs -l static:+verbatim=upstream_native_dep --crate-type rlib 2>&1 | $(CGREP) "upstream_native_dep"

View file

@ -1,4 +1,4 @@
#![feature(raw_dylib, native_link_modifiers_verbatim)]
#![feature(raw_dylib)]
#[link(name = "extern_1.dll", kind = "raw-dylib", modifiers = "+verbatim")]
extern {

View file

@ -1,4 +1,3 @@
#![feature(native_link_modifiers_verbatim)]
#[link(name = "native_dep.ext", kind = "static", modifiers = "+verbatim")]
extern "C" {
fn native_f1() -> i32;

View file

@ -1,5 +0,0 @@
#[link(name = "foo", modifiers = "+verbatim")]
//~^ ERROR: linking modifier `verbatim` is unstable
extern "C" {}
fn main() {}

View file

@ -1,12 +0,0 @@
error[E0658]: linking modifier `verbatim` is unstable
--> $DIR/feature-gate-native_link_modifiers_verbatim.rs:1:34
|
LL | #[link(name = "foo", modifiers = "+verbatim")]
| ^^^^^^^^^^^
|
= note: see issue #81490 <https://github.com/rust-lang/rust/issues/81490> for more information
= help: add `#![feature(native_link_modifiers_verbatim)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View file

@ -1,4 +1,3 @@
#![feature(native_link_modifiers_verbatim)]
#![feature(link_cfg)]
// Top-level ill-formed

View file

@ -1,143 +1,143 @@
error: unexpected `#[link]` argument, expected one of: name, kind, modifiers, cfg, wasm_import_module, import_name_type
--> $DIR/link-attr-validation-late.rs:5:22
--> $DIR/link-attr-validation-late.rs:4:22
|
LL | #[link(name = "...", "literal")]
| ^^^^^^^^^
error: unexpected `#[link]` argument, expected one of: name, kind, modifiers, cfg, wasm_import_module, import_name_type
--> $DIR/link-attr-validation-late.rs:6:22
--> $DIR/link-attr-validation-late.rs:5:22
|
LL | #[link(name = "...", unknown)]
| ^^^^^^^
error: multiple `name` arguments in a single `#[link]` attribute
--> $DIR/link-attr-validation-late.rs:10:22
--> $DIR/link-attr-validation-late.rs:9:22
|
LL | #[link(name = "foo", name = "bar")]
| ^^^^^^^^^^^^
error: multiple `kind` arguments in a single `#[link]` attribute
--> $DIR/link-attr-validation-late.rs:11:38
--> $DIR/link-attr-validation-late.rs:10:38
|
LL | #[link(name = "...", kind = "dylib", kind = "bar")]
| ^^^^^^^^^^^^
error: multiple `modifiers` arguments in a single `#[link]` attribute
--> $DIR/link-attr-validation-late.rs:12:47
--> $DIR/link-attr-validation-late.rs:11:47
|
LL | #[link(name = "...", modifiers = "+verbatim", modifiers = "bar")]
| ^^^^^^^^^^^^^^^^^
error: multiple `cfg` arguments in a single `#[link]` attribute
--> $DIR/link-attr-validation-late.rs:13:34
--> $DIR/link-attr-validation-late.rs:12:34
|
LL | #[link(name = "...", cfg(FALSE), cfg(FALSE))]
| ^^^^^^^^^^
error: multiple `wasm_import_module` arguments in a single `#[link]` attribute
--> $DIR/link-attr-validation-late.rs:14:36
--> $DIR/link-attr-validation-late.rs:13:36
|
LL | #[link(wasm_import_module = "foo", wasm_import_module = "bar")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: link name must be of the form `name = "string"`
--> $DIR/link-attr-validation-late.rs:18:8
--> $DIR/link-attr-validation-late.rs:17:8
|
LL | #[link(name)]
| ^^^^
error[E0459]: `#[link]` attribute requires a `name = "string"` argument
--> $DIR/link-attr-validation-late.rs:18:1
--> $DIR/link-attr-validation-late.rs:17:1
|
LL | #[link(name)]
| ^^^^^^^^^^^^^ missing `name` argument
error: link name must be of the form `name = "string"`
--> $DIR/link-attr-validation-late.rs:20:8
--> $DIR/link-attr-validation-late.rs:19:8
|
LL | #[link(name())]
| ^^^^^^
error[E0459]: `#[link]` attribute requires a `name = "string"` argument
--> $DIR/link-attr-validation-late.rs:20:1
--> $DIR/link-attr-validation-late.rs:19:1
|
LL | #[link(name())]
| ^^^^^^^^^^^^^^^ missing `name` argument
error: link kind must be of the form `kind = "string"`
--> $DIR/link-attr-validation-late.rs:22:22
--> $DIR/link-attr-validation-late.rs:21:22
|
LL | #[link(name = "...", kind)]
| ^^^^
error: link kind must be of the form `kind = "string"`
--> $DIR/link-attr-validation-late.rs:23:22
--> $DIR/link-attr-validation-late.rs:22:22
|
LL | #[link(name = "...", kind())]
| ^^^^^^
error: link modifiers must be of the form `modifiers = "string"`
--> $DIR/link-attr-validation-late.rs:24:22
--> $DIR/link-attr-validation-late.rs:23:22
|
LL | #[link(name = "...", modifiers)]
| ^^^^^^^^^
error: link modifiers must be of the form `modifiers = "string"`
--> $DIR/link-attr-validation-late.rs:25:22
--> $DIR/link-attr-validation-late.rs:24:22
|
LL | #[link(name = "...", modifiers())]
| ^^^^^^^^^^^
error: link cfg must be of the form `cfg(/* predicate */)`
--> $DIR/link-attr-validation-late.rs:26:22
--> $DIR/link-attr-validation-late.rs:25:22
|
LL | #[link(name = "...", cfg)]
| ^^^
error: link cfg must be of the form `cfg(/* predicate */)`
--> $DIR/link-attr-validation-late.rs:27:22
--> $DIR/link-attr-validation-late.rs:26:22
|
LL | #[link(name = "...", cfg = "literal")]
| ^^^^^^^^^^^^^^^
error: link cfg must have a single predicate argument
--> $DIR/link-attr-validation-late.rs:28:22
--> $DIR/link-attr-validation-late.rs:27:22
|
LL | #[link(name = "...", cfg("literal"))]
| ^^^^^^^^^^^^^^
error: wasm import module must be of the form `wasm_import_module = "string"`
--> $DIR/link-attr-validation-late.rs:29:22
--> $DIR/link-attr-validation-late.rs:28:22
|
LL | #[link(name = "...", wasm_import_module)]
| ^^^^^^^^^^^^^^^^^^
error: wasm import module must be of the form `wasm_import_module = "string"`
--> $DIR/link-attr-validation-late.rs:30:22
--> $DIR/link-attr-validation-late.rs:29:22
|
LL | #[link(name = "...", wasm_import_module())]
| ^^^^^^^^^^^^^^^^^^^^
error: invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed
--> $DIR/link-attr-validation-late.rs:34:34
--> $DIR/link-attr-validation-late.rs:33:34
|
LL | #[link(name = "...", modifiers = "")]
| ^^
error: invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed
--> $DIR/link-attr-validation-late.rs:35:34
--> $DIR/link-attr-validation-late.rs:34:34
|
LL | #[link(name = "...", modifiers = "no-plus-minus")]
| ^^^^^^^^^^^^^^^
error: unknown linking modifier `unknown`, expected one of: bundle, verbatim, whole-archive, as-needed
--> $DIR/link-attr-validation-late.rs:36:34
--> $DIR/link-attr-validation-late.rs:35:34
|
LL | #[link(name = "...", modifiers = "+unknown")]
| ^^^^^^^^^^
error: multiple `verbatim` modifiers in a single `modifiers` argument
--> $DIR/link-attr-validation-late.rs:37:34
--> $DIR/link-attr-validation-late.rs:36:34
|
LL | #[link(name = "...", modifiers = "+verbatim,+verbatim")]
| ^^^^^^^^^^^^^^^^^^^^^