Skip to content

cfg_version #15533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

cfg_version #15533

wants to merge 1 commit into from

Conversation

mo8it
Copy link
Contributor

@mo8it mo8it commented May 16, 2025

What does this PR try to resolve?

#15531

@rustbot rustbot added A-build-scripts Area: build.rs scripts A-cfg-expr Area: Platform cfg expressions labels May 16, 2025
@mo8it
Copy link
Contributor Author

mo8it commented May 16, 2025

@epage I will of course take care of proper error handling, but I just want to get feedback on the initial direction.

cfg(nightly) can be already parsed as a Name.

@mo8it mo8it changed the title Start with cfg_version parsing cfg_version May 16, 2025
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tweaked the PR description a bit. We usually keep a tracking issue open until stabilization.

@@ -416,6 +416,7 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul
let values = cfg_map.entry(k.as_str()).or_default();
values.push(v.as_str());
}
Cfg::Version(..) => todo!(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea what to do here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the following code will be relevant:

if honor_rust_version.unwrap_or(true) {
let rustc_version = target_data.rustc.version.clone().into();
let mut incompatible = Vec::new();
let mut local_incompatible = false;
for unit in unit_graph.keys() {
let Some(pkg_msrv) = unit.pkg.rust_version() else {
continue;
};
if pkg_msrv.is_compatible_with(&rustc_version) {
continue;
}
local_incompatible |= unit.is_local();
incompatible.push((unit, pkg_msrv));
}

Comment on lines +254 to +255
self.t.next();
self.eat(&Token::LeftParen)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you have --cfg version=hello and so need to support #[cfg(version)1.30.0)] and #[cfg(version = "hello")]?

Comment on lines +437 to +443
while let Some(&(end, ch)) = self.s.peek() {
if ch == ')' {
let mut iter = self.orig[start..end].split('.');
let major = iter.next().unwrap().parse().unwrap();
if let Some(minor) = iter.next().map(|s| s.parse().unwrap()) {
if let Some(patch) = iter.next().map(|s| s.parse().unwrap()) {
if iter.next().is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some fairly deep nesting. Is there an alternative?

@epage
Copy link
Contributor

epage commented May 16, 2025

cfg(nightly) can be already parsed as a Name.

I'm not sure what this is referring to as I don't see this in the RFC or the rustc version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a stylistic thing, as you add tests, we prefer tests to be added in a commit before the change, with them passing. Your change then includes updating the tests to make sure they pass. How to apply this is dependent on the PR (and sometimes it just doesn't work). In this case, I'd write the tests without #[cfg(version)] and then add it in the follow ups.

@@ -416,6 +416,7 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul
let values = cfg_map.entry(k.as_str()).or_default();
values.push(v.as_str());
}
Cfg::Version(..) => todo!(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have this behind an unstable gate or insta-stabilize once the stabilization report for the rustc side is done?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-scripts Area: build.rs scripts A-cfg-expr Area: Platform cfg expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants