Skip to content

Commit

Permalink
Rollup merge of rust-lang#130739 - jieyouxu:stage0_run_make, r=Kobzol
Browse files Browse the repository at this point in the history
Pass bootstrap cargo when `--stage 0` and `COMPILETEST_FORCE_STAGE0`

Follow-up to rust-lang#130642 (comment) to make sure that when

```
$ COMPILETEST_FORCE_STAGE0=1 ./x test run-make --stage 0
```

is used, bootstrap cargo is used in order to avoid building stage 1 rustc. Note that run-make tests are usually not written with `--stage 0` in mind and some tests may rely on stage1 rustc (nightly) behavior, and it is expected that some tests will fail under this invocation.

cc `@bjorn3` can you please test if this suits your needs for `cg_clif` to avoid the unnecessary stage1 rustc rebuild?

r? bootstrap
  • Loading branch information
compiler-errors authored Sep 24, 2024
2 parents 3975a95 + 6d8150f commit dcd099e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 69 deletions.
13 changes: 9 additions & 4 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1730,8 +1730,15 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
let is_rustdoc = suite.ends_with("rustdoc-ui") || suite.ends_with("rustdoc-js");

if mode == "run-make" {
let cargo = builder.ensure(tool::Cargo { compiler, target: compiler.host });
cmd.arg("--cargo-path").arg(cargo);
let cargo_path = if builder.top_stage == 0 {
// If we're using `--stage 0`, we should provide the bootstrap cargo.
builder.initial_cargo.clone()
} else {
// We need to properly build cargo using the suitable stage compiler.
builder.ensure(tool::Cargo { compiler, target: compiler.host })
};

cmd.arg("--cargo-path").arg(cargo_path);
}

// Avoid depending on rustdoc when we don't need it.
Expand Down Expand Up @@ -2088,8 +2095,6 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
cmd.arg("--rustfix-coverage");
}

cmd.env("BOOTSTRAP_CARGO", &builder.initial_cargo);

cmd.arg("--channel").arg(&builder.config.channel);

if !builder.config.omit_git_hash {
Expand Down
5 changes: 3 additions & 2 deletions src/tools/run-make-support/src/external_deps/cargo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::command::Command;
use crate::env_var;

/// Returns a command that can be used to invoke Cargo.
/// Returns a command that can be used to invoke cargo. The cargo is provided by compiletest
/// through the `CARGO` env var.
pub fn cargo() -> Command {
Command::new(env_var("BOOTSTRAP_CARGO"))
Command::new(env_var("CARGO"))
}
58 changes: 25 additions & 33 deletions tests/run-make/compiler-builtins/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,38 @@
#![deny(warnings)]

use std::collections::HashSet;
use std::path::PathBuf;

use run_make_support::object::read::Object;
use run_make_support::object::read::archive::ArchiveFile;
use run_make_support::object::{ObjectSection, ObjectSymbol, RelocationTarget};
use run_make_support::rfs::{read, read_dir};
use run_make_support::{cmd, env_var, object};
use run_make_support::{cargo, env_var, object, path, target};

fn main() {
let target_dir = PathBuf::from("target");
let target = env_var("TARGET");

println!("Testing compiler_builtins for {}", target);

let manifest_path = PathBuf::from("Cargo.toml");

let path = env_var("PATH");
let rustc = env_var("RUSTC");
let cargo = env_var("CARGO");
let mut cmd = cmd(cargo);
cmd.args(&[
"build",
"--manifest-path",
manifest_path.to_str().unwrap(),
"-Zbuild-std=core",
"--target",
&target,
])
.env("PATH", path)
.env("RUSTC", rustc)
.env("RUSTFLAGS", "-Copt-level=0 -Cdebug-assertions=yes")
.env("CARGO_TARGET_DIR", &target_dir)
.env("RUSTC_BOOTSTRAP", "1")
// Visual Studio 2022 requires that the LIB env var be set so it can
// find the Windows SDK.
.env("LIB", std::env::var("LIB").unwrap_or_default());

cmd.run();

let rlibs_path = target_dir.join(target).join("debug").join("deps");
let target_dir = path("target");

println!("Testing compiler_builtins for {}", target());

cargo()
.args(&[
"build",
"--manifest-path",
"Cargo.toml",
"-Zbuild-std=core",
"--target",
&target(),
])
.env("PATH", env_var("PATH"))
.env("RUSTC", env_var("RUSTC"))
.env("RUSTFLAGS", "-Copt-level=0 -Cdebug-assertions=yes")
.env("CARGO_TARGET_DIR", &target_dir)
.env("RUSTC_BOOTSTRAP", "1")
// Visual Studio 2022 requires that the LIB env var be set so it can
// find the Windows SDK.
.env("LIB", std::env::var("LIB").unwrap_or_default())
.run();

let rlibs_path = target_dir.join(target()).join("debug").join("deps");
let compiler_builtins_rlib = read_dir(rlibs_path)
.find_map(|e| {
let path = e.unwrap().path();
Expand Down
48 changes: 18 additions & 30 deletions tests/run-make/thumb-none-cortex-m/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
//@ only-thumb

use std::path::PathBuf;

use run_make_support::rfs::create_dir;
use run_make_support::{cmd, env_var, target};
use run_make_support::{cargo, cmd, env, env_var, target};

const CRATE: &str = "cortex-m";
const CRATE_URL: &str = "https://github.com/rust-embedded/cortex-m";
Expand All @@ -28,32 +25,23 @@ fn main() {
// See below link for git usage:
// https://stackoverflow.com/questions/3489173#14091182
cmd("git").args(["clone", CRATE_URL, CRATE]).run();
std::env::set_current_dir(CRATE).unwrap();
env::set_current_dir(CRATE);
cmd("git").args(["reset", "--hard", CRATE_SHA1]).run();

let target_dir = PathBuf::from("target");
let manifest_path = PathBuf::from("Cargo.toml");

let path = env_var("PATH");
let rustc = env_var("RUSTC");
let cargo = env_var("CARGO");
// FIXME: extract cargo invocations to a proper command
// https://github.com/rust-lang/rust/issues/128734
let mut cmd = cmd(cargo);
cmd.args(&[
"build",
"--manifest-path",
manifest_path.to_str().unwrap(),
"-Zbuild-std=core",
"--target",
&target(),
])
.env("PATH", path)
.env("RUSTC", rustc)
.env("CARGO_TARGET_DIR", &target_dir)
// Don't make lints fatal, but they need to at least warn
// or they break Cargo's target info parsing.
.env("RUSTFLAGS", "-Copt-level=0 -Cdebug-assertions=yes --cap-lints=warn");

cmd.run();
cargo()
.args(&[
"build",
"--manifest-path",
"Cargo.toml",
"-Zbuild-std=core",
"--target",
&target(),
])
.env("PATH", env_var("PATH"))
.env("RUSTC", env_var("RUSTC"))
.env("CARGO_TARGET_DIR", "target")
// Don't make lints fatal, but they need to at least warn
// or they break Cargo's target info parsing.
.env("RUSTFLAGS", "-Copt-level=0 -Cdebug-assertions=yes --cap-lints=warn")
.run();
}

0 comments on commit dcd099e

Please sign in to comment.