Skip to content

Commit 7ffd8d3

Browse files
committed
merge tests + cleanup
1 parent 9702309 commit 7ffd8d3

File tree

10 files changed

+24
-67
lines changed

10 files changed

+24
-67
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,11 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
347347

348348
if flavor == RlibFlavor::Normal && sess.opts.unstable_opts.split_bundled_libs {
349349
let suffix = &sess.target.staticlib_suffix;
350-
let bundle_lib = PathBuf::from(format!("{}.bundle.{name}{suffix}", out_filename.display()));
351-
match fs::copy(location, bundle_lib) {
352-
Ok(_) => {},
353-
Err(_) => sess.fatal("unable to create file for bundle lib"),
354-
}
350+
let bundle_lib =
351+
PathBuf::from(format!("{}.bundle.{name}{suffix}", out_filename.display()));
352+
fs::copy(location, bundle_lib).unwrap_or_else(|e| {
353+
sess.fatal(format!("Unable to create bundle lib: {}", e));
354+
});
355355
} else {
356356
ab.add_archive(&location, |_| false).unwrap_or_else(|e| {
357357
sess.fatal(&format!(
@@ -2387,8 +2387,10 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
23872387
{
23882388
let suffix = &sess.target.staticlib_suffix;
23892389
let cratepath = &src.rlib.as_ref().unwrap().0;
2390-
let bundle_lib =
2391-
PathBuf::from(format!("{}.bundle.{name}{suffix}", cratepath.display()));
2390+
let bundle_lib = PathBuf::from(format!(
2391+
"{}.bundle.{name}{suffix}",
2392+
cratepath.display()
2393+
));
23922394
if whole_archive == Some(true) {
23932395
cmd.link_whole_rlib(&fix_windows_verbatim_for_gcc(&bundle_lib));
23942396
} else {

src/test/run-make/native-link-modifier-bundle-split/Makefile

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/test/run-make/native-link-modifier-bundle-split/bundled.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/test/run-make/native-link-modifier-bundle-split/cdylib-bundled.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/test/run-make/native-link-modifier-bundle-split/cdylib-non-bundled.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/test/run-make/native-link-modifier-bundle-split/native-staticlib.c

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/test/run-make/native-link-modifier-bundle-split/non-bundled.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/test/run-make/native-link-modifier-bundle/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# We're using the llvm-nm instead of the system nm to ensure it is compatible
77
# with the LLVM bitcode generated by rustc.
88
NM = "$(LLVM_BIN_DIR)"/llvm-nm
9+
SPLIT = "-Zsplit-bundled-libs"
10+
BUNDLED_LIB = "libbundled.rlib.bundle.native-staticlib.a"
11+
912

1013
all: $(call NATIVE_STATICLIB,native-staticlib)
1114
# Build a staticlib and a rlib, the `native_func` symbol will be bundled into them
@@ -31,3 +34,15 @@ all: $(call NATIVE_STATICLIB,native-staticlib)
3134
# The cdylib will contain the `native_func` symbol in the end
3235
$(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args | $(CGREP) -e '-l[" ]*native-staticlib'
3336
$(NM) $(call DYLIB,cdylib_non_bundled) | $(CGREP) -e "[Tt] _*native_func"
37+
38+
# Build a staticlib and a rlib, the `native_func` symbol will be bundled only into staticlib
39+
$(RUSTC) bundled.rs --crate-type=staticlib --crate-type=rlib $(SPLIT) --crate-name=bundled_split
40+
$(NM) $(TMPDIR)/libbundled_split.a | $(CGREP) -e "T _*native_func"
41+
$(NM) $(TMPDIR)/libbundled_split.a | $(CGREP) -e "U _*native_func"
42+
$(NM) $(TMPDIR)/libbundled_split.rlib | $(CGREP) -ve "T _*native_func"
43+
$(NM) $(TMPDIR)/libbundled_split.rlib | $(CGREP) -e "U _*native_func"
44+
45+
# Build a cdylib, `native-staticlib` will appear on the linker line because it was not bundled previously
46+
# The cdylib will contain the `native_func` symbol in the end
47+
$(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args $(SPLIT) --crate-name=cdylib_non_bundled_split | $(CGREP) -e '-l[" ]*native-staticlib'
48+
$(NM) $(call DYLIB,cdylib_non_bundled_split) | $(CGREP) -e "[Tt] _*native_func"
Binary file not shown.

0 commit comments

Comments
 (0)