Skip to content

Commit

Permalink
Fix wasm (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald authored Mar 9, 2024
1 parent dfb9ac7 commit 7f7e8e7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 26 deletions.
15 changes: 11 additions & 4 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
[alias]
rend3-doc = ["doc", "--no-deps", "--lib", "--workspace", "--exclude", "scene-viewer", "--exclude", "rend3-cube-example"]
rend3-doc = [
"doc",
"--no-deps",
"--lib",
"--workspace",
"--exclude",
"scene-viewer",
"--exclude",
"rend3-cube-example",
]

[build]
rustflags = [
"--cfg=web_sys_unstable_apis"
]
rustflags = []
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:

env:
RUSTFLAGS: --cfg=web_sys_unstable_apis -D warnings
RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings

jobs:
Expand Down Expand Up @@ -66,15 +66,13 @@ jobs:
- name: clippy
run: |
cargo +1.76 clippy --target ${{ matrix.target }} --profile ci
if: matrix.target != 'wasm32-unknown-unknown'
- name: doc
run: |
cargo +1.76 doc --target ${{ matrix.target }} --profile ci --no-deps
if: matrix.target != 'wasm32-unknown-unknown'
- name: download test resources
if: matrix.os != 'macos-14'
if: matrix.os != 'macos-14' && matrix.target != 'wasm32-unknown-unknown'
run: |
bash ./build.bash download-assets
Expand Down
4 changes: 2 additions & 2 deletions build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ case $1 in
else
WASM_BUILD_DIR=debug
fi
RUSTFLAGS=--cfg=web_sys_unstable_apis cargo build --target wasm32-unknown-unknown $BUILD_FLAGS --bin $@
cargo build --target wasm32-unknown-unknown $BUILD_FLAGS --bin $@
mkdir -p target/generated/
rm -rf target/generated/*
cp -r examples/$1/resources target/generated/ || true
Expand All @@ -28,7 +28,7 @@ case $1 in
cargo clippy
cargo test
cargo rend3-doc
RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknown --workspace --exclude rend3-imgui --exclude rend3-imgui-example
cargo clippy --target wasm32-unknown-unknown --workspace --exclude rend3-imgui --exclude rend3-imgui-example
cargo deny --all-features check
;;
download-assets)
Expand Down
3 changes: 3 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ ndk-glue = { version = "0.7", features = ["logger"] }
rend3-test = { version = "^0.3.0", path = "../rend3-test" }
tokio = "1"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = { version = "0.3" }

[package.metadata.android]
build_targets = ["aarch64-linux-android"]

Expand Down
1 change: 1 addition & 0 deletions rend3-framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pollster = "0.3"
console_error_panic_hook = "0.1"
console_log = "1"
js-sys = "0.3"
gloo-net = { version = "0.5", default-features = false, features = ["http"] }
once_cell = "1.8"
wasm-bindgen = "0.2.87"
wasm-bindgen-futures = "0.4"
Expand Down
29 changes: 13 additions & 16 deletions rend3-framework/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ pub enum AssetError {
#[source]
error: std::io::Error,
},
#[cfg(target_arch = "wasm32")]
#[error("Could not read {path} from network")]
NetworkError {
path: SsoString,
#[source]
error: gloo_net::Error,
},
}

pub enum AssetPath<'a> {
Expand Down Expand Up @@ -86,28 +93,18 @@ impl AssetLoader {
#[cfg(target_arch = "wasm32")]
pub async fn get_asset(&self, path: AssetPath<'_>) -> Result<Vec<u8>, AssetError> {
let full_path = path.get_path(&self.base);
let response = reqwest::get(&*full_path)
.await

gloo_net::http::Request::get(&full_path)
.build()
.map_err(|error| AssetError::NetworkError {
path: SsoString::from(&*full_path),
error,
})?;

let status = response.status();
if !status.is_success() {
return Err(AssetError::NetworkStatusError {
path: SsoString::from(&*full_path),
status,
});
}

Ok(response
.bytes()
})?
.binary()
.await
.map_err(|error| AssetError::NetworkError {
path: SsoString::from(&*full_path),
error,
})?
.to_vec())
})
}
}

0 comments on commit 7f7e8e7

Please sign in to comment.