@@ -75,14 +75,21 @@ impl Step for CleanTools {
7575 }
7676}
7777
78+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
79+ pub enum SourceType {
80+ InTree ,
81+ Submodule ,
82+ }
83+
7884#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
7985struct ToolBuild {
8086 compiler : Compiler ,
8187 target : Interned < String > ,
8288 tool : & ' static str ,
8389 path : & ' static str ,
8490 mode : Mode ,
85- is_ext_tool : bool ,
91+ is_optional_tool : bool ,
92+ source_type : SourceType ,
8693 extra_features : Vec < String > ,
8794}
8895
@@ -102,7 +109,7 @@ impl Step for ToolBuild {
102109 let target = self . target ;
103110 let tool = self . tool ;
104111 let path = self . path ;
105- let is_ext_tool = self . is_ext_tool ;
112+ let is_optional_tool = self . is_optional_tool ;
106113
107114 match self . mode {
108115 Mode :: ToolRustc => {
@@ -115,7 +122,15 @@ impl Step for ToolBuild {
115122 _ => panic ! ( "unexpected Mode for tool build" )
116123 }
117124
118- let mut cargo = prepare_tool_cargo ( builder, compiler, self . mode , target, "build" , path) ;
125+ let mut cargo = prepare_tool_cargo (
126+ builder,
127+ compiler,
128+ self . mode ,
129+ target,
130+ "build" ,
131+ path,
132+ self . source_type ,
133+ ) ;
119134 cargo. arg ( "--features" ) . arg ( self . extra_features . join ( " " ) ) ;
120135
121136 let _folder = builder. fold_output ( || format ! ( "stage{}-{}" , compiler. stage, tool) ) ;
@@ -216,7 +231,7 @@ impl Step for ToolBuild {
216231 } ) ;
217232
218233 if !is_expected {
219- if !is_ext_tool {
234+ if !is_optional_tool {
220235 exit ( 1 ) ;
221236 } else {
222237 return None ;
@@ -238,6 +253,7 @@ pub fn prepare_tool_cargo(
238253 target : Interned < String > ,
239254 command : & ' static str ,
240255 path : & ' static str ,
256+ source_type : SourceType ,
241257) -> Command {
242258 let mut cargo = builder. cargo ( compiler, mode, target, command) ;
243259 let dir = builder. src . join ( path) ;
@@ -247,6 +263,10 @@ pub fn prepare_tool_cargo(
247263 // stages and such and it's just easier if they're not dynamically linked.
248264 cargo. env ( "RUSTC_NO_PREFER_DYNAMIC" , "1" ) ;
249265
266+ if source_type == SourceType :: Submodule {
267+ cargo. env ( "RUSTC_EXTERNAL_TOOL" , "1" ) ;
268+ }
269+
250270 if let Some ( dir) = builder. openssl_install_dir ( target) {
251271 cargo. env ( "OPENSSL_STATIC" , "1" ) ;
252272 cargo. env ( "OPENSSL_DIR" , dir) ;
@@ -274,7 +294,8 @@ pub fn prepare_tool_cargo(
274294}
275295
276296macro_rules! tool {
277- ( $( $name: ident, $path: expr, $tool_name: expr, $mode: expr $( , llvm_tools = $llvm: expr) * ; ) +) => {
297+ ( $( $name: ident, $path: expr, $tool_name: expr, $mode: expr
298+ $( , llvm_tools = $llvm: expr) * $( , is_external_tool = $external: expr) * ; ) +) => {
278299 #[ derive( Copy , PartialEq , Eq , Clone ) ]
279300 pub enum Tool {
280301 $(
@@ -351,7 +372,12 @@ macro_rules! tool {
351372 tool: $tool_name,
352373 mode: $mode,
353374 path: $path,
354- is_ext_tool: false ,
375+ is_optional_tool: false ,
376+ source_type: if false $( || $external) * {
377+ SourceType :: Submodule
378+ } else {
379+ SourceType :: InTree
380+ } ,
355381 extra_features: Vec :: new( ) ,
356382 } ) . expect( "expected to build -- essential tool" )
357383 }
@@ -370,7 +396,8 @@ tool!(
370396 Compiletest , "src/tools/compiletest" , "compiletest" , Mode :: ToolBootstrap , llvm_tools = true ;
371397 BuildManifest , "src/tools/build-manifest" , "build-manifest" , Mode :: ToolBootstrap ;
372398 RemoteTestClient , "src/tools/remote-test-client" , "remote-test-client" , Mode :: ToolBootstrap ;
373- RustInstaller , "src/tools/rust-installer" , "fabricate" , Mode :: ToolBootstrap ;
399+ RustInstaller , "src/tools/rust-installer" , "fabricate" , Mode :: ToolBootstrap ,
400+ is_external_tool = true ;
374401 RustdocTheme , "src/tools/rustdoc-themes" , "rustdoc-themes" , Mode :: ToolBootstrap ;
375402) ;
376403
@@ -401,7 +428,8 @@ impl Step for RemoteTestServer {
401428 tool : "remote-test-server" ,
402429 mode : Mode :: ToolStd ,
403430 path : "src/tools/remote-test-server" ,
404- is_ext_tool : false ,
431+ is_optional_tool : false ,
432+ source_type : SourceType :: InTree ,
405433 extra_features : Vec :: new ( ) ,
406434 } ) . expect ( "expected to build -- essential tool" )
407435 }
@@ -449,12 +477,15 @@ impl Step for Rustdoc {
449477 target : builder. config . build ,
450478 } ) ;
451479
452- let mut cargo = prepare_tool_cargo ( builder,
453- build_compiler,
454- Mode :: ToolRustc ,
455- target,
456- "build" ,
457- "src/tools/rustdoc" ) ;
480+ let mut cargo = prepare_tool_cargo (
481+ builder,
482+ build_compiler,
483+ Mode :: ToolRustc ,
484+ target,
485+ "build" ,
486+ "src/tools/rustdoc" ,
487+ SourceType :: InTree ,
488+ ) ;
458489
459490 // Most tools don't get debuginfo, but rustdoc should.
460491 cargo. env ( "RUSTC_DEBUGINFO" , builder. config . rust_debuginfo . to_string ( ) )
@@ -525,7 +556,8 @@ impl Step for Cargo {
525556 tool : "cargo" ,
526557 mode : Mode :: ToolRustc ,
527558 path : "src/tools/cargo" ,
528- is_ext_tool : false ,
559+ is_optional_tool : false ,
560+ source_type : SourceType :: Submodule ,
529561 extra_features : Vec :: new ( ) ,
530562 } ) . expect ( "expected to build -- essential tool" )
531563 }
@@ -574,7 +606,8 @@ macro_rules! tool_extended {
574606 mode: Mode :: ToolRustc ,
575607 path: $path,
576608 extra_features: $sel. extra_features,
577- is_ext_tool: true ,
609+ is_optional_tool: true ,
610+ source_type: SourceType :: Submodule ,
578611 } )
579612 }
580613 }
0 commit comments