Skip to content

Commit 8890061

Browse files
committed
Use version_check crate instead of handcrafted version parsing
1 parent 2c05518 commit 8890061

File tree

2 files changed

+12
-35
lines changed

2 files changed

+12
-35
lines changed

serde/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ serde_derive = { version = "1.0", optional = true, path = "../serde_derive" }
2323
[dev-dependencies]
2424
serde_derive = { version = "1.0", path = "../serde_derive" }
2525

26+
[build-dependencies]
27+
version_check = "0.1.3"
28+
2629

2730
### FEATURES #################################################################
2831

serde/build.rs

+9-35
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,13 @@
1-
use std::env;
2-
use std::process::Command;
3-
use std::str::{self, FromStr};
1+
extern crate version_check;
42

53
fn main() {
6-
let rustc = match env::var_os("RUSTC") {
7-
Some(rustc) => rustc,
8-
None => return,
4+
match version_check::is_min_version("1.26.0") {
5+
Some((true, _)) => {
6+
println!("cargo:rustc-cfg=integer128");
7+
},
8+
Some((false, _)) => {}
9+
None => {
10+
println!("could not figure out the rustc version");
11+
},
912
};
10-
11-
let output = match Command::new(rustc).arg("--version").output() {
12-
Ok(output) => output,
13-
Err(_) => return,
14-
};
15-
16-
let version = match str::from_utf8(&output.stdout) {
17-
Ok(version) => version,
18-
Err(_) => return,
19-
};
20-
21-
let mut pieces = version.split('.');
22-
if pieces.next() != Some("rustc 1") {
23-
return;
24-
}
25-
26-
let next = match pieces.next() {
27-
Some(next) => next,
28-
None => return,
29-
};
30-
31-
let minor = match u32::from_str(next) {
32-
Ok(minor) => minor,
33-
Err(_) => return,
34-
};
35-
36-
if minor >= 26 {
37-
println!("cargo:rustc-cfg=integer128");
38-
}
3913
}

0 commit comments

Comments
 (0)