@@ -18,18 +18,19 @@ use std::path::Path;
18
18
use utils:: { copy_doc_dir, parse_rustc_version, CargoMetadata } ;
19
19
use Metadata ;
20
20
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" ;
23
23
24
- static TARGETS : & [ & str ] = & [
24
+ const DEFAULT_TARGET : & str = "x86_64-unknown-linux-gnu" ;
25
+ const TARGETS : & [ & str ] = & [
25
26
"i686-pc-windows-msvc" ,
26
27
"i686-unknown-linux-gnu" ,
27
28
"x86_64-apple-darwin" ,
28
29
"x86_64-pc-windows-msvc" ,
29
30
"x86_64-unknown-linux-gnu" ,
30
31
] ;
31
32
32
- static ESSENTIAL_FILES_VERSIONED : & [ & str ] = & [
33
+ const ESSENTIAL_FILES_VERSIONED : & [ & str ] = & [
33
34
"brush.svg" ,
34
35
"wheel.svg" ,
35
36
"down-arrow.svg" ,
@@ -46,7 +47,7 @@ static ESSENTIAL_FILES_VERSIONED: &[&str] = &[
46
47
"noscript.css" ,
47
48
"rust-logo.png" ,
48
49
] ;
49
- static ESSENTIAL_FILES_UNVERSIONED : & [ & str ] = & [
50
+ const ESSENTIAL_FILES_UNVERSIONED : & [ & str ] = & [
50
51
"FiraSans-Medium.woff" ,
51
52
"FiraSans-Regular.woff" ,
52
53
"SourceCodePro-Regular.woff" ,
@@ -56,8 +57,8 @@ static ESSENTIAL_FILES_UNVERSIONED: &[&str] = &[
56
57
"SourceSerifPro-It.ttf.woff" ,
57
58
] ;
58
59
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" ;
61
62
62
63
pub struct RustwideBuilder {
63
64
workspace : Workspace ,
@@ -189,7 +190,7 @@ impl RustwideBuilder {
189
190
}
190
191
191
192
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" ) ;
193
194
let dest = :: tempdir:: TempDir :: new ( "essential-files" ) ?;
194
195
195
196
let files = ESSENTIAL_FILES_VERSIONED
@@ -303,7 +304,7 @@ impl RustwideBuilder {
303
304
. build ( & self . toolchain , & krate, sandbox)
304
305
. run ( |build| {
305
306
let mut files_list = None ;
306
- let ( mut has_docs, mut in_target ) = ( false , false ) ;
307
+ let mut has_docs = false ;
307
308
let mut successful_targets = Vec :: new ( ) ;
308
309
309
310
// Do an initial build and then copy the sources in the database
@@ -319,20 +320,7 @@ impl RustwideBuilder {
319
320
320
321
if let Some ( name) = res. cargo_metadata . root ( ) . library_name ( ) {
321
322
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 ( ) ;
336
324
}
337
325
}
338
326
@@ -341,22 +329,24 @@ impl RustwideBuilder {
341
329
self . copy_docs (
342
330
& build. host_target_dir ( ) ,
343
331
local_storage. path ( ) ,
344
- if in_target { & res . target } else { "" } ,
332
+ "" ,
345
333
true ,
346
334
) ?;
347
335
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 ;
359
341
}
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
+ ) ?;
360
350
}
361
351
self . upload_docs ( & conn, name, version, local_storage. path ( ) ) ?;
362
352
}
@@ -374,9 +364,9 @@ impl RustwideBuilder {
374
364
res. cargo_metadata . root ( ) ,
375
365
& build. host_source_dir ( ) ,
376
366
& res. result ,
367
+ & res. target ,
377
368
files_list,
378
369
successful_targets,
379
- & res. default_target ,
380
370
& CratesIoData :: get_from_network ( res. cargo_metadata . root ( ) ) ?,
381
371
has_docs,
382
372
has_examples,
@@ -425,6 +415,7 @@ impl RustwideBuilder {
425
415
let cargo_metadata =
426
416
CargoMetadata :: load ( & self . workspace , & self . toolchain , & build. host_source_dir ( ) ) ?;
427
417
418
+ let is_default_target = target. is_none ( ) ;
428
419
let target = target. or_else ( || metadata. default_target . as_ref ( ) . map ( |s| s. as_str ( ) ) ) ;
429
420
430
421
let mut rustdoc_flags: Vec < String > = vec ! [
@@ -484,6 +475,20 @@ impl RustwideBuilder {
484
475
. run ( )
485
476
. is_ok ( )
486
477
} ) ;
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
+ }
487
492
488
493
Ok ( FullBuildResult {
489
494
result : BuildResult {
@@ -493,8 +498,7 @@ impl RustwideBuilder {
493
498
successful,
494
499
} ,
495
500
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 ( ) ,
498
502
} )
499
503
}
500
504
@@ -542,7 +546,6 @@ impl RustwideBuilder {
542
546
struct FullBuildResult {
543
547
result : BuildResult ,
544
548
target : String ,
545
- default_target : Option < String > ,
546
549
cargo_metadata : CargoMetadata ,
547
550
}
548
551
0 commit comments