@@ -26,7 +26,6 @@ static TARGETS: &[&str] = &[
26
26
"x86_64-pc-windows-msvc" ,
27
27
"x86_64-unknown-linux-gnu" ,
28
28
] ;
29
- static DEFAULT_TARGET : & str = "x86_64-unknown-linux-gnu" ;
30
29
31
30
static ESSENTIAL_FILES_VERSIONED : & [ & str ] = & [
32
31
"brush.svg" ,
@@ -267,7 +266,7 @@ impl RustwideBuilder {
267
266
. build ( & self . toolchain , & krate, sandbox)
268
267
. run ( |build| {
269
268
let mut files_list = None ;
270
- let mut has_docs = false ;
269
+ let ( mut has_docs, mut in_target ) = ( false , false ) ;
271
270
let mut successful_targets = Vec :: new ( ) ;
272
271
273
272
// Do an initial build and then copy the sources in the database
@@ -281,54 +280,47 @@ impl RustwideBuilder {
281
280
build. host_source_dir ( ) ,
282
281
) ?) ;
283
282
284
- has_docs = res
285
- . cargo_metadata
286
- . root ( )
287
- . library_name ( )
288
- . map ( |name| {
289
- build
290
- . host_target_dir ( )
291
- . join ( & res. target )
292
- . join ( "doc" )
293
- . join ( name)
294
- . is_dir ( )
295
- } )
296
- . unwrap_or ( false ) ;
283
+ if let Some ( name) = res. cargo_metadata . root ( ) . library_name ( ) {
284
+ let host_target = build. host_target_dir ( ) ;
285
+ if host_target
286
+ . join ( & res. target )
287
+ . join ( "doc" )
288
+ . join ( & name)
289
+ . is_dir ( )
290
+ {
291
+ has_docs = true ;
292
+ in_target = true ;
293
+ // hack for proc-macro documentation:
294
+ // it really should be in target/$target/doc,
295
+ // but rustdoc has a bug and puts it in target/doc
296
+ } else if host_target. join ( "doc" ) . join ( name) . is_dir ( ) {
297
+ has_docs = true ;
298
+ }
299
+ }
297
300
}
298
301
299
302
if has_docs {
300
303
debug ! ( "adding documentation for the default target to the database" ) ;
301
304
self . copy_docs (
302
305
& build. host_target_dir ( ) ,
303
306
local_storage. path ( ) ,
304
- & res. target ,
307
+ if in_target { & res. target } else { "" } ,
305
308
true ,
306
309
) ?;
307
310
308
- // Then build the documentation for all the targets
309
- for target in TARGETS {
310
- debug ! ( "building package {} {} for {}" , name, version, target) ;
311
- let target_res = self . execute_build ( Some ( target) , & build, & limits) ?;
312
- if target_res. successful {
313
- // Cargo is not giving any error and not generating documentation of some crates
314
- // when we use a target compile options. Check documentation exists before
315
- // adding target to successfully_targets.
316
- if build. host_target_dir ( ) . join ( target) . join ( "doc" ) . is_dir ( ) {
317
- debug ! (
318
- "adding documentation for target {} to the database" ,
319
- target
320
- ) ;
321
- self . copy_docs (
322
- & build. host_target_dir ( ) ,
323
- local_storage. path ( ) ,
324
- target,
325
- false ,
326
- ) ?;
327
- successful_targets. push ( target. to_string ( ) ) ;
328
- }
311
+ if in_target {
312
+ // Then build the documentation for all the targets
313
+ for target in TARGETS {
314
+ debug ! ( "building package {} {} for {}" , name, version, target) ;
315
+ self . build_target (
316
+ target,
317
+ & build,
318
+ & limits,
319
+ & local_storage. path ( ) ,
320
+ & mut successful_targets,
321
+ ) ?;
329
322
}
330
323
}
331
-
332
324
self . upload_docs ( & conn, name, version, local_storage. path ( ) ) ?;
333
325
}
334
326
@@ -362,6 +354,28 @@ impl RustwideBuilder {
362
354
Ok ( res. successful )
363
355
}
364
356
357
+ fn build_target (
358
+ & self ,
359
+ target : & str ,
360
+ build : & Build ,
361
+ limits : & Limits ,
362
+ local_storage : & Path ,
363
+ successful_targets : & mut Vec < String > ,
364
+ ) -> Result < ( ) > {
365
+ let target_res = self . execute_build ( Some ( target) , build, limits) ?;
366
+ if target_res. successful {
367
+ // Cargo is not giving any error and not generating documentation of some crates
368
+ // when we use a target compile options. Check documentation exists before
369
+ // adding target to successfully_targets.
370
+ if build. host_target_dir ( ) . join ( target) . join ( "doc" ) . is_dir ( ) {
371
+ debug ! ( "adding documentation for target {} to the database" , target, ) ;
372
+ self . copy_docs ( & build. host_target_dir ( ) , local_storage, target, false ) ?;
373
+ successful_targets. push ( target. to_string ( ) ) ;
374
+ }
375
+ }
376
+ Ok ( ( ) )
377
+ }
378
+
365
379
fn execute_build (
366
380
& self ,
367
381
target : Option < & str > ,
@@ -372,14 +386,7 @@ impl RustwideBuilder {
372
386
let cargo_metadata =
373
387
CargoMetadata :: load ( & self . workspace , & self . toolchain , & build. host_source_dir ( ) ) ?;
374
388
375
- let target = if let Some ( target) = target {
376
- target
377
- } else if let Some ( target) = metadata. default_target . as_ref ( ) . map ( |s| s. as_str ( ) ) {
378
- target
379
- } else {
380
- DEFAULT_TARGET
381
- }
382
- . to_string ( ) ;
389
+ let target = target. or_else ( || metadata. default_target . as_ref ( ) . map ( |s| s. as_str ( ) ) ) ;
383
390
384
391
let mut rustdoc_flags: Vec < String > = vec ! [
385
392
"-Z" . to_string( ) ,
@@ -401,13 +408,11 @@ impl RustwideBuilder {
401
408
if let Some ( package_rustdoc_args) = & metadata. rustdoc_args {
402
409
rustdoc_flags. append ( & mut package_rustdoc_args. iter ( ) . map ( |s| s. to_owned ( ) ) . collect ( ) ) ;
403
410
}
404
- let mut cargo_args = vec ! [
405
- "doc" . to_owned( ) ,
406
- "--lib" . to_owned( ) ,
407
- "--no-deps" . to_owned( ) ,
408
- "--target" . to_owned( ) ,
409
- target. to_owned( ) ,
410
- ] ;
411
+ let mut cargo_args = vec ! [ "doc" . to_owned( ) , "--lib" . to_owned( ) , "--no-deps" . to_owned( ) ] ;
412
+ if let Some ( explicit_target) = target {
413
+ cargo_args. push ( "--target" . to_owned ( ) ) ;
414
+ cargo_args. push ( explicit_target. to_owned ( ) ) ;
415
+ } ;
411
416
if let Some ( features) = & metadata. features {
412
417
cargo_args. push ( "--features" . to_owned ( ) ) ;
413
418
cargo_args. push ( features. join ( " " ) ) ;
@@ -431,8 +436,9 @@ impl RustwideBuilder {
431
436
"RUSTFLAGS" ,
432
437
metadata
433
438
. rustc_args
439
+ . as_ref ( )
434
440
. map ( |args| args. join ( " " ) )
435
- . unwrap_or ( "" . to_owned ( ) ) ,
441
+ . unwrap_or_default ( ) ,
436
442
)
437
443
. env ( "RUSTDOCFLAGS" , rustdoc_flags. join ( " " ) )
438
444
. args ( & cargo_args)
@@ -446,7 +452,7 @@ impl RustwideBuilder {
446
452
docsrs_version : format ! ( "docsrs {}" , :: BUILD_VERSION ) ,
447
453
successful,
448
454
cargo_metadata,
449
- target : target. to_string ( ) ,
455
+ target : target. unwrap_or_default ( ) . to_string ( ) ,
450
456
} )
451
457
}
452
458
0 commit comments