mirror of https://github.com/sotrh/learn-wgpu
switched to custom wasm-builder instead of wasm-pack for examples
parent
514e957099
commit
2898a72bc0
@ -1,16 +1 @@
|
||||
export RES_PATH=learn-wgpu
|
||||
# (trap 'killall background' INT;
|
||||
# wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/pong code/showcase/pong
|
||||
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial1_window code/beginner/tutorial1-window
|
||||
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial2_surface code/beginner/tutorial2-surface
|
||||
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial3_pipeline code/beginner/tutorial3-pipeline
|
||||
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial4_buffer code/beginner/tutorial4-buffer
|
||||
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial5_textures code/beginner/tutorial5-textures
|
||||
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial6_uniforms code/beginner/tutorial6-uniforms
|
||||
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial7_instancing code/beginner/tutorial7-instancing
|
||||
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial8_depth code/beginner/tutorial8-depth
|
||||
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial9_models code/beginner/tutorial9-models
|
||||
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial10_lighting code/intermediate/tutorial10-lighting
|
||||
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial11_normals code/intermediate/tutorial11-normals
|
||||
wasm-pack build --out-dir ../../../docs/.vuepress/components/wasm/tutorial12_camera code/intermediate/tutorial12-camera
|
||||
# )
|
||||
cargo r -p wasm-builder wasm-targets.json
|
@ -0,0 +1 @@
|
||||
Cargo.lock
|
@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "wasm-builder"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
||||
log = "0.4"
|
||||
env_logger = "0.10"
|
||||
rayon = "1"
|
||||
serde = { version = "1", features = ["derive"]}
|
||||
serde_json = "1"
|
||||
wasm-bindgen-cli-support = "0.2.84"
|
@ -0,0 +1,75 @@
|
||||
use std::{process::Command, path::PathBuf};
|
||||
|
||||
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
||||
use wasm_bindgen_cli_support::Bindgen;
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
struct WasmTarget {
|
||||
package: String,
|
||||
out: String,
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
env_logger::init();
|
||||
|
||||
let input = match std::env::args().skip(1).next() {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
log::info!("No input file supplied");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
let json = std::fs::read_to_string(input)?;
|
||||
|
||||
let targets: Vec<WasmTarget> = serde_json::from_str(&json)?;
|
||||
|
||||
// Tell cargo to build all targets as wasm32-unknown-unknown
|
||||
let mut command = Command::new("cargo");
|
||||
|
||||
let start_time = std::time::Instant::now();
|
||||
|
||||
command
|
||||
.arg("build")
|
||||
.arg("--release")
|
||||
.arg("--target")
|
||||
.arg("wasm32-unknown-unknown");
|
||||
for target in &targets {
|
||||
command.arg("-p").arg(&target.package);
|
||||
}
|
||||
command.spawn()?.wait()?;
|
||||
|
||||
let errors = targets
|
||||
.par_iter()
|
||||
.map(|target| {
|
||||
let path = PathBuf::from(&target.out);
|
||||
|
||||
// Ignore contents to prevent cargo-watch looping
|
||||
std::fs::create_dir_all(&path)?;
|
||||
std::fs::write(path.join(".gitignore"), "*\n")?;
|
||||
|
||||
Bindgen::new()
|
||||
.bundler(true)?
|
||||
.input_path(format!(
|
||||
"target/wasm32-unknown-unknown/release/{}.wasm",
|
||||
target.package
|
||||
))
|
||||
.out_name("demo")
|
||||
.generate(path)
|
||||
})
|
||||
.filter_map(|r| r.err())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if !errors.is_empty() {
|
||||
for error in &errors {
|
||||
log::error!("{}", error);
|
||||
}
|
||||
log::error!("Encountered {} error(s)", errors.len());
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let time_taken = std::time::Instant::now() - start_time;
|
||||
log::info!("Success fully processed {} target(s) in {:?}", targets.len(), time_taken);
|
||||
|
||||
Ok(())
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
[
|
||||
{
|
||||
"package": "tutorial1-window",
|
||||
"out": "docs/.vuepress/components/wasm/tutorial1_window"
|
||||
},
|
||||
{
|
||||
"package": "tutorial2-surface",
|
||||
"out": "docs/.vuepress/components/wasm/tutorial2_surface"
|
||||
},
|
||||
{
|
||||
"package": "tutorial3-pipeline",
|
||||
"out": "docs/.vuepress/components/wasm/tutorial3_pipeline"
|
||||
},
|
||||
{
|
||||
"package": "tutorial4-buffer",
|
||||
"out": "docs/.vuepress/components/wasm/tutorial4_buffer"
|
||||
},
|
||||
{
|
||||
"package": "tutorial5-textures",
|
||||
"out": "docs/.vuepress/components/wasm/tutorial5_textures"
|
||||
},
|
||||
{
|
||||
"package": "tutorial6-uniforms",
|
||||
"out": "docs/.vuepress/components/wasm/tutorial6_uniforms"
|
||||
},
|
||||
{
|
||||
"package": "tutorial7-instancing",
|
||||
"out": "docs/.vuepress/components/wasm/tutorial7_instancing"
|
||||
},
|
||||
{
|
||||
"package": "tutorial8-depth",
|
||||
"out": "docs/.vuepress/components/wasm/tutorial8_depth"
|
||||
},
|
||||
{
|
||||
"package": "tutorial9-models",
|
||||
"out": "docs/.vuepress/components/wasm/tutorial9_models"
|
||||
},
|
||||
{
|
||||
"package": "tutorial10-lighting",
|
||||
"out": "docs/.vuepress/components/wasm/tutorial10_lighting"
|
||||
},
|
||||
{
|
||||
"package": "tutorial11-normals",
|
||||
"out": "docs/.vuepress/components/wasm/tutorial11_normals"
|
||||
},
|
||||
{
|
||||
"package": "tutorial12-camera",
|
||||
"out": "docs/.vuepress/components/wasm/tutorial12_camera"
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue