Merge pull request #335 from chronotope/fix-wasm
Put wasm-bindgen and js-sys behind a wasm-bindgen feature gate
This commit is contained in:
commit
c045750e06
11
.travis.yml
11
.travis.yml
|
@ -16,16 +16,19 @@ matrix:
|
||||||
include:
|
include:
|
||||||
- rust: nightly
|
- rust: nightly
|
||||||
env: CLIPPY=y
|
env: CLIPPY=y
|
||||||
|
- rust: stable
|
||||||
|
os: osx
|
||||||
|
env: WASMBIND=y
|
||||||
|
- rust: beta
|
||||||
|
os: osx
|
||||||
|
env: WASMBIND=y
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- LD_LIBRARY_PATH: /usr/local/lib
|
- LD_LIBRARY_PATH: /usr/local/lib
|
||||||
- CLIPPY: n
|
- CLIPPY: n
|
||||||
install:
|
install:
|
||||||
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then source $HOME/.nvm/nvm.sh; fi
|
- if [ "$TRAVIS_OS_NAME" = "osx" ] && [ "$WASMBIND" = "y" ] ; then source ./ci/install-node.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
|
|
||||||
script: ./ci/travis.sh
|
script: ./ci/travis.sh
|
||||||
notifications:
|
notifications:
|
||||||
email: false
|
email: false
|
||||||
|
|
|
@ -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.
|
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.
|
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
|
## 0.4.8
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
|
|
|
@ -26,6 +26,7 @@ name = "chrono"
|
||||||
[features]
|
[features]
|
||||||
default = ["clock"]
|
default = ["clock"]
|
||||||
clock = ["time"]
|
clock = ["time"]
|
||||||
|
wasmbind = ["wasm-bindgen", "js-sys"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libc = { version = "0.2", default-features = false }
|
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 }
|
rustc-serialize = { version = "0.3.20", optional = true }
|
||||||
serde = { version = "1", optional = true }
|
serde = { version = "1", optional = true }
|
||||||
|
|
||||||
|
|
||||||
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
|
[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
|
||||||
wasm-bindgen = { version = "0.2" }
|
wasm-bindgen = { version = "0.2", optional = true }
|
||||||
js-sys = "0.3" # contains FFI bindings for the JS Date API
|
js-sys = { version = "0.3", optional = true } # contains FFI bindings for the JS Date API
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_json = { version = "1" }
|
serde_json = { version = "1" }
|
||||||
|
|
|
@ -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
|
28
ci/travis.sh
28
ci/travis.sh
|
@ -29,6 +29,21 @@ build_and_test() {
|
||||||
# also vary the local time zone to (hopefully) catch tz-dependent bugs
|
# 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
|
# also avoid doc-testing multiple times---it takes a lot and rarely helps
|
||||||
cargo clean
|
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
|
channel build -v
|
||||||
TZ=ACST-9:30 channel test -v --lib
|
TZ=ACST-9:30 channel test -v --lib
|
||||||
channel build -v --features rustc-serialize
|
channel build -v --features rustc-serialize
|
||||||
|
@ -47,9 +62,11 @@ build_and_test() {
|
||||||
TZ=UTC0 channel test -v --no-default-features --features serde --lib
|
TZ=UTC0 channel test -v --no-default-features --features serde --lib
|
||||||
channel build -v --no-default-features --features serde,rustc-serialize
|
channel build -v --no-default-features --features serde,rustc-serialize
|
||||||
TZ=Asia/Katmandu channel test -v --no-default-features --features serde,rustc-serialize --lib
|
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
|
touch tests/wasm.rs # ensure rebuild happens so TZ / NOW take effect
|
||||||
TZ=ACST-9:30 NOW=$(date +%s) wasm-pack test --node
|
TZ=ACST-9:30 NOW=$(date +%s) wasm-pack test --node
|
||||||
touch tests/wasm.rs
|
touch tests/wasm.rs
|
||||||
|
@ -58,13 +75,6 @@ build_and_test() {
|
||||||
TZ=UTC0 NOW=$(date +%s) wasm-pack test --node
|
TZ=UTC0 NOW=$(date +%s) wasm-pack test --node
|
||||||
touch tests/wasm.rs
|
touch tests/wasm.rs
|
||||||
TZ=Asia/Katmandu NOW=$(date +%s) wasm-pack test --node
|
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() {
|
build_only() {
|
||||||
|
|
|
@ -414,9 +414,9 @@ extern crate serde as serdelib;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate doc_comment;
|
extern crate doc_comment;
|
||||||
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
|
#[cfg(all(target_arch = "wasm32", feature="wasmbind"))]
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
|
#[cfg(all(target_arch = "wasm32", feature="wasmbind"))]
|
||||||
extern crate js_sys;
|
extern crate js_sys;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -87,13 +87,13 @@ impl Local {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a `DateTime` which corresponds to the current 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<Local> {
|
pub fn now() -> DateTime<Local> {
|
||||||
tm_to_datetime(oldtime::now())
|
tm_to_datetime(oldtime::now())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a `DateTime` which corresponds to the current date.
|
/// 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> {
|
pub fn now() -> DateTime<Local> {
|
||||||
use super::Utc;
|
use super::Utc;
|
||||||
let now: DateTime<Utc> = super::Utc::now();
|
let now: DateTime<Utc> = super::Utc::now();
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
//! The UTC (Coordinated Universal Time) time zone.
|
//! The UTC (Coordinated Universal Time) time zone.
|
||||||
|
|
||||||
use std::fmt;
|
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 oldtime;
|
||||||
|
|
||||||
use naive::{NaiveDate, NaiveDateTime};
|
use naive::{NaiveDate, NaiveDateTime};
|
||||||
|
@ -38,7 +38,7 @@ impl Utc {
|
||||||
pub fn today() -> Date<Utc> { Utc::now().date() }
|
pub fn today() -> Date<Utc> { Utc::now().date() }
|
||||||
|
|
||||||
/// Returns a `DateTime` which corresponds to the current 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> {
|
pub fn now() -> DateTime<Utc> {
|
||||||
let spec = oldtime::get_time();
|
let spec = oldtime::get_time();
|
||||||
let naive = NaiveDateTime::from_timestamp(spec.sec, spec.nsec as u32);
|
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.
|
/// 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> {
|
pub fn now() -> DateTime<Utc> {
|
||||||
let now = js_sys::Date::new_0();
|
let now = js_sys::Date::new_0();
|
||||||
let millisecs_since_unix_epoch: u64 = now.get_time() as u64;
|
let millisecs_since_unix_epoch: u64 = now.get_time() as u64;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
|
#[cfg(all(target_arch = "wasm32", feature = "wasmbind"))]
|
||||||
mod test {
|
mod test {
|
||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
extern crate wasm_bindgen_test;
|
extern crate wasm_bindgen_test;
|
||||||
|
|
Loading…
Reference in New Issue