Replace just with cargo-run-wasm (#310)

This commit is contained in:
Jay Oster 2022-10-02 21:13:48 -07:00 committed by GitHub
parent a2c639823f
commit 9f7896cd2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 45 deletions

2
.cargo/config.toml Normal file
View file

@ -0,0 +1,2 @@
[alias]
run-wasm = ["run", "--release", "--package", "run-wasm", "--"]

View file

@ -114,10 +114,8 @@ jobs:
toolchain: stable
target: wasm32-unknown-unknown
override: true
- name: Install tools
run: cargo install --locked wasm-bindgen-cli just
- name: Just build
run: just build ${{ matrix.example }}
- name: WASM build
run: cargo run-wasm --build-only ${{ matrix.example }}
# See https://github.com/parasyte/pixels-ci-rust-version
rust-version:

View file

@ -37,4 +37,5 @@ winit = "0.27"
members = [
"examples/*",
"internals/*",
"run-wasm",
]

View file

@ -6,11 +6,10 @@ Minimal example for WebGL2.
## Install build dependencies
Install the WASM32 target and a few CLI tools:
Install the WASM32 target:
```bash
rustup target add wasm32-unknown-unknown
cargo install --locked wasm-bindgen-cli just miniserve
```
## Running on the Web
@ -18,18 +17,18 @@ cargo install --locked wasm-bindgen-cli just miniserve
Build the project and start a local server to host it:
```bash
just serve minimal-web
cargo run-wasm --release minimal-web
```
Open http://localhost:8080/ in your browser to run the example.
Open http://localhost:8000/ in your browser to run the example.
To build the project without serving it:
```bash
just build minimal-web
cargo run-wasm --release --build-only minimal-web
```
The build files are stored in `./target/minimal-web/`.
The build files are stored in `./target/wasm-examples/minimal-web/`.
## Running on native targets

View file

@ -1,24 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style type="text/css">
body {
background-color: #000;
margin: 0;
overflow: hidden;
}
</style>
<title>Hello Pixels + Web</title>
</head>
<body>
<script type="module">
import init from "./minimal-web.js";
window.addEventListener("load", () => {
init();
});
</script>
</body>
</html>

View file

@ -1,11 +0,0 @@
serve package: (build package)
miniserve --index index.html ./target/{{package}}/
build package:
mkdir -p ./target/{{package}}/
cp ./examples/{{package}}/index.html ./target/{{package}}/
cargo build --release --package {{package}} --target wasm32-unknown-unknown
wasm-bindgen --target web --no-typescript --out-dir ./target/{{package}}/ ./target/wasm32-unknown-unknown/release/{{package}}.wasm
clean package:
rm -rf ./target/{{package}}/

8
run-wasm/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "run-wasm"
version = "0.1.0"
edition = "2021"
[dependencies.cargo-run-wasm]
git = "https://github.com/rukai/cargo-run-wasm.git"
rev = "49d53e5eda86aaf66bfb271cb2e7e37cbcf4cfbb"

9
run-wasm/src/main.rs Normal file
View file

@ -0,0 +1,9 @@
fn main() {
let css = r#"body {
background-color: #000;
margin: 0;
overflow: hidden;
}"#;
cargo_run_wasm::run_wasm_with_css(css);
}