Skip to content
1 change: 1 addition & 0 deletions crates/build-rs-test-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fn smoke_test_inputs() {
dbg!(cargo_encoded_rustflags());
dbg!(cargo_feature("unstable"));
dbg!(cargo_manifest_dir());
dbg!(cargo_manifest_path());
dbg!(cargo_manifest_links());
dbg!(cargo_pkg_authors());
dbg!(cargo_pkg_description());
Expand Down
24 changes: 11 additions & 13 deletions crates/build-rs/src/allow_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ use std::{process::Command, sync::OnceLock};
fn rust_version_minor() -> u32 {
static VERSION_MINOR: OnceLock<u32> = OnceLock::new();
*VERSION_MINOR.get_or_init(|| {
crate::input::cargo_pkg_rust_version()
.split('.')
.nth(1)
version_minor(&crate::input::cargo_pkg_rust_version().unwrap_or_default())
// assume build-rs's MSRV if none specified for the current package
.unwrap_or(env!("CARGO_PKG_RUST_VERSION").split('.').nth(1).unwrap())
.parse()
.unwrap()
.unwrap_or_else(|| version_minor(env!("CARGO_PKG_RUST_VERSION")).unwrap())
})
}

Expand All @@ -25,16 +21,18 @@ fn cargo_version_minor() -> u32 {
// > cargo -V # example output
// cargo 1.82.0 (8f40fc59f 2024-08-21)

String::from_utf8(out.stdout).expect("`cargo -V` should output valid UTF-8")
["cargo 1.".len()..]
.split('.')
.next()
.expect("`cargo -V` format should be stable")
.parse()
.unwrap()
let out = std::str::from_utf8(&out.stdout).expect("`cargo -V` should output valid UTF-8");
let version = out.split(' ').nth(1).unwrap();
version_minor(version).unwrap()
})
}

fn version_minor(version: &str) -> Option<u32> {
let minor = version.split('.').nth(1)?;
let minor = minor.parse().unwrap();
Some(minor)
}

pub(crate) fn double_colon_directives() -> bool {
// cargo errors on `cargo::` directives with insufficient package.rust-version
rust_version_minor() >= 77
Expand Down
Loading