From c8030393787fbcfa205793a5e3f2c4bf7378ec29 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 11 May 2018 16:22:00 -0700 Subject: [PATCH 1/2] Automatically detect support for i128/u128 --- Cargo.toml | 5 +++-- README.md | 5 ++++- build.rs | 35 +++++++++++++++++++++++++++++++++++ src/lib.rs | 4 ++-- 4 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 build.rs diff --git a/Cargo.toml b/Cargo.toml index 1d72805..8a296d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,12 +10,13 @@ repository = "https://github.com/rust-num/num-integer" name = "num-integer" version = "0.1.37" readme = "README.md" +build = "build.rs" [package.metadata.docs.rs] -all-features = true +features = ["std"] [dependencies.num-traits] -version = "0.2.3" +version = "0.2.4" default-features = false [features] diff --git a/README.md b/README.md index e299edf..4b3d42e 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,10 @@ default-features = false There is no functional difference with and without `std` at this time, but there may be in the future. -Implementations for `i128` and `u128` are only available when `i128` is enabled. +Implementations for `i128` and `u128` are only available with Rust 1.26 and +later. The build script automatically detects this, but you can make it +mandatory by enabling the `i128` crate feature. + ## Releases diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..fd60866 --- /dev/null +++ b/build.rs @@ -0,0 +1,35 @@ +use std::env; +use std::io::Write; +use std::process::{Command, Stdio}; + +fn main() { + if probe("fn main() { 0i128; }") { + println!("cargo:rustc-cfg=has_i128"); + } else if env::var_os("CARGO_FEATURE_I128").is_some() { + panic!("i128 support was not detected!"); + } +} + +/// Test if a code snippet can be compiled +fn probe(code: &str) -> bool { + let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into()); + let out_dir = env::var_os("OUT_DIR").expect("environment variable OUT_DIR"); + + let mut child = Command::new(rustc) + .arg("--out-dir") + .arg(out_dir) + .arg("--emit=obj") + .arg("-") + .stdin(Stdio::piped()) + .spawn() + .expect("rustc probe"); + + child + .stdin + .as_mut() + .expect("rustc stdin") + .write_all(code.as_bytes()) + .expect("write rustc stdin"); + + child.wait().expect("rustc probe").success() +} diff --git a/src/lib.rs b/src/lib.rs index 0929835..9f6a6e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -503,7 +503,7 @@ impl_integer_for_isize!(i16, test_integer_i16); impl_integer_for_isize!(i32, test_integer_i32); impl_integer_for_isize!(i64, test_integer_i64); impl_integer_for_isize!(isize, test_integer_isize); -#[cfg(feature = "i128")] +#[cfg(has_i128)] impl_integer_for_isize!(i128, test_integer_i128); macro_rules! impl_integer_for_usize { @@ -677,7 +677,7 @@ impl_integer_for_usize!(u16, test_integer_u16); impl_integer_for_usize!(u32, test_integer_u32); impl_integer_for_usize!(u64, test_integer_u64); impl_integer_for_usize!(usize, test_integer_usize); -#[cfg(feature = "i128")] +#[cfg(has_i128)] impl_integer_for_usize!(u128, test_integer_u128); /// An iterator over binomial coefficients. From 5b5988c76a0aca62f2834018f270950344f51e09 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 11 May 2018 16:25:13 -0700 Subject: [PATCH 2/2] Release 0.1.38 --- Cargo.toml | 2 +- RELEASES.md | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8a296d6..ac66aa3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ categories = ["algorithms", "science", "no-std"] license = "MIT/Apache-2.0" repository = "https://github.com/rust-num/num-integer" name = "num-integer" -version = "0.1.37" +version = "0.1.38" readme = "README.md" build = "build.rs" diff --git a/RELEASES.md b/RELEASES.md index 29bad0e..655b9aa 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,13 @@ +# Release 0.1.38 + +- [Support for 128-bit integers is now automatically detected and enabled.][69] + Setting the `i128` crate feature now causes the build script to panic if such + support is not detected. + +**Contributors**: @cuviper + +[8]: https://github.com/rust-num/num-integer/pull/8 + # Release 0.1.37 - [`Integer` is now implemented for `i128` and `u128`][7] starting with Rust