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