Skip to content

Commit d778189

Browse files
bors[bot]cuviper
andcommitted
Merge #8
8: Automatically detect support for i128/u128 r=cuviper a=cuviper Co-authored-by: Josh Stone <[email protected]>
2 parents 584f6f4 + 5b5988c commit d778189

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ categories = ["algorithms", "science", "no-std"]
88
license = "MIT/Apache-2.0"
99
repository = "https://github.com/rust-num/num-integer"
1010
name = "num-integer"
11-
version = "0.1.37"
11+
version = "0.1.38"
1212
readme = "README.md"
13+
build = "build.rs"
1314

1415
[package.metadata.docs.rs]
15-
all-features = true
16+
features = ["std"]
1617

1718
[dependencies.num-traits]
18-
version = "0.2.3"
19+
version = "0.2.4"
1920
default-features = false
2021

2122
[features]

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ default-features = false
3636
There is no functional difference with and without `std` at this time, but
3737
there may be in the future.
3838

39-
Implementations for `i128` and `u128` are only available when `i128` is enabled.
39+
Implementations for `i128` and `u128` are only available with Rust 1.26 and
40+
later. The build script automatically detects this, but you can make it
41+
mandatory by enabling the `i128` crate feature.
42+
4043

4144
## Releases
4245

RELEASES.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# Release 0.1.38
2+
3+
- [Support for 128-bit integers is now automatically detected and enabled.][69]
4+
Setting the `i128` crate feature now causes the build script to panic if such
5+
support is not detected.
6+
7+
**Contributors**: @cuviper
8+
9+
[8]: https://github.com/rust-num/num-integer/pull/8
10+
111
# Release 0.1.37
212

313
- [`Integer` is now implemented for `i128` and `u128`][7] starting with Rust

build.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::env;
2+
use std::io::Write;
3+
use std::process::{Command, Stdio};
4+
5+
fn main() {
6+
if probe("fn main() { 0i128; }") {
7+
println!("cargo:rustc-cfg=has_i128");
8+
} else if env::var_os("CARGO_FEATURE_I128").is_some() {
9+
panic!("i128 support was not detected!");
10+
}
11+
}
12+
13+
/// Test if a code snippet can be compiled
14+
fn probe(code: &str) -> bool {
15+
let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
16+
let out_dir = env::var_os("OUT_DIR").expect("environment variable OUT_DIR");
17+
18+
let mut child = Command::new(rustc)
19+
.arg("--out-dir")
20+
.arg(out_dir)
21+
.arg("--emit=obj")
22+
.arg("-")
23+
.stdin(Stdio::piped())
24+
.spawn()
25+
.expect("rustc probe");
26+
27+
child
28+
.stdin
29+
.as_mut()
30+
.expect("rustc stdin")
31+
.write_all(code.as_bytes())
32+
.expect("write rustc stdin");
33+
34+
child.wait().expect("rustc probe").success()
35+
}

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl_integer_for_isize!(i16, test_integer_i16);
503503
impl_integer_for_isize!(i32, test_integer_i32);
504504
impl_integer_for_isize!(i64, test_integer_i64);
505505
impl_integer_for_isize!(isize, test_integer_isize);
506-
#[cfg(feature = "i128")]
506+
#[cfg(has_i128)]
507507
impl_integer_for_isize!(i128, test_integer_i128);
508508

509509
macro_rules! impl_integer_for_usize {
@@ -677,7 +677,7 @@ impl_integer_for_usize!(u16, test_integer_u16);
677677
impl_integer_for_usize!(u32, test_integer_u32);
678678
impl_integer_for_usize!(u64, test_integer_u64);
679679
impl_integer_for_usize!(usize, test_integer_usize);
680-
#[cfg(feature = "i128")]
680+
#[cfg(has_i128)]
681681
impl_integer_for_usize!(u128, test_integer_u128);
682682

683683
/// An iterator over binomial coefficients.

0 commit comments

Comments
 (0)