@@ -350,7 +350,11 @@ impl RustwideBuilder {
350
350
if res. result . successful {
351
351
if let Some ( name) = res. cargo_metadata . root ( ) . library_name ( ) {
352
352
let host_target = build. host_target_dir ( ) ;
353
- has_docs = host_target. join ( "doc" ) . join ( name) . is_dir ( ) ;
353
+ has_docs = if metadata. proc_macro {
354
+ host_target. join ( "doc" ) . join ( name) . is_dir ( )
355
+ } else {
356
+ host_target. join ( "doc" ) . join ( HOST_TARGET ) . join ( name) . is_dir ( )
357
+ }
354
358
}
355
359
}
356
360
@@ -656,7 +660,16 @@ impl RustwideBuilder {
656
660
if let Some ( cpu_limit) = self . config . build_cpu_limit {
657
661
cargo_args. push ( format ! ( "-j{}" , cpu_limit) ) ;
658
662
}
659
- if target != HOST_TARGET {
663
+ // Cargo has a series of frightening bugs around cross-compiling proc-macros:
664
+ // - Passing `--target` causes RUSTDOCFLAGS to fail to be passed 🤦
665
+ // - Passing `--target` will *create* `target/{target-name}/doc` but will put the docs in `target/doc` anyway
666
+ // As a result, it's not possible for us to support cross-compiling proc-macros.
667
+ // However, all these caveats unfortunately still apply when `{target-name}` is the host.
668
+ // So, only pass `--target` for crates that aren't proc-macros.
669
+ //
670
+ // Originally, this had a simpler check `target != HOST_TARGET`, but *that* was buggy when `HOST_TARGET` wasn't the same as the default target.
671
+ // Rather than trying to keep track of it all, only special case proc-macros, which are what we actually care about.
672
+ if !metadata. proc_macro {
660
673
cargo_args. push ( "--target" . into ( ) ) ;
661
674
cargo_args. push ( target. into ( ) ) ;
662
675
} ;
@@ -935,4 +948,66 @@ mod tests {
935
948
Ok ( ( ) )
936
949
} )
937
950
}
951
+
952
+ #[ test]
953
+ #[ ignore]
954
+ fn test_proc_macro ( ) {
955
+ wrapper ( |env| {
956
+ let crate_ = "thiserror-impl" ;
957
+ let version = "1.0.26" ;
958
+ let mut builder = RustwideBuilder :: init ( env) . unwrap ( ) ;
959
+ assert ! ( builder. build_package( crate_, version, PackageKind :: CratesIo ) ?) ;
960
+
961
+ let storage = env. storage ( ) ;
962
+
963
+ // doc archive exists
964
+ let doc_archive = rustdoc_archive_path ( crate_, version) ;
965
+ assert ! ( storage. exists( & doc_archive) ?) ;
966
+
967
+ // source archive exists
968
+ let source_archive = source_archive_path ( crate_, version) ;
969
+ assert ! ( storage. exists( & source_archive) ?) ;
970
+
971
+ Ok ( ( ) )
972
+ } ) ;
973
+ }
974
+
975
+ #[ test]
976
+ #[ ignore]
977
+ fn test_cross_compile_non_host_default ( ) {
978
+ wrapper ( |env| {
979
+ let crate_ = "xingapi" ;
980
+ let version = "0.3.3" ;
981
+ let mut builder = RustwideBuilder :: init ( env) . unwrap ( ) ;
982
+ assert ! ( builder. build_package( crate_, version, PackageKind :: CratesIo ) ?) ;
983
+
984
+ let storage = env. storage ( ) ;
985
+
986
+ // doc archive exists
987
+ let doc_archive = rustdoc_archive_path ( crate_, version) ;
988
+ assert ! ( storage. exists( & doc_archive) ?) ;
989
+
990
+ // source archive exists
991
+ let source_archive = source_archive_path ( crate_, version) ;
992
+ assert ! ( storage. exists( & source_archive) ?) ;
993
+
994
+ let target = "x86_64-unknown-linux-gnu" ;
995
+ let crate_path = crate_. replace ( "-" , "_" ) ;
996
+ let target_docs_present = storage. exists_in_archive (
997
+ & doc_archive,
998
+ & format ! ( "{}/{}/index.html" , target, crate_path) ,
999
+ ) ?;
1000
+
1001
+ let web = env. frontend ( ) ;
1002
+ let target_url = format ! (
1003
+ "/{}/{}/{}/{}/index.html" ,
1004
+ crate_, version, target, crate_path
1005
+ ) ;
1006
+
1007
+ assert ! ( target_docs_present) ;
1008
+ assert_success ( & target_url, web) ?;
1009
+
1010
+ Ok ( ( ) )
1011
+ } ) ;
1012
+ }
938
1013
}
0 commit comments