Skip to content

Commit

Permalink
Auto merge of #2564 - RalfJung:no-more-xargo, r=oli-obk
Browse files Browse the repository at this point in the history
use rustc-build-sysroot instead of xargo

This uses my crate https://github.com/RalfJung/rustc-build-sysroot instead of xargo to do the sysroot builds. That has the advantage of simplifying the Miri setup process and saving significant amounts of CI time for Miri users (since they don't have to build xargo from source all the time). Also xargo has a lot more functionality than we need so this should be easier to maintain and tweak for our needs.

With this, Miri no longer honors the `XARGO_RUST_SRC` env var to determine where the standard library sources are taken from. The README anyway says to use `MIRI_LIB_SRC` which will still work.

TODO:
- [x] add support for no-std targets
- [x] test that this works in the rustc repo
  • Loading branch information
bors committed Sep 28, 2022
2 parents 6d4ef31 + a773d47 commit b4e028d
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 219 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ jobs:
# contains package information of crates installed via `cargo install`.
~/.cargo/.crates.toml
~/.cargo/.crates2.json
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock', 'cargo-miri/src/version.rs') }}
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo

- name: Install rustup-toolchain-install-master and xargo
- name: Install rustup-toolchain-install-master
if: ${{ steps.cache.outputs.cache-hit == 'false' }}
shell: bash
run: |
cargo install -f rustup-toolchain-install-master
cargo install -f xargo
- name: Install "master" toolchain
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ for you. If you don't want all of these to happen, you can add individual `.auto
## Building and testing Miri

Invoking Miri requires getting a bunch of flags right and setting up a custom
sysroot with xargo. The `miri` script takes care of that for you. With the
sysroot. The `miri` script takes care of that for you. With the
build environment prepared, compiling Miri is just one command away:

```
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ binaries, and as such worth documenting:
some compiler flags to prepare the code for interpretation; with `host`, this is not done.
This environment variable is useful to be sure that the compiled `rlib`s are compatible
with Miri.
* `MIRI_CALLED_FROM_XARGO` is set during the Miri-induced `xargo` sysroot build,
* `MIRI_CALLED_FROM_SETUP` is set during the Miri sysroot build,
which will re-invoke `cargo-miri` as the `rustc` to use for this build.
* `MIRI_CALLED_FROM_RUSTDOC` when set to any value tells `cargo-miri` that it is
running as a child process of `rustdoc`, which invokes it twice for each doc-test
Expand Down
74 changes: 74 additions & 0 deletions cargo-miri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cargo-miri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ directories = "3"
rustc_version = "0.4"
serde_json = "1.0.40"
cargo_metadata = "0.15.0"
rustc-build-sysroot = "0.2.1"

# A noop dependency that changes in the Rust repository, it's a bit of a hack.
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`
Expand Down
7 changes: 3 additions & 4 deletions cargo-miri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mod util;
mod arg;
mod phases;
mod setup;
mod version;

use std::{env, iter};

Expand All @@ -23,8 +22,8 @@ fn main() {
// Dispatch to `cargo-miri` phase. Here is a rough idea of "who calls who".
//
// Initially, we are invoked as `cargo-miri miri run/test`. We first run the setup phase:
// - We call `xargo`, and set `RUSTC` back to us, together with `MIRI_CALLED_FROM_XARGO`,
// so that xargo's rustc invocations end up in `phase_rustc` with `RustcPhase::Setup`.
// - We use `rustc-build-sysroot`, and set `RUSTC` back to us, together with `MIRI_CALLED_FROM_SETUP`,
// so that the sysroot build rustc invocations end up in `phase_rustc` with `RustcPhase::Setup`.
// There we then call the Miri driver with `MIRI_BE_RUSTC` to perform the actual build.
//
// Then we call `cargo run/test`, exactly forwarding all user flags, plus some configuration so
Expand Down Expand Up @@ -53,7 +52,7 @@ fn main() {
// the Miri driver for interpretation.

// Dispatch running as part of sysroot compilation.
if env::var_os("MIRI_CALLED_FROM_XARGO").is_some() {
if env::var_os("MIRI_CALLED_FROM_SETUP").is_some() {
phase_rustc(args, RustcPhase::Setup);
return;
}
Expand Down
16 changes: 10 additions & 6 deletions cargo-miri/src/phases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::io::BufReader;
use std::path::PathBuf;
use std::process::Command;

use rustc_version::VersionMeta;

use crate::{setup::*, util::*};

const CARGO_MIRI_HELP: &str = r#"Runs binary crates and tests in Miri
Expand Down Expand Up @@ -90,12 +92,14 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
let verbose = num_arg_flag("-v");

// Determine the involved architectures.
let host = version_info().host;
let rustc_version = VersionMeta::for_command(miri_for_host())
.expect("failed to determine underlying rustc version of Miri");
let host = &rustc_version.host;
let target = get_arg_flag_value("--target");
let target = target.as_ref().unwrap_or(&host);
let target = target.as_ref().unwrap_or(host);

// We always setup.
setup(&subcommand, &host, target);
setup(&subcommand, target, &rustc_version);

// Invoke actual cargo for the job, but with different flags.
// We re-use `cargo test` and `cargo run`, which makes target and binary handling very easy but
Expand Down Expand Up @@ -146,7 +150,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {
if get_arg_flag_value("--target").is_none() {
// No target given. Explicitly pick the host.
cmd.arg("--target");
cmd.arg(&host);
cmd.arg(host);
}

// Set ourselves as runner for al binaries invoked by cargo.
Expand Down Expand Up @@ -204,7 +208,7 @@ pub fn phase_cargo_miri(mut args: impl Iterator<Item = String>) {

#[derive(Debug, Copy, Clone, PartialEq)]
pub enum RustcPhase {
/// `rustc` called via `xargo` for sysroot build.
/// `rustc` called during sysroot build.
Setup,
/// `rustc` called by `cargo` for regular build.
Build,
Expand Down Expand Up @@ -264,7 +268,7 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
let verbose = std::env::var("MIRI_VERBOSE")
.map_or(0, |verbose| verbose.parse().expect("verbosity flag must be an integer"));
let target_crate = is_target_crate();
// Determine whether this is cargo/xargo invoking rustc to get some infos.
// Determine whether this is cargo invoking rustc to get some infos.
let info_query = get_arg_flag_value("--print").is_some() || has_arg_flag("-vV");

let store_json = |info: CrateRunInfo| {
Expand Down
Loading

0 comments on commit b4e028d

Please sign in to comment.