Skip to content

Commit

Permalink
Move wasm32-unknown-unknown with JS env support behind js feature
Browse files Browse the repository at this point in the history
  • Loading branch information
tesaguri committed Oct 6, 2021
1 parent 0da62e4 commit 010f83d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ jobs:
target:
-
features:
-
- derive
- hmac-sha1
- js
- js,derive
- js,hmac-sha1
include:
- features: ''
- features: js
target: wasm32-unknown-unknown
steps:
- uses: actions/checkout@v2
Expand Down
8 changes: 5 additions & 3 deletions oauth1-request/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ either = { version = "1.2", optional = true }
hmac = { version = "0.11", optional = true }
sha-1 = { version = "0.9", optional = true }

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
# `js` feature
js-sys = { version = "0.3", optional = true }

[dev-dependencies]
# Trick to make `proc-macro-crate` work in doctests.
oauth1-request = { version = "0.5", path = "", default-features = false }
version-sync = "0.9"

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
js-sys = "0.3"

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
getrandom = { version = "0.2", features = ["js"] }
wasm-bindgen-test = "0.3"
Expand All @@ -46,4 +47,5 @@ wasm-bindgen-test = "0.3"
default = ["derive", "hmac-sha1"]
derive = ["oauth1-request-derive"]
hmac-sha1 = ["hmac", "sha-1"]
js = ["js-sys"]
serde = ["oauth-credentials/serde"]
2 changes: 1 addition & 1 deletion oauth1-request/src/serializer/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl<'a, SM: SignatureMethod> Serializer for Authorizer<'a, SM> {
fn get_current_timestamp() -> u64 {
cfg_if::cfg_if! {
// `std::time::SystemTime::now` is not supported and panics on `wasm32-unknown-unknown` target
if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
if #[cfg(all(feature = "js", target_arch = "wasm32", target_os = "unknown"))] {
(js_sys::Date::now() / 1000.0) as u64
} else {
use std::time::{SystemTime, UNIX_EPOCH};
Expand Down

0 comments on commit 010f83d

Please sign in to comment.