Skip to content

Commit 7f7e8e7

Browse files
authored
Fix wasm (#582)
1 parent dfb9ac7 commit 7f7e8e7

File tree

6 files changed

+32
-26
lines changed

6 files changed

+32
-26
lines changed

.cargo/config.toml

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
[alias]
2-
rend3-doc = ["doc", "--no-deps", "--lib", "--workspace", "--exclude", "scene-viewer", "--exclude", "rend3-cube-example"]
2+
rend3-doc = [
3+
"doc",
4+
"--no-deps",
5+
"--lib",
6+
"--workspace",
7+
"--exclude",
8+
"scene-viewer",
9+
"--exclude",
10+
"rend3-cube-example",
11+
]
312

413
[build]
5-
rustflags = [
6-
"--cfg=web_sys_unstable_apis"
7-
]
14+
rustflags = []

.github/workflows/ci.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
pull_request:
77

88
env:
9-
RUSTFLAGS: --cfg=web_sys_unstable_apis -D warnings
9+
RUSTFLAGS: -D warnings
1010
RUSTDOCFLAGS: -D warnings
1111

1212
jobs:
@@ -66,15 +66,13 @@ jobs:
6666
- name: clippy
6767
run: |
6868
cargo +1.76 clippy --target ${{ matrix.target }} --profile ci
69-
if: matrix.target != 'wasm32-unknown-unknown'
7069
7170
- name: doc
7271
run: |
7372
cargo +1.76 doc --target ${{ matrix.target }} --profile ci --no-deps
74-
if: matrix.target != 'wasm32-unknown-unknown'
7573
7674
- name: download test resources
77-
if: matrix.os != 'macos-14'
75+
if: matrix.os != 'macos-14' && matrix.target != 'wasm32-unknown-unknown'
7876
run: |
7977
bash ./build.bash download-assets
8078

build.bash

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ case $1 in
1212
else
1313
WASM_BUILD_DIR=debug
1414
fi
15-
RUSTFLAGS=--cfg=web_sys_unstable_apis cargo build --target wasm32-unknown-unknown $BUILD_FLAGS --bin $@
15+
cargo build --target wasm32-unknown-unknown $BUILD_FLAGS --bin $@
1616
mkdir -p target/generated/
1717
rm -rf target/generated/*
1818
cp -r examples/$1/resources target/generated/ || true
@@ -28,7 +28,7 @@ case $1 in
2828
cargo clippy
2929
cargo test
3030
cargo rend3-doc
31-
RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknown --workspace --exclude rend3-imgui --exclude rend3-imgui-example
31+
cargo clippy --target wasm32-unknown-unknown --workspace --exclude rend3-imgui --exclude rend3-imgui-example
3232
cargo deny --all-features check
3333
;;
3434
download-assets)

examples/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ ndk-glue = { version = "0.7", features = ["logger"] }
8585
rend3-test = { version = "^0.3.0", path = "../rend3-test" }
8686
tokio = "1"
8787

88+
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
89+
wasm-bindgen-test = { version = "0.3" }
90+
8891
[package.metadata.android]
8992
build_targets = ["aarch64-linux-android"]
9093

rend3-framework/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pollster = "0.3"
3434
console_error_panic_hook = "0.1"
3535
console_log = "1"
3636
js-sys = "0.3"
37+
gloo-net = { version = "0.5", default-features = false, features = ["http"] }
3738
once_cell = "1.8"
3839
wasm-bindgen = "0.2.87"
3940
wasm-bindgen-futures = "0.4"

rend3-framework/src/assets.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ pub enum AssetError {
1212
#[source]
1313
error: std::io::Error,
1414
},
15+
#[cfg(target_arch = "wasm32")]
16+
#[error("Could not read {path} from network")]
17+
NetworkError {
18+
path: SsoString,
19+
#[source]
20+
error: gloo_net::Error,
21+
},
1522
}
1623

1724
pub enum AssetPath<'a> {
@@ -86,28 +93,18 @@ impl AssetLoader {
8693
#[cfg(target_arch = "wasm32")]
8794
pub async fn get_asset(&self, path: AssetPath<'_>) -> Result<Vec<u8>, AssetError> {
8895
let full_path = path.get_path(&self.base);
89-
let response = reqwest::get(&*full_path)
90-
.await
96+
97+
gloo_net::http::Request::get(&full_path)
98+
.build()
9199
.map_err(|error| AssetError::NetworkError {
92100
path: SsoString::from(&*full_path),
93101
error,
94-
})?;
95-
96-
let status = response.status();
97-
if !status.is_success() {
98-
return Err(AssetError::NetworkStatusError {
99-
path: SsoString::from(&*full_path),
100-
status,
101-
});
102-
}
103-
104-
Ok(response
105-
.bytes()
102+
})?
103+
.binary()
106104
.await
107105
.map_err(|error| AssetError::NetworkError {
108106
path: SsoString::from(&*full_path),
109107
error,
110-
})?
111-
.to_vec())
108+
})
112109
}
113110
}

0 commit comments

Comments
 (0)