Merge rust-bitcoin/rust-bitcoin#2146: Create uniform build script
fde6479c6a
Create uniform build script (yancy) Pull request description: Previously, each unique compiler cfg attribute that appeared in the codebase was hard coded and emitted to stdout at compile time. This meant keeping the file up to date as different compiler cfg attributes changed. It's inconsequential to emit a compiler version that's not used, so this change just emits all possibilities to reduce the maintenance burden of the build script. Note that there is a bit of diff noise in one of the `build.rs` since I simply did a copy of one to the other to make them uniform. ACKs for top commit: Kixunil: ACKfde6479c6a
tcharding: ACKfde6479c6a
apoelstra: ACKfde6479c6a
Tree-SHA512: 401134c168a604a092b72c3980fae6d20adda761273ea47a887cf4c01838536241a45f310cbc2b5941311d533e1d10c848062198af70c0ed619a57973e842840
This commit is contained in:
commit
0b1fe094e4
|
@ -1,10 +1,13 @@
|
||||||
|
const MSRV_MINOR: u64 = 48;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let rustc = std::env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
|
let rustc = std::env::var_os("RUSTC");
|
||||||
|
let rustc = rustc.as_ref().map(std::path::Path::new).unwrap_or_else(|| "rustc".as_ref());
|
||||||
let output = std::process::Command::new(rustc)
|
let output = std::process::Command::new(rustc)
|
||||||
.arg("--version")
|
.arg("--version")
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to run rustc --version");
|
.unwrap_or_else(|error| panic!("Failed to run `{:?} --version`: {:?}", rustc, error));
|
||||||
assert!(output.status.success(), "Failed to get rust version");
|
assert!(output.status.success(), "{:?} -- version returned non-zero exit code", rustc);
|
||||||
let stdout = String::from_utf8(output.stdout).expect("rustc produced non-UTF-8 output");
|
let stdout = String::from_utf8(output.stdout).expect("rustc produced non-UTF-8 output");
|
||||||
let version_prefix = "rustc ";
|
let version_prefix = "rustc ";
|
||||||
if !stdout.starts_with(version_prefix) {
|
if !stdout.starts_with(version_prefix) {
|
||||||
|
@ -16,16 +19,15 @@ fn main() {
|
||||||
let version = &version[..end];
|
let version = &version[..end];
|
||||||
let mut version_components = version.split('.');
|
let mut version_components = version.split('.');
|
||||||
let major = version_components.next().unwrap();
|
let major = version_components.next().unwrap();
|
||||||
assert_eq!(major, "1", "Unexpected Rust version");
|
assert_eq!(major, "1", "Unexpected Rust major version");
|
||||||
let minor = version_components
|
let minor = version_components
|
||||||
.next()
|
.next()
|
||||||
.unwrap_or("0")
|
.unwrap_or("0")
|
||||||
.parse::<u64>()
|
.parse::<u64>()
|
||||||
.expect("invalid Rust minor version");
|
.expect("invalid Rust minor version");
|
||||||
|
|
||||||
for activate_version in &[53, 60] {
|
// print cfg for all interesting versions less than or equal to minor
|
||||||
if minor >= *activate_version {
|
for version in MSRV_MINOR..=minor {
|
||||||
println!("cargo:rustc-cfg=rust_v_1_{}", activate_version);
|
println!("cargo:rustc-cfg=rust_v_1_{}", version);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
const MSRV_MINOR: u64 = 48;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let rustc = std::env::var_os("RUSTC");
|
let rustc = std::env::var_os("RUSTC");
|
||||||
let rustc = rustc.as_ref().map(std::path::Path::new).unwrap_or_else(|| "rustc".as_ref());
|
let rustc = rustc.as_ref().map(std::path::Path::new).unwrap_or_else(|| "rustc".as_ref());
|
||||||
|
@ -25,11 +27,7 @@ fn main() {
|
||||||
.expect("invalid Rust minor version");
|
.expect("invalid Rust minor version");
|
||||||
|
|
||||||
// print cfg for all interesting versions less than or equal to minor
|
// print cfg for all interesting versions less than or equal to minor
|
||||||
// 46 adds `track_caller`
|
for version in MSRV_MINOR..=minor {
|
||||||
// 55 adds `kind()` to `ParseIntError`
|
|
||||||
for version in &[46, 55] {
|
|
||||||
if *version <= minor {
|
|
||||||
println!("cargo:rustc-cfg=rust_v_1_{}", version);
|
println!("cargo:rustc-cfg=rust_v_1_{}", version);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue