about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-08-12 13:26:25 -0400
committerOneirical <manchot@videotron.ca>2024-08-15 10:17:25 -0400
commit2e4d5bbba7b4efe27b8afca47fef98a2254e684b (patch)
tree51113921393f2cb0081582954fbe62854fd58259 /tests
parent3139ff09e9d07f7700f8d15ed25a231e29c43627 (diff)
downloadrust-2e4d5bbba7b4efe27b8afca47fef98a2254e684b.tar.gz
rust-2e4d5bbba7b4efe27b8afca47fef98a2254e684b.zip
rewrite rlib-format-packed-bundled-libs to rmake
Diffstat (limited to 'tests')
-rw-r--r--tests/run-make/rlib-format-packed-bundled-libs/Makefile39
-rw-r--r--tests/run-make/rlib-format-packed-bundled-libs/rmake.rs81
2 files changed, 81 insertions, 39 deletions
diff --git a/tests/run-make/rlib-format-packed-bundled-libs/Makefile b/tests/run-make/rlib-format-packed-bundled-libs/Makefile
deleted file mode 100644
index f454da67893..00000000000
--- a/tests/run-make/rlib-format-packed-bundled-libs/Makefile
+++ /dev/null
@@ -1,39 +0,0 @@
-include ../tools.mk
-
-# ignore-cross-compile
-
-# Make sure rlib format with -Zpacked_bundled_libs is correct.
-
-# We're using the llvm-nm instead of the system nm to ensure it is compatible
-# with the LLVM bitcode generated by rustc.
-# Except on Windows where piping/IO redirection under MSYS2 is wonky with llvm-nm.
-ifndef IS_WINDOWS
-NM = "$(LLVM_BIN_DIR)"/llvm-nm
-else
-NM = nm
-endif
-
-all: $(call NATIVE_STATICLIB,native_dep_1) $(call NATIVE_STATICLIB,native_dep_2) $(call NATIVE_STATICLIB,native_dep_3)
-	$(RUSTC) rust_dep_up.rs --crate-type=rlib -Zpacked_bundled_libs
-	$(NM) $(TMPDIR)/librust_dep_up.rlib | $(CGREP) -e "U.*native_f2"
-	$(NM) $(TMPDIR)/librust_dep_up.rlib | $(CGREP) -e "U.*native_f3"
-	$(NM) $(TMPDIR)/librust_dep_up.rlib | $(CGREP) -e "T.*rust_dep_up"
-	$(AR) t $(TMPDIR)/librust_dep_up.rlib | $(CGREP) "native_dep_2"
-	$(AR) t $(TMPDIR)/librust_dep_up.rlib | $(CGREP) "native_dep_3"
-	$(RUSTC) rust_dep_local.rs --extern rlib=$(TMPDIR)/librust_dep_up.rlib -Zpacked_bundled_libs --crate-type=rlib
-	$(NM) $(TMPDIR)/librust_dep_local.rlib | $(CGREP) -e "U.*native_f1"
-	$(NM) $(TMPDIR)/librust_dep_local.rlib | $(CGREP) -e "T.*rust_dep_local"
-	$(AR) t $(TMPDIR)/librust_dep_local.rlib | $(CGREP) "native_dep_1"
-
-	# Make sure compiler doesn't use files, that it shouldn't know about.
-	rm $(TMPDIR)/*native_dep_*
-
-	$(RUSTC) main.rs --extern lib=$(TMPDIR)/librust_dep_local.rlib -o $(TMPDIR)/main.exe -Zpacked_bundled_libs --print link-args | $(CGREP) -e "native_dep_1.*native_dep_2.*native_dep_3"
-
-ifndef IS_MSVC
-	$(NM) $(TMPDIR)/main.exe | $(CGREP) -e "T.*native_f1"
-	$(NM) $(TMPDIR)/main.exe | $(CGREP) -e "T.*native_f2"
-	$(NM) $(TMPDIR)/main.exe | $(CGREP) -e "T.*native_f3"
-	$(NM) $(TMPDIR)/main.exe | $(CGREP) -e "T.*rust_dep_local"
-	$(NM) $(TMPDIR)/main.exe | $(CGREP) -e "T.*rust_dep_up"
-endif
diff --git a/tests/run-make/rlib-format-packed-bundled-libs/rmake.rs b/tests/run-make/rlib-format-packed-bundled-libs/rmake.rs
new file mode 100644
index 00000000000..7cd0932ecf3
--- /dev/null
+++ b/tests/run-make/rlib-format-packed-bundled-libs/rmake.rs
@@ -0,0 +1,81 @@
+// `-Z packed_bundled_libs` is an unstable rustc flag that makes the compiler
+// only require a native library and no supplementary object files to compile.
+// Output files compiled with this flag should still contain all expected symbols -
+// that is what this test checks.
+// See https://github.com/rust-lang/rust/pull/100101
+
+// FIXME(Oneirical): MSVC and cross-compile
+
+use run_make_support::{
+    bin_name, build_native_static_lib, cwd, filename_contains, llvm_ar, llvm_nm, rfs,
+    rust_lib_name, rustc, shallow_find_files,
+};
+
+fn main() {
+    build_native_static_lib("native_dep_1");
+    build_native_static_lib("native_dep_2");
+    build_native_static_lib("native_dep_3");
+    rustc().input("rust_dep_up.rs").crate_type("rlib").arg("-Zpacked_bundled_libs").run();
+    llvm_nm()
+        .input(rust_lib_name("rust_dep_up"))
+        .run()
+        .assert_stdout_contains_regex("U.*native_f2");
+    llvm_nm()
+        .input(rust_lib_name("rust_dep_up"))
+        .run()
+        .assert_stdout_contains_regex("U.*native_f3");
+    llvm_nm()
+        .input(rust_lib_name("rust_dep_up"))
+        .run()
+        .assert_stdout_contains_regex("T.*rust_dep_up");
+    llvm_ar()
+        .table_of_contents()
+        .arg(rust_lib_name("rust_dep_up"))
+        .run()
+        .assert_stdout_contains("native_dep_2");
+    llvm_ar()
+        .table_of_contents()
+        .arg(rust_lib_name("rust_dep_up"))
+        .run()
+        .assert_stdout_contains("native_dep_3");
+    rustc()
+        .input("rust_dep_local.rs")
+        .extern_("rlib", rust_lib_name("rust_dep_up"))
+        .arg("-Zpacked_bundled_libs")
+        .crate_type("rlib")
+        .run();
+    llvm_nm()
+        .input(rust_lib_name("rust_dep_local"))
+        .run()
+        .assert_stdout_contains_regex("U.*native_f1");
+    llvm_nm()
+        .input(rust_lib_name("rust_dep_local"))
+        .run()
+        .assert_stdout_contains_regex("T.*rust_dep_local");
+    llvm_ar()
+        .table_of_contents()
+        .arg(rust_lib_name("rust_dep_local"))
+        .run()
+        .assert_stdout_contains("native_dep_1");
+
+    // Ensure the compiler will not use files it should not know about.
+    for file in shallow_find_files(cwd(), |path| filename_contains(path, "native_dep_")) {
+        rfs::remove_file(file);
+    }
+
+    rustc()
+        .input("main.rs")
+        .extern_("lib", rust_lib_name("rust_dep_local"))
+        .output(bin_name("main"))
+        .arg("-Zpacked_bundled_libs")
+        .print("link-args")
+        .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");
+}