Merge pull request #686 from dhardy/master

Fix #682
diff --git a/.travis.yml b/.travis.yml
index bd22c0f..b41e681 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -149,8 +149,8 @@
         #- cargo web test --target wasm32-unknown-emscripten
         #- cargo web test --nodejs --target wasm32-unknown-emscripten
         #- cargo build --target wasm32-unknown-unknown # without any features
-        - cargo build --target wasm32-unknown-unknown --features=rand_os/wasm-bindgen
-        - cd rand_os && cargo web test --target wasm32-unknown-unknown --features=stdweb
+        - cargo build --target wasm32-unknown-unknown --features=wasm-bindgen
+        - cargo web test --target wasm32-unknown-unknown --features=stdweb
 
     - rust: nightly
       env: DESCRIPTION="cross-platform builder (doesn't run tests)"
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 061d1cb..6aa0a24 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,11 @@
 You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.html) useful.
 
 
+## [0.6.4] - 2019-01-08
+### Fixes
+- Move wasm-bindgen shims to correct crate (#686)
+- Make `wasm32-unknown-unknown` compile but fail at run-time if missing bindingsg (#686)
+
 ## [0.6.3] - 2019-01-04
 ### Fixes
 - Make the `std` feature require the optional `rand_os` dependency (#675)
diff --git a/Cargo.toml b/Cargo.toml
index a5f3176..d802d36 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "rand"
-version = "0.6.3"
+version = "0.6.4"
 authors = ["The Rand Project Developers", "The Rust Project Developers"]
 license = "MIT/Apache-2.0"
 readme = "README.md"
diff --git a/README.md b/README.md
index 95970af..314a57f 100644
--- a/README.md
+++ b/README.md
@@ -74,8 +74,15 @@
 
 ## Crate Features
 
-Rand is built with only the `std` feature enabled by default. The following
-optional features are available:
+Rand is built with the `std` and `rand_os` features enabled by default:
+
+-   `std` enables functionality dependent on the `std` lib and implies `alloc`
+    and `rand_os`
+-   `rand_os` enables the `rand_os` crate, `rngs::OsRng` and enables its usage;
+    the continued existance of this feature is not guaranteed so users are
+    encouraged to specify `std` instead
+
+The following optional features are available:
 
 - `alloc` can be used instead of `std` to provide `Vec` and `Box`.
 - `log` enables some logging via the `log` crate.
diff --git a/rand_os/CHANGELOG.md b/rand_os/CHANGELOG.md
index b23c990..459f7bd 100644
--- a/rand_os/CHANGELOG.md
+++ b/rand_os/CHANGELOG.md
@@ -4,5 +4,10 @@
 The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
+
+## [0.1.1] - 2019-01-08
+### Additions
+- Add support for x86_64-fortanix-unknown-sgx target (#670)
+
 ## [0.1.0] - 2019-01-04
 Initial release.
diff --git a/rand_os/Cargo.toml b/rand_os/Cargo.toml
index 7413c15..2f9224a 100644
--- a/rand_os/Cargo.toml
+++ b/rand_os/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "rand_os"
-version = "0.1.0"
+version = "0.1.1"
 authors = ["The Rand Project Developers"]
 license = "MIT/Apache-2.0"
 readme = "README.md"
@@ -21,9 +21,8 @@
 [target.'cfg(unix)'.dependencies]
 libc = "0.2"
 
-# TODO: check if all features are required
 [target.'cfg(windows)'.dependencies]
-winapi = { version = "0.3", features = ["minwindef", "ntsecapi", "profileapi", "winnt"] }
+winapi = { version = "0.3", features = ["minwindef", "ntsecapi", "winnt"] }
 
 [target.'cfg(target_os = "cloudabi")'.dependencies]
 cloudabi = "0.0.3"
diff --git a/rand_os/src/lib.rs b/rand_os/src/lib.rs
index 4f139d9..67b0dfe 100644
--- a/rand_os/src/lib.rs
+++ b/rand_os/src/lib.rs
@@ -126,8 +126,8 @@
 #![deny(missing_docs)]
 #![deny(missing_debug_implementations)]
 #![doc(test(attr(allow(unused_variables), deny(warnings))))]
-// for stdweb
-#![recursion_limit="128"]
+
+#![cfg_attr(feature = "stdweb", recursion_limit="128")]
 
 pub extern crate rand_core;
 #[cfg(feature = "log")]
@@ -333,13 +333,33 @@
     wasm32_stdweb
 );
 
+/// Per #678 we use run-time failure where WASM bindings are missing
 #[cfg(all(
     target_arch = "wasm32",
     not(target_os = "emscripten"),
     not(feature = "wasm-bindgen"),
     not(feature = "stdweb"),
 ))]
-compile_error!("enable either wasm_bindgen or stdweb feature");
+mod imp {
+    use rand_core::{Error, ErrorKind};
+    use super::OsRngImpl;
+    
+    #[derive(Clone, Debug)]
+    pub struct OsRng;
+
+    impl OsRngImpl for OsRng {
+        fn new() -> Result<OsRng, Error> {
+            Err(Error::new(ErrorKind::Unavailable,
+                "OsRng: support for wasm32 requires emscripten, stdweb or wasm-bindgen"))
+        }
+
+        fn fill_chunk(&mut self, _dest: &mut [u8]) -> Result<(), Error> {
+            unimplemented!()
+        }
+
+        fn method_str(&self) -> &'static str { unimplemented!() }
+    }
+}
 
 #[cfg(not(any(
     target_os = "android",
@@ -362,3 +382,58 @@
     target_env = "sgx"
 )))]
 compile_error!("OS RNG support is not available for this platform");
+
+// Due to rustwasm/wasm-bindgen#201 this can't be defined in the inner os
+// modules, so hack around it for now and place it at the root.
+#[cfg(all(feature = "wasm-bindgen", target_arch = "wasm32"))]
+#[doc(hidden)]
+#[allow(missing_debug_implementations)]
+pub mod __wbg_shims {
+
+    // `extern { type Foo; }` isn't supported on 1.22 syntactically, so use a
+    // macro to work around that.
+    macro_rules! rust_122_compat {
+        ($($t:tt)*) => ($($t)*)
+    }
+
+    rust_122_compat! {
+        extern crate wasm_bindgen;
+
+        pub use wasm_bindgen::prelude::*;
+
+        #[wasm_bindgen]
+        extern "C" {
+            pub type Function;
+            #[wasm_bindgen(constructor)]
+            pub fn new(s: &str) -> Function;
+            #[wasm_bindgen(method)]
+            pub fn call(this: &Function, self_: &JsValue) -> JsValue;
+
+            pub type This;
+            #[wasm_bindgen(method, getter, structural, js_name = self)]
+            pub fn self_(me: &This) -> JsValue;
+            #[wasm_bindgen(method, getter, structural)]
+            pub fn crypto(me: &This) -> JsValue;
+
+            #[derive(Clone, Debug)]
+            pub type BrowserCrypto;
+
+            // TODO: these `structural` annotations here ideally wouldn't be here to
+            // avoid a JS shim, but for now with feature detection they're
+            // unavoidable.
+            #[wasm_bindgen(method, js_name = getRandomValues, structural, getter)]
+            pub fn get_random_values_fn(me: &BrowserCrypto) -> JsValue;
+            #[wasm_bindgen(method, js_name = getRandomValues, structural)]
+            pub fn get_random_values(me: &BrowserCrypto, buf: &mut [u8]);
+
+            #[wasm_bindgen(js_name = require)]
+            pub fn node_require(s: &str) -> NodeCrypto;
+
+            #[derive(Clone, Debug)]
+            pub type NodeCrypto;
+
+            #[wasm_bindgen(method, js_name = randomFillSync, structural)]
+            pub fn random_fill_sync(me: &NodeCrypto, buf: &mut [u8]);
+        }
+    }
+}
diff --git a/src/deprecated.rs b/src/deprecated.rs
index 76055c1..88eb09f 100644
--- a/src/deprecated.rs
+++ b/src/deprecated.rs
@@ -291,45 +291,12 @@
 impl CryptoRng for StdRng {}
 
 
-#[cfg(all(feature="std",
-          any(target_os = "linux", target_os = "android",
-              target_os = "netbsd",
-              target_os = "dragonfly",
-              target_os = "haiku",
-              target_os = "emscripten",
-              target_os = "solaris",
-              target_os = "cloudabi",
-              target_os = "macos", target_os = "ios",
-              target_os = "freebsd",
-              target_os = "openbsd", target_os = "bitrig",
-              target_os = "redox",
-              target_os = "fuchsia",
-              windows,
-              all(target_arch = "wasm32", feature = "stdweb"),
-              all(target_arch = "wasm32", feature = "wasm-bindgen"),
-)))]
+#[cfg(feature="rand_os")]
 #[derive(Clone, Debug)]
 #[deprecated(since="0.6.0", note="import with rand::rngs::OsRng instead")]
 pub struct OsRng(rngs::OsRng);
 
-#[cfg(all(feature="std",
-          any(target_os = "linux", target_os = "android",
-              target_os = "netbsd",
-              target_os = "dragonfly",
-              target_os = "haiku",
-              target_os = "emscripten",
-              target_os = "solaris",
-              target_os = "cloudabi",
-              target_os = "macos", target_os = "ios",
-              target_os = "freebsd",
-              target_os = "openbsd", target_os = "bitrig",
-              target_os = "redox",
-              target_os = "fuchsia",
-              windows,
-              all(target_arch = "wasm32", feature = "stdweb"),
-              all(target_arch = "wasm32", feature = "wasm-bindgen"),
-)))]
-#[cfg(feature="std")]
+#[cfg(feature="rand_os")]
 impl RngCore for OsRng {
     #[inline(always)]
     fn next_u32(&mut self) -> u32 {
@@ -352,48 +319,14 @@
     }
 }
 
-#[cfg(all(feature="std",
-          any(target_os = "linux", target_os = "android",
-              target_os = "netbsd",
-              target_os = "dragonfly",
-              target_os = "haiku",
-              target_os = "emscripten",
-              target_os = "solaris",
-              target_os = "cloudabi",
-              target_os = "macos", target_os = "ios",
-              target_os = "freebsd",
-              target_os = "openbsd", target_os = "bitrig",
-              target_os = "redox",
-              target_os = "fuchsia",
-              windows,
-              all(target_arch = "wasm32", feature = "stdweb"),
-              all(target_arch = "wasm32", feature = "wasm-bindgen"),
-)))]
-#[cfg(feature="std")]
+#[cfg(feature="rand_os")]
 impl OsRng {
     pub fn new() -> Result<Self, Error> {
         rngs::OsRng::new().map(OsRng)
     }
 }
 
-#[cfg(all(feature="std",
-          any(target_os = "linux", target_os = "android",
-              target_os = "netbsd",
-              target_os = "dragonfly",
-              target_os = "haiku",
-              target_os = "emscripten",
-              target_os = "solaris",
-              target_os = "cloudabi",
-              target_os = "macos", target_os = "ios",
-              target_os = "freebsd",
-              target_os = "openbsd", target_os = "bitrig",
-              target_os = "redox",
-              target_os = "fuchsia",
-              windows,
-              all(target_arch = "wasm32", feature = "stdweb"),
-              all(target_arch = "wasm32", feature = "wasm-bindgen"),
-)))]
-#[cfg(feature="std")]
+#[cfg(feature="rand_os")]
 impl CryptoRng for OsRng {}
 
 
diff --git a/src/lib.rs b/src/lib.rs
index 052621e..ca231b5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -58,17 +58,12 @@
 #![cfg_attr(not(feature="std"), no_std)]
 #![cfg_attr(all(feature="alloc", not(feature="std")), feature(alloc))]
 #![cfg_attr(all(feature="simd_support", feature="nightly"), feature(stdsimd))]
-#![cfg_attr(feature = "stdweb", recursion_limit="128")]
 
 #[cfg(feature = "std")] extern crate core;
 #[cfg(all(feature = "alloc", not(feature="std")))] #[macro_use] extern crate alloc;
 
 #[cfg(feature="simd_support")] extern crate packed_simd;
 
-#[cfg(all(target_arch="wasm32", not(target_os="emscripten"), feature="stdweb"))]
-#[macro_use]
-extern crate stdweb;
-
 #[cfg(feature = "rand_os")]
 extern crate rand_os;
 
@@ -119,23 +114,7 @@
 #[cfg(feature="std")] #[doc(hidden)] pub use deprecated::EntropyRng;
 
 #[allow(deprecated)]
-#[cfg(all(feature="std",
-          any(target_os = "linux", target_os = "android",
-              target_os = "netbsd",
-              target_os = "dragonfly",
-              target_os = "haiku",
-              target_os = "emscripten",
-              target_os = "solaris",
-              target_os = "cloudabi",
-              target_os = "macos", target_os = "ios",
-              target_os = "freebsd",
-              target_os = "openbsd", target_os = "bitrig",
-              target_os = "redox",
-              target_os = "fuchsia",
-              windows,
-              all(target_arch = "wasm32", feature = "stdweb"),
-              all(target_arch = "wasm32", feature = "wasm-bindgen"),
-)))]
+#[cfg(feature="rand_os")]
 #[doc(hidden)]
 pub use deprecated::OsRng;
 
@@ -152,23 +131,7 @@
     pub use rngs::TimerError;
 }
 #[allow(deprecated)]
-#[cfg(all(feature="std",
-          any(target_os = "linux", target_os = "android",
-              target_os = "netbsd",
-              target_os = "dragonfly",
-              target_os = "haiku",
-              target_os = "emscripten",
-              target_os = "solaris",
-              target_os = "cloudabi",
-              target_os = "macos", target_os = "ios",
-              target_os = "freebsd",
-              target_os = "openbsd", target_os = "bitrig",
-              target_os = "redox",
-              target_os = "fuchsia",
-              windows,
-              all(target_arch = "wasm32", feature = "stdweb"),
-              all(target_arch = "wasm32", feature = "wasm-bindgen"),
-)))]
+#[cfg(feature="rand_os")]
 #[doc(hidden)]
 pub mod os {
     pub use deprecated::OsRng;
@@ -712,61 +675,6 @@
     thread_rng().gen()
 }
 
-// Due to rustwasm/wasm-bindgen#201 this can't be defined in the inner os
-// modules, so hack around it for now and place it at the root.
-#[cfg(all(feature = "wasm-bindgen", target_arch = "wasm32"))]
-#[doc(hidden)]
-#[allow(missing_debug_implementations)]
-pub mod __wbg_shims {
-
-    // `extern { type Foo; }` isn't supported on 1.22 syntactically, so use a
-    // macro to work around that.
-    macro_rules! rust_122_compat {
-        ($($t:tt)*) => ($($t)*)
-    }
-
-    rust_122_compat! {
-        extern crate wasm_bindgen;
-
-        pub use wasm_bindgen::prelude::*;
-
-        #[wasm_bindgen]
-        extern "C" {
-            pub type Function;
-            #[wasm_bindgen(constructor)]
-            pub fn new(s: &str) -> Function;
-            #[wasm_bindgen(method)]
-            pub fn call(this: &Function, self_: &JsValue) -> JsValue;
-
-            pub type This;
-            #[wasm_bindgen(method, getter, structural, js_name = self)]
-            pub fn self_(me: &This) -> JsValue;
-            #[wasm_bindgen(method, getter, structural)]
-            pub fn crypto(me: &This) -> JsValue;
-
-            #[derive(Clone, Debug)]
-            pub type BrowserCrypto;
-
-            // TODO: these `structural` annotations here ideally wouldn't be here to
-            // avoid a JS shim, but for now with feature detection they're
-            // unavoidable.
-            #[wasm_bindgen(method, js_name = getRandomValues, structural, getter)]
-            pub fn get_random_values_fn(me: &BrowserCrypto) -> JsValue;
-            #[wasm_bindgen(method, js_name = getRandomValues, structural)]
-            pub fn get_random_values(me: &BrowserCrypto, buf: &mut [u8]);
-
-            #[wasm_bindgen(js_name = require)]
-            pub fn node_require(s: &str) -> NodeCrypto;
-
-            #[derive(Clone, Debug)]
-            pub type NodeCrypto;
-
-            #[wasm_bindgen(method, js_name = randomFillSync, structural)]
-            pub fn random_fill_sync(me: &NodeCrypto, buf: &mut [u8]);
-        }
-    }
-}
-
 #[cfg(test)]
 mod test {
     use rngs::mock::StepRng;
diff --git a/src/rngs/entropy.rs b/src/rngs/entropy.rs
index 8736324..372b4d7 100644
--- a/src/rngs/entropy.rs
+++ b/src/rngs/entropy.rs
@@ -191,43 +191,11 @@
 }
 
 
-#[cfg(all(feature="std",
-          any(target_os = "linux", target_os = "android",
-              target_os = "netbsd",
-              target_os = "dragonfly",
-              target_os = "haiku",
-              target_os = "emscripten",
-              target_os = "solaris",
-              target_os = "cloudabi",
-              target_os = "macos", target_os = "ios",
-              target_os = "freebsd",
-              target_os = "openbsd", target_os = "bitrig",
-              target_os = "redox",
-              target_os = "fuchsia",
-              windows,
-              all(target_arch = "wasm32", feature = "stdweb"),
-              all(target_arch = "wasm32", feature = "wasm-bindgen"),
-)))]
+#[cfg(feature="rand_os")]
 #[derive(Clone, Debug)]
 pub struct Os(rngs::OsRng);
 
-#[cfg(all(feature="std",
-          any(target_os = "linux", target_os = "android",
-              target_os = "netbsd",
-              target_os = "dragonfly",
-              target_os = "haiku",
-              target_os = "emscripten",
-              target_os = "solaris",
-              target_os = "cloudabi",
-              target_os = "macos", target_os = "ios",
-              target_os = "freebsd",
-              target_os = "openbsd", target_os = "bitrig",
-              target_os = "redox",
-              target_os = "fuchsia",
-              windows,
-              all(target_arch = "wasm32", feature = "stdweb"),
-              all(target_arch = "wasm32", feature = "wasm-bindgen"),
-)))]
+#[cfg(feature="rand_os")]
 impl EntropySource for Os {
     fn new_and_fill(dest: &mut [u8]) -> Result<Self, Error> {
         let mut rng = rngs::OsRng::new()?;
@@ -240,23 +208,7 @@
     }
 }
 
-#[cfg(not(all(feature="std",
-              any(target_os = "linux", target_os = "android",
-                  target_os = "netbsd",
-                  target_os = "dragonfly",
-                  target_os = "haiku",
-                  target_os = "emscripten",
-                  target_os = "solaris",
-                  target_os = "cloudabi",
-                  target_os = "macos", target_os = "ios",
-                  target_os = "freebsd",
-                  target_os = "openbsd", target_os = "bitrig",
-                  target_os = "redox",
-                  target_os = "fuchsia",
-                  windows,
-                  all(target_arch = "wasm32", feature = "stdweb"),
-                  all(target_arch = "wasm32", feature = "wasm-bindgen"),
-))))]
+#[cfg(not(feature="std"))]
 type Os = NoSource;
 
 
diff --git a/src/rngs/mod.rs b/src/rngs/mod.rs
index 528e24d..847fc94 100644
--- a/src/rngs/mod.rs
+++ b/src/rngs/mod.rs
@@ -178,5 +178,5 @@
 pub use self::std::StdRng;
 #[cfg(feature="std")] pub use self::thread::ThreadRng;
 
-#[cfg(feature="std")]
+#[cfg(feature="rand_os")]
 pub use rand_os::OsRng;
diff --git a/src/rngs/thread.rs b/src/rngs/thread.rs
index be77ddf..7977d85 100644
--- a/src/rngs/thread.rs
+++ b/src/rngs/thread.rs
@@ -132,7 +132,6 @@
 #[cfg(test)]
 mod test {
     #[test]
-    #[cfg(not(feature="stdweb"))]
     fn test_thread_rng() {
         use Rng;
         let mut r = ::thread_rng();