@@ -26,7 +26,6 @@ static TARGETS: &[&str] = &[
2626 "x86_64-pc-windows-msvc" ,
2727 "x86_64-unknown-linux-gnu" ,
2828] ;
29- static DEFAULT_TARGET : & str = "x86_64-unknown-linux-gnu" ;
3029
3130static ESSENTIAL_FILES_VERSIONED : & [ & str ] = & [
3231 "brush.svg" ,
@@ -267,7 +266,7 @@ impl RustwideBuilder {
267266 . build ( & self . toolchain , & krate, sandbox)
268267 . run ( |build| {
269268 let mut files_list = None ;
270- let mut has_docs = false ;
269+ let ( mut has_docs, mut in_target ) = ( false , false ) ;
271270 let mut successful_targets = Vec :: new ( ) ;
272271
273272 // Do an initial build and then copy the sources in the database
@@ -281,54 +280,47 @@ impl RustwideBuilder {
281280 build. host_source_dir ( ) ,
282281 ) ?) ;
283282
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+ }
297300 }
298301
299302 if has_docs {
300303 debug ! ( "adding documentation for the default target to the database" ) ;
301304 self . copy_docs (
302305 & build. host_target_dir ( ) ,
303306 local_storage. path ( ) ,
304- & res. target ,
307+ if in_target { & res. target } else { "" } ,
305308 true ,
306309 ) ?;
307310
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+ ) ?;
329322 }
330323 }
331-
332324 self . upload_docs ( & conn, name, version, local_storage. path ( ) ) ?;
333325 }
334326
@@ -362,6 +354,28 @@ impl RustwideBuilder {
362354 Ok ( res. successful )
363355 }
364356
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+
365379 fn execute_build (
366380 & self ,
367381 target : Option < & str > ,
@@ -372,14 +386,7 @@ impl RustwideBuilder {
372386 let cargo_metadata =
373387 CargoMetadata :: load ( & self . workspace , & self . toolchain , & build. host_source_dir ( ) ) ?;
374388
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 ( ) ) ) ;
383390
384391 let mut rustdoc_flags: Vec < String > = vec ! [
385392 "-Z" . to_string( ) ,
@@ -401,13 +408,11 @@ impl RustwideBuilder {
401408 if let Some ( package_rustdoc_args) = & metadata. rustdoc_args {
402409 rustdoc_flags. append ( & mut package_rustdoc_args. iter ( ) . map ( |s| s. to_owned ( ) ) . collect ( ) ) ;
403410 }
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+ } ;
411416 if let Some ( features) = & metadata. features {
412417 cargo_args. push ( "--features" . to_owned ( ) ) ;
413418 cargo_args. push ( features. join ( " " ) ) ;
@@ -431,8 +436,9 @@ impl RustwideBuilder {
431436 "RUSTFLAGS" ,
432437 metadata
433438 . rustc_args
439+ . as_ref ( )
434440 . map ( |args| args. join ( " " ) )
435- . unwrap_or ( "" . to_owned ( ) ) ,
441+ . unwrap_or_default ( ) ,
436442 )
437443 . env ( "RUSTDOCFLAGS" , rustdoc_flags. join ( " " ) )
438444 . args ( & cargo_args)
@@ -446,7 +452,7 @@ impl RustwideBuilder {
446452 docsrs_version : format ! ( "docsrs {}" , :: BUILD_VERSION ) ,
447453 successful,
448454 cargo_metadata,
449- target : target. to_string ( ) ,
455+ target : target. unwrap_or_default ( ) . to_string ( ) ,
450456 } )
451457 }
452458
0 commit comments