@@ -7,6 +7,7 @@ use serde::Serialize;
77
88use crate :: CargoResult ;
99use crate :: core:: compiler:: BuildRunner ;
10+ use crate :: core:: compiler:: CompileKind ;
1011
1112/// Structure used to deal with Rustdoc fingerprinting
1213///
@@ -30,10 +31,17 @@ impl RustDocFingerprint {
3031 /// was the same as the one is currently being used in this `cargo doc` call.
3132 ///
3233 /// In case it's not,
33- /// it takes care of removing the `<artifact -dir>/doc/` folder
34+ /// it takes care of removing the `<build -dir>/doc/` folder
3435 /// as well as overwriting the rustdoc fingerprint info.
3536 /// This is to guarantee that we won't end up with mixed versions of the `js/html/css` files
3637 /// which `rustdoc` autogenerates without any versioning.
38+ ///
39+ /// Each requested target platform maintains its own fingerprint file.
40+ /// That is, if you run `cargo doc` and then `cargo doc --target wasm32-wasip1`,
41+ /// you will have two separate fingerprint files:
42+ ///
43+ /// * `<build-dir>/.rustdoc_fingerprint.json` for host
44+ /// * `<build-dir>/wasm32-wasip1/.rustdoc_fingerprint.json`
3745 pub fn check_rustdoc_fingerprint ( build_runner : & BuildRunner < ' _ , ' _ > ) -> CargoResult < ( ) > {
3846 if build_runner
3947 . bcx
@@ -43,47 +51,52 @@ impl RustDocFingerprint {
4351 {
4452 return Ok ( ( ) ) ;
4553 }
46- let actual_rustdoc_target_data = RustDocFingerprint {
54+ let new_fingerprint = RustDocFingerprint {
4755 rustc_vv : build_runner. bcx . rustc ( ) . verbose_version . clone ( ) ,
4856 } ;
4957
50- check_fingerprint ( build_runner, & actual_rustdoc_target_data) ?;
58+ for kind in & build_runner. bcx . build_config . requested_kinds {
59+ check_fingerprint ( build_runner, & new_fingerprint, * kind) ?;
60+ }
5161
5262 Ok ( ( ) )
5363 }
5464}
5565
56- /// Checks rustdoc fingerprint file.
66+ /// Checks rustdoc fingerprint file for a given [`CompileKind`] .
5767fn check_fingerprint (
5868 build_runner : & BuildRunner < ' _ , ' _ > ,
59- actual_rustdoc_target_data : & RustDocFingerprint ,
69+ new_fingerprint : & RustDocFingerprint ,
70+ kind : CompileKind ,
6071) -> CargoResult < ( ) > {
6172 let fingerprint_path = build_runner
6273 . files ( )
63- . host_build_root ( )
74+ . layout ( kind)
75+ . build_dir ( )
76+ . root ( )
6477 . join ( ".rustdoc_fingerprint.json" ) ;
78+
6579 let write_fingerprint = || -> CargoResult < ( ) > {
66- paths:: write (
67- & fingerprint_path,
68- serde_json:: to_string ( & actual_rustdoc_target_data) ?,
69- )
80+ paths:: write ( & fingerprint_path, serde_json:: to_string ( new_fingerprint) ?)
7081 } ;
82+
7183 let Ok ( rustdoc_data) = paths:: read ( & fingerprint_path) else {
7284 // If the fingerprint does not exist, do not clear out the doc
7385 // directories. Otherwise this ran into problems where projects
7486 // like bootstrap were creating the doc directory before running
7587 // `cargo doc` in a way that deleting it would break it.
7688 return write_fingerprint ( ) ;
7789 } ;
90+
7891 match serde_json:: from_str :: < RustDocFingerprint > ( & rustdoc_data) {
79- Ok ( fingerprint ) => {
80- if fingerprint . rustc_vv == actual_rustdoc_target_data . rustc_vv {
92+ Ok ( on_disk_fingerprint ) => {
93+ if on_disk_fingerprint . rustc_vv == new_fingerprint . rustc_vv {
8194 return Ok ( ( ) ) ;
8295 } else {
8396 tracing:: debug!(
8497 "doc fingerprint changed:\n original:\n {}\n new:\n {}" ,
85- fingerprint . rustc_vv,
86- actual_rustdoc_target_data . rustc_vv
98+ on_disk_fingerprint . rustc_vv,
99+ new_fingerprint . rustc_vv
87100 ) ;
88101 }
89102 }
@@ -96,20 +109,16 @@ fn check_fingerprint(
96109 "fingerprint {:?} mismatch, clearing doc directories" ,
97110 fingerprint_path
98111 ) ;
99- build_runner
100- . bcx
101- . all_kinds
102- . iter ( )
103- . map ( |kind| {
104- build_runner
105- . files ( )
106- . layout ( * kind)
107- . artifact_dir ( )
108- . expect ( "artifact-dir was not locked" )
109- . doc ( )
110- } )
111- . filter ( |path| path. exists ( ) )
112- . try_for_each ( |path| clean_doc ( path) ) ?;
112+ let doc_dir = build_runner
113+ . files ( )
114+ . layout ( kind)
115+ . artifact_dir ( )
116+ . expect ( "artifact-dir was not locked" )
117+ . doc ( ) ;
118+ if doc_dir. exists ( ) {
119+ clean_doc ( doc_dir) ?;
120+ }
121+
113122 write_fingerprint ( ) ?;
114123
115124 Ok ( ( ) )
0 commit comments