@@ -18,19 +18,18 @@ use std::path::Path;
1818use utils:: { copy_doc_dir, parse_rustc_version, CargoMetadata } ;
1919use Metadata ;
2020
21- const USER_AGENT : & str = "docs.rs builder (https://github.com/rust-lang/docs.rs)" ;
22- const DEFAULT_RUSTWIDE_WORKSPACE : & str = ".rustwide" ;
21+ static USER_AGENT : & str = "docs.rs builder (https://github.com/rust-lang/docs.rs)" ;
22+ static DEFAULT_RUSTWIDE_WORKSPACE : & str = ".rustwide" ;
2323
24- const DEFAULT_TARGET : & str = "x86_64-unknown-linux-gnu" ;
25- const TARGETS : & [ & str ] = & [
24+ static TARGETS : & [ & str ] = & [
2625 "i686-pc-windows-msvc" ,
2726 "i686-unknown-linux-gnu" ,
2827 "x86_64-apple-darwin" ,
2928 "x86_64-pc-windows-msvc" ,
3029 "x86_64-unknown-linux-gnu" ,
3130] ;
3231
33- const ESSENTIAL_FILES_VERSIONED : & [ & str ] = & [
32+ static ESSENTIAL_FILES_VERSIONED : & [ & str ] = & [
3433 "brush.svg" ,
3534 "wheel.svg" ,
3635 "down-arrow.svg" ,
@@ -47,7 +46,7 @@ const ESSENTIAL_FILES_VERSIONED: &[&str] = &[
4746 "noscript.css" ,
4847 "rust-logo.png" ,
4948] ;
50- const ESSENTIAL_FILES_UNVERSIONED : & [ & str ] = & [
49+ static ESSENTIAL_FILES_UNVERSIONED : & [ & str ] = & [
5150 "FiraSans-Medium.woff" ,
5251 "FiraSans-Regular.woff" ,
5352 "SourceCodePro-Regular.woff" ,
@@ -57,8 +56,8 @@ const ESSENTIAL_FILES_UNVERSIONED: &[&str] = &[
5756 "SourceSerifPro-It.ttf.woff" ,
5857] ;
5958
60- const DUMMY_CRATE_NAME : & str = "acme-client" ;
61- const DUMMY_CRATE_VERSION : & str = "0.0.0" ;
59+ static DUMMY_CRATE_NAME : & str = "acme-client" ;
60+ static DUMMY_CRATE_VERSION : & str = "0.0.0" ;
6261
6362pub struct RustwideBuilder {
6463 workspace : Workspace ,
@@ -190,7 +189,7 @@ impl RustwideBuilder {
190189 }
191190
192191 info ! ( "copying essential files for {}" , self . rustc_version) ;
193- let source = build. host_target_dir ( ) . join ( "doc" ) ;
192+ let source = build. host_target_dir ( ) . join ( & res . target ) . join ( "doc" ) ;
194193 let dest = :: tempdir:: TempDir :: new ( "essential-files" ) ?;
195194
196195 let files = ESSENTIAL_FILES_VERSIONED
@@ -304,7 +303,7 @@ impl RustwideBuilder {
304303 . build ( & self . toolchain , & krate, sandbox)
305304 . run ( |build| {
306305 let mut files_list = None ;
307- let mut has_docs = false ;
306+ let ( mut has_docs, mut in_target ) = ( false , false ) ;
308307 let mut successful_targets = Vec :: new ( ) ;
309308
310309 // Do an initial build and then copy the sources in the database
@@ -320,7 +319,20 @@ impl RustwideBuilder {
320319
321320 if let Some ( name) = res. cargo_metadata . root ( ) . library_name ( ) {
322321 let host_target = build. host_target_dir ( ) ;
323- has_docs = host_target. join ( "doc" ) . join ( name) . is_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+ }
324336 }
325337 }
326338
@@ -329,24 +341,22 @@ impl RustwideBuilder {
329341 self . copy_docs (
330342 & build. host_target_dir ( ) ,
331343 local_storage. path ( ) ,
332- "" ,
344+ if in_target { & res . target } else { "" } ,
333345 true ,
334346 ) ?;
335347
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 ;
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+ ) ?;
341359 }
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- ) ?;
350360 }
351361 self . upload_docs ( & conn, name, version, local_storage. path ( ) ) ?;
352362 }
@@ -364,9 +374,9 @@ impl RustwideBuilder {
364374 res. cargo_metadata . root ( ) ,
365375 & build. host_source_dir ( ) ,
366376 & res. result ,
367- & res. target ,
368377 files_list,
369378 successful_targets,
379+ & res. default_target ,
370380 & CratesIoData :: get_from_network ( res. cargo_metadata . root ( ) ) ?,
371381 has_docs,
372382 has_examples,
@@ -415,7 +425,6 @@ impl RustwideBuilder {
415425 let cargo_metadata =
416426 CargoMetadata :: load ( & self . workspace , & self . toolchain , & build. host_source_dir ( ) ) ?;
417427
418- let is_default_target = target. is_none ( ) ;
419428 let target = target. or_else ( || metadata. default_target . as_ref ( ) . map ( |s| s. as_str ( ) ) ) ;
420429
421430 let mut rustdoc_flags: Vec < String > = vec ! [
@@ -475,20 +484,6 @@ impl RustwideBuilder {
475484 . run ( )
476485 . is_ok ( )
477486 } ) ;
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- }
492487
493488 Ok ( FullBuildResult {
494489 result : BuildResult {
@@ -498,7 +493,8 @@ impl RustwideBuilder {
498493 successful,
499494 } ,
500495 cargo_metadata,
501- target : target. unwrap_or ( DEFAULT_TARGET ) . to_string ( ) ,
496+ target : target. unwrap_or_default ( ) . to_string ( ) ,
497+ default_target : metadata. default_target . clone ( ) ,
502498 } )
503499 }
504500
@@ -546,6 +542,7 @@ impl RustwideBuilder {
546542struct FullBuildResult {
547543 result : BuildResult ,
548544 target : String ,
545+ default_target : Option < String > ,
549546 cargo_metadata : CargoMetadata ,
550547}
551548
0 commit comments