Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rust-lang/rust
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cbc3f76d68d049c9089d7c1e8f8bcae5040f6cce
Choose a base ref
..
head repository: rust-lang/rust
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 990d60e1df5c0580264d864f25aab226011c722c
Choose a head ref
23 changes: 14 additions & 9 deletions src/tools/run-make-support/src/external_deps/rustc.rs
Original file line number Diff line number Diff line change
@@ -33,9 +33,15 @@ pub fn aux_build() -> Rustc {
#[must_use]
pub struct Rustc {
cmd: Command,
target: Option<String>,
}

crate::macros::impl_common_helpers!(Rustc);
/// Only fill in the target just before execution, so that it can be overridden.
crate::macros::impl_common_helpers!(Rustc, |rustc: &mut Rustc| {
if let Some(target) = &rustc.target {
rustc.cmd.arg(&format!("--target={target}"));
}
});

pub fn rustc_path() -> String {
env_var("RUSTC")
@@ -59,25 +65,23 @@ impl Rustc {
let mut cmd = setup_common();
cmd.arg("-L").arg(cwd());

let mut rustc = Self { cmd };
// Automatically support cross-compilation
rustc.target(target());
rustc
// Automatically default to cross-compilation
Self { cmd, target: Some(target()) }
}

/// Construct a bare `rustc` invocation with no flags set.
#[track_caller]
pub fn bare() -> Self {
let cmd = setup_common();
Self { cmd }
Self { cmd, target: None }
}

/// Construct a new `rustc` invocation with `aux_build` preset (setting `--crate-type=lib`).
#[track_caller]
pub fn new_aux_build() -> Self {
let mut cmd = setup_common();
cmd.arg("--crate-type=lib");
Self { cmd }
Self { cmd, target: None }
}

// Argument provider methods
@@ -253,8 +257,9 @@ impl Rustc {

/// Specify the target triple, or a path to a custom target json spec file.
pub fn target<S: AsRef<str>>(&mut self, target: S) -> &mut Self {
let target = target.as_ref();
self.cmd.arg(format!("--target={target}"));
// We store the target as a separate field, so that it can be specified multiple times.
// This is in particular useful to override the default target set in Rustc::new().
self.target = Some(target.as_ref().to_string());
self
}

9 changes: 9 additions & 0 deletions src/tools/run-make-support/src/macros.rs
Original file line number Diff line number Diff line change
@@ -23,10 +23,16 @@
/// }
/// ```
///
/// You can pass an optional second parameter which should be a function that is passed
/// `&mut self` just before the command is executed.
///
/// [`Command`]: crate::command::Command
/// [`CompletedProcess`]: crate::command::CompletedProcess
macro_rules! impl_common_helpers {
($wrapper: ident) => {
$crate::macros::impl_common_helpers!($wrapper, |_| {});
};
($wrapper: ident, $before_exec: expr) => {
impl $wrapper {
/// Specify an environment variable.
pub fn env<K, V>(&mut self, key: K, value: V) -> &mut Self
@@ -118,12 +124,14 @@ macro_rules! impl_common_helpers {
/// Run the constructed command and assert that it is successfully run.
#[track_caller]
pub fn run(&mut self) -> crate::command::CompletedProcess {
$before_exec(&mut *self);
self.cmd.run()
}

/// Run the constructed command and assert that it does not successfully run.
#[track_caller]
pub fn run_fail(&mut self) -> crate::command::CompletedProcess {
$before_exec(&mut *self);
self.cmd.run_fail()
}

@@ -133,6 +141,7 @@ macro_rules! impl_common_helpers {
/// whenever possible.
#[track_caller]
pub fn run_unchecked(&mut self) -> crate::command::CompletedProcess {
$before_exec(&mut *self);
self.cmd.run_unchecked()
}

4 changes: 2 additions & 2 deletions tests/run-make/amdgpu-kd/rmake.rs
Original file line number Diff line number Diff line change
@@ -6,10 +6,10 @@
//@ needs-llvm-components: amdgpu
//@ needs-rust-lld

use run_make_support::{bare_rustc, llvm_readobj};
use run_make_support::{llvm_readobj, rustc};

fn main() {
bare_rustc()
rustc()
.crate_name("foo")
.target("amdgcn-amd-amdhsa")
.arg("-Ctarget-cpu=gfx900")
4 changes: 2 additions & 2 deletions tests/run-make/atomic-lock-free/rmake.rs
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@

//@ only-linux

use run_make_support::{bare_rustc, llvm_components_contain, llvm_readobj};
use run_make_support::{llvm_components_contain, llvm_readobj, rustc};

fn compile(target: &str) {
bare_rustc().input("atomic_lock_free.rs").target(target).run();
rustc().input("atomic_lock_free.rs").target(target).run();
}

fn check() {
4 changes: 2 additions & 2 deletions tests/run-make/avr-rjmp-offset/rmake.rs
Original file line number Diff line number Diff line change
@@ -15,10 +15,10 @@
// crashes... so I'm going to disable this test for windows for now.
//@ ignore-windows-gnu

use run_make_support::{bare_rustc, llvm_objdump};
use run_make_support::{llvm_objdump, rustc};

fn main() {
bare_rustc()
rustc()
.input("avr-rjmp-offsets.rs")
.opt_level("s")
.panic("abort")
4 changes: 2 additions & 2 deletions tests/run-make/comment-section/rmake.rs
Original file line number Diff line number Diff line change
@@ -7,12 +7,12 @@
// FIXME(jieyouxu): check cross-compile setup
//@ ignore-cross-compile

use run_make_support::{bare_rustc, cwd, env_var, llvm_readobj, rfs};
use run_make_support::{cwd, env_var, llvm_readobj, rfs, rustc};

fn main() {
let target = env_var("TARGET");

bare_rustc()
rustc()
.arg("-")
.stdin_buf("fn main() {}")
.emit("link,obj")
1 change: 1 addition & 0 deletions tests/run-make/llvm-ident/rmake.rs
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ fn main() {
.arg("-Csave-temps")
.codegen_units(16)
.opt_level("2")
.target(&env_var("TARGET"))
.stdin_buf("fn main(){}")
.run();

10 changes: 3 additions & 7 deletions tests/run-make/min-global-align/rmake.rs
Original file line number Diff line number Diff line change
@@ -7,21 +7,17 @@
// Reason: this test is specific to linux, considering compilation is targeted
// towards linux architectures only.

use run_make_support::{assert_count_is, bare_rustc, llvm_components_contain, rfs};
use run_make_support::{assert_count_is, llvm_components_contain, rfs, rustc};

fn main() {
// Most targets are happy with default alignment -- take i686 for example.
if llvm_components_contain("x86") {
bare_rustc()
.target("i686-unknown-linux-gnu")
.emit("llvm-ir")
.input("min_global_align.rs")
.run();
rustc().target("i686-unknown-linux-gnu").emit("llvm-ir").input("min_global_align.rs").run();
assert_count_is(3, rfs::read_to_string("min_global_align.ll"), "align 1");
}
// SystemZ requires even alignment for PC-relative addressing.
if llvm_components_contain("systemz") {
bare_rustc()
rustc()
.target("s390x-unknown-linux-gnu")
.emit("llvm-ir")
.input("min_global_align.rs")
15 changes: 5 additions & 10 deletions tests/run-make/mismatching-target-triples/rmake.rs
Original file line number Diff line number Diff line change
@@ -5,16 +5,11 @@
// error message is used.
// See https://github.com/rust-lang/rust/issues/10814

use run_make_support::bare_rustc;
use run_make_support::rustc;

fn main() {
bare_rustc().input("foo.rs").target("i686-unknown-linux-gnu").run();
bare_rustc()
.input("bar.rs")
.library_search_path(".")
.target("x86_64-unknown-linux-gnu")
.run_fail()
.assert_stderr_contains(
r#"couldn't find crate `foo` with expected target triple x86_64-unknown-linux-gnu"#,
);
rustc().input("foo.rs").target("i686-unknown-linux-gnu").run();
rustc().input("bar.rs").target("x86_64-unknown-linux-gnu").run_fail().assert_stderr_contains(
r#"couldn't find crate `foo` with expected target triple x86_64-unknown-linux-gnu"#,
);
}
4 changes: 2 additions & 2 deletions tests/run-make/musl-default-linking/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use run_make_support::{bare_rustc, rustc, serde_json};
use run_make_support::{rustc, serde_json};

// Please do NOT add more targets to this list!
// Per https://github.com/rust-lang/compiler-team/issues/422,
@@ -36,7 +36,7 @@ fn main() {
continue;
}

let target_spec_json = bare_rustc()
let target_spec_json = rustc()
.print("target-spec-json")
.target(target)
.arg("-Zunstable-options")
6 changes: 3 additions & 3 deletions tests/run-make/print-cfg/rmake.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ use std::collections::HashSet;
use std::iter::FromIterator;
use std::path::PathBuf;

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

struct PrintCfg {
target: &'static str,
@@ -86,7 +86,7 @@ fn check(PrintCfg { target, includes, disallow }: PrintCfg) {

// --print=cfg
{
let output = bare_rustc().target(target).print("cfg").run();
let output = rustc().target(target).print("cfg").run();
let stdout = output.stdout_utf8();

check_(&stdout, includes, disallow);
@@ -96,7 +96,7 @@ fn check(PrintCfg { target, includes, disallow }: PrintCfg) {
{
let tmp_path = PathBuf::from(format!("{target}.cfg"));

bare_rustc().target(target).print(&format!("cfg={}", tmp_path.display())).run();
rustc().target(target).print(&format!("cfg={}", tmp_path.display())).run();

let output = rfs::read_to_string(&tmp_path);

10 changes: 3 additions & 7 deletions tests/run-make/print-target-cpus-native/rmake.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
//@ needs-llvm-components: aarch64 x86
// FIXME(#132514): Is needs-llvm-components actually necessary for this test?

use run_make_support::{assert_contains_regex, bare_rustc, rfs, rustc, target};
use run_make_support::{assert_contains_regex, rfs, rustc, target};

// Test that when querying `--print=target-cpus` for a target with the same
// architecture as the host, the first CPU is "native" with a suitable remark.
@@ -17,7 +17,7 @@ fn main() {

// With an explicit target that happens to be the host.
let host = target(); // Because of ignore-cross-compile, assume host == target.
bare_rustc().print("target-cpus").target(host).run().assert_stdout_contains_regex(expected);
rustc().print("target-cpus").target(host).run().assert_stdout_contains_regex(expected);

// With an explicit output path.
rustc().print("target-cpus=./xyzzy.txt").run().assert_stdout_equals("");
@@ -34,10 +34,6 @@ fn main() {
};
for target in cross_targets {
println!("Trying target: {target}");
bare_rustc()
.print("target-cpus")
.target(target)
.run()
.assert_stdout_contains_regex(expected);
rustc().print("target-cpus").target(target).run().assert_stdout_contains_regex(expected);
}
}
9 changes: 3 additions & 6 deletions tests/run-make/print-to-output/rmake.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@

use std::path::PathBuf;

use run_make_support::{bare_rustc, rfs, target};
use run_make_support::{rfs, rustc, target};

struct Option<'a> {
target: &'a str,
@@ -44,16 +44,13 @@ fn check(args: Option) {
}

// --print={option}
let stdout = bare_rustc().target(args.target).print(args.option).run().stdout_utf8();
let stdout = rustc().target(args.target).print(args.option).run().stdout_utf8();

// --print={option}=PATH
let output = {
let tmp_path = PathBuf::from(format!("{}.txt", args.option));

bare_rustc()
.target(args.target)
.print(&format!("{}={}", args.option, tmp_path.display()))
.run();
rustc().target(args.target).print(&format!("{}={}", args.option, tmp_path.display())).run();

rfs::read_to_string(&tmp_path)
};
6 changes: 3 additions & 3 deletions tests/run-make/rust-lld-custom-target/rmake.rs
Original file line number Diff line number Diff line change
@@ -8,13 +8,13 @@
//@ needs-rust-lld
//@ only-x86_64-unknown-linux-gnu

use run_make_support::bare_rustc;
use run_make_support::regex::Regex;
use run_make_support::rustc;

fn main() {
// Compile to a custom target spec with rust-lld enabled by default. We'll check that by asking
// the linker to display its version number with a link-arg.
let output = bare_rustc()
let output = rustc()
.crate_type("cdylib")
.arg("-Wlinker-messages")
.target("custom-target.json")
@@ -28,7 +28,7 @@ fn main() {
);

// But it can also be disabled via linker features.
let output = bare_rustc()
let output = rustc()
.crate_type("cdylib")
.arg("-Wlinker-messages")
.target("custom-target.json")
4 changes: 2 additions & 2 deletions tests/run-make/rustdoc-target-spec-json-path/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Test that rustdoc will properly canonicalize the target spec json path just like rustc.

use run_make_support::{bare_rustc, cwd, rustdoc};
use run_make_support::{cwd, rustc, rustdoc};

fn main() {
let out_dir = "rustdoc-target-spec-json-path";
bare_rustc().crate_type("lib").input("dummy_core.rs").target("target.json").run();
rustc().crate_type("lib").input("dummy_core.rs").target("target.json").run();
rustdoc()
.input("my_crate.rs")
.out_dir(out_dir)
4 changes: 2 additions & 2 deletions tests/run-make/simd-ffi/rmake.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
// Note that this test does not check linking or binary execution.
// See https://github.com/rust-lang/rust/pull/21233

use run_make_support::{bare_rustc, llvm_components_contain};
use run_make_support::{llvm_components_contain, rustc};

fn main() {
let mut targets = Vec::new();
@@ -52,7 +52,7 @@ fn main() {
// enabled by-default for i686 and ARM; these features will be invalid
// on some platforms, but LLVM just prints a warning so that's fine for
// now.
bare_rustc()
rustc()
.target(&target)
.emit("llvm-ir,asm")
.input("simd.rs")
Loading