diff --git a/.travis.yml b/.travis.yml index d6f2342057..73f50230a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ matrix: install: - if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then rustup target add wasm32-unknown-unknown; fi +- if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo install cargo-no-std-check; fi - if [ -n "$TARGET" ]; then rustup target add "$TARGET" && sudo apt-get install --yes qemu-user-static; fi - if [ "$TARGET" == "armv7-unknown-linux-gnueabihf" ]; then sudo apt-get install --yes crossbuild-essential-armhf && export QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf; fi - rustup component add rustfmt @@ -25,7 +26,7 @@ script: - if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo check --tests --manifest-path=fuzz/Cargo.toml; fi - if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo check --benches --manifest-path=benches/Cargo.toml; fi # Make sure `no_std` version checks. -- if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo +nightly check --no-default-features --features core; fi +- if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo no-std-check --no-default-features --features core; fi # Check that `vec_memory` feature works. - cargo check --features vec_memory - travis_wait 60 ./test.sh diff --git a/Cargo.toml b/Cargo.toml index b8ab4bf0fe..6e18a409c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,8 @@ wasmi-validation = { version = "0.3", path = "validation", default-features = fa parity-wasm = { version = "0.41.0", default-features = false } memory_units = "0.3.0" libm = { version = "0.1.2", optional = true } -num-rational = "0.2.2" -num-traits = "0.2.8" +num-rational = { version = "0.2.2", default-features = false } +num-traits = { version = "0.2.8", default-features = false } libc = "0.2.58" errno = { version = "0.2.4", optional = true } @@ -32,6 +32,7 @@ std = [ "parity-wasm/std", "wasmi-validation/std", "num-rational/std", + "num-rational/bigint-std", "num-traits/std" ] # Enable for no_std support diff --git a/src/nan_preserving_float.rs b/src/nan_preserving_float.rs index 994c91a23b..b062c8d52c 100644 --- a/src/nan_preserving_float.rs +++ b/src/nan_preserving_float.rs @@ -2,6 +2,7 @@ use core::cmp::{Ordering, PartialEq, PartialOrd}; use core::ops::{Add, Div, Mul, Neg, Rem, Sub}; +use num_traits::float::FloatCore; macro_rules! impl_binop { ($for:ident, $is:ident, $op:ident, $func_name:ident) => { @@ -63,7 +64,7 @@ macro_rules! float { } pub fn fract(self) -> Self { - self.to_float().fract().into() + FloatCore::fract(self.to_float()).into() } pub fn min(self, other: Self) -> Self { diff --git a/src/value.rs b/src/value.rs index 8d5061af7a..7d8fea9a63 100644 --- a/src/value.rs +++ b/src/value.rs @@ -368,6 +368,9 @@ impl WrapInto for F64 { macro_rules! impl_try_truncate_into { (@primitive $from: ident, $into: ident, $to_primitive:path) => { impl TryTruncateInto<$into, TrapKind> for $from { + // FIXME: BigRational uses the num-bigint crate, which requires std + // as of version `0.2.6`. `num-bigint` 0.3 will have no_std support. + #[cfg(feature = "std")] fn try_truncate_into(self) -> Result<$into, TrapKind> { // Casting from a float to an integer will round the float towards zero num_rational::BigRational::from_float(self) @@ -375,6 +378,12 @@ macro_rules! impl_try_truncate_into { .and_then(|val| $to_primitive(&val)) .ok_or(TrapKind::InvalidConversionToInt) } + + #[cfg(not(feature = "std"))] + fn try_truncate_into(self) -> Result<$into, TrapKind> { + // Casting from a float to an integer will round the float towards zero + $to_primitive(&self).ok_or(TrapKind::InvalidConversionToInt) + } } }; (@wrapped $from:ident, $intermediate:ident, $into:ident) => {