Skip to content

Commit 638329b

Browse files
authored
Merge pull request #20121 from Veykril/push-vkkuutpsuypq
Do not append `--compile-time-deps` to overwritten build script commands
2 parents 7d5579d + 0609735 commit 638329b

File tree

3 files changed

+49
-48
lines changed

3 files changed

+49
-48
lines changed

src/tools/rust-analyzer/crates/proc-macro-srv/proc-macro-test/build.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,11 @@ fn main() {
109109

110110
let mut artifact_path = None;
111111
for message in Message::parse_stream(output.stdout.as_slice()) {
112-
if let Message::CompilerArtifact(artifact) = message.unwrap() {
113-
if artifact.target.kind.contains(&cargo_metadata::TargetKind::ProcMacro)
114-
&& (artifact.package_id.repr.starts_with(&repr)
115-
|| artifact.package_id.repr == pkgid)
116-
{
117-
artifact_path = Some(PathBuf::from(&artifact.filenames[0]));
118-
}
112+
if let Message::CompilerArtifact(artifact) = message.unwrap()
113+
&& artifact.target.kind.contains(&cargo_metadata::TargetKind::ProcMacro)
114+
&& (artifact.package_id.repr.starts_with(&repr) || artifact.package_id.repr == pkgid)
115+
{
116+
artifact_path = Some(PathBuf::from(&artifact.filenames[0]));
119117
}
120118
}
121119

src/tools/rust-analyzer/crates/project-model/src/build_dependencies.rs

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ use toolchain::Tool;
2020

2121
use crate::{
2222
CargoConfig, CargoFeatures, CargoWorkspace, InvocationStrategy, ManifestPath, Package, Sysroot,
23-
TargetKind,
24-
toolchain_info::{QueryConfig, version},
25-
utf8_stdout,
23+
TargetKind, utf8_stdout,
2624
};
2725

2826
/// Output of the build script and proc-macro building steps for a workspace.
@@ -64,6 +62,7 @@ impl WorkspaceBuildScripts {
6462
workspace: &CargoWorkspace,
6563
progress: &dyn Fn(String),
6664
sysroot: &Sysroot,
65+
toolchain: Option<&semver::Version>,
6766
) -> io::Result<WorkspaceBuildScripts> {
6867
let current_dir = workspace.workspace_root();
6968

@@ -74,6 +73,7 @@ impl WorkspaceBuildScripts {
7473
workspace.manifest_path(),
7574
current_dir,
7675
sysroot,
76+
toolchain,
7777
)?;
7878
Self::run_per_ws(cmd, workspace, progress)
7979
}
@@ -95,6 +95,7 @@ impl WorkspaceBuildScripts {
9595
&ManifestPath::try_from(working_directory.clone()).unwrap(),
9696
working_directory,
9797
&Sysroot::empty(),
98+
None,
9899
)?;
99100
// NB: Cargo.toml could have been modified between `cargo metadata` and
100101
// `cargo check`. We shouldn't assume that package ids we see here are
@@ -387,12 +388,13 @@ impl WorkspaceBuildScripts {
387388
manifest_path: &ManifestPath,
388389
current_dir: &AbsPath,
389390
sysroot: &Sysroot,
391+
toolchain: Option<&semver::Version>,
390392
) -> io::Result<Command> {
391-
let mut cmd = match config.run_build_script_command.as_deref() {
393+
match config.run_build_script_command.as_deref() {
392394
Some([program, args @ ..]) => {
393395
let mut cmd = toolchain::command(program, current_dir, &config.extra_env);
394396
cmd.args(args);
395-
cmd
397+
Ok(cmd)
396398
}
397399
_ => {
398400
let mut cmd = sysroot.tool(Tool::Cargo, current_dir, &config.extra_env);
@@ -444,40 +446,35 @@ impl WorkspaceBuildScripts {
444446

445447
cmd.arg("--keep-going");
446448

447-
cmd
449+
// If [`--compile-time-deps` flag](https://github.com/rust-lang/cargo/issues/14434) is
450+
// available in current toolchain's cargo, use it to build compile time deps only.
451+
const COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION: semver::Version = semver::Version {
452+
major: 1,
453+
minor: 89,
454+
patch: 0,
455+
pre: semver::Prerelease::EMPTY,
456+
build: semver::BuildMetadata::EMPTY,
457+
};
458+
459+
let cargo_comp_time_deps_available =
460+
toolchain.is_some_and(|v| *v >= COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION);
461+
462+
if cargo_comp_time_deps_available {
463+
cmd.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly");
464+
cmd.arg("-Zunstable-options");
465+
cmd.arg("--compile-time-deps");
466+
} else if config.wrap_rustc_in_build_scripts {
467+
// Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
468+
// that to compile only proc macros and build scripts during the initial
469+
// `cargo check`.
470+
// We don't need this if we are using `--compile-time-deps` flag.
471+
let myself = std::env::current_exe()?;
472+
cmd.env("RUSTC_WRAPPER", myself);
473+
cmd.env("RA_RUSTC_WRAPPER", "1");
474+
}
475+
Ok(cmd)
448476
}
449-
};
450-
451-
// If [`--compile-time-deps` flag](https://github.com/rust-lang/cargo/issues/14434) is
452-
// available in current toolchain's cargo, use it to build compile time deps only.
453-
const COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION: semver::Version = semver::Version {
454-
major: 1,
455-
minor: 89,
456-
patch: 0,
457-
pre: semver::Prerelease::EMPTY,
458-
build: semver::BuildMetadata::EMPTY,
459-
};
460-
461-
let query_config = QueryConfig::Cargo(sysroot, manifest_path);
462-
let toolchain = version::get(query_config, &config.extra_env).ok().flatten();
463-
let cargo_comp_time_deps_available =
464-
toolchain.is_some_and(|v| v >= COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION);
465-
466-
if cargo_comp_time_deps_available {
467-
cmd.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly");
468-
cmd.arg("-Zunstable-options");
469-
cmd.arg("--compile-time-deps");
470-
} else if config.wrap_rustc_in_build_scripts {
471-
// Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
472-
// that to compile only proc macros and build scripts during the initial
473-
// `cargo check`.
474-
// We don't need this if we are using `--compile-time-deps` flag.
475-
let myself = std::env::current_exe()?;
476-
cmd.env("RUSTC_WRAPPER", myself);
477-
cmd.env("RA_RUSTC_WRAPPER", "1");
478477
}
479-
480-
Ok(cmd)
481478
}
482479
}
483480

src/tools/rust-analyzer/crates/project-model/src/workspace.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,16 @@ impl ProjectWorkspace {
636636
match &self.kind {
637637
ProjectWorkspaceKind::DetachedFile { cargo: Some((cargo, _, None)), .. }
638638
| ProjectWorkspaceKind::Cargo { cargo, error: None, .. } => {
639-
WorkspaceBuildScripts::run_for_workspace(config, cargo, progress, &self.sysroot)
640-
.with_context(|| {
641-
format!("Failed to run build scripts for {}", cargo.workspace_root())
642-
})
639+
WorkspaceBuildScripts::run_for_workspace(
640+
config,
641+
cargo,
642+
progress,
643+
&self.sysroot,
644+
self.toolchain.as_ref(),
645+
)
646+
.with_context(|| {
647+
format!("Failed to run build scripts for {}", cargo.workspace_root())
648+
})
643649
}
644650
_ => Ok(WorkspaceBuildScripts::default()),
645651
}

0 commit comments

Comments
 (0)