Skip to content

Commit b398bc6

Browse files
committed
Cleanup unstable flags handling
1 parent df85aac commit b398bc6

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

crates/project-model/src/build_dependencies.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ impl BuildScriptOutput {
6262
self.cfgs.is_empty()
6363
&& self.envs.is_empty()
6464
&& self.out_dir.is_none()
65-
&& self.proc_macro_dylib_path == ProcMacroDylibPath::NotBuilt
65+
&& matches!(
66+
self.proc_macro_dylib_path,
67+
ProcMacroDylibPath::NotBuilt | ProcMacroDylibPath::NotProcMacro
68+
)
6669
}
6770
}
6871

@@ -462,10 +465,10 @@ impl WorkspaceBuildScripts {
462465
let lockfile_path =
463466
<_ as AsRef<Utf8Path>>::as_ref(manifest_path).with_extension("lock");
464467
if let Some((temp_dir, target_lockfile)) = make_lockfile_copy(&lockfile_path) {
468+
requires_unstable_options = true;
465469
temp_dir_guard = Some(temp_dir);
466470
cmd.arg("--lockfile-path");
467471
cmd.arg(target_lockfile.as_str());
468-
requires_unstable_options = true;
469472
}
470473
}
471474
match &config.features {
@@ -499,7 +502,7 @@ impl WorkspaceBuildScripts {
499502
// available in current toolchain's cargo, use it to build compile time deps only.
500503
const COMP_TIME_DEPS_MIN_TOOLCHAIN_VERSION: semver::Version = semver::Version {
501504
major: 1,
502-
minor: 189,
505+
minor: 89,
503506
patch: 0,
504507
pre: semver::Prerelease::EMPTY,
505508
build: semver::BuildMetadata::EMPTY,

crates/project-model/src/cargo_workspace.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,6 @@ impl FetchMetadata {
601601
}
602602
command.current_dir(current_dir);
603603

604-
let mut needs_nightly = false;
605604
let mut other_options = vec![];
606605
// cargo metadata only supports a subset of flags of what cargo usually accepts, and usually
607606
// the only relevant flags for metadata here are unstable ones, so we pass those along
@@ -611,15 +610,13 @@ impl FetchMetadata {
611610
if arg == "-Z"
612611
&& let Some(arg) = extra_args.next()
613612
{
614-
needs_nightly = true;
615613
other_options.push("-Z".to_owned());
616614
other_options.push(arg.to_owned());
617615
}
618616
}
619617

620618
let mut lockfile_path = None;
621619
if cargo_toml.is_rust_manifest() {
622-
needs_nightly = true;
623620
other_options.push("-Zscript".to_owned());
624621
} else if config
625622
.toolchain_version
@@ -637,10 +634,6 @@ impl FetchMetadata {
637634

638635
command.other_options(other_options.clone());
639636

640-
if needs_nightly {
641-
command.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly");
642-
}
643-
644637
// Pre-fetch basic metadata using `--no-deps`, which:
645638
// - avoids fetching registries like crates.io,
646639
// - skips dependency resolution and does not modify lockfiles,
@@ -710,7 +703,7 @@ impl FetchMetadata {
710703
other_options.push(target_lockfile.to_string());
711704
using_lockfile_copy = true;
712705
}
713-
if using_lockfile_copy {
706+
if using_lockfile_copy || other_options.iter().any(|it| it.starts_with("-Z")) {
714707
command.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly");
715708
other_options.push("-Zunstable-options".to_owned());
716709
}

crates/project-model/src/workspace.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,14 +1316,17 @@ fn cargo_to_crate_graph(
13161316
public_deps.add_to_crate_graph(crate_graph, from);
13171317

13181318
// Add dep edge of all targets to the package's lib target
1319-
if let Some((to, name)) = lib_tgt.clone() {
1320-
match to != from && kind != TargetKind::BuildScript {
1321-
true => {
1322-
let name = CrateName::normalize_dashes(&name);
1323-
add_dep(crate_graph, from, name, to);
1324-
}
1325-
false => (),
1326-
}
1319+
if let Some((to, name)) = lib_tgt.clone()
1320+
&& to != from
1321+
&& kind != TargetKind::BuildScript
1322+
{
1323+
// (build script can not depend on its library target)
1324+
1325+
// For root projects with dashes in their name,
1326+
// cargo metadata does not do any normalization,
1327+
// so we do it ourselves currently
1328+
let name = CrateName::normalize_dashes(&name);
1329+
add_dep(crate_graph, from, name, to);
13271330
}
13281331
}
13291332
}

0 commit comments

Comments
 (0)