Skip to content

Commit

Permalink
rewrite native-link-modifier-bundle to rmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Aug 13, 2024
1 parent 2b8e93d commit 30fa7f6
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 47 deletions.
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ run-make/libtest-junit/Makefile
run-make/libtest-thread-limit/Makefile
run-make/macos-deployment-target/Makefile
run-make/min-global-align/Makefile
run-make/native-link-modifier-bundle/Makefile
run-make/no-alloc-shim/Makefile
run-make/remap-path-prefix-dwarf/Makefile
run-make/reproducible-build/Makefile
Expand Down
38 changes: 0 additions & 38 deletions tests/run-make/native-link-modifier-bundle/Makefile

This file was deleted.

90 changes: 90 additions & 0 deletions tests/run-make/native-link-modifier-bundle/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// This test exercises the `bundle` link argument, which can be turned on or off.

// 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.
// See https://github.com/rust-lang/rust/pull/95818

//@ ignore-cross-compile
// Reason: cross-compilation fails to export native symbols

use run_make_support::{
build_native_static_lib, dynamic_lib_name, is_msvc, llvm_nm, rust_lib_name, rustc,
static_lib_name,
};

fn main() {
build_native_static_lib("native-staticlib");
// Build a staticlib and a rlib, the `native_func` symbol will be bundled into them
rustc().input("bundled.rs").crate_type("staticlib").crate_type("rlib").run();
llvm_nm()
.input(static_lib_name("bundled"))
.run()
.assert_stdout_contains_regex("T _*native_func");
llvm_nm()
.input(static_lib_name("bundled"))
.run()
.assert_stdout_contains_regex("U _*native_func");
llvm_nm().input(rust_lib_name("bundled")).run().assert_stdout_contains_regex("T _*native_func");
llvm_nm().input(rust_lib_name("bundled")).run().assert_stdout_contains_regex("U _*native_func");

// Build a staticlib and a rlib, the `native_func` symbol will not be bundled into it
build_native_static_lib("native-staticlib");
rustc().input("non-bundled.rs").crate_type("staticlib").crate_type("rlib").run();
llvm_nm()
.input(static_lib_name("non_bundled"))
.run()
.assert_stdout_not_contains_regex("T _*native_func");
llvm_nm()
.input(static_lib_name("non_bundled"))
.run()
.assert_stdout_contains_regex("U _*native_func");
llvm_nm()
.input(rust_lib_name("non_bundled"))
.run()
.assert_stdout_not_contains_regex("T _*native_func");
llvm_nm()
.input(rust_lib_name("non_bundled"))
.run()
.assert_stdout_contains_regex("U _*native_func");

// This part of the test does not function on Windows MSVC - no symbols are printed.
if !is_msvc() {
// 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()
.input("cdylib-bundled.rs")
.crate_type("cdylib")
.print("link-args")
.run()
.assert_stdout_not_contains(r#"-l[" ]*native-staticlib"#);
llvm_nm()
.input(dynamic_lib_name("cdylib_bundled"))
.run()
.assert_stdout_contains_regex("[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()
.input("cdylib-non-bundled.rs")
.crate_type("cdylib")
.print("link-args")
.run()
.assert_stdout_contains_regex(r#"-l[" ]*native-staticlib"#);
llvm_nm()
.input(dynamic_lib_name("cdylib_non_bundled"))
.run()
.assert_stdout_contains_regex("[Tt] _*native_func");
}
}
19 changes: 11 additions & 8 deletions tests/run-make/rlib-format-packed-bundled-libs/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
// that is what this test checks.
// See https://github.com/rust-lang/rust/pull/100101

// FIXME(Oneirical): MSVC and cross-compile
//@ ignore-cross-compile
// Reason: cross-compilation fails to export native symbols

use run_make_support::{
bin_name, build_native_static_lib, cwd, filename_contains, llvm_ar, llvm_nm, rfs,
bin_name, build_native_static_lib, cwd, filename_contains, is_msvc, llvm_ar, llvm_nm, rfs,
rust_lib_name, rustc, shallow_find_files,
};

Expand Down Expand Up @@ -72,10 +73,12 @@ fn main() {
.run()
.assert_stdout_contains_regex("native_dep_1.*native_dep_2.*native_dep_3");

//FIXME(Oneirical): This part will apparently fail on MSVC
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f1");
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f2");
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f3");
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*rust_dep_local");
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*rust_dep_up");
// The binary "main" will not contain any symbols on MSVC.
if !is_msvc() {
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f1");
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f2");
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*native_f3");
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*rust_dep_local");
llvm_nm().input(bin_name("main")).run().assert_stdout_contains_regex("T.*rust_dep_up");
}
}

0 comments on commit 30fa7f6

Please sign in to comment.