From 9f7896cd2f1c80989e8f29ec6e3b6687183250a4 Mon Sep 17 00:00:00 2001 From: Jay Oster Date: Sun, 2 Oct 2022 21:13:48 -0700 Subject: [PATCH] Replace just with cargo-run-wasm (#310) --- .cargo/config.toml | 2 ++ .github/workflows/ci.yml | 6 ++---- Cargo.toml | 1 + examples/minimal-web/README.md | 11 +++++------ examples/minimal-web/index.html | 24 ------------------------ justfile | 11 ----------- run-wasm/Cargo.toml | 8 ++++++++ run-wasm/src/main.rs | 9 +++++++++ 8 files changed, 27 insertions(+), 45 deletions(-) create mode 100644 .cargo/config.toml delete mode 100644 examples/minimal-web/index.html delete mode 100644 justfile create mode 100644 run-wasm/Cargo.toml create mode 100644 run-wasm/src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..a9f1242 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[alias] +run-wasm = ["run", "--release", "--package", "run-wasm", "--"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a203df..34700b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/Cargo.toml b/Cargo.toml index 7a46792..332464c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,4 +37,5 @@ winit = "0.27" members = [ "examples/*", "internals/*", + "run-wasm", ] diff --git a/examples/minimal-web/README.md b/examples/minimal-web/README.md index 09a1be6..d53a316 100644 --- a/examples/minimal-web/README.md +++ b/examples/minimal-web/README.md @@ -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 diff --git a/examples/minimal-web/index.html b/examples/minimal-web/index.html deleted file mode 100644 index d19bf55..0000000 --- a/examples/minimal-web/index.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - Hello Pixels + Web - - - - - diff --git a/justfile b/justfile deleted file mode 100644 index bb4d244..0000000 --- a/justfile +++ /dev/null @@ -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}}/ diff --git a/run-wasm/Cargo.toml b/run-wasm/Cargo.toml new file mode 100644 index 0000000..72e8c4b --- /dev/null +++ b/run-wasm/Cargo.toml @@ -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" diff --git a/run-wasm/src/main.rs b/run-wasm/src/main.rs new file mode 100644 index 0000000..ecda326 --- /dev/null +++ b/run-wasm/src/main.rs @@ -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); +}