Skip to content

Commit

Permalink
Auto merge of rust-lang#128075 - Oneirical:try-your-damnetest, r=<try>
Browse files Browse the repository at this point in the history
Migrate `rlib-format-packed-bundled-libs-2`, `native-link-modifier-whole-archive` and `no-builtins-attribute` `run-make` tests to rmake

Part of rust-lang#121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html).

Please try:

try-job: x86_64-msvc
try-job: test-various
  • Loading branch information
bors committed Jul 23, 2024
2 parents d111ccd + 3347dfb commit 1a2928b
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 92 deletions.
23 changes: 23 additions & 0 deletions src/tools/run-make-support/src/external_deps/cc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ pub fn cc() -> Cc {
Cc::new()
}

/// Construct a new platform-specific CXX compiler invocation.
/// CXX_DEFAULT_FLAGS is passed from compiletest.
#[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)]
Expand Down Expand Up @@ -44,6 +51,22 @@ impl Cc {
Self { cmd }
}

/// 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");

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<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg(path.as_ref());
Expand Down
2 changes: 1 addition & 1 deletion src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_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::{
Expand Down
3 changes: 0 additions & 3 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ run-make/lto-linkage-used-attr/Makefile
run-make/macos-deployment-target/Makefile
run-make/min-global-align/Makefile
run-make/native-link-modifier-bundle/Makefile
run-make/native-link-modifier-whole-archive/Makefile
run-make/no-alloc-shim/Makefile
run-make/no-builtins-attribute/Makefile
run-make/no-duplicate-libs/Makefile
run-make/panic-abort-eh_frame/Makefile
run-make/pdb-buildinfo-cl-cmd/Makefile
Expand All @@ -68,7 +66,6 @@ run-make/redundant-libs/Makefile
run-make/remap-path-prefix-dwarf/Makefile
run-make/reproducible-build-2/Makefile
run-make/reproducible-build/Makefile
run-make/rlib-format-packed-bundled-libs-2/Makefile
run-make/rlib-format-packed-bundled-libs/Makefile
run-make/sanitizer-cdylib-link/Makefile
run-make/sanitizer-dylib-link/Makefile
Expand Down
52 changes: 0 additions & 52 deletions tests/run-make/native-link-modifier-whole-archive/Makefile

This file was deleted.

86 changes: 86 additions & 0 deletions tests/run-make/native-link-modifier-whole-archive/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// This test case makes sure that native libraries are linked with appropriate semantics
// when the `[+-]bundle,[+-]whole-archive` modifiers are applied to them.
// The test works by checking that the resulting executables produce the expected output,
// part of which is emitted by otherwise unreferenced C code. If +whole-archive didn't work
// that code would never make it into the final executable and we'd thus be missing some
// of the output.
// See https://github.com/rust-lang/rust/issues/88085

//@ ignore-cross-compile
// Reason: compiling C++ code does not work well when cross-compiling
// plus, the compiled binary is executed

use run_make_support::{cxx, is_msvc, llvm_ar, run, run_with_args, rustc, static_lib_name};

fn main() {
let mut cxx = cxx();
if is_msvc() {
cxx.arg("-EHs");
}
cxx.input("c_static_lib_with_constructor.cpp")
.arg("-c")
.out_exe("libc_static_lib_with_constructor")
.run();

let mut llvm_ar = llvm_ar();
llvm_ar.obj_to_ar();
if is_msvc() {
llvm_ar
.output_input(
static_lib_name("c_static_lib_with_constructor"),
"libc_static_lib_with_constructor.obj",
)
.run();
} else {
llvm_ar
.output_input(
static_lib_name("c_static_lib_with_constructor"),
"libc_static_lib_with_constructor",
)
.run();
}

// Native lib linked directly into executable
rustc()
.input("directly_linked.rs")
.arg("-lstatic:+whole-archive=c_static_lib_with_constructor")
.run();

// Native lib linked into test executable, +whole-archive
rustc()
.input("directly_linked_test_plus_whole_archive.rs")
.arg("--test")
.arg("-lstatic:+whole-archive=c_static_lib_with_constructor")
.run();

// Native lib linked into test executable, -whole-archive
rustc()
.input("directly_linked_test_minus_whole_archive.rs")
.arg("--test")
.arg("-lstatic:-whole-archive=c_static_lib_with_constructor")
.run();

// Native lib linked into rlib with via commandline
rustc()
.input("rlib_with_cmdline_native_lib.rs")
.crate_type("rlib")
.arg("-lstatic:-bundle,+whole-archive=c_static_lib_with_constructor")
.run();
// Native lib linked into RLIB via `-l static:-bundle,+whole-archive`
// RLIB linked into executable
rustc().input("indirectly_linked.rs").run();

// Native lib linked into rlib via `#[link()]` attribute on extern block.
rustc().input("native_lib_in_src.rs").crate_type("rlib").run();
// Native lib linked into RLIB via #[link] attribute, RLIB linked into executable
rustc().input("indirectly_linked_via_attr.rs").run();

run("directly_linked").assert_stdout_contains("static-initializer.directly_linked.");
run_with_args("directly_linked_test_plus_whole_archive", &["--nocapture"])
.assert_stdout_contains("static-initializer.");
run_with_args("directly_linked_test_minus_whole_archive", &["--nocapture"])
.assert_stdout_not_contains("static-initializer.");
run("indirectly_linked").assert_stdout_contains("static-initializer.indirectly_linked.");
run("indirectly_linked_via_attr")
.assert_stdout_contains("static-initializer.native_lib_in_src.");
}
9 changes: 0 additions & 9 deletions tests/run-make/no-builtins-attribute/Makefile

This file was deleted.

13 changes: 13 additions & 0 deletions tests/run-make/no-builtins-attribute/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// `no_builtins` is an attribute related to LLVM's optimizations. In order to ensure that it has an
// effect on link-time optimizations (LTO), it should be added to function declarations in a crate.
// This test uses the `llvm-filecheck` tool to determine that this attribute is successfully
// being added to these function declarations.
// See https://github.com/rust-lang/rust/pull/113716

use run_make_support::{llvm_filecheck, rfs, rustc};

fn main() {
rustc().input("no_builtins.rs").emit("link").run();
rustc().input("main.rs").emit("llvm-ir").run();
llvm_filecheck().patterns("filecheck.main.txt").stdin(rfs::read("main.ll")).run();
}
27 changes: 0 additions & 27 deletions tests/run-make/rlib-format-packed-bundled-libs-2/Makefile

This file was deleted.

32 changes: 32 additions & 0 deletions tests/run-make/rlib-format-packed-bundled-libs-2/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// `-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.
// This test simply checks that this flag can be passed alongside verbatim syntax
// in rustc flags without a compilation failure or the removal of expected symbols.
// See https://github.com/rust-lang/rust/pull/100101

//FIXME(Oneirical): try it on test-various

use run_make_support::{llvm_ar, llvm_readobj, regex, rfs, rust_lib_name, rustc};

fn main() {
// Build a strangely named dependency.
rustc().input("native_dep.rs").crate_type("staticlib").output("native_dep.ext").run();

rustc().input("rust_dep.rs").crate_type("rlib").arg("-Zpacked_bundled_libs").run();
let symbols = llvm_readobj().symbols().input(rust_lib_name("rust_dep")).run().stdout_utf8();
let re = regex::Regex::new("U.*native_f1").unwrap();
assert!(re.is_match(&symbols));
llvm_ar()
.arg("t")
.arg(rust_lib_name("rust_dep"))
.run()
.assert_stdout_contains("native_dep.ext");

// Ensure the compiler does not use files it should not be aware of.
rfs::remove_file("native_dep.ext");
rustc()
.input("main.rs")
.extern_("rust_dep", rust_lib_name("rust_dep"))
.arg("-Zpacked_bundled_libs")
.run();
}

0 comments on commit 1a2928b

Please sign in to comment.