diff --git a/Cargo.toml b/Cargo.toml index 74a9be1..8630ae5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "webgl" -version = "0.1.0" +name = "maxwell" +version = "0.1.1" authors = ["Magnus Ulimoen "] edition = "2018" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "rlib"] [features] default = ["console_error_panic_hook", "wee_alloc"] diff --git a/index.html b/index.html index f70884a..26eac1f 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ - WebGL waves + Maxwell waves diff --git a/main.js b/main.js index 6b57c4f..11a0291 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,7 @@ -import { Universe, set_panic_hook, default as init } from "./webgl.js"; +import { Universe, set_panic_hook, default as init } from "./maxwell.js"; async function run() { - let wasm = await init("./webgl_bg.wasm"); + let wasm = await init("./maxwell_bg.wasm"); set_panic_hook(); const canvas = document.getElementById("glCanvas"); diff --git a/make_wasm.py b/make_wasm.py index d4e4b0c..804fedb 100755 --- a/make_wasm.py +++ b/make_wasm.py @@ -3,31 +3,63 @@ from argparse import ArgumentParser from subprocess import check_call from shutil import copyfile +import tempfile +import pathlib if __name__ == "__main__": parser = ArgumentParser(description="Build js and wasm") - parser.add_argument("-r", help="Build release type", - dest="release", action="store_true") + parser.add_argument( + "-r", help="Build release type", dest="release", action="store_true" + ) + parser.add_argument( + "--destdir", + default=pathlib.Path("publish"), + type=pathlib.Path, + help="Destination suitable for being copied directly to the webserver", + ) args = parser.parse_args() - if args.release: - check_call(["cargo", "build", "--release", - "--target", "wasm32-unknown-unknown"]) - target = "target/wasm32-unknown-unknown/release/webgl.wasm" - else: - check_call(["cargo", "build", - "--target", "wasm32-unknown-unknown"]) - target = "target/wasm32-unknown-unknown/debug/webgl.wasm" + publish = args.destdir + publish.mkdir(exist_ok=True) - check_call(["wasm-bindgen", target, "--out-dir", ".", - "--no-typescript", "--target", "web"]) + target_triple = "wasm32-unknown-unknown" + command = ["cargo", "build", "--target", target_triple] + target = ( + pathlib.Path("target") + .joinpath(target_triple) + .joinpath("release" if args.release else "debug") + .joinpath("maxwell.wasm") + ) + if args.release: + command.append("--release") + + check_call(command) + assert target.exists() + + check_call( + [ + "wasm-bindgen", + str(target), + "--out-dir", + str(publish), + "--no-typescript", + "--target", + "web", + ] + ) if args.release: try: - copyfile("webgl_bg.wasm", "before-wasm-opt.wasm") - check_call(["wasm-opt", "-O4", "before-wasm-opt.wasm", - "-o", "webgl_bg.wasm"]) + with tempfile.TemporaryDirectory() as d_: + d = pathlib.Path(d_) + wasm_bg = publish.joinpath("maxwell_bg.wasm") + wasm_to_opt = d.joinpath("before-wasm-opt.wasm") + copyfile(wasm_bg, wasm_to_opt) + check_call(["wasm-opt", "-O4", str(wasm_to_opt), "-o", str(wasm_bg)]) except FileNotFoundError: print("wasm-opt not found, not optimising further") pass + + for f in ["index.html", "main.js", "style.css"]: + copyfile(f, publish.joinpath(f)) diff --git a/src/lib.rs b/src/lib.rs index 339bb5c..c301b07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,8 +2,7 @@ use wasm_bindgen::prelude::*; mod maxwell; mod operators; -use maxwell::{System, WorkBuffers}; -use operators::Upwind4; +pub use crate::maxwell::{System, WorkBuffers}; #[cfg(feature = "wee_alloc")] #[global_allocator] @@ -35,7 +34,7 @@ impl Universe { } pub fn advance(&mut self, dt: f32) { - System::advance::(&self.sys.0, &mut self.sys.1, dt, Some(&mut self.wb)); + System::advance::(&self.sys.0, &mut self.sys.1, dt, Some(&mut self.wb)); std::mem::swap(&mut self.sys.0, &mut self.sys.1); }