diff --git a/src/cargo/core/compiler/build_runner/compilation_files.rs b/src/cargo/core/compiler/build_runner/compilation_files.rs index 46329f947cd..8cb56d22adb 100644 --- a/src/cargo/core/compiler/build_runner/compilation_files.rs +++ b/src/cargo/core/compiler/build_runner/compilation_files.rs @@ -449,7 +449,13 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> { /// /// Returns `None` if the unit shouldn't be uplifted (for example, a /// dependent rlib). - fn uplift_to(&self, unit: &Unit, file_type: &FileType, from_path: &Path) -> Option { + fn uplift_to( + &self, + unit: &Unit, + file_type: &FileType, + from_path: &Path, + bcx: &BuildContext<'_, '_>, + ) -> Option { // Tests, check, doc, etc. should not be uplifted. if unit.mode != CompileMode::Build || file_type.flavor == FileFlavor::Rmeta { return None; @@ -460,6 +466,11 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> { return None; } + // Build script bins are never uplifted. + if bcx.gctx.cli_unstable().build_dir_new_layout && unit.target.is_custom_build() { + return None; + } + // - Binaries: The user always wants to see these, even if they are // implicitly built (for example for integration tests). // - dylibs: This ensures that the dynamic linker pulls in all the @@ -645,7 +656,7 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> { // If, the `different_binary_name` feature is enabled, the name of the hardlink will // be the name of the binary provided by the user in `Cargo.toml`. - let hardlink = self.uplift_to(unit, &file_type, &path); + let hardlink = self.uplift_to(unit, &file_type, &path, bcx); let export_path = if unit.target.is_custom_build() { None } else { @@ -905,8 +916,8 @@ fn use_extra_filename(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool { } // No metadata in these cases: // - // - dylib, cdylib, executable: `pkg_dir` avoids collisions for us and rustc isn't looking these - // up by `-Cextra-filename` + // - dylib, cdylib, executable, build-scripts: `pkg_dir` avoids collisions for us and rustc isn't + // looking these up by `-Cextra-filename` // // The __CARGO_DEFAULT_LIB_METADATA env var is used to override this to // force metadata in the hash. This is only used for building libstd. For @@ -915,7 +926,10 @@ fn use_extra_filename(bcx: &BuildContext<'_, '_>, unit: &Unit) -> bool { // installs. In addition it prevents accidentally loading a libstd of a // different compiler at runtime. // See https://github.com/rust-lang/cargo/issues/3005 - if (unit.target.is_dylib() || unit.target.is_cdylib() || unit.target.is_executable()) + if (unit.target.is_dylib() + || unit.target.is_cdylib() + || unit.target.is_executable() + || unit.target.is_custom_build()) && bcx.gctx.get_env("__CARGO_DEFAULT_LIB_METADATA").is_err() { return false; diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 1cd4c994faf..f4f77b70950 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -349,7 +349,12 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul } // Building the command to execute - let to_exec = script_dir.join(unit.target.name()); + let bin_name = if bcx.gctx.cli_unstable().build_dir_new_layout { + unit.target.crate_name() + } else { + unit.target.name().to_string() + }; + let to_exec = script_dir.join(bin_name); // Start preparing the process to execute, starting out with some // environment variables. Note that the profile-related environment diff --git a/tests/testsuite/build_dir.rs b/tests/testsuite/build_dir.rs index d1ce0b828b9..0d4b88084b0 100644 --- a/tests/testsuite/build_dir.rs +++ b/tests/testsuite/build_dir.rs @@ -281,9 +281,8 @@ fn build_script_should_output_to_build_dir() { [ROOT]/foo/build-dir/CACHEDIR.TAG [ROOT]/foo/build-dir/debug/.cargo-build-lock [ROOT]/foo/build-dir/debug/build/foo/[HASH]/out/foo.txt -[ROOT]/foo/build-dir/debug/build/foo/[HASH]/out/build_script_build[..].d -[ROOT]/foo/build-dir/debug/build/foo/[HASH]/out/build_script_build[..][EXE] -[ROOT]/foo/build-dir/debug/build/foo/[HASH]/out/build-script-build[EXE] +[ROOT]/foo/build-dir/debug/build/foo/[HASH]/out/build_script_build.d +[ROOT]/foo/build-dir/debug/build/foo/[HASH]/out/build_script_build[EXE] [ROOT]/foo/build-dir/debug/build/foo/[HASH]/out/foo[..][EXE] [ROOT]/foo/build-dir/debug/build/foo/[HASH]/out/foo[..].d [ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/invoked.timestamp diff --git a/tests/testsuite/clean_new_layout.rs b/tests/testsuite/clean_new_layout.rs index de0e7c6f288..b69ecc23497 100644 --- a/tests/testsuite/clean_new_layout.rs +++ b/tests/testsuite/clean_new_layout.rs @@ -401,7 +401,7 @@ fn build_script() { .with_stderr_data(str![[r#" [COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc [..] build.rs [..]` -[RUNNING] `[ROOT]/foo/target/debug/build/foo/[HASH]/out/build-script-build` +[RUNNING] `[ROOT]/foo/target/debug/build/foo/[HASH]/out/build_script_build` [RUNNING] `rustc [..] src/main.rs [..]` [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s