Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/cargo/core/compiler/build_runner/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> {
fn uplift_to(
&self,
unit: &Unit,
file_type: &FileType,
from_path: &Path,
bcx: &BuildContext<'_, '_>,
) -> Option<PathBuf> {
// Tests, check, doc, etc. should not be uplifted.
if unit.mode != CompileMode::Build || file_type.flavor == FileFlavor::Rmeta {
return None;
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions tests/testsuite/build_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/clean_new_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down