Put wasm-bindgen and js-sys behind a wasm-bindgen feature gate

Fixes #334
This commit is contained in:
Brandon W Maister 2019-09-02 11:00:34 -04:00
parent 630cade52a
commit 2839d8d7db
9 changed files with 54 additions and 24 deletions

View File

@ -16,16 +16,19 @@ matrix:
include:
- rust: nightly
env: CLIPPY=y
- rust: stable
os: osx
env: WASMBIND=y
- rust: beta
os: osx
env: WASMBIND=y
env:
global:
- LD_LIBRARY_PATH: /usr/local/lib
- CLIPPY: n
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
- if [ "$TRAVIS_RUST_VERSION" != "1.13.0" ]; then curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh; fi
- if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "$WASMBIND" = "y" ] ; then source ./ci/install-node.sh; fi
script: ./ci/travis.sh
notifications:
email: false

View File

@ -8,6 +8,15 @@ Chrono obeys the principle of [Semantic Versioning](http://semver.org/).
There were/are numerous minor versions before 1.0 due to the language changes.
Versions with only mechanical changes will be omitted from the following list.
## 0.4.9
### Fixes
* Make Datetime arithmatic adjust their offsets after discovering their new
timestamps (@quodlibetor #337)
* Put wasm-bindgen related code and dependencies behind a `wasmbind` feature
gate. (@quodlibetor #335)
## 0.4.8
### Fixes

View File

@ -26,6 +26,7 @@ name = "chrono"
[features]
default = ["clock"]
clock = ["time"]
wasmbind = ["wasm-bindgen", "js-sys"]
[dependencies]
libc = { version = "0.2", default-features = false }
@ -35,10 +36,9 @@ num-traits = { version = "0.2", default-features = false }
rustc-serialize = { version = "0.3.20", optional = true }
serde = { version = "1", optional = true }
[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
wasm-bindgen = { version = "0.2", optional = true }
js-sys = { version = "0.3", optional = true } # contains FFI bindings for the JS Date API
[dev-dependencies]
serde_json = { version = "1" }

8
ci/install-node.sh Normal file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env sh
echo "installing node via nvm"
source "$HOME/.nvm/nvm.sh"
nvm install 10
nvm use 10
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

View File

@ -29,6 +29,21 @@ build_and_test() {
# also vary the local time zone to (hopefully) catch tz-dependent bugs
# also avoid doc-testing multiple times---it takes a lot and rarely helps
cargo clean
if [ "${WASMBIND}" != "y" ]; then
build_and_test_nonwasm
else
build_and_test_wasm
fi
if [[ "$CHANNEL" == stable ]]; then
if [[ -n "$TRAVIS" ]] ; then
check_readme
fi
fi
}
build_and_test_nonwasm() {
channel build -v
TZ=ACST-9:30 channel test -v --lib
channel build -v --features rustc-serialize
@ -47,9 +62,11 @@ build_and_test() {
TZ=UTC0 channel test -v --no-default-features --features serde --lib
channel build -v --no-default-features --features serde,rustc-serialize
TZ=Asia/Katmandu channel test -v --no-default-features --features serde,rustc-serialize --lib
}
build_and_test_wasm() {
channel build --features wasmbind -v
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
touch tests/wasm.rs
@ -58,13 +75,6 @@ build_and_test() {
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
check_readme
fi
fi
}
build_only() {

View File

@ -414,9 +414,9 @@ extern crate serde as serdelib;
#[cfg(test)]
#[macro_use]
extern crate doc_comment;
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(all(target_arch = "wasm32", feature="wasmbind"))]
extern crate wasm_bindgen;
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(all(target_arch = "wasm32", feature="wasmbind"))]
extern crate js_sys;
#[cfg(test)]

View File

@ -87,13 +87,13 @@ impl Local {
}
/// Returns a `DateTime` which corresponds to the current date.
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
#[cfg(not(all(target_arch = "wasm32", feature = "wasmbind")))]
pub fn now() -> DateTime<Local> {
tm_to_datetime(oldtime::now())
}
/// Returns a `DateTime` which corresponds to the current date.
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(all(target_arch = "wasm32", feature = "wasmbind"))]
pub fn now() -> DateTime<Local> {
use super::Utc;
let now: DateTime<Utc> = super::Utc::now();

View File

@ -4,7 +4,7 @@
//! The UTC (Coordinated Universal Time) time zone.
use std::fmt;
#[cfg(all(feature="clock", not(all(target_arch = "wasm32", not(target_os = "emscripten")))))]
#[cfg(all(feature="clock", not(all(target_arch = "wasm32", feature = "wasmbind"))))]
use oldtime;
use naive::{NaiveDate, NaiveDateTime};
@ -38,7 +38,7 @@ impl Utc {
pub fn today() -> Date<Utc> { Utc::now().date() }
/// Returns a `DateTime` which corresponds to the current date.
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
#[cfg(not(all(target_arch = "wasm32", feature = "wasmbind")))]
pub fn now() -> DateTime<Utc> {
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(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(all(target_arch = "wasm32", feature = "wasmbind"))]
pub fn now() -> DateTime<Utc> {
let now = js_sys::Date::new_0();
let millisecs_since_unix_epoch: u64 = now.get_time() as u64;

View File

@ -1,4 +1,4 @@
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(all(target_arch = "wasm32", feature = "wasmbind"))]
mod test {
extern crate chrono;
extern crate wasm_bindgen_test;