about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2024-06-28 14:20:47 -0400
committerOneirical <manchot@videotron.ca>2024-08-01 10:56:48 -0400
commitb485dd14956ea5d744be38cc5201b8a983be7582 (patch)
treeb044d3ff4fa01528f813619204a668d26b40dc31 /tests
parentc0e32983f5b06a6f7d8cc776ccac71de6512ed6d (diff)
downloadrust-b485dd14956ea5d744be38cc5201b8a983be7582.tar.gz
rust-b485dd14956ea5d744be38cc5201b8a983be7582.zip
rewrite reproducible-build-2 to rmake
Diffstat (limited to 'tests')
-rw-r--r--tests/run-make/reproducible-build-2/Makefile27
-rw-r--r--tests/run-make/reproducible-build-2/rmake.rs45
2 files changed, 45 insertions, 27 deletions
diff --git a/tests/run-make/reproducible-build-2/Makefile b/tests/run-make/reproducible-build-2/Makefile
deleted file mode 100644
index 68fcac8b47f..00000000000
--- a/tests/run-make/reproducible-build-2/Makefile
+++ /dev/null
@@ -1,27 +0,0 @@
-# ignore-cross-compile
-include ../tools.mk
-
-# ignore-musl
-# ignore-windows
-# Objects are reproducible but their path is not.
-
-all:  \
-	fat_lto \
-	sysroot
-
-fat_lto:
-	rm -rf $(TMPDIR) && mkdir $(TMPDIR)
-	$(RUSTC) reproducible-build-aux.rs
-	$(RUSTC) reproducible-build.rs -C lto=fat
-	cp $(TMPDIR)/reproducible-build $(TMPDIR)/reproducible-build-a
-	$(RUSTC) reproducible-build.rs -C lto=fat
-	cmp "$(TMPDIR)/reproducible-build-a" "$(TMPDIR)/reproducible-build" || exit 1
-
-sysroot:
-	rm -rf $(TMPDIR) && mkdir $(TMPDIR)
-	$(RUSTC) reproducible-build-aux.rs
-	$(RUSTC) reproducible-build.rs --crate-type rlib --sysroot $(shell $(RUSTC) --print sysroot) --remap-path-prefix=$(shell $(RUSTC) --print sysroot)=/sysroot
-	cp -R $(shell $(RUSTC) --print sysroot) $(TMPDIR)/sysroot
-	cp $(TMPDIR)/libreproducible_build.rlib $(TMPDIR)/libfoo.rlib
-	$(RUSTC) reproducible-build.rs --crate-type rlib --sysroot $(TMPDIR)/sysroot --remap-path-prefix=$(TMPDIR)/sysroot=/sysroot
-	cmp "$(TMPDIR)/libreproducible_build.rlib" "$(TMPDIR)/libfoo.rlib" || exit 1
diff --git a/tests/run-make/reproducible-build-2/rmake.rs b/tests/run-make/reproducible-build-2/rmake.rs
new file mode 100644
index 00000000000..6286b607605
--- /dev/null
+++ b/tests/run-make/reproducible-build-2/rmake.rs
@@ -0,0 +1,45 @@
+// Builds with fat link-time-optimizations and the --sysroot flag used to be
+// non-deterministic - that means, compiling twice with no changes would create
+// slightly different outputs. This has been fixed by #63352 and #63505.
+// Test 1: Compile with fat-lto twice, check that both compilation outputs are identical.
+// Test 2: Compile with sysroot, then change the sysroot path from absolute to relative.
+// Outputs should be identical.
+// See https://github.com/rust-lang/rust/issues/34902
+
+//FIXME(Oneirical): excluded ignore-musl ignore-windows ignore-cross-compile
+
+use run_make_support::{fs_wrapper, rust_lib_name, rustc};
+
+fn main() {
+    // test 1: fat lto
+    rustc().input("reproducible-build-aux.rs").run();
+    rustc().input("reproducible-build.rs").arg("-Clto=fat").run();
+    fs_wrapper::rename("reproducible-build", "reproducible-build-a");
+    rustc().input("reproducible-build.rs").arg("-Clto=fat").run();
+    assert_eq!(fs_wrapper::read("reproducible-build"), fs_wrapper::read("reproducible-build-a"));
+
+    // test 2: sysroot
+    let sysroot = rustc().print("sysroot").run().stdout_utf8();
+    let sysroot = sysroot.trim();
+
+    rustc().input("reproducible-build-aux.rs").run();
+    rustc()
+        .input("reproducible-build.rs")
+        .crate_type("rlib")
+        .sysroot(&sysroot)
+        .arg(format!("--remap-path-prefix={sysroot}=/sysroot"))
+        .run();
+    fs_wrapper::copy_dir_all(&sysroot, "sysroot");
+    fs_wrapper::rename(rust_lib_name("reproducible_build"), rust_lib_name("foo"));
+    rustc()
+        .input("reproducible-build.rs")
+        .crate_type("rlib")
+        .sysroot("sysroot")
+        .arg("--remap-path-prefix=/sysroot=/sysroot")
+        .run();
+
+    assert_eq!(
+        fs_wrapper::read(rust_lib_name("reproducible_build")),
+        fs_wrapper::read(rust_lib_name("foo"))
+    );
+}