@@ -34,6 +34,12 @@ pub enum SourceType {
3434 Submodule ,
3535}
3636
37+ #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
38+ pub enum ToolArtifactKind {
39+ Binary ,
40+ Library ,
41+ }
42+
3743#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
3844struct ToolBuild {
3945 compiler : Compiler ,
@@ -47,6 +53,8 @@ struct ToolBuild {
4753 allow_features : & ' static str ,
4854 /// Additional arguments to pass to the `cargo` invocation.
4955 cargo_args : Vec < String > ,
56+ /// Whether the tool builds a binary or a library.
57+ artifact_kind : ToolArtifactKind ,
5058}
5159
5260impl Builder < ' _ > {
@@ -79,7 +87,7 @@ impl Builder<'_> {
7987/// for using this type as `type Output = ToolBuildResult;`
8088#[ derive( Clone ) ]
8189pub struct ToolBuildResult {
82- /// Executable path of the corresponding tool that was built.
90+ /// Artifact path of the corresponding tool that was built.
8391 pub tool_path : PathBuf ,
8492 /// Compiler used to build the tool. For non-`ToolRustc` tools this is equal to `target_compiler`.
8593 /// For `ToolRustc` this is one stage before of the `target_compiler`.
@@ -179,8 +187,14 @@ impl Step for ToolBuild {
179187 if tool == "tidy" {
180188 tool = "rust-tidy" ;
181189 }
182- let tool_path =
183- copy_link_tool_bin ( builder, self . compiler , self . target , self . mode , tool) ;
190+ let tool_path = match self . artifact_kind {
191+ ToolArtifactKind :: Binary => {
192+ copy_link_tool_bin ( builder, self . compiler , self . target , self . mode , tool)
193+ }
194+ ToolArtifactKind :: Library => builder
195+ . cargo_out ( self . compiler , self . mode , self . target )
196+ . join ( format ! ( "lib{tool}.rlib" ) ) ,
197+ } ;
184198
185199 ToolBuildResult { tool_path, build_compiler : self . compiler , target_compiler }
186200 }
@@ -330,6 +344,7 @@ macro_rules! bootstrap_tool {
330344 $( , is_unstable_tool = $unstable: expr) *
331345 $( , allow_features = $allow_features: expr) ?
332346 $( , submodules = $submodules: expr) ?
347+ $( , artifact_kind = $artifact_kind: expr) ?
333348 ;
334349 ) +) => {
335350 #[ derive( PartialEq , Eq , Clone ) ]
@@ -389,6 +404,7 @@ macro_rules! bootstrap_tool {
389404 builder. require_submodule( submodule, None ) ;
390405 }
391406 ) *
407+
392408 builder. ensure( ToolBuild {
393409 compiler: self . compiler,
394410 target: self . target,
@@ -407,7 +423,12 @@ macro_rules! bootstrap_tool {
407423 } ,
408424 extra_features: vec![ ] ,
409425 allow_features: concat!( $( $allow_features) * ) ,
410- cargo_args: vec![ ]
426+ cargo_args: vec![ ] ,
427+ artifact_kind: if false $( || $artifact_kind == ToolArtifactKind :: Library ) * {
428+ ToolArtifactKind :: Library
429+ } else {
430+ ToolArtifactKind :: Binary
431+ }
411432 } )
412433 }
413434 }
@@ -491,6 +512,7 @@ impl Step for RustcPerf {
491512 // Only build the collector package, which is used for benchmarking through
492513 // a CLI.
493514 cargo_args : vec ! [ "-p" . to_string( ) , "collector" . to_string( ) ] ,
515+ artifact_kind : ToolArtifactKind :: Binary ,
494516 } ;
495517 let res = builder. ensure ( tool. clone ( ) ) ;
496518 // We also need to symlink the `rustc-fake` binary to the corresponding directory,
@@ -548,6 +570,7 @@ impl Step for ErrorIndex {
548570 extra_features : Vec :: new ( ) ,
549571 allow_features : "" ,
550572 cargo_args : Vec :: new ( ) ,
573+ artifact_kind : ToolArtifactKind :: Binary ,
551574 } )
552575 }
553576}
@@ -583,6 +606,7 @@ impl Step for RemoteTestServer {
583606 extra_features : Vec :: new ( ) ,
584607 allow_features : "" ,
585608 cargo_args : Vec :: new ( ) ,
609+ artifact_kind : ToolArtifactKind :: Binary ,
586610 } )
587611 }
588612}
@@ -687,6 +711,7 @@ impl Step for Rustdoc {
687711 extra_features,
688712 allow_features : "" ,
689713 cargo_args : Vec :: new ( ) ,
714+ artifact_kind : ToolArtifactKind :: Binary ,
690715 } ) ;
691716
692717 // don't create a stage0-sysroot/bin directory.
@@ -741,6 +766,7 @@ impl Step for Cargo {
741766 extra_features : Vec :: new ( ) ,
742767 allow_features : "" ,
743768 cargo_args : Vec :: new ( ) ,
769+ artifact_kind : ToolArtifactKind :: Binary ,
744770 } )
745771 }
746772}
@@ -789,6 +815,7 @@ impl Step for LldWrapper {
789815 extra_features : Vec :: new ( ) ,
790816 allow_features : "" ,
791817 cargo_args : Vec :: new ( ) ,
818+ artifact_kind : ToolArtifactKind :: Binary ,
792819 } ) ;
793820
794821 let libdir_bin = builder. sysroot_target_bindir ( self . target_compiler , target) ;
@@ -849,6 +876,7 @@ impl Step for RustAnalyzer {
849876 source_type : SourceType :: InTree ,
850877 allow_features : RustAnalyzer :: ALLOW_FEATURES ,
851878 cargo_args : Vec :: new ( ) ,
879+ artifact_kind : ToolArtifactKind :: Binary ,
852880 } )
853881 }
854882}
@@ -893,6 +921,7 @@ impl Step for RustAnalyzerProcMacroSrv {
893921 source_type : SourceType :: InTree ,
894922 allow_features : RustAnalyzer :: ALLOW_FEATURES ,
895923 cargo_args : Vec :: new ( ) ,
924+ artifact_kind : ToolArtifactKind :: Binary ,
896925 } ) ;
897926
898927 // Copy `rust-analyzer-proc-macro-srv` to `<sysroot>/libexec/`
@@ -947,6 +976,7 @@ impl Step for LlvmBitcodeLinker {
947976 extra_features : self . extra_features ,
948977 allow_features : "" ,
949978 cargo_args : Vec :: new ( ) ,
979+ artifact_kind : ToolArtifactKind :: Binary ,
950980 } ) ;
951981
952982 if tool_result. target_compiler . stage > 0 {
@@ -1126,6 +1156,7 @@ fn run_tool_build_step(
11261156 source_type : SourceType :: InTree ,
11271157 allow_features : "" ,
11281158 cargo_args : vec ! [ ] ,
1159+ artifact_kind : ToolArtifactKind :: Binary ,
11291160 } ) ;
11301161
11311162 // FIXME: This should just be an if-let-chain, but those are unstable.
@@ -1204,6 +1235,7 @@ impl Step for TestFloatParse {
12041235 extra_features : Vec :: new ( ) ,
12051236 allow_features : "" ,
12061237 cargo_args : Vec :: new ( ) ,
1238+ artifact_kind : ToolArtifactKind :: Binary ,
12071239 } )
12081240 }
12091241}
0 commit comments