@@ -18,18 +18,19 @@ use std::path::Path;
1818use utils:: { copy_doc_dir, parse_rustc_version, CargoMetadata } ;
1919use Metadata ;
2020
21- static USER_AGENT : & str = "docs.rs builder (https://github.com/rust-lang/docs.rs)" ;
22- static DEFAULT_RUSTWIDE_WORKSPACE : & str = ".rustwide" ;
21+ const USER_AGENT : & str = "docs.rs builder (https://github.com/rust-lang/docs.rs)" ;
22+ const DEFAULT_RUSTWIDE_WORKSPACE : & str = ".rustwide" ;
2323
24- static TARGETS : & [ & str ] = & [
24+ const DEFAULT_TARGET : & str = "x86_64-unknown-linux-gnu" ;
25+ const TARGETS : & [ & str ] = & [
2526 "i686-pc-windows-msvc" ,
2627 "i686-unknown-linux-gnu" ,
2728 "x86_64-apple-darwin" ,
2829 "x86_64-pc-windows-msvc" ,
2930 "x86_64-unknown-linux-gnu" ,
3031] ;
3132
32- static ESSENTIAL_FILES_VERSIONED : & [ & str ] = & [
33+ const ESSENTIAL_FILES_VERSIONED : & [ & str ] = & [
3334 "brush.svg" ,
3435 "wheel.svg" ,
3536 "down-arrow.svg" ,
@@ -46,7 +47,7 @@ static ESSENTIAL_FILES_VERSIONED: &[&str] = &[
4647 "noscript.css" ,
4748 "rust-logo.png" ,
4849] ;
49- static ESSENTIAL_FILES_UNVERSIONED : & [ & str ] = & [
50+ const ESSENTIAL_FILES_UNVERSIONED : & [ & str ] = & [
5051 "FiraSans-Medium.woff" ,
5152 "FiraSans-Regular.woff" ,
5253 "SourceCodePro-Regular.woff" ,
@@ -56,8 +57,8 @@ static ESSENTIAL_FILES_UNVERSIONED: &[&str] = &[
5657 "SourceSerifPro-It.ttf.woff" ,
5758] ;
5859
59- static DUMMY_CRATE_NAME : & str = "acme-client" ;
60- static DUMMY_CRATE_VERSION : & str = "0.0.0" ;
60+ const DUMMY_CRATE_NAME : & str = "acme-client" ;
61+ const DUMMY_CRATE_VERSION : & str = "0.0.0" ;
6162
6263pub struct RustwideBuilder {
6364 workspace : Workspace ,
@@ -189,7 +190,7 @@ impl RustwideBuilder {
189190 }
190191
191192 info ! ( "copying essential files for {}" , self . rustc_version) ;
192- let source = build. host_target_dir ( ) . join ( & res . target ) . join ( "doc" ) ;
193+ let source = build. host_target_dir ( ) . join ( "doc" ) ;
193194 let dest = :: tempdir:: TempDir :: new ( "essential-files" ) ?;
194195
195196 let files = ESSENTIAL_FILES_VERSIONED
@@ -303,7 +304,7 @@ impl RustwideBuilder {
303304 . build ( & self . toolchain , & krate, sandbox)
304305 . run ( |build| {
305306 let mut files_list = None ;
306- let ( mut has_docs, mut in_target ) = ( false , false ) ;
307+ let mut has_docs = false ;
307308 let mut successful_targets = Vec :: new ( ) ;
308309
309310 // Do an initial build and then copy the sources in the database
@@ -319,20 +320,7 @@ impl RustwideBuilder {
319320
320321 if let Some ( name) = res. cargo_metadata . root ( ) . library_name ( ) {
321322 let host_target = build. host_target_dir ( ) ;
322- if host_target
323- . join ( & res. target )
324- . join ( "doc" )
325- . join ( & name)
326- . is_dir ( )
327- {
328- has_docs = true ;
329- in_target = true ;
330- // hack for proc-macro documentation:
331- // it really should be in target/$target/doc,
332- // but rustdoc has a bug and puts it in target/doc
333- } else if host_target. join ( "doc" ) . join ( name) . is_dir ( ) {
334- has_docs = true ;
335- }
323+ has_docs = host_target. join ( "doc" ) . join ( name) . is_dir ( ) ;
336324 }
337325 }
338326
@@ -341,22 +329,24 @@ impl RustwideBuilder {
341329 self . copy_docs (
342330 & build. host_target_dir ( ) ,
343331 local_storage. path ( ) ,
344- if in_target { & res . target } else { "" } ,
332+ "" ,
345333 true ,
346334 ) ?;
347335
348- if in_target {
349- // Then build the documentation for all the targets
350- for target in TARGETS {
351- debug ! ( "building package {} {} for {}" , name, version, target) ;
352- self . build_target (
353- target,
354- & build,
355- & limits,
356- & local_storage. path ( ) ,
357- & mut successful_targets,
358- ) ?;
336+ successful_targets. push ( res. target . clone ( ) ) ;
337+ // Then build the documentation for all the targets
338+ for target in TARGETS {
339+ if * target == res. target {
340+ continue ;
359341 }
342+ debug ! ( "building package {} {} for {}" , name, version, & target) ;
343+ self . build_target (
344+ & target,
345+ & build,
346+ & limits,
347+ & local_storage. path ( ) ,
348+ & mut successful_targets,
349+ ) ?;
360350 }
361351 self . upload_docs ( & conn, name, version, local_storage. path ( ) ) ?;
362352 }
@@ -374,9 +364,9 @@ impl RustwideBuilder {
374364 res. cargo_metadata . root ( ) ,
375365 & build. host_source_dir ( ) ,
376366 & res. result ,
367+ & res. target ,
377368 files_list,
378369 successful_targets,
379- & res. default_target ,
380370 & CratesIoData :: get_from_network ( res. cargo_metadata . root ( ) ) ?,
381371 has_docs,
382372 has_examples,
@@ -425,6 +415,7 @@ impl RustwideBuilder {
425415 let cargo_metadata =
426416 CargoMetadata :: load ( & self . workspace , & self . toolchain , & build. host_source_dir ( ) ) ?;
427417
418+ let is_default_target = target. is_none ( ) ;
428419 let target = target. or_else ( || metadata. default_target . as_ref ( ) . map ( |s| s. as_str ( ) ) ) ;
429420
430421 let mut rustdoc_flags: Vec < String > = vec ! [
@@ -484,6 +475,20 @@ impl RustwideBuilder {
484475 . run ( )
485476 . is_ok ( )
486477 } ) ;
478+ // If we're passed a default_target which requires a cross-compile,
479+ // cargo will put the output in `target/<target>/doc`.
480+ // However, if this is the default build, we don't want it there,
481+ // we want it in `target/doc`.
482+ if let Some ( explicit_target) = target {
483+ if is_default_target {
484+ // mv target/$explicit_target/doc target/doc
485+ let target_dir = build. host_target_dir ( ) ;
486+ let old_dir = target_dir. join ( explicit_target) . join ( "doc" ) ;
487+ let new_dir = target_dir. join ( "doc" ) ;
488+ debug ! ( "rename {} to {}" , old_dir. display( ) , new_dir. display( ) ) ;
489+ std:: fs:: rename ( old_dir, new_dir) ?;
490+ }
491+ }
487492
488493 Ok ( FullBuildResult {
489494 result : BuildResult {
@@ -493,8 +498,7 @@ impl RustwideBuilder {
493498 successful,
494499 } ,
495500 cargo_metadata,
496- target : target. unwrap_or_default ( ) . to_string ( ) ,
497- default_target : metadata. default_target . clone ( ) ,
501+ target : target. unwrap_or ( DEFAULT_TARGET ) . to_string ( ) ,
498502 } )
499503 }
500504
@@ -542,7 +546,6 @@ impl RustwideBuilder {
542546struct FullBuildResult {
543547 result : BuildResult ,
544548 target : String ,
545- default_target : Option < String > ,
546549 cargo_metadata : CargoMetadata ,
547550}
548551
0 commit comments