From c424bc61bfe5836b4dc78526001b402592256e0f Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 19 Jul 2024 15:51:49 -0400 Subject: [PATCH] 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 840bfa0d2b4..5eeeb887444 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 a4bb9056346..085120764b4 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 dc1b0906278..114709cc300 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 74917570a01..00000000000 --- 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 00000000000..9bee91232ce --- /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"); +}