From 4dad2a332bfd2dcbd20e99cd70c6cd63f9c92be0 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 19 Jul 2024 15:24:52 -0400 Subject: [PATCH 1/3] rewrite interdependent-c-libraries to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../interdependent-c-libraries/Makefile | 15 --------------- .../interdependent-c-libraries/rmake.rs | 19 +++++++++++++++++++ 3 files changed, 19 insertions(+), 16 deletions(-) delete mode 100644 tests/run-make/interdependent-c-libraries/Makefile create mode 100644 tests/run-make/interdependent-c-libraries/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 36f7f68ef7b35..dc1b09062781b 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -21,7 +21,6 @@ run-make/foreign-exceptions/Makefile run-make/foreign-rust-exceptions/Makefile run-make/incr-add-rust-src-component/Makefile run-make/incr-foreign-head-span/Makefile -run-make/interdependent-c-libraries/Makefile run-make/issue-35164/Makefile run-make/issue-36710/Makefile run-make/issue-47551/Makefile diff --git a/tests/run-make/interdependent-c-libraries/Makefile b/tests/run-make/interdependent-c-libraries/Makefile deleted file mode 100644 index 53a696d82bf12..0000000000000 --- a/tests/run-make/interdependent-c-libraries/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -# The rust crate foo will link to the native library foo, while the rust crate -# bar will link to the native library bar. There is also a dependency between -# the native library bar to the natibe library foo. -# -# This test ensures that the ordering of -lfoo and -lbar on the command line is -# correct to complete the linkage. If passed as "-lfoo -lbar", then the 'foo' -# library will be stripped out, and the linkage will fail. - -all: $(call NATIVE_STATICLIB,foo) $(call NATIVE_STATICLIB,bar) - $(RUSTC) foo.rs - $(RUSTC) bar.rs - $(RUSTC) main.rs --print link-args diff --git a/tests/run-make/interdependent-c-libraries/rmake.rs b/tests/run-make/interdependent-c-libraries/rmake.rs new file mode 100644 index 0000000000000..cd3759d2d71d3 --- /dev/null +++ b/tests/run-make/interdependent-c-libraries/rmake.rs @@ -0,0 +1,19 @@ +// The rust crate foo will link to the native library foo, while the rust crate +// bar will link to the native library bar. There is also a dependency between +// the native library bar to the natibe library foo. +// This test ensures that the ordering of -lfoo and -lbar on the command line is +// correct to complete the linkage. If passed as "-lfoo -lbar", then the 'foo' +// library will be stripped out, and the linkage will fail. +// See https://github.com/rust-lang/rust/commit/e6072fa0c4c22d62acf3dcb78c8ee260a1368bd7 + +// FIXME(Oneirical): test-various + +use run_make_support::{build_native_static_lib, rustc}; + +fn main() { + build_native_static_lib("foo"); + build_native_static_lib("bar"); + rustc().input("foo.rs").run(); + rustc().input("bar.rs").run(); + rustc().input("main.rs").print("link-args").run(); +} From c424bc61bfe5836b4dc78526001b402592256e0f Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 19 Jul 2024 15:51:49 -0400 Subject: [PATCH 2/3] rewrite compiler-rt-works-on-mingw to rmake --- .../run-make-support/src/external_deps/cc.rs | 21 +++++++++++++++++++ src/tools/run-make-support/src/lib.rs | 2 +- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../compiler-rt-works-on-mingw/Makefile | 9 -------- .../compiler-rt-works-on-mingw/rmake.rs | 15 +++++++++++++ 5 files changed, 37 insertions(+), 11 deletions(-) delete mode 100644 tests/run-make/compiler-rt-works-on-mingw/Makefile create mode 100644 tests/run-make/compiler-rt-works-on-mingw/rmake.rs diff --git a/src/tools/run-make-support/src/external_deps/cc.rs b/src/tools/run-make-support/src/external_deps/cc.rs index 840bfa0d2b46e..5eeeb887444fa 100644 --- a/src/tools/run-make-support/src/external_deps/cc.rs +++ b/src/tools/run-make-support/src/external_deps/cc.rs @@ -15,6 +15,12 @@ pub fn cc() -> Cc { Cc::new() } +/// Construct a new platform-specific CXX compiler invocation. +#[track_caller] +pub fn cxx() -> Cc { + Cc::new_cxx() +} + /// A platform-specific C compiler invocation builder. The specific C compiler used is /// passed down from compiletest. #[derive(Debug)] @@ -44,6 +50,21 @@ impl Cc { Self { cmd } } + /// Construct a new platform-specific CXX compiler invocation. + #[track_caller] + pub fn new_cxx() -> Self { + let compiler = env_var("CXX"); + + let mut cmd = Command::new(compiler); + + let default_cflags = env_var("CXX_DEFAULT_FLAGS"); + for flag in default_cflags.split(char::is_whitespace) { + cmd.arg(flag); + } + + Self { cmd } + } + /// Specify path of the input file. pub fn input>(&mut self, path: P) -> &mut Self { self.cmd.arg(path.as_ref()); diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index a4bb9056346d9..085120764b463 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -44,7 +44,7 @@ pub use external_deps::{c_build, cc, clang, htmldocck, llvm, python, rustc, rust // These rely on external dependencies. pub use c_build::{build_native_dynamic_lib, build_native_static_lib}; -pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc}; +pub use cc::{cc, cxx, extra_c_flags, extra_cxx_flags, Cc}; pub use clang::{clang, Clang}; pub use htmldocck::htmldocck; pub use llvm::{ diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index dc1b09062781b..114709cc3005e 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -2,7 +2,6 @@ run-make/branch-protection-check-IBT/Makefile run-make/c-unwind-abi-catch-lib-panic/Makefile run-make/cat-and-grep-sanity-check/Makefile run-make/cdylib-dylib-linkage/Makefile -run-make/compiler-rt-works-on-mingw/Makefile run-make/cross-lang-lto-clang/Makefile run-make/cross-lang-lto-pgo-smoketest/Makefile run-make/cross-lang-lto-upstream-rlibs/Makefile diff --git a/tests/run-make/compiler-rt-works-on-mingw/Makefile b/tests/run-make/compiler-rt-works-on-mingw/Makefile deleted file mode 100644 index 74917570a0142..0000000000000 --- a/tests/run-make/compiler-rt-works-on-mingw/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -include ../tools.mk - -# only-windows-gnu - -all: - $(CXX) foo.cpp -c -o $(TMPDIR)/foo.o - $(AR) crus $(TMPDIR)/libfoo.a $(TMPDIR)/foo.o - $(RUSTC) foo.rs -lfoo -lstdc++ - $(call RUN,foo) diff --git a/tests/run-make/compiler-rt-works-on-mingw/rmake.rs b/tests/run-make/compiler-rt-works-on-mingw/rmake.rs new file mode 100644 index 0000000000000..9bee91232ce66 --- /dev/null +++ b/tests/run-make/compiler-rt-works-on-mingw/rmake.rs @@ -0,0 +1,15 @@ +// `compiler-rt` ("runtime") is a suite of LLVM features compatible with rustc. +// After building it was enabled on Windows-gnu in #29874, this test checks +// that compilation and execution with it are successful. +// See https://github.com/rust-lang/rust/pull/29478 + +//@ only-windows-gnu + +use run_make_support::{cxx, is_msvc, llvm_ar, run, rustc, static_lib_name}; + +fn main() { + cxx().input("foo.cpp").arg("-c").out_exe("foo.o").run(); + llvm_ar().obj_to_ar().output_input(static_lib_name("foo"), "foo.o").run(); + rustc().input("foo.rs").arg("-lfoo").arg("-lstdc++").run(); + run("foo"); +} From e175b83fd55e9901eb659a7acd7a8add830eef12 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 19 Jul 2024 16:01:06 -0400 Subject: [PATCH 3/3] rewrite incr-foreign-head-span to rmake --- src/tools/compiletest/src/command-list.rs | 1 + .../run-make-support/src/external_deps/cc.rs | 2 ++ .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../compiler-rt-works-on-mingw/rmake.rs | 4 +-- .../run-make/incr-foreign-head-span/Makefile | 21 ---------------- .../run-make/incr-foreign-head-span/rmake.rs | 25 +++++++++++++++++++ .../interdependent-c-libraries/rmake.rs | 4 ++- 7 files changed, 33 insertions(+), 25 deletions(-) delete mode 100644 tests/run-make/incr-foreign-head-span/Makefile create mode 100644 tests/run-make/incr-foreign-head-span/rmake.rs diff --git a/src/tools/compiletest/src/command-list.rs b/src/tools/compiletest/src/command-list.rs index 6735e9faa7a67..c356f4266f016 100644 --- a/src/tools/compiletest/src/command-list.rs +++ b/src/tools/compiletest/src/command-list.rs @@ -201,6 +201,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ "only-wasm32-wasip1", "only-watchos", "only-windows", + "only-windows-gnu", "only-x86", "only-x86_64", "only-x86_64-fortanix-unknown-sgx", diff --git a/src/tools/run-make-support/src/external_deps/cc.rs b/src/tools/run-make-support/src/external_deps/cc.rs index 5eeeb887444fa..19a89705acc1e 100644 --- a/src/tools/run-make-support/src/external_deps/cc.rs +++ b/src/tools/run-make-support/src/external_deps/cc.rs @@ -16,6 +16,7 @@ pub fn cc() -> Cc { } /// Construct a new platform-specific CXX compiler invocation. +/// CXX_DEFAULT_FLAGS is passed from compiletest. #[track_caller] pub fn cxx() -> Cc { Cc::new_cxx() @@ -51,6 +52,7 @@ impl Cc { } /// Construct a new platform-specific CXX compiler invocation. + /// CXX_DEFAULT_FLAGS is passed from compiletest. #[track_caller] pub fn new_cxx() -> Self { let compiler = env_var("CXX"); diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 114709cc3005e..14e9a83b4c034 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -19,7 +19,6 @@ run-make/foreign-double-unwind/Makefile run-make/foreign-exceptions/Makefile run-make/foreign-rust-exceptions/Makefile run-make/incr-add-rust-src-component/Makefile -run-make/incr-foreign-head-span/Makefile run-make/issue-35164/Makefile run-make/issue-36710/Makefile run-make/issue-47551/Makefile diff --git a/tests/run-make/compiler-rt-works-on-mingw/rmake.rs b/tests/run-make/compiler-rt-works-on-mingw/rmake.rs index 9bee91232ce66..f1b41f96312de 100644 --- a/tests/run-make/compiler-rt-works-on-mingw/rmake.rs +++ b/tests/run-make/compiler-rt-works-on-mingw/rmake.rs @@ -1,6 +1,6 @@ // `compiler-rt` ("runtime") is a suite of LLVM features compatible with rustc. -// After building it was enabled on Windows-gnu in #29874, this test checks -// that compilation and execution with it are successful. +// After building it was enabled on Windows-gnu in #29874, this test is a basic smoke test to +// check if building and linking to it can work at all. // See https://github.com/rust-lang/rust/pull/29478 //@ only-windows-gnu diff --git a/tests/run-make/incr-foreign-head-span/Makefile b/tests/run-make/incr-foreign-head-span/Makefile deleted file mode 100644 index 9be4b0f601c30..0000000000000 --- a/tests/run-make/incr-foreign-head-span/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -include ../tools.mk - -# ignore-none no-std is not supported -# ignore-nvptx64-nvidia-cuda FIXME: can't find crate for 'std' - -# Ensure that modifying a crate on disk (without recompiling it) -# does not cause ICEs in downstream crates. -# Previously, we would call `SourceMap.guess_head_span` on a span -# from an external crate, which would cause us to read an upstream -# source file from disk during compilation of a downstream crate -# See #86480 for more details - -INCR=$(TMPDIR)/incr - -all: - cp first_crate.rs second_crate.rs $(TMPDIR) - $(RUSTC) $(TMPDIR)/first_crate.rs -C incremental=$(INCR) --target $(TARGET) --crate-type lib - $(RUSTC) $(TMPDIR)/second_crate.rs -C incremental=$(INCR) --target $(TARGET) --extern first_crate=$(TMPDIR)/libfirst_crate.rlib --crate-type lib - rm $(TMPDIR)/first_crate.rs - $(RUSTC) $(TMPDIR)/second_crate.rs -C incremental=$(INCR) --target $(TARGET) --cfg second_run --crate-type lib - diff --git a/tests/run-make/incr-foreign-head-span/rmake.rs b/tests/run-make/incr-foreign-head-span/rmake.rs new file mode 100644 index 0000000000000..92e2ed5f8793a --- /dev/null +++ b/tests/run-make/incr-foreign-head-span/rmake.rs @@ -0,0 +1,25 @@ +// Ensure that modifying a crate on disk (without recompiling it) +// does not cause ICEs (internal compiler errors) in downstream crates. +// Previously, we would call `SourceMap.guess_head_span` on a span +// from an external crate, which would cause us to read an upstream +// source file from disk during compilation of a downstream crate. +// See https://github.com/rust-lang/rust/issues/86480 + +//@ ignore-none +// Reason: no-std is not supported +//@ ignore-nvptx64-nvidia-cuda +// Reason: can't find crate for 'std' + +use run_make_support::{rfs, rust_lib_name, rustc}; + +fn main() { + rustc().input("first_crate.rs").incremental("incr").crate_type("lib").run(); + rustc() + .input("second_crate.rs") + .incremental("incr") + .extern_("first_crate", rust_lib_name("first_crate")) + .crate_type("lib") + .run(); + rfs::remove_file("first_crate.rs"); + rustc().input("second_crate.rs").incremental("incr").cfg("second_run").crate_type("lib").run(); +} diff --git a/tests/run-make/interdependent-c-libraries/rmake.rs b/tests/run-make/interdependent-c-libraries/rmake.rs index cd3759d2d71d3..ee8cc76c9ccbe 100644 --- a/tests/run-make/interdependent-c-libraries/rmake.rs +++ b/tests/run-make/interdependent-c-libraries/rmake.rs @@ -6,7 +6,9 @@ // library will be stripped out, and the linkage will fail. // See https://github.com/rust-lang/rust/commit/e6072fa0c4c22d62acf3dcb78c8ee260a1368bd7 -// FIXME(Oneirical): test-various +//@ ignore-cross-compile +// Reason: linkage still fails as the object files produced are not in the correct +// format in the `build_native_static_lib` step use run_make_support::{build_native_static_lib, rustc};