Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for compilation on wasm32-wasi #365

Merged
merged 1 commit into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ num-traits = { version = "0.2", default-features = false }
rustc-serialize = { version = "0.3.20", optional = true }
serde = { version = "1.0.99", default-features = false, optional = true }

[target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies]
[target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dependencies]
wasm-bindgen = { version = "0.2", optional = true }
js-sys = { version = "0.3", optional = true } # contains FFI bindings for the JS Date API

Expand All @@ -49,7 +49,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")))'.dev-dependencies]
[target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dev-dependencies]
wasm-bindgen-test = "0.2"

[package.metadata.docs.rs]
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ extern crate serde as serdelib;
#[cfg(test)]
#[macro_use]
extern crate doc_comment;
#[cfg(all(target_arch = "wasm32", feature="wasmbind"))]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))]
extern crate wasm_bindgen;
#[cfg(all(target_arch = "wasm32", feature="wasmbind"))]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))]
extern crate js_sys;
#[cfg(feature = "bench")]
extern crate test;
Expand Down
4 changes: 2 additions & 2 deletions src/offset/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ impl Local {
}

/// Returns a `DateTime` which corresponds to the current date.
#[cfg(not(all(target_arch = "wasm32", feature = "wasmbind")))]
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), 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", feature = "wasmbind"))]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))]
pub fn now() -> DateTime<Local> {
use super::Utc;
let now: DateTime<Utc> = super::Utc::now();
Expand Down
9 changes: 6 additions & 3 deletions src/offset/utc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
//! The UTC (Coordinated Universal Time) time zone.

use core::fmt;
#[cfg(all(feature="clock", not(all(target_arch = "wasm32", feature = "wasmbind"))))]
#[cfg(all(
feature = "clock",
not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))
))]
use oldtime;

use naive::{NaiveDate, NaiveDateTime};
Expand Down Expand Up @@ -38,15 +41,15 @@ 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", feature = "wasmbind")))]
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind")))]
pub fn now() -> DateTime<Utc> {
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(all(target_arch = "wasm32", feature = "wasmbind"))]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), 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;
Expand Down
2 changes: 1 addition & 1 deletion tests/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(all(target_arch = "wasm32", feature = "wasmbind"))]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))]
mod test {
extern crate chrono;
extern crate wasm_bindgen_test;
Expand Down