From 2c05518810dbd9d175ad70cd7984c70cb17e369b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 15 May 2018 12:37:47 -0700 Subject: [PATCH 1/4] Build script that does nothing Eventually we will want a build script that enables Serde impls for i128 and u128. As a first step here is a build script that does nothing to see whether we can roll this out without breaking anyone's workflow, without having a supported feature at stake in the event that it needs to be rolled back. --- serde/Cargo.toml | 3 ++- serde/build.rs | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 serde/build.rs diff --git a/serde/Cargo.toml b/serde/Cargo.toml index 9443045c..a9a89c9c 100644 --- a/serde/Cargo.toml +++ b/serde/Cargo.toml @@ -10,7 +10,8 @@ documentation = "https://docs.serde.rs/serde/" keywords = ["serde", "serialization", "no_std"] categories = ["encoding"] readme = "README.md" -include = ["Cargo.toml", "src/**/*.rs", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] +include = ["Cargo.toml", "build.rs", "src/**/*.rs", "README.md", "LICENSE-APACHE", "LICENSE-MIT"] +build = "build.rs" [badges] travis-ci = { repository = "serde-rs/serde" } diff --git a/serde/build.rs b/serde/build.rs new file mode 100644 index 00000000..c66bf0e4 --- /dev/null +++ b/serde/build.rs @@ -0,0 +1,39 @@ +use std::env; +use std::process::Command; +use std::str::{self, FromStr}; + +fn main() { + let rustc = match env::var_os("RUSTC") { + Some(rustc) => rustc, + None => return, + }; + + let output = match Command::new(rustc).arg("--version").output() { + Ok(output) => output, + Err(_) => return, + }; + + let version = match str::from_utf8(&output.stdout) { + Ok(version) => version, + Err(_) => return, + }; + + let mut pieces = version.split('.'); + if pieces.next() != Some("rustc 1") { + return; + } + + let next = match pieces.next() { + Some(next) => next, + None => return, + }; + + let minor = match u32::from_str(next) { + Ok(minor) => minor, + Err(_) => return, + }; + + if minor >= 26 { + println!("cargo:rustc-cfg=integer128"); + } +} From 8890061f8213d605b9dff36d9e950f7d081b74b5 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 18 May 2018 14:41:40 +0200 Subject: [PATCH 2/4] Use `version_check` crate instead of handcrafted version parsing --- serde/Cargo.toml | 3 +++ serde/build.rs | 44 +++++++++----------------------------------- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/serde/Cargo.toml b/serde/Cargo.toml index a9a89c9c..22f5e5b8 100644 --- a/serde/Cargo.toml +++ b/serde/Cargo.toml @@ -23,6 +23,9 @@ serde_derive = { version = "1.0", optional = true, path = "../serde_derive" } [dev-dependencies] serde_derive = { version = "1.0", path = "../serde_derive" } +[build-dependencies] +version_check = "0.1.3" + ### FEATURES ################################################################# diff --git a/serde/build.rs b/serde/build.rs index c66bf0e4..4a6db049 100644 --- a/serde/build.rs +++ b/serde/build.rs @@ -1,39 +1,13 @@ -use std::env; -use std::process::Command; -use std::str::{self, FromStr}; +extern crate version_check; fn main() { - let rustc = match env::var_os("RUSTC") { - Some(rustc) => rustc, - None => return, + match version_check::is_min_version("1.26.0") { + Some((true, _)) => { + println!("cargo:rustc-cfg=integer128"); + }, + Some((false, _)) => {} + None => { + println!("could not figure out the rustc version"); + }, }; - - let output = match Command::new(rustc).arg("--version").output() { - Ok(output) => output, - Err(_) => return, - }; - - let version = match str::from_utf8(&output.stdout) { - Ok(version) => version, - Err(_) => return, - }; - - let mut pieces = version.split('.'); - if pieces.next() != Some("rustc 1") { - return; - } - - let next = match pieces.next() { - Some(next) => next, - None => return, - }; - - let minor = match u32::from_str(next) { - Ok(minor) => minor, - Err(_) => return, - }; - - if minor >= 26 { - println!("cargo:rustc-cfg=integer128"); - } } From 9f114548f4a34e4e001f5521213b6b8499a4d71d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 18 May 2018 11:48:05 -0700 Subject: [PATCH 3/4] Revert "Use `version_check` crate instead of handcrafted version parsing" This reverts commit 8890061f8213d605b9dff36d9e950f7d081b74b5. --- serde/Cargo.toml | 3 --- serde/build.rs | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/serde/Cargo.toml b/serde/Cargo.toml index 22f5e5b8..a9a89c9c 100644 --- a/serde/Cargo.toml +++ b/serde/Cargo.toml @@ -23,9 +23,6 @@ serde_derive = { version = "1.0", optional = true, path = "../serde_derive" } [dev-dependencies] serde_derive = { version = "1.0", path = "../serde_derive" } -[build-dependencies] -version_check = "0.1.3" - ### FEATURES ################################################################# diff --git a/serde/build.rs b/serde/build.rs index 4a6db049..c66bf0e4 100644 --- a/serde/build.rs +++ b/serde/build.rs @@ -1,13 +1,39 @@ -extern crate version_check; +use std::env; +use std::process::Command; +use std::str::{self, FromStr}; fn main() { - match version_check::is_min_version("1.26.0") { - Some((true, _)) => { - println!("cargo:rustc-cfg=integer128"); - }, - Some((false, _)) => {} - None => { - println!("could not figure out the rustc version"); - }, + let rustc = match env::var_os("RUSTC") { + Some(rustc) => rustc, + None => return, }; + + let output = match Command::new(rustc).arg("--version").output() { + Ok(output) => output, + Err(_) => return, + }; + + let version = match str::from_utf8(&output.stdout) { + Ok(version) => version, + Err(_) => return, + }; + + let mut pieces = version.split('.'); + if pieces.next() != Some("rustc 1") { + return; + } + + let next = match pieces.next() { + Some(next) => next, + None => return, + }; + + let minor = match u32::from_str(next) { + Ok(minor) => minor, + Err(_) => return, + }; + + if minor >= 26 { + println!("cargo:rustc-cfg=integer128"); + } } From c80f9238d77ec40a4fbfbe1cd19522214ab00282 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 18 May 2018 12:34:36 -0700 Subject: [PATCH 4/4] Link to i128 announcement --- serde/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/serde/build.rs b/serde/build.rs index c66bf0e4..cc191484 100644 --- a/serde/build.rs +++ b/serde/build.rs @@ -33,6 +33,8 @@ fn main() { Err(_) => return, }; + // 128-bit integers stabilized in Rust 1.26: + // https://blog.rust-lang.org/2018/05/10/Rust-1.26.html if minor >= 26 { println!("cargo:rustc-cfg=integer128"); }