2018-11-25 09:08:24 -06:00
|
|
|
#![feature(inner_deref)]
|
|
|
|
|
2017-01-24 06:28:36 -06:00
|
|
|
extern crate cargo_metadata;
|
|
|
|
|
|
|
|
use std::path::{PathBuf, Path};
|
2018-12-15 08:08:03 -06:00
|
|
|
use std::io::{self, Write, BufRead};
|
2017-01-24 06:28:36 -06:00
|
|
|
use std::process::Command;
|
2018-11-25 10:09:49 -06:00
|
|
|
use std::fs::{self, File};
|
2017-01-24 06:28:36 -06:00
|
|
|
|
2019-02-07 06:00:42 -06:00
|
|
|
const CARGO_MIRI_HELP: &str = r#"Interprets bin crates and tests in Miri
|
2017-01-24 06:28:36 -06:00
|
|
|
|
|
|
|
Usage:
|
2019-02-07 06:00:27 -06:00
|
|
|
cargo miri [subcommand] [options] [--] [<miri opts>...]
|
2018-11-25 09:30:11 -06:00
|
|
|
|
|
|
|
Subcommands:
|
|
|
|
run Run binaries (default)
|
|
|
|
test Run tests
|
|
|
|
setup Only perform automatic setup, but without asking questions (for getting a proper libstd)
|
2017-01-24 06:28:36 -06:00
|
|
|
|
|
|
|
Common options:
|
|
|
|
-h, --help Print this message
|
|
|
|
--features Features to compile for the package
|
|
|
|
-V, --version Print version info and exit
|
|
|
|
|
2019-02-07 06:00:27 -06:00
|
|
|
Other [options] are the same as `cargo rustc`. Everything after the "--" is
|
|
|
|
passed verbatim to Miri.
|
2017-01-24 06:28:36 -06:00
|
|
|
|
2019-02-07 06:00:27 -06:00
|
|
|
The config flag `miri` is automatically defined for convenience. You can use
|
2017-01-24 06:28:36 -06:00
|
|
|
it to configure the resource limits
|
|
|
|
|
2019-02-07 06:00:27 -06:00
|
|
|
#![cfg_attr(miri, memory_size = 42)]
|
2017-01-24 06:28:36 -06:00
|
|
|
|
|
|
|
available resource limits are `memory_size`, `step_limit`, `stack_limit`
|
|
|
|
"#;
|
|
|
|
|
2018-11-25 09:30:11 -06:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
2018-11-25 09:08:24 -06:00
|
|
|
enum MiriCommand {
|
|
|
|
Run,
|
|
|
|
Test,
|
|
|
|
Setup,
|
|
|
|
}
|
|
|
|
|
2017-01-24 06:28:36 -06:00
|
|
|
fn show_help() {
|
|
|
|
println!("{}", CARGO_MIRI_HELP);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn show_version() {
|
2018-09-16 08:06:05 -05:00
|
|
|
println!("miri {} ({} {})",
|
|
|
|
env!("CARGO_PKG_VERSION"), env!("VERGEN_SHA_SHORT"), env!("VERGEN_COMMIT_DATE"));
|
2017-01-24 06:28:36 -06:00
|
|
|
}
|
|
|
|
|
2018-11-25 09:30:11 -06:00
|
|
|
fn show_error(msg: String) -> ! {
|
|
|
|
eprintln!("fatal error: {}", msg);
|
|
|
|
std::process::exit(1)
|
|
|
|
}
|
|
|
|
|
2019-02-07 06:00:27 -06:00
|
|
|
// Determines whether a --flag is present
|
|
|
|
fn has_arg_flag(name: &str) -> bool {
|
|
|
|
let mut args = std::env::args().take_while(|val| val != "--");
|
|
|
|
args.any(|val| val == name)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Gets the value of a --flag
|
2018-12-10 02:23:27 -06:00
|
|
|
fn get_arg_flag_value(name: &str) -> Option<String> {
|
|
|
|
// stop searching at `--`
|
2019-02-07 06:00:27 -06:00
|
|
|
let mut args = std::env::args().take_while(|val| val != "--");
|
|
|
|
loop {
|
|
|
|
let arg = match args.next() {
|
|
|
|
Some(arg) => arg,
|
|
|
|
None => return None,
|
|
|
|
};
|
|
|
|
if !arg.starts_with(name) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let suffix = &arg[name.len()..]; // strip leading `name`
|
|
|
|
if suffix.is_empty() {
|
|
|
|
// This argument is exactly `name`, the next one is the value
|
|
|
|
return args.next();
|
|
|
|
} else if suffix.starts_with('=') {
|
|
|
|
// This argument is `name=value`, get the value
|
|
|
|
return Some(suffix[1..].to_owned()); // strip leading `=`
|
|
|
|
}
|
2018-12-10 02:23:27 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn list_targets() -> impl Iterator<Item=cargo_metadata::Target> {
|
2018-11-25 09:08:24 -06:00
|
|
|
// We need to get the manifest, and then the metadata, to enumerate targets.
|
2018-12-10 03:52:59 -06:00
|
|
|
let manifest_path = get_arg_flag_value("--manifest-path").map(|m|
|
|
|
|
Path::new(&m).canonicalize().unwrap()
|
|
|
|
);
|
2018-11-25 09:08:24 -06:00
|
|
|
|
|
|
|
let mut metadata = if let Ok(metadata) = cargo_metadata::metadata(
|
2018-12-10 02:23:27 -06:00
|
|
|
manifest_path.as_ref().map(AsRef::as_ref),
|
2018-11-25 09:08:24 -06:00
|
|
|
)
|
|
|
|
{
|
|
|
|
metadata
|
|
|
|
} else {
|
2018-11-27 01:16:52 -06:00
|
|
|
show_error(format!("error: Could not obtain cargo metadata."));
|
2018-11-25 09:08:24 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
let current_dir = std::env::current_dir();
|
|
|
|
|
|
|
|
let package_index = metadata
|
|
|
|
.packages
|
|
|
|
.iter()
|
|
|
|
.position(|package| {
|
|
|
|
let package_manifest_path = Path::new(&package.manifest_path);
|
|
|
|
if let Some(ref manifest_path) = manifest_path {
|
|
|
|
package_manifest_path == manifest_path
|
|
|
|
} else {
|
|
|
|
let current_dir = current_dir.as_ref().expect(
|
|
|
|
"could not read current directory",
|
|
|
|
);
|
|
|
|
let package_manifest_directory = package_manifest_path.parent().expect(
|
|
|
|
"could not find parent directory of package manifest",
|
|
|
|
);
|
|
|
|
package_manifest_directory == current_dir
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.expect("could not find matching package");
|
|
|
|
let package = metadata.packages.remove(package_index);
|
|
|
|
|
|
|
|
// Finally we got the list of targets to build
|
|
|
|
package.targets.into_iter()
|
|
|
|
}
|
|
|
|
|
2018-12-15 08:08:03 -06:00
|
|
|
fn xargo_version() -> Option<(u32, u32, u32)> {
|
|
|
|
let out = Command::new("xargo").arg("--version").output().ok()?;
|
|
|
|
if !out.status.success() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
// Parse output. The first line looks like "xargo 0.3.12 (b004f1c 2018-12-13)".
|
|
|
|
let line = out.stderr.lines().nth(0)
|
|
|
|
.expect("malformed `xargo --version` output: not at least one line")
|
|
|
|
.expect("malformed `xargo --version` output: error reading first line");
|
2018-12-19 01:41:31 -06:00
|
|
|
let (name, version) = {
|
|
|
|
let mut split = line.split(' ');
|
|
|
|
(split.next().expect("malformed `xargo --version` output: empty"),
|
|
|
|
split.next().expect("malformed `xargo --version` output: not at least two words"))
|
|
|
|
};
|
|
|
|
if name != "xargo" {
|
|
|
|
panic!("malformed `xargo --version` output: application name is not `xargo`");
|
|
|
|
}
|
2018-12-15 08:08:03 -06:00
|
|
|
let mut version_pieces = version.split('.');
|
|
|
|
let major = version_pieces.next()
|
|
|
|
.expect("malformed `xargo --version` output: not a major version piece")
|
|
|
|
.parse()
|
|
|
|
.expect("malformed `xargo --version` output: major version is not an integer");
|
|
|
|
let minor = version_pieces.next()
|
|
|
|
.expect("malformed `xargo --version` output: not a minor version piece")
|
|
|
|
.parse()
|
|
|
|
.expect("malformed `xargo --version` output: minor version is not an integer");
|
|
|
|
let patch = version_pieces.next()
|
|
|
|
.expect("malformed `xargo --version` output: not a patch version piece")
|
|
|
|
.parse()
|
|
|
|
.expect("malformed `xargo --version` output: patch version is not an integer");
|
|
|
|
if !version_pieces.next().is_none() {
|
|
|
|
panic!("malformed `xargo --version` output: more than three pieces in version");
|
|
|
|
}
|
|
|
|
Some((major, minor, patch))
|
|
|
|
}
|
|
|
|
|
2018-11-25 09:30:11 -06:00
|
|
|
fn ask(question: &str) {
|
|
|
|
let mut buf = String::new();
|
|
|
|
print!("{} [Y/n] ", question);
|
|
|
|
io::stdout().flush().unwrap();
|
|
|
|
io::stdin().read_line(&mut buf).unwrap();
|
2018-11-27 01:16:52 -06:00
|
|
|
match buf.trim().to_lowercase().as_ref() {
|
|
|
|
"" | "y" | "yes" => {}, // proceed
|
|
|
|
"n" | "no" => show_error(format!("Aborting as per your request")),
|
2018-11-25 09:30:11 -06:00
|
|
|
a => show_error(format!("I do not understand `{}`", a))
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Perform the setup requires to make `cargo miri` work: Getting a custom-built libstd. Then sets MIRI_SYSROOT.
|
|
|
|
/// Skipped if MIRI_SYSROOT is already set, in that case we expect the user has done all this already.
|
|
|
|
fn setup(ask_user: bool) {
|
|
|
|
if std::env::var("MIRI_SYSROOT").is_ok() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// First, we need xargo
|
2018-12-15 08:08:03 -06:00
|
|
|
let xargo = xargo_version();
|
|
|
|
if xargo.map_or(true, |v| v < (0, 3, 13)) {
|
2018-11-25 09:30:11 -06:00
|
|
|
if ask_user {
|
2018-12-15 08:08:03 -06:00
|
|
|
ask("It seems you do not have a recent enough xargo installed. I will run `cargo install xargo -f`. Proceed?");
|
2018-11-25 15:29:25 -06:00
|
|
|
} else {
|
2018-12-15 08:08:03 -06:00
|
|
|
println!("Installing xargo: `cargo install xargo -f`");
|
2018-11-25 09:30:11 -06:00
|
|
|
}
|
2018-12-18 12:41:32 -06:00
|
|
|
if !Command::new("cargo").args(&["install", "xargo", "-f"]).status().unwrap().success() {
|
2018-11-25 09:30:11 -06:00
|
|
|
show_error(format!("Failed to install xargo"));
|
|
|
|
}
|
|
|
|
}
|
2018-11-25 10:09:49 -06:00
|
|
|
|
|
|
|
// Then, we also need rust-src. Let's see if it is already installed.
|
|
|
|
let sysroot = Command::new("rustc").args(&["--print", "sysroot"]).output().unwrap().stdout;
|
|
|
|
let sysroot = std::str::from_utf8(&sysroot[..]).unwrap();
|
2018-11-25 10:30:50 -06:00
|
|
|
let src = Path::new(sysroot.trim_end_matches('\n')).join("lib").join("rustlib").join("src");
|
2018-11-25 10:09:49 -06:00
|
|
|
if !src.exists() {
|
|
|
|
if ask_user {
|
|
|
|
ask("It seems you do not have the rust-src component installed. I will run `rustup component add rust-src`. Proceed?");
|
2018-11-25 15:29:25 -06:00
|
|
|
} else {
|
|
|
|
println!("Installing rust-src component: `rustup component add rust-src`");
|
2018-11-25 10:09:49 -06:00
|
|
|
}
|
|
|
|
if !Command::new("rustup").args(&["component", "add", "rust-src"]).status().unwrap().success() {
|
|
|
|
show_error(format!("Failed to install rust-src component"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-27 04:26:53 -06:00
|
|
|
// Next, we need our own libstd. We will do this work in whatever is a good cache dir for this platform.
|
|
|
|
let dirs = directories::ProjectDirs::from("miri", "miri", "miri").unwrap();
|
|
|
|
let dir = dirs.cache_dir();
|
2018-11-25 10:09:49 -06:00
|
|
|
if !dir.exists() {
|
2018-11-27 04:43:02 -06:00
|
|
|
fs::create_dir_all(&dir).unwrap();
|
2018-11-25 10:09:49 -06:00
|
|
|
}
|
|
|
|
// The interesting bit: Xargo.toml
|
|
|
|
File::create(dir.join("Xargo.toml")).unwrap()
|
|
|
|
.write_all(br#"
|
|
|
|
[dependencies.std]
|
2018-12-02 07:03:29 -06:00
|
|
|
default_features = false
|
|
|
|
# We need the `panic_unwind` feature because we use the `unwind` panic strategy.
|
|
|
|
# Using `abort` works for libstd, but then libtest will not compile.
|
2018-11-26 01:37:31 -06:00
|
|
|
features = ["panic_unwind"]
|
2018-11-25 10:09:49 -06:00
|
|
|
|
|
|
|
[dependencies.test]
|
|
|
|
stage = 1
|
|
|
|
"#).unwrap();
|
|
|
|
// The boring bits: A dummy project for xargo
|
|
|
|
File::create(dir.join("Cargo.toml")).unwrap()
|
|
|
|
.write_all(br#"
|
|
|
|
[package]
|
|
|
|
name = "miri-xargo"
|
|
|
|
description = "A dummy project for building libstd with xargo."
|
|
|
|
version = "0.0.0"
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
path = "lib.rs"
|
|
|
|
"#).unwrap();
|
|
|
|
File::create(dir.join("lib.rs")).unwrap();
|
|
|
|
// Run xargo
|
2018-12-10 02:32:54 -06:00
|
|
|
let target = get_arg_flag_value("--target");
|
|
|
|
let mut command = Command::new("xargo");
|
|
|
|
command.arg("build").arg("-q")
|
2018-11-25 10:09:49 -06:00
|
|
|
.current_dir(&dir)
|
|
|
|
.env("RUSTFLAGS", miri::miri_default_args().join(" "))
|
2018-12-10 02:32:54 -06:00
|
|
|
.env("XARGO_HOME", dir.to_str().unwrap());
|
|
|
|
if let Some(ref target) = target {
|
|
|
|
command.arg("--target").arg(&target);
|
|
|
|
}
|
|
|
|
if !command.status().unwrap().success()
|
2018-11-25 10:09:49 -06:00
|
|
|
{
|
|
|
|
show_error(format!("Failed to run xargo"));
|
|
|
|
}
|
|
|
|
|
2018-12-10 02:32:54 -06:00
|
|
|
// That should be it! But we need to figure out where xargo built stuff.
|
|
|
|
// Unfortunately, it puts things into a different directory when the
|
|
|
|
// architecture matches the host.
|
|
|
|
let is_host = match target {
|
|
|
|
None => true,
|
|
|
|
Some(target) => target == rustc_version::version_meta().unwrap().host,
|
|
|
|
};
|
|
|
|
let sysroot = if is_host { dir.join("HOST") } else { PathBuf::from(dir) };
|
2018-11-30 02:23:44 -06:00
|
|
|
std::env::set_var("MIRI_SYSROOT", &sysroot);
|
|
|
|
if !ask_user {
|
|
|
|
println!("A libstd for miri is now available in `{}`", sysroot.display());
|
|
|
|
}
|
2018-11-25 09:30:11 -06:00
|
|
|
}
|
|
|
|
|
2017-01-24 06:28:36 -06:00
|
|
|
fn main() {
|
|
|
|
// Check for version and help flags even when invoked as 'cargo-miri'
|
|
|
|
if std::env::args().any(|a| a == "--help" || a == "-h") {
|
|
|
|
show_help();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if std::env::args().any(|a| a == "--version" || a == "-V") {
|
|
|
|
show_version();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some("miri") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
|
2018-11-19 15:59:41 -06:00
|
|
|
// this arm is when `cargo miri` is called. We call `cargo rustc` for
|
|
|
|
// each applicable target, but with the RUSTC env var set to the `cargo-miri`
|
|
|
|
// binary so that we come back in the other branch, and dispatch
|
|
|
|
// the invocations to rustc and miri, respectively.
|
2019-02-07 06:00:27 -06:00
|
|
|
in_cargo_miri();
|
2018-12-12 10:03:40 -06:00
|
|
|
} else if let Some("rustc") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) {
|
|
|
|
// This arm is executed when cargo-miri runs `cargo rustc` with the `RUSTC_WRAPPER` env var set to itself:
|
2018-11-19 15:59:41 -06:00
|
|
|
// Dependencies get dispatched to rustc, the final test/binary to miri.
|
2019-02-07 06:00:27 -06:00
|
|
|
inside_cargo_rustc();
|
|
|
|
} else {
|
|
|
|
show_error(format!("Must be called with either `miri` or `rustc` as first argument."))
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 06:28:36 -06:00
|
|
|
|
2019-02-07 06:00:27 -06:00
|
|
|
fn in_cargo_miri() {
|
|
|
|
let (subcommand, skip) = match std::env::args().nth(2).deref() {
|
|
|
|
Some("test") => (MiriCommand::Test, 3),
|
|
|
|
Some("run") => (MiriCommand::Run, 3),
|
|
|
|
Some("setup") => (MiriCommand::Setup, 3),
|
|
|
|
// Default command, if there is an option or nothing
|
|
|
|
Some(s) if s.starts_with("-") => (MiriCommand::Run, 2),
|
|
|
|
None => (MiriCommand::Run, 2),
|
|
|
|
// Unvalid command
|
|
|
|
Some(s) => {
|
|
|
|
show_error(format!("Unknown command `{}`", s))
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let verbose = has_arg_flag("-v");
|
2017-01-24 06:28:36 -06:00
|
|
|
|
2019-02-07 06:00:27 -06:00
|
|
|
// We always setup
|
|
|
|
let ask = subcommand != MiriCommand::Setup;
|
|
|
|
setup(ask);
|
|
|
|
if subcommand == MiriCommand::Setup {
|
|
|
|
// Stop here.
|
|
|
|
return;
|
|
|
|
}
|
2017-01-24 06:28:36 -06:00
|
|
|
|
2019-02-07 06:00:27 -06:00
|
|
|
// Now run the command.
|
|
|
|
for target in list_targets() {
|
|
|
|
let mut args = std::env::args().skip(skip);
|
|
|
|
let kind = target.kind.get(0).expect(
|
|
|
|
"badly formatted cargo metadata: target::kind is an empty array",
|
|
|
|
);
|
|
|
|
// Now we run `cargo rustc $FLAGS $ARGS`, giving the user the
|
|
|
|
// change to add additional flags. "FLAGS" is set to identify
|
|
|
|
// this target. The user gets to control what gets actually passed to Miri.
|
|
|
|
// However, we need to add a flag to what gets passed to rustc for the finaly
|
|
|
|
// binary, so that we know to interpret that with Miri.
|
|
|
|
// So after the first "--", we add "-Zcargo-miri-marker".
|
|
|
|
let mut cmd = Command::new("cargo");
|
|
|
|
cmd.arg("rustc");
|
|
|
|
match (subcommand, &kind[..]) {
|
|
|
|
(MiriCommand::Run, "bin") => {
|
|
|
|
// FIXME: We just run all the binaries here.
|
|
|
|
// We should instead support `cargo miri --bin foo`.
|
|
|
|
cmd.arg("--bin").arg(target.name);
|
|
|
|
}
|
|
|
|
(MiriCommand::Test, "test") => {
|
|
|
|
cmd.arg("--test").arg(target.name);
|
2017-08-10 10:48:38 -05:00
|
|
|
}
|
2019-02-07 06:00:27 -06:00
|
|
|
(MiriCommand::Test, "lib") |
|
|
|
|
(MiriCommand::Test, "bin") => {
|
|
|
|
cmd.arg(format!("--{}", kind)).arg(target.name).arg("--profile").arg("test");
|
|
|
|
}
|
|
|
|
// The remaining targets we do not even want to build
|
|
|
|
_ => continue,
|
|
|
|
}
|
|
|
|
// add user-defined args until first "--"
|
|
|
|
while let Some(arg) = args.next() {
|
|
|
|
if arg == "--" {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cmd.arg(arg);
|
|
|
|
}
|
|
|
|
// add "--" "-Zcargo-miri-marker" and the remaining user flags
|
|
|
|
cmd
|
|
|
|
.arg("--")
|
|
|
|
.arg("cargo-miri-marker")
|
|
|
|
.args(args);
|
|
|
|
let path = std::env::current_exe().expect("current executable path invalid");
|
|
|
|
cmd.env("RUSTC_WRAPPER", path);
|
|
|
|
if verbose {
|
|
|
|
eprintln!("+ {:?}", cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
let exit_status = cmd
|
|
|
|
.spawn()
|
|
|
|
.expect("could not run cargo")
|
|
|
|
.wait()
|
|
|
|
.expect("failed to wait for cargo?");
|
|
|
|
|
|
|
|
if !exit_status.success() {
|
|
|
|
std::process::exit(exit_status.code().unwrap_or(-1))
|
2017-01-24 06:28:36 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-07 06:00:27 -06:00
|
|
|
fn inside_cargo_rustc() {
|
|
|
|
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
|
|
|
|
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
|
|
|
|
let sys_root = if let Ok(sysroot) = ::std::env::var("MIRI_SYSROOT") {
|
|
|
|
sysroot
|
|
|
|
} else if let (Some(home), Some(toolchain)) = (home, toolchain) {
|
|
|
|
format!("{}/toolchains/{}", home, toolchain)
|
|
|
|
} else {
|
|
|
|
option_env!("RUST_SYSROOT")
|
|
|
|
.map(|s| s.to_owned())
|
|
|
|
.or_else(|| {
|
|
|
|
Command::new("rustc")
|
|
|
|
.arg("--print")
|
|
|
|
.arg("sysroot")
|
|
|
|
.output()
|
|
|
|
.ok()
|
|
|
|
.and_then(|out| String::from_utf8(out.stdout).ok())
|
|
|
|
.map(|s| s.trim().to_owned())
|
|
|
|
})
|
|
|
|
.expect("need to specify RUST_SYSROOT env var during miri compilation, or use rustup or multirust")
|
|
|
|
};
|
2017-01-24 06:28:36 -06:00
|
|
|
|
2019-02-07 06:00:27 -06:00
|
|
|
// this conditional check for the --sysroot flag is there so users can call `cargo-miri` directly
|
|
|
|
// without having to pass --sysroot or anything
|
|
|
|
let rustc_args = std::env::args().skip(2);
|
|
|
|
let mut args: Vec<String> = if std::env::args().any(|s| s == "--sysroot") {
|
|
|
|
rustc_args.collect()
|
|
|
|
} else {
|
|
|
|
rustc_args
|
|
|
|
.chain(Some("--sysroot".to_owned()))
|
|
|
|
.chain(Some(sys_root))
|
|
|
|
.collect()
|
|
|
|
};
|
|
|
|
args.splice(0..0, miri::miri_default_args().iter().map(ToString::to_string));
|
|
|
|
|
|
|
|
// see if we have cargo-miri-marker, which means we want to interpret this crate in Miri
|
|
|
|
// (and remove the marker).
|
|
|
|
let needs_miri = if let Some(pos) = args.iter().position(|arg| arg == "cargo-miri-marker") {
|
|
|
|
args.remove(pos);
|
|
|
|
true
|
2017-01-24 06:28:36 -06:00
|
|
|
} else {
|
2019-02-07 06:00:27 -06:00
|
|
|
false
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let mut command = if needs_miri {
|
|
|
|
let mut path = std::env::current_exe().expect("current executable path invalid");
|
|
|
|
path.set_file_name("miri");
|
|
|
|
Command::new(path)
|
|
|
|
} else {
|
|
|
|
Command::new("rustc")
|
|
|
|
};
|
|
|
|
command.args(&args);
|
|
|
|
if has_arg_flag("-v") {
|
|
|
|
eprintln!("+ {:?}", command);
|
|
|
|
}
|
|
|
|
|
|
|
|
match command.status() {
|
|
|
|
Ok(exit) => {
|
|
|
|
if !exit.success() {
|
|
|
|
std::process::exit(exit.code().unwrap_or(42));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(ref e) if needs_miri => panic!("error during miri run: {:?}", e),
|
|
|
|
Err(ref e) => panic!("error during rustc call: {:?}", e),
|
2017-01-24 06:28:36 -06:00
|
|
|
}
|
|
|
|
}
|