Skip to content

Commit ff9e698

Browse files
RalfJungMuscraft
authored andcommitted
Merge pull request rust-lang#4470 from nia-e/custom-cargo-bin
allow using different cargo binary
2 parents a1ac259 + c54f4b5 commit ff9e698

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/tools/miri/CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ https. Add the following to your `.gitconfig`:
348348

349349
The following environment variables are relevant to `./miri`:
350350

351+
* `CARGO` sets the binary used to execute Cargo; if none is specified, defaults to `cargo`.
351352
* `MIRI_AUTO_OPS` indicates whether the automatic execution of rustfmt, clippy and toolchain setup
352353
(as controlled by the `./auto-*` files) should be skipped. If it is set to `no`, they are skipped.
353354
This is used to allow automated IDE actions to avoid the auto ops.

src/tools/miri/miri

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ if [ -n "$MIRI_IN_RA" ]; then
1515
CARGO_FLAGS+=("--message-format=json" "-Zroot-dir=$ROOT_DIR")
1616
TARGET_DIR="$ROOT_DIR"/target
1717
fi
18+
1819
# Run cargo.
19-
cargo $TOOLCHAIN build --manifest-path "$ROOT_DIR"/miri-script/Cargo.toml \
20+
${CARGO:-cargo} $TOOLCHAIN build --manifest-path "$ROOT_DIR"/miri-script/Cargo.toml \
2021
--target-dir "$TARGET_DIR" "${CARGO_FLAGS[@]}" || \
2122
( echo "Failed to build miri-script. Is the 'stable' toolchain installed?"; exit 1 )
2223
# Instead of doing just `cargo run --manifest-path .. $@`, we invoke miri-script binary directly.

src/tools/miri/miri-script/src/util.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub struct MiriEnv {
3838
pub miri_dir: PathBuf,
3939
/// active_toolchain is passed as `+toolchain` argument to cargo/rustc invocations.
4040
toolchain: String,
41+
/// The cargo binary to use.
42+
cargo_bin: String,
4143
/// Extra flags to pass to cargo.
4244
cargo_extra_flags: Vec<String>,
4345
/// The rustc sysroot
@@ -106,6 +108,9 @@ impl MiriEnv {
106108
sh.set_var("PATH", new_path);
107109
}
108110

111+
// Get the cargo binary to use, if one is set.
112+
let cargo_bin = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_string());
113+
109114
// Get extra flags for cargo.
110115
let cargo_extra_flags = std::env::var("CARGO_EXTRA_FLAGS").unwrap_or_default();
111116
let mut cargo_extra_flags = flagsplit(&cargo_extra_flags);
@@ -119,7 +124,7 @@ impl MiriEnv {
119124
// Also set `-Zroot-dir` for cargo, to print diagnostics relative to the miri dir.
120125
cargo_extra_flags.push(format!("-Zroot-dir={}", miri_dir.display()));
121126

122-
Ok(MiriEnv { miri_dir, toolchain, sh, sysroot, cargo_extra_flags, libdir })
127+
Ok(MiriEnv { miri_dir, toolchain, sh, sysroot, cargo_bin, cargo_extra_flags, libdir })
123128
}
124129

125130
/// Make sure the `features` you pass here exist for the specified `crate_dir`. For example, the
@@ -130,12 +135,12 @@ impl MiriEnv {
130135
cmd: &str,
131136
features: &[String],
132137
) -> Cmd<'_> {
133-
let MiriEnv { toolchain, cargo_extra_flags, .. } = self;
138+
let MiriEnv { toolchain, cargo_extra_flags, cargo_bin, .. } = self;
134139
let manifest_path = path!(self.miri_dir / crate_dir.as_ref() / "Cargo.toml");
135140
let features = features_to_args(features);
136141
cmd!(
137142
self.sh,
138-
"cargo +{toolchain} {cmd} {cargo_extra_flags...} --manifest-path {manifest_path} {features...}"
143+
"{cargo_bin} +{toolchain} {cmd} {cargo_extra_flags...} --manifest-path {manifest_path} {features...}"
139144
)
140145
}
141146

@@ -147,12 +152,12 @@ impl MiriEnv {
147152
features: &[String],
148153
args: impl IntoIterator<Item = impl AsRef<OsStr>>,
149154
) -> Result<()> {
150-
let MiriEnv { sysroot, toolchain, cargo_extra_flags, .. } = self;
155+
let MiriEnv { sysroot, toolchain, cargo_extra_flags, cargo_bin, .. } = self;
151156
let path = path!(self.miri_dir / crate_dir.as_ref());
152157
let features = features_to_args(features);
153158
// Install binaries to the miri toolchain's `sysroot` so they do not interact with other toolchains.
154159
// (Not using `cargo_cmd` as `install` is special and doesn't use `--manifest-path`.)
155-
cmd!(self.sh, "cargo +{toolchain} install {cargo_extra_flags...} --path {path} --force --root {sysroot} {features...} {args...}").run()?;
160+
cmd!(self.sh, "{cargo_bin} +{toolchain} install {cargo_extra_flags...} --path {path} --force --root {sysroot} {features...} {args...}").run()?;
156161
Ok(())
157162
}
158163

0 commit comments

Comments
 (0)