@@ -887,40 +887,64 @@ fn use_extra_filename(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool {
887887 // Doc tests do not have metadata.
888888 return false ;
889889 }
890- if unit. mode . is_any_test ( ) || unit. mode . is_check ( ) {
891- // These always use metadata.
892- return true ;
893- }
894- // No metadata in these cases:
895- //
896- // - dylibs:
897- // - if any dylib names are encoded in executables, so they can't be renamed.
898- // - TODO: Maybe use `-install-name` on macOS or `-soname` on other UNIX systems
899- // to specify the dylib name to be used by the linker instead of the filename.
900- // - Windows MSVC executables: The path to the PDB is embedded in the
901- // executable, and we don't want the PDB path to include the hash in it.
902- // - wasm32-unknown-emscripten executables: When using emscripten, the path to the
903- // .wasm file is embedded in the .js file, so we don't want the hash in there.
904- //
905- // This is only done for local packages, as we don't expect to export
906- // dependencies.
907- //
908- // The __CARGO_DEFAULT_LIB_METADATA env var is used to override this to
909- // force metadata in the hash. This is only used for building libstd. For
910- // example, if libstd is placed in a common location, we don't want a file
911- // named /usr/lib/libstd.so which could conflict with other rustc
912- // installs. In addition it prevents accidentally loading a libstd of a
913- // different compiler at runtime.
914- // See https://github.com/rust-lang/cargo/issues/3005
915- let short_name = bcx. target_data . short_name ( & unit. kind ) ;
916- if ( unit. target . is_dylib ( )
917- || unit. target . is_cdylib ( )
918- || ( unit. target . is_executable ( ) && short_name == "wasm32-unknown-emscripten" )
919- || ( unit. target . is_executable ( ) && short_name. contains ( "msvc" ) ) )
920- && unit. pkg . package_id ( ) . source_id ( ) . is_path ( )
921- && bcx. gctx . get_env ( "__CARGO_DEFAULT_LIB_METADATA" ) . is_err ( )
922- {
923- return false ;
890+ if bcx. gctx . cli_unstable ( ) . build_dir_new_layout {
891+ if unit. mode . is_any_test ( ) || unit. mode . is_check ( ) {
892+ // These always use metadata.
893+ return true ;
894+ }
895+ // No metadata in these cases:
896+ //
897+ // - dylib, cdylib, executable: `pkg_dir` avoids collisions for us and rustc isn't looking these
898+ // up by `-Cextra-filename`
899+ //
900+ // The __CARGO_DEFAULT_LIB_METADATA env var is used to override this to
901+ // force metadata in the hash. This is only used for building libstd. For
902+ // example, if libstd is placed in a common location, we don't want a file
903+ // named /usr/lib/libstd.so which could conflict with other rustc
904+ // installs. In addition it prevents accidentally loading a libstd of a
905+ // different compiler at runtime.
906+ // See https://github.com/rust-lang/cargo/issues/3005
907+ if ( unit. target . is_dylib ( ) || unit. target . is_cdylib ( ) || unit. target . is_executable ( ) )
908+ && bcx. gctx . get_env ( "__CARGO_DEFAULT_LIB_METADATA" ) . is_err ( )
909+ {
910+ return false ;
911+ }
912+ } else {
913+ if unit. mode . is_any_test ( ) || unit. mode . is_check ( ) {
914+ // These always use metadata.
915+ return true ;
916+ }
917+ // No metadata in these cases:
918+ //
919+ // - dylibs:
920+ // - if any dylib names are encoded in executables, so they can't be renamed.
921+ // - TODO: Maybe use `-install-name` on macOS or `-soname` on other UNIX systems
922+ // to specify the dylib name to be used by the linker instead of the filename.
923+ // - Windows MSVC executables: The path to the PDB is embedded in the
924+ // executable, and we don't want the PDB path to include the hash in it.
925+ // - wasm32-unknown-emscripten executables: When using emscripten, the path to the
926+ // .wasm file is embedded in the .js file, so we don't want the hash in there.
927+ //
928+ // This is only done for local packages, as we don't expect to export
929+ // dependencies.
930+ //
931+ // The __CARGO_DEFAULT_LIB_METADATA env var is used to override this to
932+ // force metadata in the hash. This is only used for building libstd. For
933+ // example, if libstd is placed in a common location, we don't want a file
934+ // named /usr/lib/libstd.so which could conflict with other rustc
935+ // installs. In addition it prevents accidentally loading a libstd of a
936+ // different compiler at runtime.
937+ // See https://github.com/rust-lang/cargo/issues/3005
938+ let short_name = bcx. target_data . short_name ( & unit. kind ) ;
939+ if ( unit. target . is_dylib ( )
940+ || unit. target . is_cdylib ( )
941+ || ( unit. target . is_executable ( ) && short_name == "wasm32-unknown-emscripten" )
942+ || ( unit. target . is_executable ( ) && short_name. contains ( "msvc" ) ) )
943+ && unit. pkg . package_id ( ) . source_id ( ) . is_path ( )
944+ && bcx. gctx . get_env ( "__CARGO_DEFAULT_LIB_METADATA" ) . is_err ( )
945+ {
946+ return false ;
947+ }
924948 }
925949 true
926950}
0 commit comments