Skip to content

Commit

Permalink
Use cfg-if for cfgs in wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
coolreader18 authored and sebcrozet committed Sep 19, 2020
1 parent 5c5f651 commit 3476316
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 45 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ edition = "2018"
now = [ "time" ]
wasm-bindgen = ["js-sys", "wasm-bindgen_rs", "web-sys"]

[dependencies]
cfg-if = "0.1"

[target.'cfg(not(any(feature = "stdweb", feature = "wasm-bindgen")))'.dependencies]
time = { version = "0.1", optional = true }

Expand Down
62 changes: 17 additions & 45 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,20 @@
#[cfg(all(
any(
cfg_if::cfg_if! {
if #[cfg(any(
all(target_arch = "wasm32", not(target_os = "wasi")),
target_arch = "asmjs"
),
all(feature = "stdweb", not(feature = "wasm-bindgen"))
))]
#[macro_use]
extern crate stdweb;
))] {
#[cfg(all(feature = "stdweb", not(feature = "wasm-bindgen")))]
#[macro_use]
extern crate stdweb;

#[cfg(not(any(
all(target_arch = "wasm32", not(target_os = "wasi")),
target_arch = "asmjs"
)))]
pub use crate::native::Instant;

#[cfg(any(
all(target_arch = "wasm32", not(target_os = "wasi")),
target_arch = "asmjs"
))]
pub use crate::wasm::Instant;

#[cfg(not(any(
all(target_arch = "wasm32", not(target_os = "wasi")),
target_arch = "asmjs"
)))]
#[cfg(feature = "now")]
pub use crate::native::now;

#[cfg(any(
all(target_arch = "wasm32", not(target_os = "wasi")),
target_arch = "asmjs"
))]
#[cfg(feature = "now")]
pub use crate::wasm::now;

pub use std::time::Duration;

#[cfg(not(any(
all(target_arch = "wasm32", not(target_os = "wasi")),
target_arch = "asmjs"
)))]
mod native;
#[cfg(any(
all(target_arch = "wasm32", not(target_os = "wasi")),
target_arch = "asmjs"
))]
mod wasm;
mod wasm;
pub use wasm::Instant;
#[cfg(feature = "now")]
pub use crate::wasm::now;
} else {
mod native;
pub use native::Instant;
#[cfg(feature = "now")]
pub use native::now;
}
}

0 comments on commit 3476316

Please sign in to comment.