Skip to content

Commit 3dea003

Browse files
committed
Auto merge of #95818 - petrochenkov:stabundle, r=wesleywiser
Stabilize the `bundle` native library modifier And remove the legacy `static-nobundle` linking kind. Stabilization report - #95818 (comment). cc #81490 Closes #37403
2 parents 52ee2a2 + a8ee1f3 commit 3dea003

35 files changed

+91
-196
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
19521952
add_local_native_libraries(cmd, sess, codegen_results);
19531953
}
19541954

1955-
// Upstream rust libraries and their nobundle static libraries
1955+
// Upstream rust libraries and their non-bundled static libraries
19561956
add_upstream_rust_crates::<B>(cmd, sess, codegen_results, crate_type, tmpdir);
19571957

19581958
// Upstream dynamic native libraries linked with `#[link]` attributes at and `-l`
@@ -2237,7 +2237,7 @@ fn add_local_native_libraries(
22372237
}
22382238
}
22392239

2240-
/// # Linking Rust crates and their nobundle static libraries
2240+
/// # Linking Rust crates and their non-bundled static libraries
22412241
///
22422242
/// Rust crates are not considered at all when creating an rlib output. All dependencies will be
22432243
/// linked when producing the final output (instead of the intermediate rlib version).

compiler/rustc_error_codes/src/error_codes/E0060.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ Using this declaration, it must be called with at least one argument, so
1616
simply calling `printf()` is invalid. But the following uses are allowed:
1717

1818
```
19-
# #![feature(static_nobundle)]
2019
# use std::os::raw::{c_char, c_int};
2120
# #[cfg_attr(all(windows, target_env = "msvc"),
22-
# link(name = "legacy_stdio_definitions", kind = "static-nobundle"))]
21+
# link(name = "legacy_stdio_definitions",
22+
# kind = "static", modifiers = "-bundle"))]
2323
# extern "C" { fn printf(_: *const c_char, ...) -> c_int; }
2424
# fn main() {
2525
unsafe {

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ declare_features! (
219219
(accepted, move_ref_pattern, "1.49.0", Some(68354), None),
220220
/// Allows specifying modifiers in the link attribute: `#[link(modifiers = "...")]`
221221
(accepted, native_link_modifiers, "1.61.0", Some(81490), None),
222+
/// Allows specifying the bundle link modifier
223+
(accepted, native_link_modifiers_bundle, "1.63.0", Some(81490), None),
222224
/// Allows specifying the whole-archive link modifier
223225
(accepted, native_link_modifiers_whole_archive, "1.61.0", Some(81490), None),
224226
/// Allows using non lexical lifetimes (RFC 2094).

compiler/rustc_feature/src/active.rs

-4
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,6 @@ declare_features! (
451451
(active, naked_functions, "1.9.0", Some(32408), None),
452452
/// Allows specifying the as-needed link modifier
453453
(active, native_link_modifiers_as_needed, "1.53.0", Some(81490), None),
454-
/// Allows specifying the bundle link modifier
455-
(active, native_link_modifiers_bundle, "1.53.0", Some(81490), None),
456454
/// Allows specifying the verbatim link modifier
457455
(active, native_link_modifiers_verbatim, "1.53.0", Some(81490), None),
458456
/// Allow negative trait implementations.
@@ -502,8 +500,6 @@ declare_features! (
502500
(active, simd_ffi, "1.0.0", Some(27731), None),
503501
/// Allows specialization of implementations (RFC 1210).
504502
(incomplete, specialization, "1.7.0", Some(31844), None),
505-
/// Allows `#[link(kind="static-nobundle"...)]`.
506-
(active, static_nobundle, "1.16.0", Some(37403), None),
507503
/// Allows attributes on expressions and non-item statements.
508504
(active, stmt_expr_attributes, "1.6.0", Some(15701), None),
509505
/// Allows lints part of the strict provenance effort.

compiler/rustc_feature/src/removed.rs

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ declare_features! (
169169
(removed, sanitizer_runtime, "1.17.0", None, None, None),
170170
(removed, simd, "1.0.0", Some(27731), None,
171171
Some("removed in favor of `#[repr(simd)]`")),
172+
/// Allows `#[link(kind = "static-nobundle", ...)]`.
173+
(removed, static_nobundle, "1.16.0", Some(37403), None,
174+
Some(r#"subsumed by `#[link(kind = "static", modifiers = "-bundle", ...)]`"#)),
172175
(removed, struct_inherit, "1.0.0", None, None, None),
173176
(removed, test_removed_feature, "1.0.0", None, None, None),
174177
/// Allows using items which are missing stability attributes

compiler/rustc_metadata/src/native_libs.rs

-19
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,6 @@ impl<'tcx> Collector<'tcx> {
9797
let span = item.name_value_literal_span().unwrap();
9898
let link_kind = match link_kind.as_str() {
9999
"static" => NativeLibKind::Static { bundle: None, whole_archive: None },
100-
"static-nobundle" => {
101-
sess.struct_span_warn(
102-
span,
103-
"link kind `static-nobundle` has been superseded by specifying \
104-
modifier `-bundle` with link kind `static`",
105-
)
106-
.emit();
107-
if !features.static_nobundle {
108-
feature_err(
109-
&sess.parse_sess,
110-
sym::static_nobundle,
111-
span,
112-
"link kind `static-nobundle` is unstable",
113-
)
114-
.emit();
115-
}
116-
NativeLibKind::Static { bundle: Some(false), whole_archive: None }
117-
}
118100
"dylib" => NativeLibKind::Dylib { as_needed: None },
119101
"framework" => {
120102
if !sess.target.is_like_osx {
@@ -264,7 +246,6 @@ impl<'tcx> Collector<'tcx> {
264246
};
265247
match (modifier, &mut kind) {
266248
("bundle", Some(NativeLibKind::Static { bundle, .. })) => {
267-
report_unstable_modifier!(native_link_modifiers_bundle);
268249
assign_modifier(bundle)
269250
}
270251
("bundle", _) => {

compiler/rustc_session/src/config.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -1920,21 +1920,6 @@ fn parse_native_lib_kind(
19201920

19211921
let kind = match kind {
19221922
"static" => NativeLibKind::Static { bundle: None, whole_archive: None },
1923-
"static-nobundle" => {
1924-
early_warn(
1925-
error_format,
1926-
"library kind `static-nobundle` has been superseded by specifying \
1927-
modifier `-bundle` with library kind `static`. Try `static:-bundle`",
1928-
);
1929-
if !nightly_options::match_is_nightly_build(matches) {
1930-
early_error(
1931-
error_format,
1932-
"library kind `static-nobundle` is unstable \
1933-
and only accepted on the nightly compiler",
1934-
);
1935-
}
1936-
NativeLibKind::Static { bundle: Some(false), whole_archive: None }
1937-
}
19381923
"dylib" => NativeLibKind::Dylib { as_needed: None },
19391924
"framework" => NativeLibKind::Framework { as_needed: None },
19401925
_ => early_error(
@@ -1987,10 +1972,7 @@ fn parse_native_lib_modifiers(
19871972
}
19881973
};
19891974
match (modifier, &mut kind) {
1990-
("bundle", NativeLibKind::Static { bundle, .. }) => {
1991-
report_unstable_modifier();
1992-
assign_modifier(bundle)
1993-
}
1975+
("bundle", NativeLibKind::Static { bundle, .. }) => assign_modifier(bundle),
19941976
("bundle", _) => early_error(
19951977
error_format,
19961978
"linking modifier `bundle` is only compatible with `static` linking kind",

library/unwind/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![no_std]
22
#![unstable(feature = "panic_unwind", issue = "32837")]
33
#![feature(link_cfg)]
4-
#![feature(native_link_modifiers_bundle)]
4+
#![cfg_attr(bootstrap, feature(native_link_modifiers_bundle))]
55
#![feature(staged_api)]
66
#![feature(c_unwind)]
77
#![feature(cfg_target_abi)]

src/doc/rustc/src/command-line-arguments.md

+20
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,26 @@ The default for this modifier is `-whole-archive`. \
8484
NOTE: The default may currently be different in some cases for backward compatibility,
8585
but it is not guaranteed. If you need whole archive semantics use `+whole-archive` explicitly.
8686

87+
### Linking modifiers: `bundle`
88+
89+
This modifier is only compatible with the `static` linking kind.
90+
Using any other kind will result in a compiler error.
91+
92+
When building a rlib or staticlib `+bundle` means that all object files from the native static
93+
library will be added to the rlib or staticlib archive, and then used from it during linking of
94+
the final binary.
95+
96+
When building a rlib `-bundle` means that the native static library is registered as a dependency
97+
of that rlib "by name", and object files from it are included only during linking of the final
98+
binary, the file search by that name is also performed during final linking. \
99+
When building a staticlib `-bundle` means that the native static library is simply not included
100+
into the archive and some higher level build system will need to add it later during linking of
101+
the final binary.
102+
103+
This modifier has no effect when building other targets like executables or dynamic libraries.
104+
105+
The default for this modifier is `+bundle`.
106+
87107
<a id="option-crate-type"></a>
88108
## `--crate-type`: a list of types of crates for the compiler to emit
89109

src/doc/unstable-book/src/language-features/native-link-modifiers-bundle.md

-19
This file was deleted.

src/test/run-make-fulldeps/static-nobundle/Makefile

-23
This file was deleted.

src/test/run-make-fulldeps/static-nobundle/bbb.rs

-13
This file was deleted.

src/test/run-make-fulldeps/static-nobundle/ccc.rs

-13
This file was deleted.

src/test/run-make-fulldeps/static-nobundle/ddd.rs

-7
This file was deleted.

src/test/run-make-fulldeps/tools.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ else
120120
# So we end up with the following hack: we link use static:-bundle to only
121121
# link the parts of libstdc++ that we actually use, which doesn't include
122122
# the dependency on the pthreads DLL.
123-
EXTRARSCXXFLAGS := -l static:-bundle=stdc++ -Z unstable-options
123+
EXTRARSCXXFLAGS := -l static:-bundle=stdc++
124124
endif
125125
else
126126
ifeq ($(UNAME),Darwin)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ignore-cross-compile
2+
# ignore-windows-msvc
3+
4+
-include ../../run-make-fulldeps/tools.mk
5+
6+
all: $(call NATIVE_STATICLIB,native-staticlib)
7+
# Build a staticlib and a rlib, the `native_func` symbol will be bundled into them
8+
$(RUSTC) bundled.rs --crate-type=staticlib --crate-type=rlib
9+
nm $(TMPDIR)/libbundled.a | $(CGREP) -e "T _*native_func"
10+
nm $(TMPDIR)/libbundled.a | $(CGREP) -e "U _*native_func"
11+
nm $(TMPDIR)/libbundled.rlib | $(CGREP) -e "T _*native_func"
12+
nm $(TMPDIR)/libbundled.rlib | $(CGREP) -e "U _*native_func"
13+
14+
# Build a staticlib and a rlib, the `native_func` symbol will not be bundled into it
15+
$(RUSTC) non-bundled.rs --crate-type=staticlib --crate-type=rlib
16+
nm $(TMPDIR)/libnon_bundled.a | $(CGREP) -ve "T _*native_func"
17+
nm $(TMPDIR)/libnon_bundled.a | $(CGREP) -e "U _*native_func"
18+
nm $(TMPDIR)/libnon_bundled.rlib | $(CGREP) -ve "T _*native_func"
19+
nm $(TMPDIR)/libnon_bundled.rlib | $(CGREP) -e "U _*native_func"
20+
21+
# Build a cdylib, `native-staticlib` will not appear on the linker line because it was bundled previously
22+
# The cdylib will contain the `native_func` symbol in the end
23+
$(RUSTC) cdylib-bundled.rs --crate-type=cdylib --print link-args | $(CGREP) -ve '-l[" ]*native-staticlib'
24+
nm $(call DYLIB,cdylib_bundled) | $(CGREP) -e "[Tt] _*native_func"
25+
26+
# Build a cdylib, `native-staticlib` will appear on the linker line because it was not bundled previously
27+
# The cdylib will contain the `native_func` symbol in the end
28+
$(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args | $(CGREP) -e '-l[" ]*native-staticlib'
29+
nm $(call DYLIB,cdylib_non_bundled) | $(CGREP) -e "[Tt] _*native_func"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#[link(name = "native-staticlib", kind = "static", modifiers = "+bundle")]
2+
extern "C" {
3+
pub fn native_func();
4+
}
5+
6+
#[no_mangle]
7+
pub extern "C" fn wrapped_func() {
8+
unsafe {
9+
native_func();
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extern crate bundled;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extern crate non_bundled;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#[link(name = "native-staticlib", kind = "static", modifiers = "-bundle")]
2+
extern "C" {
3+
pub fn native_func();
4+
}
5+
6+
#[no_mangle]
7+
pub extern "C" fn wrapped_func() {
8+
unsafe {
9+
native_func();
10+
}
11+
}

src/test/run-make/native-link-modifier-whole-archive/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ all: $(TMPDIR)/$(call BIN,directly_linked) $(TMPDIR)/$(call BIN,indirectly_linke
1717

1818
# Native lib linked directly into executable
1919
$(TMPDIR)/$(call BIN,directly_linked): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
20-
$(RUSTC) directly_linked.rs -Z unstable-options -l static:+whole-archive=c_static_lib_with_constructor
20+
$(RUSTC) directly_linked.rs -l static:+whole-archive=c_static_lib_with_constructor
2121

2222
# Native lib linked into RLIB via `-l static:-bundle,+whole-archive`, RLIB linked into executable
2323
$(TMPDIR)/$(call BIN,indirectly_linked): $(TMPDIR)/librlib_with_cmdline_native_lib.rlib
@@ -29,7 +29,7 @@ $(TMPDIR)/$(call BIN,indirectly_linked_via_attr): $(TMPDIR)/libnative_lib_in_src
2929

3030
# Native lib linked into rlib with via commandline
3131
$(TMPDIR)/librlib_with_cmdline_native_lib.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
32-
$(RUSTC) rlib_with_cmdline_native_lib.rs -Z unstable-options --crate-type=rlib -l static:-bundle,+whole-archive=c_static_lib_with_constructor
32+
$(RUSTC) rlib_with_cmdline_native_lib.rs --crate-type=rlib -l static:-bundle,+whole-archive=c_static_lib_with_constructor
3333

3434
# Native lib linked into rlib via `#[link()]` attribute on extern block.
3535
$(TMPDIR)/libnative_lib_in_src.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor)

src/test/run-make/native-link-modifier-whole-archive/native_lib_in_src.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(native_link_modifiers_bundle)]
2-
31
use std::io::Write;
42

53
#[link(name = "c_static_lib_with_constructor",

src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-2.rs

-9
This file was deleted.

src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-3.rs

-3
This file was deleted.

src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle-3.stderr

-2
This file was deleted.

src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle.rs

-5
This file was deleted.

src/test/ui/feature-gates/feature-gate-native_link_modifiers_bundle.stderr

-12
This file was deleted.

src/test/ui/feature-gates/feature-gate-static-nobundle-2.rs

-4
This file was deleted.

src/test/ui/feature-gates/feature-gate-static-nobundle-2.stderr

-2
This file was deleted.

src/test/ui/feature-gates/feature-gate-static-nobundle.rs

-6
This file was deleted.

0 commit comments

Comments
 (0)