From b7e1dec58976c49d93d83606aca1ee17f153143d Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Thu, 17 Sep 2020 11:24:37 +0200 Subject: [PATCH] Add empty player subcrate, update build scripts --- Cargo.toml | 1 + Makefile | 24 +++++++++++++++-- frontend/core/Cargo.toml | 2 +- frontend/core/static/app.js | 43 +++++++++++++++++++++++++++++++ frontend/core/static/index.html | 16 ++++++++++++ frontend/core/static/package.json | 13 ++++++++++ frontend/player/Cargo.toml | 12 +++++++++ frontend/player/src/lib.rs | 5 ++++ 8 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 frontend/core/static/app.js create mode 100644 frontend/core/static/index.html create mode 100644 frontend/core/static/package.json create mode 100644 frontend/player/Cargo.toml create mode 100644 frontend/player/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 5595f26..bd5b30e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" [workspace] members = [ "frontend/core", + "frontend/player", ] [profile.release] diff --git a/Makefile b/Makefile index 200ebbd..5c159ec 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,29 @@ all: build-frontend -build-frontend: +build-frontend: build-frontend-core build-frontend-player + +build-frontend-core: cd frontend/core && \ - wasm-pack build --dev --target web --out-name wasm --out-dir ./static + wasm-pack build \ + --dev \ + --target web \ + --no-typescript \ + --out-name audioview_core \ + --out-dir ./static/wasm/ + +build-frontend-player: + RUSTFLAGS='-C target-feature=+atomics,+bulk-memory' \ + cargo build -p audioview-frontend-player --target-dir ./target --target wasm32-unknown-unknown -Z build-std=std,panic_abort && \ + wasm-bindgen \ + target/wasm32-unknown-unknown/debug/audioview_frontend_player.wasm \ + --out-name audioview_player \ + --out-dir ./frontend/core/static/wasm/ \ + --target no-modules + +clean: + cargo clean + rm -rf frontend/core/static/wasm/ build-doc: cargo doc --all --no-deps diff --git a/frontend/core/Cargo.toml b/frontend/core/Cargo.toml index bbae2f6..092a9f9 100644 --- a/frontend/core/Cargo.toml +++ b/frontend/core/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Rob Watson "] edition = "2018" [lib] -crate-type = ["cdylib", "rlib"] +crate-type = ["cdylib"] [dependencies] yew = "0.17" diff --git a/frontend/core/static/app.js b/frontend/core/static/app.js new file mode 100644 index 0000000..5f11209 --- /dev/null +++ b/frontend/core/static/app.js @@ -0,0 +1,43 @@ +const { run_app } = wasm_bindgen; + +async function loadWasm() { + let msg = 'This demo requires a current version of Firefox (e.g., 79.0)'; + if (typeof SharedArrayBuffer !== 'function') { + alert('this browser does not have SharedArrayBuffer support enabled' + '\n\n' + msg); + return + } + + // Test for bulk memory operations with passive data segments + // (module (memory 1) (data passive "")) + const buf = new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, + 0x05, 0x03, 0x01, 0x00, 0x01, 0x0b, 0x03, 0x01, 0x01, 0x00]); + if (!WebAssembly.validate(buf)) { + alert('this browser does not support passive wasm memory, demo does not work' + '\n\n' + msg); + return + } + + let res = await wasm_bindgen('/wasm/audioview_player_bg.wasm'); + console.log(res); + //run_app(); +} + +window.addEventListener("DOMContentLoaded", () => { + console.log("Loading wasm module..."); + loadWasm(); + + //console.log("Setting up audio worklet..."); + + //const ctx = new AudioContext(); + //ctx.audioWorklet.addModule("worklet.js?t=" + new Date().getTime()) + //.then(() => { + //const workletNode = new AudioWorkletNode(ctx, 'audio-worker'); + + //workletNode.connect(ctx.destination); + + //fetch('audioview.wasm?t=' + new Date().getTime()) + //.then(r => r.arrayBuffer()) + //.then(r => workletNode.port.postMessage({ type: 'loadWasm', data: r })) + //.catch(err => console.log(err)); + //}) + //.catch(err => console.error(err)); +}); diff --git a/frontend/core/static/index.html b/frontend/core/static/index.html new file mode 100644 index 0000000..332e972 --- /dev/null +++ b/frontend/core/static/index.html @@ -0,0 +1,16 @@ + + + + + Audioview + + + + + + + + diff --git a/frontend/core/static/package.json b/frontend/core/static/package.json new file mode 100644 index 0000000..393bbec --- /dev/null +++ b/frontend/core/static/package.json @@ -0,0 +1,13 @@ +{ + "name": "audioview-frontend-core", + "collaborators": [ + "Rob Watson " + ], + "version": "0.1.0", + "files": [ + "audioview_core_bg.wasm", + "audioview_core.js" + ], + "module": "audioview_core.js", + "sideEffects": false +} \ No newline at end of file diff --git a/frontend/player/Cargo.toml b/frontend/player/Cargo.toml new file mode 100644 index 0000000..0e06423 --- /dev/null +++ b/frontend/player/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "audioview-frontend-player" +version = "0.1.0" +authors = ["Rob Watson "] +edition = "2018" + +[lib] +crate-type = ["cdylib"] + + +[dependencies] +wasm-bindgen = { version = "0.2" } diff --git a/frontend/player/src/lib.rs b/frontend/player/src/lib.rs new file mode 100644 index 0000000..cb542ca --- /dev/null +++ b/frontend/player/src/lib.rs @@ -0,0 +1,5 @@ +use wasm_bindgen::prelude::*; + +pub fn main() { + println!("Hello, world"); +}