Skip to content

Commit ad36143

Browse files
committed
fix: Avoid to use web-sys when target os is WASI.
1 parent 111a2ff commit ad36143

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

.github/workflows/tests.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ jobs:
136136

137137
- name: Install wasmtime
138138
run: |
139-
curl https://wasmtime.dev/install.sh -sSf | bash
140-
source ~/.bashrc
139+
curl https://wasmtime.dev/install.sh -sSf | sh
141140
142141
- uses: actions/cache@v3
143142
with:

crates/history/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ categories = ["api-bindings", "history", "wasm"]
1212
rust-version = "1.64"
1313

1414
[dependencies]
15-
wasm-bindgen = "0.2"
1615
gloo-utils = { version = "0.2.0", path = "../utils" }
1716
gloo-events = { version = "0.2.0", path = "../events" }
1817
serde = { version = "1", features = ["derive"] }
1918
serde-wasm-bindgen = "0.6.0"
2019
serde_urlencoded = { version = "0.7", optional = true }
2120
thiserror = { version = "1.0", optional = true }
2221

23-
[dependencies.web-sys]
22+
[target.'cfg(not(target_os = "wasi"))'.dependencies]
23+
wasm-bindgen = "0.2"
24+
25+
[target.'cfg(not(target_os = "wasi"))'.dependencies.web-sys]
2426
version = "0.3"
2527
features = ["History", "Window", "Location", "Url"]
2628

crates/history/src/any.rs

+30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::borrow::Cow;
22

3+
#[cfg(not(target_os = "wasi"))]
34
use crate::browser::BrowserHistory;
5+
#[cfg(not(target_os = "wasi"))]
46
use crate::hash::HashHistory;
57
use crate::history::History;
68
use crate::listener::HistoryListener;
@@ -13,8 +15,10 @@ use crate::{error::HistoryResult, query::ToQuery};
1315
#[derive(Clone, PartialEq, Debug)]
1416
pub enum AnyHistory {
1517
/// A Browser History.
18+
#[cfg(not(target_os = "wasi"))]
1619
Browser(BrowserHistory),
1720
/// A Hash History
21+
#[cfg(not(target_os = "wasi"))]
1822
Hash(HashHistory),
1923
/// A Memory History
2024
Memory(MemoryHistory),
@@ -23,31 +27,39 @@ pub enum AnyHistory {
2327
impl History for AnyHistory {
2428
fn len(&self) -> usize {
2529
match self {
30+
#[cfg(not(target_os = "wasi"))]
2631
Self::Browser(m) => m.len(),
32+
#[cfg(not(target_os = "wasi"))]
2733
Self::Hash(m) => m.len(),
2834
Self::Memory(m) => m.len(),
2935
}
3036
}
3137

3238
fn go(&self, delta: isize) {
3339
match self {
40+
#[cfg(not(target_os = "wasi"))]
3441
Self::Browser(m) => m.go(delta),
42+
#[cfg(not(target_os = "wasi"))]
3543
Self::Hash(m) => m.go(delta),
3644
Self::Memory(m) => m.go(delta),
3745
}
3846
}
3947

4048
fn push<'a>(&self, route: impl Into<Cow<'a, str>>) {
4149
match self {
50+
#[cfg(not(target_os = "wasi"))]
4251
Self::Browser(m) => m.push(route),
52+
#[cfg(not(target_os = "wasi"))]
4353
Self::Hash(m) => m.push(route),
4454
Self::Memory(m) => m.push(route),
4555
}
4656
}
4757

4858
fn replace<'a>(&self, route: impl Into<Cow<'a, str>>) {
4959
match self {
60+
#[cfg(not(target_os = "wasi"))]
5061
Self::Browser(m) => m.replace(route),
62+
#[cfg(not(target_os = "wasi"))]
5163
Self::Hash(m) => m.replace(route),
5264
Self::Memory(m) => m.replace(route),
5365
}
@@ -58,7 +70,9 @@ impl History for AnyHistory {
5870
T: 'static,
5971
{
6072
match self {
73+
#[cfg(not(target_os = "wasi"))]
6174
Self::Browser(m) => m.push_with_state(route, state),
75+
#[cfg(not(target_os = "wasi"))]
6276
Self::Hash(m) => m.push_with_state(route, state),
6377
Self::Memory(m) => m.push_with_state(route, state),
6478
}
@@ -69,7 +83,9 @@ impl History for AnyHistory {
6983
T: 'static,
7084
{
7185
match self {
86+
#[cfg(not(target_os = "wasi"))]
7287
Self::Browser(m) => m.replace_with_state(route, state),
88+
#[cfg(not(target_os = "wasi"))]
7389
Self::Hash(m) => m.replace_with_state(route, state),
7490
Self::Memory(m) => m.replace_with_state(route, state),
7591
}
@@ -85,7 +101,9 @@ impl History for AnyHistory {
85101
Q: ToQuery,
86102
{
87103
match self {
104+
#[cfg(not(target_os = "wasi"))]
88105
Self::Browser(m) => m.push_with_query(route, query),
106+
#[cfg(not(target_os = "wasi"))]
89107
Self::Hash(m) => m.push_with_query(route, query),
90108
Self::Memory(m) => m.push_with_query(route, query),
91109
}
@@ -100,7 +118,9 @@ impl History for AnyHistory {
100118
Q: ToQuery,
101119
{
102120
match self {
121+
#[cfg(not(target_os = "wasi"))]
103122
Self::Browser(m) => m.replace_with_query(route, query),
123+
#[cfg(not(target_os = "wasi"))]
104124
Self::Hash(m) => m.replace_with_query(route, query),
105125
Self::Memory(m) => m.replace_with_query(route, query),
106126
}
@@ -118,7 +138,9 @@ impl History for AnyHistory {
118138
T: 'static,
119139
{
120140
match self {
141+
#[cfg(not(target_os = "wasi"))]
121142
Self::Browser(m) => m.push_with_query_and_state(route, query, state),
143+
#[cfg(not(target_os = "wasi"))]
122144
Self::Hash(m) => m.push_with_query_and_state(route, query, state),
123145
Self::Memory(m) => m.push_with_query_and_state(route, query, state),
124146
}
@@ -136,7 +158,9 @@ impl History for AnyHistory {
136158
T: 'static,
137159
{
138160
match self {
161+
#[cfg(not(target_os = "wasi"))]
139162
Self::Browser(m) => m.replace_with_query_and_state(route, query, state),
163+
#[cfg(not(target_os = "wasi"))]
140164
Self::Hash(m) => m.replace_with_query_and_state(route, query, state),
141165
Self::Memory(m) => m.replace_with_query_and_state(route, query, state),
142166
}
@@ -147,27 +171,33 @@ impl History for AnyHistory {
147171
CB: Fn() + 'static,
148172
{
149173
match self {
174+
#[cfg(not(target_os = "wasi"))]
150175
Self::Browser(m) => m.listen(callback),
176+
#[cfg(not(target_os = "wasi"))]
151177
Self::Hash(m) => m.listen(callback),
152178
Self::Memory(m) => m.listen(callback),
153179
}
154180
}
155181

156182
fn location(&self) -> Location {
157183
match self {
184+
#[cfg(not(target_os = "wasi"))]
158185
Self::Browser(m) => m.location(),
186+
#[cfg(not(target_os = "wasi"))]
159187
Self::Hash(m) => m.location(),
160188
Self::Memory(m) => m.location(),
161189
}
162190
}
163191
}
164192

193+
#[cfg(not(target_os = "wasi"))]
165194
impl From<BrowserHistory> for AnyHistory {
166195
fn from(m: BrowserHistory) -> AnyHistory {
167196
AnyHistory::Browser(m)
168197
}
169198
}
170199

200+
#[cfg(not(target_os = "wasi"))]
171201
impl From<HashHistory> for AnyHistory {
172202
fn from(m: HashHistory) -> AnyHistory {
173203
AnyHistory::Hash(m)

crates/history/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#![deny(missing_docs, missing_debug_implementations)]
55

66
mod any;
7+
#[cfg(not(target_os = "wasi"))]
78
mod browser;
89
#[cfg(feature = "query")]
910
mod error;
11+
#[cfg(not(target_os = "wasi"))]
1012
mod hash;
1113
mod history;
1214
mod listener;
@@ -18,7 +20,9 @@ mod state;
1820
mod utils;
1921

2022
pub use any::AnyHistory;
23+
#[cfg(not(target_os = "wasi"))]
2124
pub use browser::BrowserHistory;
25+
#[cfg(not(target_os = "wasi"))]
2226
pub use hash::HashHistory;
2327
pub use memory::MemoryHistory;
2428

crates/history/src/state.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(not(target_os = "wasi"))]
2+
13
use std::any::Any;
24
use std::collections::HashMap;
35
use std::rc::Rc;

0 commit comments

Comments
 (0)