Skip to content

Commit 158c3e9

Browse files
authored
Merge pull request #671 from svenstaro/fix-emscripten-target
Disable i128 and u128 on emscripten (fixes #669)
2 parents 8255494 + 0540168 commit 158c3e9

File tree

10 files changed

+29
-24
lines changed

10 files changed

+29
-24
lines changed

.travis.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ matrix:
141141
addons:
142142
chrome: stable
143143
script:
144-
# testing wasm32-unknown-emscripten fails because of rust-lang/rust#49877
145-
- cargo build --target wasm32-unknown-emscripten
144+
# Testing wasm32-unknown-emscripten fails because of rust-lang/rust#49877
145+
# However, we can still build and link all tests to make sure that works.
146+
# This is actually useful as it finds stuff such as rust-random/rand#669
147+
- EMCC_CFLAGS="-s ERROR_ON_UNDEFINED_SYMBOLS=0" cargo web test --target wasm32-unknown-emscripten --no-run
146148
#- cargo web test --target wasm32-unknown-emscripten
147149
#- cargo web test --nodejs --target wasm32-unknown-emscripten
148150
#- cargo build --target wasm32-unknown-unknown # without any features

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ A [separate changelog is kept for rand_core](rand_core/CHANGELOG.md).
99
You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.html) useful.
1010

1111

12+
## [0.6.2] - Unreleased
13+
- Disable `i128` and `u128` if the `target_os` is `emscripten`.
14+
1215
## [0.6.1] - 2018-11-22
1316
- Support sampling `Duration` also for `no_std` (only since Rust 1.25) (#649)
1417
- Disable default features of `libc` (#647)

rand_chacha/src/chacha.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl ChaChaRng {
114114
/// byte-offset.
115115
///
116116
/// Note: this function is currently only available with Rust 1.26 or later.
117-
#[cfg(rustc_1_26)]
117+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))]
118118
pub fn get_word_pos(&self) -> u128 {
119119
let mut c = (self.0.core.state[13] as u64) << 32
120120
| (self.0.core.state[12] as u64);
@@ -135,7 +135,7 @@ impl ChaChaRng {
135135
/// 60 bits.
136136
///
137137
/// Note: this function is currently only available with Rust 1.26 or later.
138-
#[cfg(rustc_1_26)]
138+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))]
139139
pub fn set_word_pos(&mut self, word_offset: u128) {
140140
let index = (word_offset as usize) & 0xF;
141141
let counter = (word_offset >> 4) as u64;
@@ -330,7 +330,7 @@ mod test {
330330
}
331331

332332
#[test]
333-
#[cfg(rustc_1_26)]
333+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))]
334334
fn test_chacha_true_values_c() {
335335
// Test vector 4 from
336336
// https://tools.ietf.org/html/draft-nir-cfrg-chacha20-poly1305-04

rand_pcg/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extern crate rand_core;
4242
#[cfg(feature="serde1")] #[macro_use] extern crate serde_derive;
4343

4444
mod pcg64;
45-
#[cfg(rustc_1_26)] mod pcg128;
45+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] mod pcg128;
4646

4747
pub use self::pcg64::{Pcg32, Lcg64Xsh32};
48-
#[cfg(rustc_1_26)] pub use self::pcg128::{Pcg64Mcg, Mcg128Xsl64};
48+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] pub use self::pcg128::{Pcg64Mcg, Mcg128Xsl64};

src/deprecated.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ impl SeedableRng for ChaChaRng {
151151
}
152152

153153
impl ChaChaRng {
154-
#[cfg(rustc_1_26)]
154+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))]
155155
pub fn get_word_pos(&self) -> u128 {
156156
self.0.get_word_pos()
157157
}
158158

159-
#[cfg(rustc_1_26)]
159+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))]
160160
pub fn set_word_pos(&mut self, word_offset: u128) {
161161
self.0.set_word_pos(word_offset)
162162
}

src/distributions/integer.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Distribution<u64> for Standard {
4545
}
4646
}
4747

48-
#[cfg(rustc_1_26)]
48+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))]
4949
impl Distribution<u128> for Standard {
5050
#[inline]
5151
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> u128 {
@@ -85,7 +85,7 @@ impl_int_from_uint! { i8, u8 }
8585
impl_int_from_uint! { i16, u16 }
8686
impl_int_from_uint! { i32, u32 }
8787
impl_int_from_uint! { i64, u64 }
88-
#[cfg(rustc_1_26)] impl_int_from_uint! { i128, u128 }
88+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] impl_int_from_uint! { i128, u128 }
8989
impl_int_from_uint! { isize, usize }
9090

9191
#[cfg(feature="simd_support")]
@@ -147,15 +147,15 @@ mod tests {
147147
rng.sample::<i16, _>(Standard);
148148
rng.sample::<i32, _>(Standard);
149149
rng.sample::<i64, _>(Standard);
150-
#[cfg(rustc_1_26)]
150+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))]
151151
rng.sample::<i128, _>(Standard);
152152

153153
rng.sample::<usize, _>(Standard);
154154
rng.sample::<u8, _>(Standard);
155155
rng.sample::<u16, _>(Standard);
156156
rng.sample::<u32, _>(Standard);
157157
rng.sample::<u64, _>(Standard);
158-
#[cfg(rustc_1_26)]
158+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))]
159159
rng.sample::<u128, _>(Standard);
160160
}
161161
}

src/distributions/uniform.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,15 @@ uniform_int_impl! { i8, i8, u8, i32, u32 }
473473
uniform_int_impl! { i16, i16, u16, i32, u32 }
474474
uniform_int_impl! { i32, i32, u32, i32, u32 }
475475
uniform_int_impl! { i64, i64, u64, i64, u64 }
476-
#[cfg(rustc_1_26)]
476+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))]
477477
uniform_int_impl! { i128, i128, u128, u128, u128 }
478478
uniform_int_impl! { isize, isize, usize, isize, usize }
479479
uniform_int_impl! { u8, i8, u8, i32, u32 }
480480
uniform_int_impl! { u16, i16, u16, i32, u32 }
481481
uniform_int_impl! { u32, i32, u32, i32, u32 }
482482
uniform_int_impl! { u64, i64, u64, i64, u64 }
483483
uniform_int_impl! { usize, isize, usize, isize, usize }
484-
#[cfg(rustc_1_26)]
484+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))]
485485
uniform_int_impl! { u128, u128, u128, i128, u128 }
486486

487487
#[cfg(all(feature = "simd_support", feature = "nightly"))]
@@ -990,7 +990,7 @@ mod tests {
990990
fn test_integers() {
991991
use core::{i8, i16, i32, i64, isize};
992992
use core::{u8, u16, u32, u64, usize};
993-
#[cfg(rustc_1_26)]
993+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))]
994994
use core::{i128, u128};
995995

996996
let mut rng = ::test::rng(251);
@@ -1054,7 +1054,7 @@ mod tests {
10541054
}
10551055
t!(i8, i16, i32, i64, isize,
10561056
u8, u16, u32, u64, usize);
1057-
#[cfg(rustc_1_26)]
1057+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))]
10581058
t!(i128, u128);
10591059

10601060
#[cfg(all(feature = "simd_support", feature = "nightly"))]

src/distributions/utils.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ macro_rules! wmul_impl {
6161
wmul_impl! { u8, u16, 8 }
6262
wmul_impl! { u16, u32, 16 }
6363
wmul_impl! { u32, u64, 32 }
64-
#[cfg(rustc_1_26)]
64+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))]
6565
wmul_impl! { u64, u128, 64 }
6666

6767
// This code is a translation of the __mulddi3 function in LLVM's
@@ -125,9 +125,9 @@ macro_rules! wmul_impl_large {
125125
)+
126126
};
127127
}
128-
#[cfg(not(rustc_1_26))]
128+
#[cfg(not(all(rustc_1_26, not(target_os = "emscripten"))))]
129129
wmul_impl_large! { u64, 32 }
130-
#[cfg(rustc_1_26)]
130+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))]
131131
wmul_impl_large! { u128, 64 }
132132

133133
macro_rules! wmul_impl_usize {

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,13 @@ macro_rules! impl_as_byte_slice {
549549
impl_as_byte_slice!(u16);
550550
impl_as_byte_slice!(u32);
551551
impl_as_byte_slice!(u64);
552-
#[cfg(rustc_1_26)] impl_as_byte_slice!(u128);
552+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] impl_as_byte_slice!(u128);
553553
impl_as_byte_slice!(usize);
554554
impl_as_byte_slice!(i8);
555555
impl_as_byte_slice!(i16);
556556
impl_as_byte_slice!(i32);
557557
impl_as_byte_slice!(i64);
558-
#[cfg(rustc_1_26)] impl_as_byte_slice!(i128);
558+
#[cfg(all(rustc_1_26, not(target_os = "emscripten")))] impl_as_byte_slice!(i128);
559559
impl_as_byte_slice!(isize);
560560

561561
macro_rules! impl_as_byte_slice_arrays {

src/rngs/small.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
1111
use {RngCore, SeedableRng, Error};
1212

13-
#[cfg(all(rustc_1_26, target_pointer_width = "64"))]
13+
#[cfg(all(all(rustc_1_26, not(target_os = "emscripten")), target_pointer_width = "64"))]
1414
type Rng = ::rand_pcg::Pcg64Mcg;
15-
#[cfg(not(all(rustc_1_26, target_pointer_width = "64")))]
15+
#[cfg(not(all(all(rustc_1_26, not(target_os = "emscripten")), target_pointer_width = "64")))]
1616
type Rng = ::rand_pcg::Pcg32;
1717

1818
/// An RNG recommended when small state, cheap initialization and good

0 commit comments

Comments
 (0)