@@ -9,6 +9,7 @@ use std::{env, fs, iter};
99
1010use  clap_complete:: shells; 
1111
12+ use  crate :: core:: build_steps:: compile:: run_cargo; 
1213use  crate :: core:: build_steps:: doc:: DocumentationFormat ; 
1314use  crate :: core:: build_steps:: synthetic_targets:: MirOptPanicAbortSyntheticTarget ; 
1415use  crate :: core:: build_steps:: tool:: { self ,  SourceType ,  Tool } ; 
@@ -2168,9 +2169,11 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
21682169#[ derive( Debug ,  Clone ,  PartialEq ,  Eq ,  Hash ) ]  
21692170struct  BookTest  { 
21702171    compiler :  Compiler , 
2172+     target :  TargetSelection , 
21712173    path :  PathBuf , 
21722174    name :  & ' static  str , 
21732175    is_ext_doc :  bool , 
2176+     dependencies :  Vec < & ' static  str > , 
21742177} 
21752178
21762179impl  Step  for  BookTest  { 
@@ -2223,6 +2226,44 @@ impl BookTest {
22232226        // Books often have feature-gated example text. 
22242227        rustbook_cmd. env ( "RUSTC_BOOTSTRAP" ,  "1" ) ; 
22252228        rustbook_cmd. env ( "PATH" ,  new_path) . arg ( "test" ) . arg ( path) ; 
2229+ 
2230+         // Books may also need to build dependencies. For example, `TheBook` has 
2231+         // code samples which use the `trpl` crate. For the `rustdoc` invocation 
2232+         // to find them them successfully, they need to be built first and their 
2233+         // paths used to generate the 
2234+         let  libs = if  !self . dependencies . is_empty ( )  { 
2235+             let  mut  lib_paths = vec ! [ ] ; 
2236+             for  dep in  self . dependencies  { 
2237+                 let  mode = Mode :: ToolBootstrap ; 
2238+                 let  target = builder. config . build ; 
2239+                 // CHECKME: is this correct, or should it be using `builder::Cargo::new`? 
2240+                 let  cargo = tool:: prepare_tool_cargo ( 
2241+                     builder, 
2242+                     self . compiler , 
2243+                     mode, 
2244+                     builder. config . build , 
2245+                     Kind :: Build , 
2246+                     dep, 
2247+                     SourceType :: Submodule , 
2248+                     & [ ] , 
2249+                 ) ; 
2250+                 // CHECKME: this is used for the "stamp" for this `run_cargo`; is this reasonable? 
2251+                 let  out_dir = builder. cargo_out ( self . compiler ,  mode,  target) ; 
2252+                 let  output_paths =
2253+                     run_cargo ( builder,  cargo,  vec ! [ ] ,  & out_dir,  vec ! [ ] ,  false ,  false ) ; 
2254+                 lib_paths. extend ( output_paths) ; 
2255+             } 
2256+             lib_paths
2257+         }  else  { 
2258+             vec ! [ ] 
2259+         } ; 
2260+ 
2261+         if  !libs. is_empty ( )  { 
2262+             let  mut  cli_args = vec ! [ String :: from( "--library-path" ) ] ; 
2263+             cli_args. extend ( libs. into_iter ( ) . map ( |path| format ! ( "{}" ,  path. display( ) ) ) ) ; 
2264+             rustbook_cmd. args ( cli_args) ; 
2265+         } 
2266+ 
22262267        builder. add_rust_test_threads ( & mut  rustbook_cmd) ; 
22272268        let  _guard = builder. msg ( 
22282269            Kind :: Test , 
@@ -2281,12 +2322,14 @@ macro_rules! test_book {
22812322        $name: ident,  $path: expr,  $book_name: expr, 
22822323        default =$default: expr
22832324        $( , submodules = $submodules: expr) ?
2325+         $( , dependencies=$dependencies: expr) ?
22842326        ; 
22852327    ) +)  => { 
22862328        $( 
22872329            #[ derive( Debug ,  Clone ,  PartialEq ,  Eq ,  Hash ) ] 
22882330            pub  struct  $name { 
22892331                compiler:  Compiler , 
2332+                 target:  TargetSelection , 
22902333            } 
22912334
22922335            impl  Step  for  $name { 
@@ -2301,6 +2344,7 @@ macro_rules! test_book {
23012344                fn  make_run( run:  RunConfig <' _>)  { 
23022345                    run. builder. ensure( $name { 
23032346                        compiler:  run. builder. compiler( run. builder. top_stage,  run. target) , 
2347+                         target:  run. target, 
23042348                    } ) ; 
23052349                } 
23062350
@@ -2310,11 +2354,22 @@ macro_rules! test_book {
23102354                            builder. require_submodule( submodule,  None ) ; 
23112355                        } 
23122356                    ) * 
2357+ 
2358+                     let  dependencies = vec![ ] ; 
2359+                     $( 
2360+                         let  mut  dependencies = dependencies; 
2361+                         for  dep in $dependencies { 
2362+                             dependencies. push( dep) ; 
2363+                         } 
2364+                     ) ?
2365+ 
23132366                    builder. ensure( BookTest  { 
23142367                        compiler:  self . compiler, 
2368+                         target:  self . target, 
23152369                        path:  PathBuf :: from( $path) , 
23162370                        name:  $book_name, 
23172371                        is_ext_doc:  !$default, 
2372+                         dependencies, 
23182373                    } ) ; 
23192374                } 
23202375            } 
@@ -2329,7 +2384,7 @@ test_book!(
23292384    RustcBook ,  "src/doc/rustc" ,  "rustc" ,  default =true ; 
23302385    RustByExample ,  "src/doc/rust-by-example" ,  "rust-by-example" ,  default =false ,  submodules=[ "src/doc/rust-by-example" ] ; 
23312386    EmbeddedBook ,  "src/doc/embedded-book" ,  "embedded-book" ,  default =false ,  submodules=[ "src/doc/embedded-book" ] ; 
2332-     TheBook ,  "src/doc/book" ,  "book" ,  default =false ,  submodules=[ "src/doc/book" ] ; 
2387+     TheBook ,  "src/doc/book" ,  "book" ,  default =false ,  submodules=[ "src/doc/book" ] ,  dependencies= [ "src/doc/book/packages/trpl" ] ; 
23332388    UnstableBook ,  "src/doc/unstable-book" ,  "unstable-book" ,  default =true ; 
23342389    EditionGuide ,  "src/doc/edition-guide" ,  "edition-guide" ,  default =false ,  submodules=[ "src/doc/edition-guide" ] ; 
23352390) ; 
0 commit comments