@@ -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