@@ -260,8 +260,13 @@ pub fn prepare_tool_cargo(
260260}
261261
262262macro_rules! tool {
263- ( $( $name: ident, $path: expr, $tool_name: expr, $mode: expr
264- $( , llvm_tools = $llvm: expr) * $( , is_external_tool = $external: expr) * ; ) +) => {
263+ ( $(
264+ $name: ident, $path: expr, $tool_name: expr, $mode: expr
265+ $( , llvm_tools = $llvm: expr) *
266+ $( , is_external_tool = $external: expr) *
267+ $( , cargo_test_root = $cargo_test_root: expr) *
268+ ;
269+ ) +) => {
265270 #[ derive( Copy , PartialEq , Eq , Clone ) ]
266271 pub enum Tool {
267272 $(
@@ -283,6 +288,15 @@ macro_rules! tool {
283288 $( Tool :: $name => false $( || $llvm) * , ) +
284289 }
285290 }
291+
292+ /// Whether this tool requires may run Cargo for test crates,
293+ /// which currently needs setting the environment variable
294+ /// `__CARGO_TEST_ROOT` to separate it from the workspace.
295+ pub fn needs_cargo_test_root( & self ) -> bool {
296+ match self {
297+ $( Tool :: $name => false $( || $cargo_test_root) * , ) +
298+ }
299+ }
286300 }
287301
288302 impl <' a> Builder <' a> {
@@ -358,8 +372,9 @@ tool!(
358372 UnstableBookGen , "src/tools/unstable-book-gen" , "unstable-book-gen" , Mode :: ToolBootstrap ;
359373 Tidy , "src/tools/tidy" , "tidy" , Mode :: ToolBootstrap ;
360374 Linkchecker , "src/tools/linkchecker" , "linkchecker" , Mode :: ToolBootstrap ;
361- CargoTest , "src/tools/cargotest" , "cargotest" , Mode :: ToolBootstrap ;
362- Compiletest , "src/tools/compiletest" , "compiletest" , Mode :: ToolBootstrap , llvm_tools = true ;
375+ CargoTest , "src/tools/cargotest" , "cargotest" , Mode :: ToolBootstrap , cargo_test_root = true ;
376+ Compiletest , "src/tools/compiletest" , "compiletest" , Mode :: ToolBootstrap ,
377+ llvm_tools = true , cargo_test_root = true ;
363378 BuildManifest , "src/tools/build-manifest" , "build-manifest" , Mode :: ToolBootstrap ;
364379 RemoteTestClient , "src/tools/remote-test-client" , "remote-test-client" , Mode :: ToolBootstrap ;
365380 RustInstaller , "src/tools/rust-installer" , "fabricate" , Mode :: ToolBootstrap ,
@@ -678,6 +693,11 @@ impl<'a> Builder<'a> {
678693 }
679694 }
680695
696+ // Set `__CARGO_TEST_ROOT` to the build directory if needed.
697+ if tool. needs_cargo_test_root ( ) {
698+ cmd. env ( "__CARGO_TEST_ROOT" , & self . config . out ) ;
699+ }
700+
681701 add_lib_path ( lib_paths, cmd) ;
682702 }
683703
0 commit comments