Skip to content

Commit

Permalink
Auto merge of #95818 - petrochenkov:stabundle, r=wesleywiser
Browse files Browse the repository at this point in the history
Stabilize the `bundle` native library modifier

And remove the legacy `static-nobundle` linking kind.

Stabilization report - #95818 (comment).

cc #81490
Closes #37403
  • Loading branch information
bors committed Jun 10, 2022
2 parents 52ee2a2 + a8ee1f3 commit 3dea003
Show file tree
Hide file tree
Showing 35 changed files with 91 additions and 196 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1952,7 +1952,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
add_local_native_libraries(cmd, sess, codegen_results);
}

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

// Upstream dynamic native libraries linked with `#[link]` attributes at and `-l`
Expand Down Expand Up @@ -2237,7 +2237,7 @@ fn add_local_native_libraries(
}
}

/// # Linking Rust crates and their nobundle static libraries
/// # Linking Rust crates and their non-bundled static libraries
///
/// Rust crates are not considered at all when creating an rlib output. All dependencies will be
/// linked when producing the final output (instead of the intermediate rlib version).
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0060.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Using this declaration, it must be called with at least one argument, so
simply calling `printf()` is invalid. But the following uses are allowed:

```
# #![feature(static_nobundle)]
# use std::os::raw::{c_char, c_int};
# #[cfg_attr(all(windows, target_env = "msvc"),
# link(name = "legacy_stdio_definitions", kind = "static-nobundle"))]
# link(name = "legacy_stdio_definitions",
# kind = "static", modifiers = "-bundle"))]
# extern "C" { fn printf(_: *const c_char, ...) -> c_int; }
# fn main() {
unsafe {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ declare_features! (
(accepted, move_ref_pattern, "1.49.0", Some(68354), None),
/// Allows specifying modifiers in the link attribute: `#[link(modifiers = "...")]`
(accepted, native_link_modifiers, "1.61.0", Some(81490), None),
/// Allows specifying the bundle link modifier
(accepted, native_link_modifiers_bundle, "1.63.0", Some(81490), None),
/// Allows specifying the whole-archive link modifier
(accepted, native_link_modifiers_whole_archive, "1.61.0", Some(81490), None),
/// Allows using non lexical lifetimes (RFC 2094).
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,6 @@ declare_features! (
(active, naked_functions, "1.9.0", Some(32408), None),
/// Allows specifying the as-needed link modifier
(active, native_link_modifiers_as_needed, "1.53.0", Some(81490), None),
/// Allows specifying the bundle link modifier
(active, native_link_modifiers_bundle, "1.53.0", Some(81490), None),
/// Allows specifying the verbatim link modifier
(active, native_link_modifiers_verbatim, "1.53.0", Some(81490), None),
/// Allow negative trait implementations.
Expand Down Expand Up @@ -502,8 +500,6 @@ declare_features! (
(active, simd_ffi, "1.0.0", Some(27731), None),
/// Allows specialization of implementations (RFC 1210).
(incomplete, specialization, "1.7.0", Some(31844), None),
/// Allows `#[link(kind="static-nobundle"...)]`.
(active, static_nobundle, "1.16.0", Some(37403), None),
/// Allows attributes on expressions and non-item statements.
(active, stmt_expr_attributes, "1.6.0", Some(15701), None),
/// Allows lints part of the strict provenance effort.
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ declare_features! (
(removed, sanitizer_runtime, "1.17.0", None, None, None),
(removed, simd, "1.0.0", Some(27731), None,
Some("removed in favor of `#[repr(simd)]`")),
/// Allows `#[link(kind = "static-nobundle", ...)]`.
(removed, static_nobundle, "1.16.0", Some(37403), None,
Some(r#"subsumed by `#[link(kind = "static", modifiers = "-bundle", ...)]`"#)),
(removed, struct_inherit, "1.0.0", None, None, None),
(removed, test_removed_feature, "1.0.0", None, None, None),
/// Allows using items which are missing stability attributes
Expand Down
19 changes: 0 additions & 19 deletions compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,6 @@ impl<'tcx> Collector<'tcx> {
let span = item.name_value_literal_span().unwrap();
let link_kind = match link_kind.as_str() {
"static" => NativeLibKind::Static { bundle: None, whole_archive: None },
"static-nobundle" => {
sess.struct_span_warn(
span,
"link kind `static-nobundle` has been superseded by specifying \
modifier `-bundle` with link kind `static`",
)
.emit();
if !features.static_nobundle {
feature_err(
&sess.parse_sess,
sym::static_nobundle,
span,
"link kind `static-nobundle` is unstable",
)
.emit();
}
NativeLibKind::Static { bundle: Some(false), whole_archive: None }
}
"dylib" => NativeLibKind::Dylib { as_needed: None },
"framework" => {
if !sess.target.is_like_osx {
Expand Down Expand Up @@ -264,7 +246,6 @@ impl<'tcx> Collector<'tcx> {
};
match (modifier, &mut kind) {
("bundle", Some(NativeLibKind::Static { bundle, .. })) => {
report_unstable_modifier!(native_link_modifiers_bundle);
assign_modifier(bundle)
}
("bundle", _) => {
Expand Down
20 changes: 1 addition & 19 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1920,21 +1920,6 @@ fn parse_native_lib_kind(

let kind = match kind {
"static" => NativeLibKind::Static { bundle: None, whole_archive: None },
"static-nobundle" => {
early_warn(
error_format,
"library kind `static-nobundle` has been superseded by specifying \
modifier `-bundle` with library kind `static`. Try `static:-bundle`",
);
if !nightly_options::match_is_nightly_build(matches) {
early_error(
error_format,
"library kind `static-nobundle` is unstable \
and only accepted on the nightly compiler",
);
}
NativeLibKind::Static { bundle: Some(false), whole_archive: None }
}
"dylib" => NativeLibKind::Dylib { as_needed: None },
"framework" => NativeLibKind::Framework { as_needed: None },
_ => early_error(
Expand Down Expand Up @@ -1987,10 +1972,7 @@ fn parse_native_lib_modifiers(
}
};
match (modifier, &mut kind) {
("bundle", NativeLibKind::Static { bundle, .. }) => {
report_unstable_modifier();
assign_modifier(bundle)
}
("bundle", NativeLibKind::Static { bundle, .. }) => assign_modifier(bundle),
("bundle", _) => early_error(
error_format,
"linking modifier `bundle` is only compatible with `static` linking kind",
Expand Down
2 changes: 1 addition & 1 deletion library/unwind/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![no_std]
#![unstable(feature = "panic_unwind", issue = "32837")]
#![feature(link_cfg)]
#![feature(native_link_modifiers_bundle)]
#![cfg_attr(bootstrap, feature(native_link_modifiers_bundle))]
#![feature(staged_api)]
#![feature(c_unwind)]
#![feature(cfg_target_abi)]
Expand Down
20 changes: 20 additions & 0 deletions src/doc/rustc/src/command-line-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ The default for this modifier is `-whole-archive`. \
NOTE: The default may currently be different in some cases for backward compatibility,
but it is not guaranteed. If you need whole archive semantics use `+whole-archive` explicitly.

### Linking modifiers: `bundle`

This modifier is only compatible with the `static` linking kind.
Using any other kind will result in a compiler error.

When building a rlib or staticlib `+bundle` means that all object files from the native static
library will be added to the rlib or staticlib archive, and then used from it during linking of
the final binary.

When building a rlib `-bundle` means that the native static library is registered as a dependency
of that rlib "by name", and object files from it are included only during linking of the final
binary, the file search by that name is also performed during final linking. \
When building a staticlib `-bundle` means that the native static library is simply not included
into the archive and some higher level build system will need to add it later during linking of
the final binary.

This modifier has no effect when building other targets like executables or dynamic libraries.

The default for this modifier is `+bundle`.

<a id="option-crate-type"></a>
## `--crate-type`: a list of types of crates for the compiler to emit

Expand Down

This file was deleted.

23 changes: 0 additions & 23 deletions src/test/run-make-fulldeps/static-nobundle/Makefile

This file was deleted.

13 changes: 0 additions & 13 deletions src/test/run-make-fulldeps/static-nobundle/bbb.rs

This file was deleted.

13 changes: 0 additions & 13 deletions src/test/run-make-fulldeps/static-nobundle/ccc.rs

This file was deleted.

7 changes: 0 additions & 7 deletions src/test/run-make-fulldeps/static-nobundle/ddd.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/run-make-fulldeps/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ else
# So we end up with the following hack: we link use static:-bundle to only
# link the parts of libstdc++ that we actually use, which doesn't include
# the dependency on the pthreads DLL.
EXTRARSCXXFLAGS := -l static:-bundle=stdc++ -Z unstable-options
EXTRARSCXXFLAGS := -l static:-bundle=stdc++
endif
else
ifeq ($(UNAME),Darwin)
Expand Down
29 changes: 29 additions & 0 deletions src/test/run-make/native-link-modifier-bundle/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ignore-cross-compile
# ignore-windows-msvc

-include ../../run-make-fulldeps/tools.mk

all: $(call NATIVE_STATICLIB,native-staticlib)
# Build a staticlib and a rlib, the `native_func` symbol will be bundled into them
$(RUSTC) bundled.rs --crate-type=staticlib --crate-type=rlib
nm $(TMPDIR)/libbundled.a | $(CGREP) -e "T _*native_func"
nm $(TMPDIR)/libbundled.a | $(CGREP) -e "U _*native_func"
nm $(TMPDIR)/libbundled.rlib | $(CGREP) -e "T _*native_func"
nm $(TMPDIR)/libbundled.rlib | $(CGREP) -e "U _*native_func"

# Build a staticlib and a rlib, the `native_func` symbol will not be bundled into it
$(RUSTC) non-bundled.rs --crate-type=staticlib --crate-type=rlib
nm $(TMPDIR)/libnon_bundled.a | $(CGREP) -ve "T _*native_func"
nm $(TMPDIR)/libnon_bundled.a | $(CGREP) -e "U _*native_func"
nm $(TMPDIR)/libnon_bundled.rlib | $(CGREP) -ve "T _*native_func"
nm $(TMPDIR)/libnon_bundled.rlib | $(CGREP) -e "U _*native_func"

# Build a cdylib, `native-staticlib` will not appear on the linker line because it was bundled previously
# The cdylib will contain the `native_func` symbol in the end
$(RUSTC) cdylib-bundled.rs --crate-type=cdylib --print link-args | $(CGREP) -ve '-l[" ]*native-staticlib'
nm $(call DYLIB,cdylib_bundled) | $(CGREP) -e "[Tt] _*native_func"

# Build a cdylib, `native-staticlib` will appear on the linker line because it was not bundled previously
# The cdylib will contain the `native_func` symbol in the end
$(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args | $(CGREP) -e '-l[" ]*native-staticlib'
nm $(call DYLIB,cdylib_non_bundled) | $(CGREP) -e "[Tt] _*native_func"
11 changes: 11 additions & 0 deletions src/test/run-make/native-link-modifier-bundle/bundled.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[link(name = "native-staticlib", kind = "static", modifiers = "+bundle")]
extern "C" {
pub fn native_func();
}

#[no_mangle]
pub extern "C" fn wrapped_func() {
unsafe {
native_func();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extern crate bundled;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extern crate non_bundled;
11 changes: 11 additions & 0 deletions src/test/run-make/native-link-modifier-bundle/non-bundled.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[link(name = "native-staticlib", kind = "static", modifiers = "-bundle")]
extern "C" {
pub fn native_func();
}

#[no_mangle]
pub extern "C" fn wrapped_func() {
unsafe {
native_func();
}
}
4 changes: 2 additions & 2 deletions src/test/run-make/native-link-modifier-whole-archive/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ all: $(TMPDIR)/$(call BIN,directly_linked) $(TMPDIR)/$(call BIN,indirectly_linke

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

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

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

# Native lib linked into rlib via `#[link()]` attribute on extern block.
$(TMPDIR)/libnative_lib_in_src.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(native_link_modifiers_bundle)]

use std::io::Write;

#[link(name = "c_static_lib_with_constructor",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions src/test/ui/feature-gates/feature-gate-static-nobundle-2.rs

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions src/test/ui/feature-gates/feature-gate-static-nobundle.rs

This file was deleted.

Loading

0 comments on commit 3dea003

Please sign in to comment.