From 8bfaca9f9b901b57d92b761e1ece39f733d7fca7 Mon Sep 17 00:00:00 2001 From: Joey Ezechiels Date: Sun, 4 Nov 2018 23:31:17 +0100 Subject: [PATCH 01/11] Add {Utc,Local}::now() constructor versions for the `wasm32` arch While likely providing only incomplete support for WebAssembly, this commit opens up chrono for use on the wasm32 architecture. --- Cargo.toml | 6 ++++++ src/lib.rs | 4 ++++ src/offset/local.rs | 10 +++++++++- src/offset/utc.rs | 15 +++++++++++++-- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cf2da02..82b8351 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,12 @@ num-traits = { version = "0.2", default-features = false } rustc-serialize = { version = "0.3.20", optional = true } serde = { version = "1", optional = true } +[target.'cfg(target_arch = "wasm32")'.dependencies] +wasm-bindgen = { version = "0.2" } +js-sys = "0.3" # contains FFI bindings for the JS Date API + + + [dev-dependencies] serde_json = { version = "1" } serde_derive = { version = "1" } diff --git a/src/lib.rs b/src/lib.rs index 0df5cdd..5a11eb5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -414,6 +414,10 @@ extern crate serde as serdelib; #[cfg(test)] #[macro_use] extern crate doc_comment; +#[cfg(target_arch = "wasm32")] +extern crate wasm_bindgen; +#[cfg(target_arch = "wasm32")] +extern crate js_sys; #[cfg(test)] doctest!("../README.md"); diff --git a/src/offset/local.rs b/src/offset/local.rs index 6aa4ab7..cce193b 100644 --- a/src/offset/local.rs +++ b/src/offset/local.rs @@ -87,9 +87,18 @@ impl Local { } /// Returns a `DateTime` which corresponds to the current date. + #[cfg(not(target_arch = "wasm32"))] pub fn now() -> DateTime { tm_to_datetime(oldtime::now()) } + + /// Returns a `DateTime` which corresponds to the current date. + #[cfg(target_arch = "wasm32")] + pub fn now() -> DateTime { + use super::Utc; + let now: DateTime = super::Utc::now(); + now.with_timezone(&Local) + } } impl TimeZone for Local { @@ -179,4 +188,3 @@ mod tests { "unexpected timestr {:?}", timestr); } } - diff --git a/src/offset/utc.rs b/src/offset/utc.rs index d4e8d10..83b92ac 100644 --- a/src/offset/utc.rs +++ b/src/offset/utc.rs @@ -4,7 +4,7 @@ //! The UTC (Coordinated Universal Time) time zone. use std::fmt; -#[cfg(feature="clock")] +#[cfg(all(feature="clock", not(target_arch = "wasm32")))] use oldtime; use naive::{NaiveDate, NaiveDateTime}; @@ -38,11 +38,23 @@ impl Utc { pub fn today() -> Date { Utc::now().date() } /// Returns a `DateTime` which corresponds to the current date. + #[cfg(not(target_arch = "wasm32"))] pub fn now() -> DateTime { let spec = oldtime::get_time(); let naive = NaiveDateTime::from_timestamp(spec.sec, spec.nsec as u32); DateTime::from_utc(naive, Utc) } + + /// Returns a `DateTime` which corresponds to the current date. + #[cfg(target_arch = "wasm32")] + pub fn now() -> DateTime { + let now = js_sys::Date::new_0(); + let millisecs_since_unix_epoch: u64 = now.get_time() as u64; + let secs = millisecs_since_unix_epoch / 1000; + let nanos = 1_000_000 * (millisecs_since_unix_epoch - 1000 * secs); + let naive = NaiveDateTime::from_timestamp(secs as i64, nanos as u32); + DateTime::from_utc(naive, Utc) + } } impl TimeZone for Utc { @@ -72,4 +84,3 @@ impl fmt::Debug for Utc { impl fmt::Display for Utc { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "UTC") } } - From 5d38faeb40699cea266424171af431f131b83e52 Mon Sep 17 00:00:00 2001 From: eV Date: Fri, 16 Aug 2019 09:35:56 +0000 Subject: [PATCH 02/11] fix local timezone, add tests --- .travis.yml | 2 ++ Cargo.toml | 5 +++-- ci/travis.sh | 10 ++++++++++ src/offset/local.rs | 5 ++++- tests/wasm.rs | 27 +++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 tests/wasm.rs diff --git a/.travis.yml b/.travis.yml index d74f342..71677ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,8 @@ env: global: - LD_LIBRARY_PATH: /usr/local/lib - CLIPPY: n +install: + - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh script: ./ci/travis.sh notifications: email: false diff --git a/Cargo.toml b/Cargo.toml index 82b8351..66fb839 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,8 +39,6 @@ serde = { version = "1", optional = true } wasm-bindgen = { version = "0.2" } js-sys = "0.3" # contains FFI bindings for the JS Date API - - [dev-dependencies] serde_json = { version = "1" } serde_derive = { version = "1" } @@ -48,6 +46,9 @@ bincode = { version = "0.8.0" } num-iter = { version = "0.1.35", default-features = false } doc-comment = "0.3" +[target.'cfg(target_arch = "wasm32")'.dev-dependencies] +wasm-bindgen-test = "0.2" + [package.metadata.docs.rs] all-features = true diff --git a/ci/travis.sh b/ci/travis.sh index 4a974b1..2a93271 100755 --- a/ci/travis.sh +++ b/ci/travis.sh @@ -48,6 +48,16 @@ build_and_test() { channel build -v --no-default-features --features serde,rustc-serialize TZ=Asia/Katmandu channel test -v --no-default-features --features serde,rustc-serialize --lib + # wasm tests + touch tests/wasm.rs # ensure rebuild happens so TZ / NOW take effect + TZ=ACST-9:30 NOW=$(date +%s) wasm-pack test --node + touch tests/wasm.rs + TZ=EST4 NOW=$(date +%s) wasm-pack test --node + touch tests/wasm.rs + TZ=UTC0 NOW=$(date +%s) wasm-pack test --node + touch tests/wasm.rs + TZ=Asia/Katmandu NOW=$(date +%s) wasm-pack test --node + if [[ "$CHANNEL" == stable ]]; then if [[ -n "$TRAVIS" ]] ; then check_readme diff --git a/src/offset/local.rs b/src/offset/local.rs index cce193b..ae43d4e 100644 --- a/src/offset/local.rs +++ b/src/offset/local.rs @@ -97,7 +97,10 @@ impl Local { pub fn now() -> DateTime { use super::Utc; let now: DateTime = super::Utc::now(); - now.with_timezone(&Local) + + // Workaround missing timezone logic in `time` crate + let offset = FixedOffset::west((js_sys::Date::new_0().get_timezone_offset() as i32) * 60); + DateTime::from_utc(now.naive_utc(), offset) } } diff --git a/tests/wasm.rs b/tests/wasm.rs new file mode 100644 index 0000000..2193548 --- /dev/null +++ b/tests/wasm.rs @@ -0,0 +1,27 @@ +extern crate chrono; +extern crate wasm_bindgen_test; + +use chrono::prelude::*; +use wasm_bindgen_test::*; + +use std::env; + +#[wasm_bindgen_test] +fn now() { + let utc: DateTime = Utc::now(); + let local: DateTime = Local::now(); + + // Ensure time fetched is correct + let actual = Utc.datetime_from_str(env!("NOW"), "%s").unwrap(); + assert!(utc - actual < chrono::Duration::minutes(5)); + + // Ensure offset retrieved when getting local time is correct + let expected_offset = match env!("TZ") { + "ACST-9:30" => FixedOffset::east(19 * 30 * 60), + "Asia/Katmandu" => FixedOffset::east(23 * 15 * 60), // No DST thankfully + "EST4" => FixedOffset::east(-4 * 60 * 60), + "UTC0" => FixedOffset::east(0), + _ => panic!("unexpected TZ"), + }; + assert_eq!(&expected_offset, local.offset()); +} From c284d7364bb306fb03926f0ab6075814076a7f12 Mon Sep 17 00:00:00 2001 From: eV Date: Fri, 16 Aug 2019 17:11:30 +0000 Subject: [PATCH 03/11] add conditionals so wasm tests build / run in the right places --- ci/travis.sh | 20 +++++++++++--------- tests/wasm.rs | 45 ++++++++++++++++++++++++--------------------- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/ci/travis.sh b/ci/travis.sh index 2a93271..be74b11 100755 --- a/ci/travis.sh +++ b/ci/travis.sh @@ -48,15 +48,17 @@ build_and_test() { channel build -v --no-default-features --features serde,rustc-serialize TZ=Asia/Katmandu channel test -v --no-default-features --features serde,rustc-serialize --lib - # wasm tests - touch tests/wasm.rs # ensure rebuild happens so TZ / NOW take effect - TZ=ACST-9:30 NOW=$(date +%s) wasm-pack test --node - touch tests/wasm.rs - TZ=EST4 NOW=$(date +%s) wasm-pack test --node - touch tests/wasm.rs - TZ=UTC0 NOW=$(date +%s) wasm-pack test --node - touch tests/wasm.rs - TZ=Asia/Katmandu NOW=$(date +%s) wasm-pack test --node + if [ -n "${TRAVIS}" ]; then + # wasm tests + touch tests/wasm.rs # ensure rebuild happens so TZ / NOW take effect + TZ=ACST-9:30 NOW=$(date +%s) wasm-pack test --node + touch tests/wasm.rs + TZ=EST4 NOW=$(date +%s) wasm-pack test --node + touch tests/wasm.rs + TZ=UTC0 NOW=$(date +%s) wasm-pack test --node + touch tests/wasm.rs + TZ=Asia/Katmandu NOW=$(date +%s) wasm-pack test --node + fi if [[ "$CHANNEL" == stable ]]; then if [[ -n "$TRAVIS" ]] ; then diff --git a/tests/wasm.rs b/tests/wasm.rs index 2193548..757f02e 100644 --- a/tests/wasm.rs +++ b/tests/wasm.rs @@ -1,27 +1,30 @@ -extern crate chrono; -extern crate wasm_bindgen_test; +#[cfg(target_arch = "wasm32")] +mod test { + extern crate chrono; + extern crate wasm_bindgen_test; -use chrono::prelude::*; -use wasm_bindgen_test::*; + use self::chrono::prelude::*; + use self::wasm_bindgen_test::*; -use std::env; + use std::env; -#[wasm_bindgen_test] -fn now() { - let utc: DateTime = Utc::now(); - let local: DateTime = Local::now(); + #[wasm_bindgen_test] + fn now() { + let utc: DateTime = Utc::now(); + let local: DateTime = Local::now(); - // Ensure time fetched is correct - let actual = Utc.datetime_from_str(env!("NOW"), "%s").unwrap(); - assert!(utc - actual < chrono::Duration::minutes(5)); + // Ensure time fetched is correct + let actual = Utc.datetime_from_str(env!("NOW"), "%s").unwrap(); + assert!(utc - actual < chrono::Duration::minutes(5)); - // Ensure offset retrieved when getting local time is correct - let expected_offset = match env!("TZ") { - "ACST-9:30" => FixedOffset::east(19 * 30 * 60), - "Asia/Katmandu" => FixedOffset::east(23 * 15 * 60), // No DST thankfully - "EST4" => FixedOffset::east(-4 * 60 * 60), - "UTC0" => FixedOffset::east(0), - _ => panic!("unexpected TZ"), - }; - assert_eq!(&expected_offset, local.offset()); + // Ensure offset retrieved when getting local time is correct + let expected_offset = match env!("TZ") { + "ACST-9:30" => FixedOffset::east(19 * 30 * 60), + "Asia/Katmandu" => FixedOffset::east(23 * 15 * 60), // No DST thankfully + "EST4" => FixedOffset::east(-4 * 60 * 60), + "UTC0" => FixedOffset::east(0), + _ => panic!("unexpected TZ"), + }; + assert_eq!(&expected_offset, local.offset()); + } } From a7645f3e73de7e77688a7667590a08bd5c997a21 Mon Sep 17 00:00:00 2001 From: eV Date: Fri, 16 Aug 2019 18:23:28 +0000 Subject: [PATCH 04/11] try to use nvm to use node 10 --- .travis.yml | 3 +++ ci/travis.sh | 1 + 2 files changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 71677ae..c39a358 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,9 @@ env: - LD_LIBRARY_PATH: /usr/local/lib - CLIPPY: n install: + - source $HOME/.nvm/nvm.sh + - nvm install 10 + - nvm use 10 - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh script: ./ci/travis.sh notifications: diff --git a/ci/travis.sh b/ci/travis.sh index be74b11..b5925cf 100755 --- a/ci/travis.sh +++ b/ci/travis.sh @@ -94,6 +94,7 @@ check_readme() { rustc --version cargo --version +node --version CHANNEL=nightly if [ "x${CLIPPY}" = xy ] ; then From ddc7fd4a043e8d2e39f678a1401aa2fada95dfb6 Mon Sep 17 00:00:00 2001 From: eV Date: Fri, 16 Aug 2019 19:14:16 +0000 Subject: [PATCH 05/11] try node 11 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c39a358..0a04ac4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,8 +23,8 @@ env: - CLIPPY: n install: - source $HOME/.nvm/nvm.sh - - nvm install 10 - - nvm use 10 + - nvm install 11 + - nvm use 11 - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh script: ./ci/travis.sh notifications: From 93e4f29ee4c948c9b63c13bcba2415a3de2f6e39 Mon Sep 17 00:00:00 2001 From: eV Date: Fri, 16 Aug 2019 19:24:48 +0000 Subject: [PATCH 06/11] see if it was just the particular tz --- .travis.yml | 4 ++-- ci/travis.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0a04ac4..c39a358 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,8 +23,8 @@ env: - CLIPPY: n install: - source $HOME/.nvm/nvm.sh - - nvm install 11 - - nvm use 11 + - nvm install 10 + - nvm use 10 - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh script: ./ci/travis.sh notifications: diff --git a/ci/travis.sh b/ci/travis.sh index b5925cf..f299504 100755 --- a/ci/travis.sh +++ b/ci/travis.sh @@ -51,8 +51,8 @@ build_and_test() { if [ -n "${TRAVIS}" ]; then # wasm tests touch tests/wasm.rs # ensure rebuild happens so TZ / NOW take effect - TZ=ACST-9:30 NOW=$(date +%s) wasm-pack test --node - touch tests/wasm.rs + #TZ=ACST-9:30 NOW=$(date +%s) wasm-pack test --node + #touch tests/wasm.rs TZ=EST4 NOW=$(date +%s) wasm-pack test --node touch tests/wasm.rs TZ=UTC0 NOW=$(date +%s) wasm-pack test --node From bd22644b0542753a167887a6d8209be859c230cd Mon Sep 17 00:00:00 2001 From: eV Date: Fri, 16 Aug 2019 20:04:09 +0000 Subject: [PATCH 07/11] only use nvm on mac --- .travis.yml | 6 +++--- ci/travis.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index c39a358..d591b2f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,9 +22,9 @@ env: - LD_LIBRARY_PATH: /usr/local/lib - CLIPPY: n install: - - source $HOME/.nvm/nvm.sh - - nvm install 10 - - nvm use 10 + - if [ "$TRAVIS_OS_NAME" = "osx" ]; then source $HOME/.nvm/nvm.sh; fi + - if [ "$TRAVIS_OS_NAME" = "osx" ]; then nvm install 10; fi + - if [ "$TRAVIS_OS_NAME" = "osx" ]; then nvm use 10; fi - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh script: ./ci/travis.sh notifications: diff --git a/ci/travis.sh b/ci/travis.sh index f299504..b5925cf 100755 --- a/ci/travis.sh +++ b/ci/travis.sh @@ -51,8 +51,8 @@ build_and_test() { if [ -n "${TRAVIS}" ]; then # wasm tests touch tests/wasm.rs # ensure rebuild happens so TZ / NOW take effect - #TZ=ACST-9:30 NOW=$(date +%s) wasm-pack test --node - #touch tests/wasm.rs + TZ=ACST-9:30 NOW=$(date +%s) wasm-pack test --node + touch tests/wasm.rs TZ=EST4 NOW=$(date +%s) wasm-pack test --node touch tests/wasm.rs TZ=UTC0 NOW=$(date +%s) wasm-pack test --node From e28719eb0dc7430baae88e065fcdb97e03945f1c Mon Sep 17 00:00:00 2001 From: eV Date: Fri, 16 Aug 2019 21:04:07 +0000 Subject: [PATCH 08/11] try to get travis working for rust 1.13.0 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d591b2f..ca0e2d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ install: - if [ "$TRAVIS_OS_NAME" = "osx" ]; then source $HOME/.nvm/nvm.sh; fi - if [ "$TRAVIS_OS_NAME" = "osx" ]; then nvm install 10; fi - if [ "$TRAVIS_OS_NAME" = "osx" ]; then nvm use 10; fi - - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + - if [ "$TRAVIS_RUST_VERSION" != "1.13.0" ]; then curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh; fi script: ./ci/travis.sh notifications: email: false From f52a29398c2df3f8a92845c56efd2114a0ba63fe Mon Sep 17 00:00:00 2001 From: eV Date: Fri, 16 Aug 2019 21:10:55 +0000 Subject: [PATCH 09/11] one more guard --- ci/travis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/travis.sh b/ci/travis.sh index b5925cf..2747fee 100755 --- a/ci/travis.sh +++ b/ci/travis.sh @@ -48,7 +48,7 @@ build_and_test() { channel build -v --no-default-features --features serde,rustc-serialize TZ=Asia/Katmandu channel test -v --no-default-features --features serde,rustc-serialize --lib - if [ -n "${TRAVIS}" ]; then + if [ -n "${TRAVIS}" ] && [ "${TRAVIS_RUST_VERSION}" != "1.13.0" ]; then # wasm tests touch tests/wasm.rs # ensure rebuild happens so TZ / NOW take effect TZ=ACST-9:30 NOW=$(date +%s) wasm-pack test --node From f21b1fbf21f680124fd79e11c8be75e74a9ba562 Mon Sep 17 00:00:00 2001 From: eV Date: Fri, 16 Aug 2019 21:51:08 +0000 Subject: [PATCH 10/11] Fix emscripten and guard against cargo test + wasm32-unknown-unknown --- Cargo.toml | 5 +++-- src/lib.rs | 7 +++++-- src/offset/local.rs | 4 ++-- src/offset/utc.rs | 6 +++--- tests/wasm.rs | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 66fb839..0ba1f9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,8 @@ num-traits = { version = "0.2", default-features = false } rustc-serialize = { version = "0.3.20", optional = true } serde = { version = "1", optional = true } -[target.'cfg(target_arch = "wasm32")'.dependencies] + +[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(cargo_web)))'.dependencies] wasm-bindgen = { version = "0.2" } js-sys = "0.3" # contains FFI bindings for the JS Date API @@ -46,7 +47,7 @@ bincode = { version = "0.8.0" } num-iter = { version = "0.1.35", default-features = false } doc-comment = "0.3" -[target.'cfg(target_arch = "wasm32")'.dev-dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(cargo_web)))'.dev-dependencies] wasm-bindgen-test = "0.2" [package.metadata.docs.rs] diff --git a/src/lib.rs b/src/lib.rs index 5a11eb5..f4f0ae9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -414,11 +414,14 @@ extern crate serde as serdelib; #[cfg(test)] #[macro_use] extern crate doc_comment; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(cargo_web)))] extern crate wasm_bindgen; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(cargo_web)))] extern crate js_sys; +#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), cargo_web))] +compile_error!("Chrono currently does not work for wasm32-unknown-unknown + cargo web"); + #[cfg(test)] doctest!("../README.md"); diff --git a/src/offset/local.rs b/src/offset/local.rs index ae43d4e..68c27c4 100644 --- a/src/offset/local.rs +++ b/src/offset/local.rs @@ -87,13 +87,13 @@ impl Local { } /// Returns a `DateTime` which corresponds to the current date. - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] pub fn now() -> DateTime { tm_to_datetime(oldtime::now()) } /// Returns a `DateTime` which corresponds to the current date. - #[cfg(target_arch = "wasm32")] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] pub fn now() -> DateTime { use super::Utc; let now: DateTime = super::Utc::now(); diff --git a/src/offset/utc.rs b/src/offset/utc.rs index 83b92ac..36f4e5f 100644 --- a/src/offset/utc.rs +++ b/src/offset/utc.rs @@ -4,7 +4,7 @@ //! The UTC (Coordinated Universal Time) time zone. use std::fmt; -#[cfg(all(feature="clock", not(target_arch = "wasm32")))] +#[cfg(all(feature="clock", not(all(target_arch = "wasm32", not(target_os = "emscripten")))))] use oldtime; use naive::{NaiveDate, NaiveDateTime}; @@ -38,7 +38,7 @@ impl Utc { pub fn today() -> Date { Utc::now().date() } /// Returns a `DateTime` which corresponds to the current date. - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] pub fn now() -> DateTime { let spec = oldtime::get_time(); let naive = NaiveDateTime::from_timestamp(spec.sec, spec.nsec as u32); @@ -46,7 +46,7 @@ impl Utc { } /// Returns a `DateTime` which corresponds to the current date. - #[cfg(target_arch = "wasm32")] + #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] pub fn now() -> DateTime { let now = js_sys::Date::new_0(); let millisecs_since_unix_epoch: u64 = now.get_time() as u64; diff --git a/tests/wasm.rs b/tests/wasm.rs index 757f02e..b95d9f0 100644 --- a/tests/wasm.rs +++ b/tests/wasm.rs @@ -1,4 +1,4 @@ -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] mod test { extern crate chrono; extern crate wasm_bindgen_test; From cc073a650f01aa6bc84f2101ed63c4fa405ecc9d Mon Sep 17 00:00:00 2001 From: eV Date: Thu, 22 Aug 2019 08:09:56 +0000 Subject: [PATCH 11/11] remove cargo web / compile time error --- Cargo.toml | 4 ++-- src/lib.rs | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0ba1f9d..4e246f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ rustc-serialize = { version = "0.3.20", optional = true } serde = { version = "1", optional = true } -[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(cargo_web)))'.dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies] wasm-bindgen = { version = "0.2" } js-sys = "0.3" # contains FFI bindings for the JS Date API @@ -47,7 +47,7 @@ bincode = { version = "0.8.0" } num-iter = { version = "0.1.35", default-features = false } doc-comment = "0.3" -[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(cargo_web)))'.dev-dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dev-dependencies] wasm-bindgen-test = "0.2" [package.metadata.docs.rs] diff --git a/src/lib.rs b/src/lib.rs index f4f0ae9..2962e65 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -414,14 +414,11 @@ extern crate serde as serdelib; #[cfg(test)] #[macro_use] extern crate doc_comment; -#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(cargo_web)))] +#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] extern crate wasm_bindgen; -#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), not(cargo_web)))] +#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] extern crate js_sys; -#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten"), cargo_web))] -compile_error!("Chrono currently does not work for wasm32-unknown-unknown + cargo web"); - #[cfg(test)] doctest!("../README.md");