| author | bors <bors@rust-lang.org> 2024-06-29 17:50:06 UTC |
| committer | bors <bors@rust-lang.org> 2024-06-29 17:50:06 UTC |
| log | d1b7355d3d7b4ead564dbecb1d240fcc74fff21b |
| tree | 022bc5ed2de759c160df26fc4696a2438813571e |
| parent | 19a1d2b404e9f56eb1792cc06ec3c86b5a260b41 |
| parent | 17950828420fa2068214b906e9fea98a771e64e8 |
Migrate `remap-path-prefix`, `debug-assertions` and `emit-stack-sizes` `run-make` tests to rmake
Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html).
Needs OSX/MSVC try jobs.
try-job: aarch64-apple
try-job: x86_64-msvc12 files changed, 165 insertions(+), 78 deletions(-)
Cargo.lock+1| ... | ... | @@ -3401,6 +3401,7 @@ name = "run_make_support" |
| 3401 | 3401 | version = "0.2.0" |
| 3402 | 3402 | dependencies = [ |
| 3403 | 3403 | "ar", |
| 3404 | "bstr", | |
| 3404 | 3405 | "gimli 0.28.1", |
| 3405 | 3406 | "object 0.34.0", |
| 3406 | 3407 | "regex", |
src/tools/run-make-support/Cargo.toml+1| ... | ... | @@ -4,6 +4,7 @@ version = "0.2.0" |
| 4 | 4 | edition = "2021" |
| 5 | 5 | |
| 6 | 6 | [dependencies] |
| 7 | bstr = "1.6.0" | |
| 7 | 8 | object = "0.34.0" |
| 8 | 9 | similar = "2.5.0" |
| 9 | 10 | wasmparser = "0.118.2" |
src/tools/run-make-support/src/lib.rs+1| ... | ... | @@ -21,6 +21,7 @@ use std::io; |
| 21 | 21 | use std::panic; |
| 22 | 22 | use std::path::{Path, PathBuf}; |
| 23 | 23 | |
| 24 | pub use bstr; | |
| 24 | 25 | pub use gimli; |
| 25 | 26 | pub use object; |
| 26 | 27 | pub use regex; |
src/tools/run-make-support/src/rustc.rs+11| ... | ... | @@ -106,6 +106,17 @@ impl Rustc { |
| 106 | 106 | self |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | /// Remap source path prefixes in all output. | |
| 110 | pub fn remap_path_prefix<P: AsRef<Path>>(&mut self, from: P, to: P) -> &mut Self { | |
| 111 | let from = from.as_ref().to_string_lossy(); | |
| 112 | let to = to.as_ref().to_string_lossy(); | |
| 113 | ||
| 114 | self.cmd.arg("--remap-path-prefix"); | |
| 115 | self.cmd.arg(format!("{from}={to}")); | |
| 116 | ||
| 117 | self | |
| 118 | } | |
| 119 | ||
| 109 | 120 | /// Specify path to the input file. |
| 110 | 121 | pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self { |
| 111 | 122 | self.cmd.arg(path.as_ref()); |
src/tools/tidy/src/allowed_run_make_makefiles.txt-3| ... | ... | @@ -18,7 +18,6 @@ run-make/cross-lang-lto-clang/Makefile |
| 18 | 18 | run-make/cross-lang-lto-pgo-smoketest/Makefile |
| 19 | 19 | run-make/cross-lang-lto-upstream-rlibs/Makefile |
| 20 | 20 | run-make/cross-lang-lto/Makefile |
| 21 | run-make/debug-assertions/Makefile | |
| 22 | 21 | run-make/dep-info-doesnt-run-much/Makefile |
| 23 | 22 | run-make/dep-info-spaces/Makefile |
| 24 | 23 | run-make/dep-info/Makefile |
| ... | ... | @@ -27,7 +26,6 @@ run-make/dump-mono-stats/Makefile |
| 27 | 26 | run-make/dylib-chain/Makefile |
| 28 | 27 | run-make/emit-path-unhashed/Makefile |
| 29 | 28 | run-make/emit-shared-files/Makefile |
| 30 | run-make/emit-stack-sizes/Makefile | |
| 31 | 29 | run-make/emit-to-stdout/Makefile |
| 32 | 30 | run-make/env-dep-info/Makefile |
| 33 | 31 | run-make/export-executable-symbols/Makefile |
| ... | ... | @@ -136,7 +134,6 @@ run-make/raw-dylib-link-ordinal/Makefile |
| 136 | 134 | run-make/raw-dylib-stdcall-ordinal/Makefile |
| 137 | 135 | run-make/redundant-libs/Makefile |
| 138 | 136 | run-make/remap-path-prefix-dwarf/Makefile |
| 139 | run-make/remap-path-prefix/Makefile | |
| 140 | 137 | run-make/reproducible-build-2/Makefile |
| 141 | 138 | run-make/reproducible-build/Makefile |
| 142 | 139 | run-make/return-non-c-like-enum-from-c/Makefile |
tests/run-make/debug-assertions/Makefile deleted-27| ... | ... | @@ -1,27 +0,0 @@ |
| 1 | # ignore-cross-compile | |
| 2 | # needs-unwind | |
| 3 | include ../tools.mk | |
| 4 | ||
| 5 | all: | |
| 6 | 	$(RUSTC) debug.rs -C debug-assertions=no | |
| 7 | 	$(call RUN,debug) good | |
| 8 | 	$(RUSTC) debug.rs -C opt-level=0 | |
| 9 | 	$(call RUN,debug) bad | |
| 10 | 	$(RUSTC) debug.rs -C opt-level=1 | |
| 11 | 	$(call RUN,debug) good | |
| 12 | 	$(RUSTC) debug.rs -C opt-level=2 | |
| 13 | 	$(call RUN,debug) good | |
| 14 | 	$(RUSTC) debug.rs -C opt-level=3 | |
| 15 | 	$(call RUN,debug) good | |
| 16 | 	$(RUSTC) debug.rs -C opt-level=s | |
| 17 | 	$(call RUN,debug) good | |
| 18 | 	$(RUSTC) debug.rs -C opt-level=z | |
| 19 | 	$(call RUN,debug) good | |
| 20 | 	$(RUSTC) debug.rs -O | |
| 21 | 	$(call RUN,debug) good | |
| 22 | 	$(RUSTC) debug.rs | |
| 23 | 	$(call RUN,debug) bad | |
| 24 | 	$(RUSTC) debug.rs -C debug-assertions=yes -O | |
| 25 | 	$(call RUN,debug) bad | |
| 26 | 	$(RUSTC) debug.rs -C debug-assertions=yes -C opt-level=1 | |
| 27 | 	$(call RUN,debug) bad |
tests/run-make/debug-assertions/debug.rs+4-6| ... | ... | @@ -1,15 +1,13 @@ |
| 1 | #![allow(internal_features)] | |
| 1 | 2 | #![feature(rustc_attrs)] |
| 2 | 3 | #![deny(warnings)] |
| 3 | 4 | |
| 4 | use std::env; | |
| 5 | 5 | use std::thread; |
| 6 | 6 | |
| 7 | 7 | fn main() { |
| 8 | let should_fail = env::args().nth(1) == Some("bad".to_string()); | |
| 9 | ||
| 10 | assert_eq!(thread::spawn(debug_assert_eq).join().is_err(), should_fail); | |
| 11 | assert_eq!(thread::spawn(debug_assert).join().is_err(), should_fail); | |
| 12 | assert_eq!(thread::spawn(overflow).join().is_err(), should_fail); | |
| 8 | assert!(thread::spawn(debug_assert_eq).join().is_ok()); | |
| 9 | assert!(thread::spawn(debug_assert).join().is_ok()); | |
| 10 | assert!(thread::spawn(overflow).join().is_ok()); | |
| 13 | 11 | } |
| 14 | 12 | |
| 15 | 13 | fn debug_assert_eq() { |
tests/run-make/debug-assertions/rmake.rs created+37| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | // debug.rs contains some "debug assertion" statements which | |
| 2 | // should only be enabled in either non-optimized builds or when | |
| 3 | // `-C debug-assertions` is set to yes. These debug assertions | |
| 4 | // are guaranteed to fail, so this test checks that the run command | |
| 5 | // fails where debug assertions should be activated, and succeeds where | |
| 6 | // debug assertions should be disabled. | |
| 7 | // See https://github.com/rust-lang/rust/pull/22980 | |
| 8 | ||
| 9 | //@ ignore-cross-compile | |
| 10 | //@ needs-unwind | |
| 11 | ||
| 12 | use run_make_support::{run, run_fail, rustc}; | |
| 13 | ||
| 14 | fn main() { | |
| 15 | rustc().input("debug.rs").arg("-Cdebug-assertions=no").run(); | |
| 16 | run("debug"); | |
| 17 | rustc().input("debug.rs").opt_level("0").run(); | |
| 18 | run_fail("debug"); | |
| 19 | rustc().input("debug.rs").opt_level("1").run(); | |
| 20 | run("debug"); | |
| 21 | rustc().input("debug.rs").opt_level("2").run(); | |
| 22 | run("debug"); | |
| 23 | rustc().input("debug.rs").opt_level("3").run(); | |
| 24 | run("debug"); | |
| 25 | rustc().input("debug.rs").opt_level("s").run(); | |
| 26 | run("debug"); | |
| 27 | rustc().input("debug.rs").opt_level("z").run(); | |
| 28 | run("debug"); | |
| 29 | rustc().input("debug.rs").opt().run(); | |
| 30 | run("debug"); | |
| 31 | rustc().input("debug.rs").run(); | |
| 32 | run_fail("debug"); | |
| 33 | rustc().input("debug.rs").opt().arg("-Cdebug-assertions=yes").run(); | |
| 34 | run_fail("debug"); | |
| 35 | rustc().input("debug.rs").opt_level("1").arg("-Cdebug-assertions=yes").run(); | |
| 36 | run_fail("debug"); | |
| 37 | } |
tests/run-make/emit-stack-sizes/Makefile deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | include ../tools.mk | |
| 2 | ||
| 3 | # ignore-windows | |
| 4 | # ignore-apple | |
| 5 | # | |
| 6 | # This feature only works when the output object format is ELF so we ignore | |
| 7 | # Apple and Windows | |
| 8 | ||
| 9 | # check that the .stack_sizes section is generated | |
| 10 | all: | |
| 11 | 	$(RUSTC) -C opt-level=3 -Z emit-stack-sizes --emit=obj foo.rs | |
| 12 | 	size -A $(TMPDIR)/foo.o | $(CGREP) .stack_sizes |
tests/run-make/emit-stack-sizes/rmake.rs created+23| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | // Running rustc with the -Z emit-stack-sizes | |
| 2 | // flag enables diagnostics to seek stack overflows | |
| 3 | // at compile time. This test compiles a rust file | |
| 4 | // with this flag, then checks that the output object | |
| 5 | // file contains the section "stack_sizes", where | |
| 6 | // this diagnostics information should be located. | |
| 7 | // See https://github.com/rust-lang/rust/pull/51946 | |
| 8 | ||
| 9 | //@ ignore-windows | |
| 10 | //@ ignore-apple | |
| 11 | // Reason: this feature only works when the output object format is ELF. | |
| 12 | // This won't be the case on Windows/OSX - for example, OSX produces a Mach-O binary. | |
| 13 | ||
| 14 | use run_make_support::{llvm_readobj, rustc}; | |
| 15 | ||
| 16 | fn main() { | |
| 17 | rustc().opt_level("3").arg("-Zemit-stack-sizes").emit("obj").input("foo.rs").run(); | |
| 18 | llvm_readobj() | |
| 19 | .arg("--section-headers") | |
| 20 | .input("foo.o") | |
| 21 | .run() | |
| 22 | .assert_stdout_contains(".stack_sizes"); | |
| 23 | } |
tests/run-make/remap-path-prefix/Makefile deleted-30| ... | ... | @@ -1,30 +0,0 @@ |
| 1 | include ../tools.mk | |
| 2 | ||
| 3 | # ignore-windows | |
| 4 | ||
| 5 | ifeq ($(UNAME),Darwin) | |
| 6 | DEBUGINFOOPTS := -Csplit-debuginfo=off | |
| 7 | else | |
| 8 | DEBUGINFOOPTS := | |
| 9 | endif | |
| 10 | ||
| 11 | all: remap remap-with-scope | |
| 12 | ||
| 13 | # Checks if remapping works if the remap-from string contains path to the working directory plus more | |
| 14 | remap: | |
| 15 | 	$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux --crate-type=lib --emit=metadata auxiliary/lib.rs | |
| 16 | 	grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1 | |
| 17 | 	! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1 | |
| 18 | ||
| 19 | remap-with-scope: | |
| 20 | 	$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=object $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs | |
| 21 | 	grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1 | |
| 22 | 	! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1 | |
| 23 | ||
| 24 | 	$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=macro $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs | |
| 25 | 	grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1 | |
| 26 | 	! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1 | |
| 27 | ||
| 28 | 	$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=diagnostics,object $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs | |
| 29 | 	grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1 | |
| 30 | 	! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1 |
tests/run-make/remap-path-prefix/rmake.rs created+87| ... | ... | @@ -0,0 +1,87 @@ |
| 1 | // Generating metadata alongside remap-path-prefix would fail to actually remap the path | |
| 2 | // in the metadata. After this was fixed in #85344, this test checks that "auxiliary" is being | |
| 3 | // successfully remapped to "/the/aux" in the rmeta files. | |
| 4 | // See https://github.com/rust-lang/rust/pull/85344 | |
| 5 | ||
| 6 | use run_make_support::bstr::ByteSlice; | |
| 7 | use run_make_support::{bstr, fs_wrapper, is_darwin, rustc}; | |
| 8 | ||
| 9 | fn main() { | |
| 10 | let mut out_simple = rustc(); | |
| 11 | let mut out_object = rustc(); | |
| 12 | let mut out_macro = rustc(); | |
| 13 | let mut out_diagobj = rustc(); | |
| 14 | out_simple | |
| 15 | .remap_path_prefix("auxiliary", "/the/aux") | |
| 16 | .crate_type("lib") | |
| 17 | .emit("metadata") | |
| 18 | .input("auxiliary/lib.rs"); | |
| 19 | out_object | |
| 20 | .remap_path_prefix("auxiliary", "/the/aux") | |
| 21 | .crate_type("lib") | |
| 22 | .emit("metadata") | |
| 23 | .input("auxiliary/lib.rs"); | |
| 24 | out_macro | |
| 25 | .remap_path_prefix("auxiliary", "/the/aux") | |
| 26 | .crate_type("lib") | |
| 27 | .emit("metadata") | |
| 28 | .input("auxiliary/lib.rs"); | |
| 29 | out_diagobj | |
| 30 | .remap_path_prefix("auxiliary", "/the/aux") | |
| 31 | .crate_type("lib") | |
| 32 | .emit("metadata") | |
| 33 | .input("auxiliary/lib.rs"); | |
| 34 | ||
| 35 | out_simple.run(); | |
| 36 | rmeta_contains("/the/aux/lib.rs"); | |
| 37 | rmeta_not_contains("auxiliary"); | |
| 38 | ||
| 39 | out_object.arg("-Zremap-path-scope=object"); | |
| 40 | out_macro.arg("-Zremap-path-scope=macro"); | |
| 41 | out_diagobj.arg("-Zremap-path-scope=diagnostics,object"); | |
| 42 | if is_darwin() { | |
| 43 | out_object.arg("-Csplit-debuginfo=off"); | |
| 44 | out_macro.arg("-Csplit-debuginfo=off"); | |
| 45 | out_diagobj.arg("-Csplit-debuginfo=off"); | |
| 46 | } | |
| 47 | ||
| 48 | out_object.run(); | |
| 49 | rmeta_contains("/the/aux/lib.rs"); | |
| 50 | rmeta_not_contains("auxiliary"); | |
| 51 | out_macro.run(); | |
| 52 | rmeta_contains("/the/aux/lib.rs"); | |
| 53 | rmeta_not_contains("auxiliary"); | |
| 54 | out_diagobj.run(); | |
| 55 | rmeta_contains("/the/aux/lib.rs"); | |
| 56 | rmeta_not_contains("auxiliary"); | |
| 57 | } | |
| 58 | ||
| 59 | //FIXME(Oneirical): These could be generalized into run_make_support | |
| 60 | // helper functions. | |
| 61 | fn rmeta_contains(expected: &str) { | |
| 62 | // Normalize to account for path differences in Windows. | |
| 63 | if !bstr::BString::from(fs_wrapper::read("liblib.rmeta")) | |
| 64 | .replace(b"\\", b"/") | |
| 65 | .contains_str(expected) | |
| 66 | { | |
| 67 | eprintln!("=== FILE CONTENTS (LOSSY) ==="); | |
| 68 | eprintln!("{}", String::from_utf8_lossy(&fs_wrapper::read("liblib.rmeta"))); | |
| 69 | eprintln!("=== SPECIFIED TEXT ==="); | |
| 70 | eprintln!("{}", expected); | |
| 71 | panic!("specified text was not found in file"); | |
| 72 | } | |
| 73 | } | |
| 74 | ||
| 75 | fn rmeta_not_contains(expected: &str) { | |
| 76 | // Normalize to account for path differences in Windows. | |
| 77 | if bstr::BString::from(fs_wrapper::read("liblib.rmeta")) | |
| 78 | .replace(b"\\", b"/") | |
| 79 | .contains_str(expected) | |
| 80 | { | |
| 81 | eprintln!("=== FILE CONTENTS (LOSSY) ==="); | |
| 82 | eprintln!("{}", String::from_utf8_lossy(&fs_wrapper::read("liblib.rmeta"))); | |
| 83 | eprintln!("=== SPECIFIED TEXT ==="); | |
| 84 | eprintln!("{}", expected); | |
| 85 | panic!("specified text was not found in file"); | |
| 86 | } | |
| 87 | } |