@@ -38,6 +38,8 @@ pub struct MiriEnv {
38
38
pub miri_dir : PathBuf ,
39
39
/// active_toolchain is passed as `+toolchain` argument to cargo/rustc invocations.
40
40
toolchain : String ,
41
+ /// The cargo binary to use.
42
+ cargo_bin : String ,
41
43
/// Extra flags to pass to cargo.
42
44
cargo_extra_flags : Vec < String > ,
43
45
/// The rustc sysroot
@@ -106,6 +108,9 @@ impl MiriEnv {
106
108
sh. set_var ( "PATH" , new_path) ;
107
109
}
108
110
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
+
109
114
// Get extra flags for cargo.
110
115
let cargo_extra_flags = std:: env:: var ( "CARGO_EXTRA_FLAGS" ) . unwrap_or_default ( ) ;
111
116
let mut cargo_extra_flags = flagsplit ( & cargo_extra_flags) ;
@@ -119,7 +124,7 @@ impl MiriEnv {
119
124
// Also set `-Zroot-dir` for cargo, to print diagnostics relative to the miri dir.
120
125
cargo_extra_flags. push ( format ! ( "-Zroot-dir={}" , miri_dir. display( ) ) ) ;
121
126
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 } )
123
128
}
124
129
125
130
/// Make sure the `features` you pass here exist for the specified `crate_dir`. For example, the
@@ -130,12 +135,12 @@ impl MiriEnv {
130
135
cmd : & str ,
131
136
features : & [ String ] ,
132
137
) -> Cmd < ' _ > {
133
- let MiriEnv { toolchain, cargo_extra_flags, .. } = self ;
138
+ let MiriEnv { toolchain, cargo_extra_flags, cargo_bin , .. } = self ;
134
139
let manifest_path = path ! ( self . miri_dir / crate_dir. as_ref( ) / "Cargo.toml" ) ;
135
140
let features = features_to_args ( features) ;
136
141
cmd ! (
137
142
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...}"
139
144
)
140
145
}
141
146
@@ -147,12 +152,12 @@ impl MiriEnv {
147
152
features : & [ String ] ,
148
153
args : impl IntoIterator < Item = impl AsRef < OsStr > > ,
149
154
) -> Result < ( ) > {
150
- let MiriEnv { sysroot, toolchain, cargo_extra_flags, .. } = self ;
155
+ let MiriEnv { sysroot, toolchain, cargo_extra_flags, cargo_bin , .. } = self ;
151
156
let path = path ! ( self . miri_dir / crate_dir. as_ref( ) ) ;
152
157
let features = features_to_args ( features) ;
153
158
// Install binaries to the miri toolchain's `sysroot` so they do not interact with other toolchains.
154
159
// (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 ( ) ?;
156
161
Ok ( ( ) )
157
162
}
158
163
0 commit comments