@@ -229,6 +229,7 @@ where
229
229
let _dep_info = run_input_output ( cmd, None ) . await ?;
230
230
// Parse the dep-info file, then hash the contents of those files.
231
231
let cwd = cwd. to_owned ( ) ;
232
+ let cwd2 = cwd. to_owned ( ) ;
232
233
let name2 = crate_name. to_owned ( ) ;
233
234
let parsed = pool
234
235
. spawn_blocking ( move || {
@@ -237,13 +238,49 @@ where
237
238
} )
238
239
. await ?;
239
240
240
- parsed. map ( move |files| {
241
- trace ! (
241
+ parsed. map ( move |mut files| {
242
+ // HACK: Ideally, if we're compiling a Cargo package, we should be
243
+ // compiling it with the same files included in the published .crate
244
+ // package to ensure maximum compatibility. While it's possible for
245
+ // the crate developers to mark files as required for the compilation
246
+ // via mechanisms such as `include_bytes!`, this is also a hack and
247
+ // may leave an undesired footprint in the compilation outputs.
248
+ // An upstream mechanism to only track required additional files is
249
+ // pending at https://github.com/rust-lang/rust/pull/84029.
250
+ // Until then, unconditionally include Cargo.toml manifest to provide
251
+ // a minimal support and to keep some crates compiling that may
252
+ // read additional info directly from the manifest file.
253
+ let cargo_manifest_dir = env_vars
254
+ . iter ( )
255
+ . find ( |( key, _) | key. to_str ( ) == Some ( "CARGO_MANIFEST_DIR" ) )
256
+ . map ( |( _, value) | Path :: new ( value) ) ;
257
+ const KNOWN_AUX_DEP_FILES : & [ ( Option < & str > , & str ) ] = & [
258
+ ( None , "Cargo.toml" ) ,
259
+ ( Some ( "libp2p_wasm_ext" ) , "src/websockets.js" ) ,
260
+ ] ;
261
+ for ( target_crate_name, file_path) in KNOWN_AUX_DEP_FILES {
262
+ let name_matches = target_crate_name. map_or ( true , |x| x == crate_name) ;
263
+ // If this is a Cargo package, try to get the same path prefix as
264
+ // other paths are probably using. If, let's say, a package registry
265
+ // is symlinked, it might be troublesome for the path transformer to
266
+ // correctly figure out which files to include.
267
+ let base_dir = cargo_manifest_dir. unwrap_or ( & cwd2) ;
268
+ let file_path = base_dir. join ( file_path) ;
269
+ if name_matches && file_path. exists ( ) {
270
+ files. push ( file_path) ;
271
+ }
272
+ }
273
+ debug ! (
242
274
"[{}]: got {} source files from dep-info in {}" ,
243
275
crate_name,
244
276
files. len( ) ,
245
277
fmt_duration_as_secs( & start. elapsed( ) )
246
278
) ;
279
+ trace ! (
280
+ "[{}]: source files calculated from dep-info: {:?}" ,
281
+ crate_name,
282
+ files
283
+ ) ;
247
284
// Just to make sure we capture temp_dir.
248
285
drop ( temp_dir) ;
249
286
files
0 commit comments