Add empty player subcrate, update build scripts

This commit is contained in:
Rob Watson 2020-09-17 11:24:37 +02:00
parent d7080bcc4b
commit b7e1dec589
8 changed files with 113 additions and 3 deletions

View File

@ -8,6 +8,7 @@ edition = "2018"
[workspace] [workspace]
members = [ members = [
"frontend/core", "frontend/core",
"frontend/player",
] ]
[profile.release] [profile.release]

View File

@ -2,9 +2,29 @@
all: build-frontend all: build-frontend
build-frontend: build-frontend: build-frontend-core build-frontend-player
build-frontend-core:
cd 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: build-doc:
cargo doc --all --no-deps cargo doc --all --no-deps

View File

@ -5,7 +5,7 @@ authors = ["Rob Watson <rob@netflux.io>"]
edition = "2018" edition = "2018"
[lib] [lib]
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib"]
[dependencies] [dependencies]
yew = "0.17" yew = "0.17"

View File

@ -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));
});

View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Audioview</title>
<script src="/wasm/audioview_player.js"></script>
<script type="module">
import init from "/wasm/audioview_core.js";
init();
</script>
<script src="app.js"></script>
<link rel="shortcut icon" href="#" />
</head>
<body>
</body>
</html>

View File

@ -0,0 +1,13 @@
{
"name": "audioview-frontend-core",
"collaborators": [
"Rob Watson <rob@netflux.io>"
],
"version": "0.1.0",
"files": [
"audioview_core_bg.wasm",
"audioview_core.js"
],
"module": "audioview_core.js",
"sideEffects": false
}

View File

@ -0,0 +1,12 @@
[package]
name = "audioview-frontend-player"
version = "0.1.0"
authors = ["Rob Watson <rob@netflux.io>"]
edition = "2018"
[lib]
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = { version = "0.2" }

View File

@ -0,0 +1,5 @@
use wasm_bindgen::prelude::*;
pub fn main() {
println!("Hello, world");
}