diff --git a/Cargo.lock b/Cargo.lock index 886d46d..e11370a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,176 +1,80 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "autocfg" -version = "1.2.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "box" version = "0.1.0" dependencies = [ - "console_error_panic_hook", "nodarium_macros", "nodarium_utils", - "serde", - "serde-wasm-bindgen", - "wasm-bindgen", - "wasm-bindgen-test", - "web-sys", ] [[package]] name = "branch" version = "0.1.0" dependencies = [ - "console_error_panic_hook", - "glam", "nodarium_macros", "nodarium_utils", - "serde", - "serde-wasm-bindgen", - "wasm-bindgen", - "wasm-bindgen-test", - "web-sys", -] - -[[package]] -name = "bumpalo" -version = "3.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "console_error_panic_hook" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" -dependencies = [ - "cfg-if", - "wasm-bindgen", ] [[package]] name = "float" version = "0.1.0" dependencies = [ - "console_error_panic_hook", "nodarium_macros", "nodarium_utils", - "serde", - "serde-wasm-bindgen", - "wasm-bindgen", - "wasm-bindgen-test", ] [[package]] name = "glam" -version = "0.27.0" +version = "0.30.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e05e7e6723e3455f4818c7b26e855439f7546cf617ef669d1adedb8669e5cb9" +checksum = "19fc433e8437a212d1b6f1e68c7824af3aed907da60afa994e7f542d18d12aa9" [[package]] name = "gravity" version = "0.1.0" dependencies = [ - "console_error_panic_hook", "glam", "nodarium_macros", "nodarium_utils", - "noise", - "serde", - "serde-wasm-bindgen", - "wasm-bindgen", - "wasm-bindgen-test", - "web-sys", +] + +[[package]] +name = "instance" +version = "0.1.0" +dependencies = [ + "glam", + "nodarium_macros", + "nodarium_utils", ] [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "js-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "log" -version = "0.4.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" [[package]] name = "math" version = "0.1.0" dependencies = [ - "console_error_panic_hook", "nodarium_macros", "nodarium_utils", - "serde", - "serde-wasm-bindgen", - "wasm-bindgen", - "wasm-bindgen-test", - "web-sys", ] [[package]] -name = "max-plantarium-triangle" -version = "0.1.0" -dependencies = [ - "console_error_panic_hook", - "nodarium_macros", - "nodarium_utils", - "serde", - "serde-wasm-bindgen", - "wasm-bindgen", - "wasm-bindgen-test", - "web-sys", -] - -[[package]] -name = "max-plantarium-vec3" -version = "0.1.0" -dependencies = [ - "console_error_panic_hook", - "nodarium_macros", - "nodarium_utils", - "serde", - "serde-wasm-bindgen", - "wasm-bindgen", - "wasm-bindgen-test", - "web-sys", -] - -[[package]] -name = "nodarium_instance" -version = "0.1.0" -dependencies = [ - "console_error_panic_hook", - "glam", - "nodarium_macros", - "nodarium_utils", - "serde", - "serde-wasm-bindgen", - "wasm-bindgen", - "wasm-bindgen-test", - "web-sys", -] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" [[package]] name = "nodarium_macros" @@ -180,7 +84,7 @@ dependencies = [ "quote", "serde", "serde_json", - "syn 1.0.109", + "syn", ] [[package]] @@ -195,29 +99,19 @@ dependencies = [ name = "nodarium_utils" version = "0.1.0" dependencies = [ - "console_error_panic_hook", "glam", - "noise", + "noise 0.9.0", "serde", "serde_json", - "wasm-bindgen", - "web-sys", ] [[package]] -name = "nodes-noise" +name = "noise" version = "0.1.0" dependencies = [ - "console_error_panic_hook", - "glam", "nodarium_macros", "nodarium_utils", - "noise", - "serde", - "serde-wasm-bindgen", - "wasm-bindgen", - "wasm-bindgen-test", - "web-sys", + "noise 0.9.0", ] [[package]] @@ -233,48 +127,35 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - [[package]] name = "output" version = "0.1.0" dependencies = [ - "console_error_panic_hook", - "glam", "nodarium_macros", "nodarium_utils", - "serde", - "serde_json", - "wasm-bindgen", - "wasm-bindgen-test", - "web-sys", ] [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" dependencies = [ "proc-macro2", ] @@ -307,103 +188,76 @@ dependencies = [ name = "random" version = "0.1.0" dependencies = [ - "console_error_panic_hook", "nodarium_macros", "nodarium_utils", - "serde", - "serde-wasm-bindgen", - "wasm-bindgen", - "wasm-bindgen-test", ] [[package]] name = "rotate" version = "0.1.0" dependencies = [ - "console_error_panic_hook", "glam", "nodarium_macros", "nodarium_utils", "serde", - "serde-wasm-bindgen", - "wasm-bindgen", - "wasm-bindgen-test", - "web-sys", ] -[[package]] -name = "ryu" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" - -[[package]] -name = "scoped-tls" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" - [[package]] name = "serde" -version = "1.0.198" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] -[[package]] -name = "serde-wasm-bindgen" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b4c031cd0d9014307d82b8abf653c0290fbdaeb4c02d00c63cf52f728628bf" -dependencies = [ - "js-sys", - "serde", - "wasm-bindgen", -] - [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn", ] [[package]] name = "serde_json" -version = "1.0.116" +version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" dependencies = [ "itoa", - "ryu", + "memchr", "serde", + "serde_core", + "zmij", ] [[package]] name = "stem" version = "0.1.0" dependencies = [ - "console_error_panic_hook", "nodarium_macros", "nodarium_utils", - "serde", - "serde-wasm-bindgen", - "wasm-bindgen", - "wasm-bindgen-test", - "web-sys", ] [[package]] name = "syn" -version = "1.0.109" +version = "2.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" dependencies = [ "proc-macro2", "quote", @@ -411,119 +265,30 @@ dependencies = [ ] [[package]] -name = "syn" -version = "2.0.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +name = "triangle" +version = "0.1.0" dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", + "nodarium_macros", + "nodarium_utils", ] [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] -name = "wasm-bindgen" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +name = "vec3" +version = "0.1.0" dependencies = [ - "cfg-if", - "wasm-bindgen-macro", + "nodarium_macros", + "nodarium_utils", + "serde", ] [[package]] -name = "wasm-bindgen-backend" -version = "0.2.92" +name = "zmij" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" -dependencies = [ - "bumpalo", - "log", - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.60", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-futures" -version = "0.4.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" -dependencies = [ - "cfg-if", - "js-sys", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.60", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.92" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" - -[[package]] -name = "wasm-bindgen-test" -version = "0.3.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9bf62a58e0780af3e852044583deee40983e5886da43a271dd772379987667b" -dependencies = [ - "console_error_panic_hook", - "js-sys", - "scoped-tls", - "wasm-bindgen", - "wasm-bindgen-futures", - "wasm-bindgen-test-macro", -] - -[[package]] -name = "wasm-bindgen-test-macro" -version = "0.3.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.60", -] - -[[package]] -name = "web-sys" -version = "0.3.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" -dependencies = [ - "js-sys", - "wasm-bindgen", -] +checksum = "94f63c051f4fe3c1509da62131a678643c5b6fbdc9273b2b79d4378ebda003d2" diff --git a/app/package.json b/app/package.json index 01464d8..e245de7 100644 --- a/app/package.json +++ b/app/package.json @@ -22,7 +22,8 @@ "idb": "^8.0.3", "jsondiffpatch": "^0.7.3", "tailwindcss": "^4.1.18", - "three": "^0.182.0" + "three": "^0.182.0", + "wabt": "^1.0.39" }, "devDependencies": { "@iconify-json/tabler": "^1.2.26", diff --git a/app/src/lib/node-registry.ts b/app/src/lib/node-registry.ts index 335645d..112818d 100644 --- a/app/src/lib/node-registry.ts +++ b/app/src/lib/node-registry.ts @@ -3,7 +3,7 @@ import fs from "fs/promises"; import path from "path"; export async function getWasm(id: `${string}/${string}/${string}`) { - const filePath = path.resolve(`../nodes/${id}/pkg/index_bg.wasm`); + const filePath = path.resolve(`../nodes/${id}/pkg/node.wasm`); try { await fs.access(filePath); diff --git a/app/src/lib/runtime/runtime-executor.ts b/app/src/lib/runtime/runtime-executor.ts index c7ff8c9..fb2403f 100644 --- a/app/src/lib/runtime/runtime-executor.ts +++ b/app/src/lib/runtime/runtime-executor.ts @@ -244,13 +244,14 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { } this.perf?.addPoint("cache-hit", 0); - log.group(`executing ${node_type.id || node.id}`); + log.group(`executing ${node_type.id}-${node.id}`); log.log(`Inputs:`, inputs); a = performance.now(); results[node.id] = node_type.execute(encoded_inputs); + log.log("Executed", node.type, node.id) b = performance.now(); - if (this.cache) { + if (this.cache && node.id !== outputNode.id) { this.cache.set(inputHash, results[node.id]); } diff --git a/app/src/routes/dev/+layout.svelte b/app/src/routes/dev/+layout.svelte new file mode 100644 index 0000000..ddf9ccd --- /dev/null +++ b/app/src/routes/dev/+layout.svelte @@ -0,0 +1,8 @@ + + +
+ {@render children()} +
diff --git a/app/src/routes/dev/+page.svelte b/app/src/routes/dev/+page.svelte index 5fc25a1..ebe4081 100644 --- a/app/src/routes/dev/+page.svelte +++ b/app/src/routes/dev/+page.svelte @@ -1,29 +1,120 @@ +
+ {#if nodeInstance} + + {/if} +
+ - - - -
- -
-
-
+
+      
+        {JSON.stringify(nodeInstance?.props)}
+      
+    
+
+ + +
+ {#if nodeWasm} + + {/if} +
+ + +
+ {#await nodeRegistry.fetchCollection("max/plantarium")} +

Loading Nodes...

+ {:then result} + {#each result.nodes as n} + + {/each} + {/await} +
+
+
+ diff --git a/app/src/routes/dev/Code.svelte b/app/src/routes/dev/Code.svelte new file mode 100644 index 0000000..a274614 --- /dev/null +++ b/app/src/routes/dev/Code.svelte @@ -0,0 +1,26 @@ + + +{#await toWat(wasm)} +

Converting to WAT

+{:then c} +
+    {c}
+  
+{/await} diff --git a/nodes/max/plantarium/.template/Cargo.toml b/nodes/max/plantarium/.template/Cargo.toml index 9185f6a..298ff9f 100644 --- a/nodes/max/plantarium/.template/Cargo.toml +++ b/nodes/max/plantarium/.template/Cargo.toml @@ -11,18 +11,8 @@ crate-type = ["cdylib", "rlib"] default = ["console_error_panic_hook"] [dependencies] -wasm-bindgen = "0.2.84" - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. utils = { version = "0.1.0", path = "../../../../packages/utils" } macros = { version = "0.1.0", path = "../../../../packages/macros" } serde = { version = "1.0", features = ["derive"] } -serde-wasm-bindgen = "0.4" console_error_panic_hook = { version = "0.1.7", optional = true } web-sys = { version = "0.3.69", features = ["console"] } - -[dev-dependencies] -wasm-bindgen-test = "0.3.34" diff --git a/nodes/max/plantarium/.template/package.json b/nodes/max/plantarium/.template/package.json index 86916c9..c066779 100644 --- a/nodes/max/plantarium/.template/package.json +++ b/nodes/max/plantarium/.template/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "wasm-pack build --release --out-name index --no-default-features", + "build": "cargo build --target wasm32-unknown-unknown --release && mkdir -p pkg && cp ../../../../target/wasm32-unknown-unknown/release/out.wasm ./pkg/node.wasm", "dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'" } } diff --git a/nodes/max/plantarium/.template/tests/web.rs b/nodes/max/plantarium/.template/tests/web.rs deleted file mode 100644 index de5c1da..0000000 --- a/nodes/max/plantarium/.template/tests/web.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Test suite for the Web and headless browsers. - -#![cfg(target_arch = "wasm32")] - -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -wasm_bindgen_test_configure!(run_in_browser); - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); -} diff --git a/nodes/max/plantarium/box/Cargo.toml b/nodes/max/plantarium/box/Cargo.toml index 3fad443..3cf9bdd 100644 --- a/nodes/max/plantarium/box/Cargo.toml +++ b/nodes/max/plantarium/box/Cargo.toml @@ -7,22 +7,6 @@ edition = "2018" [lib] crate-type = ["cdylib", "rlib"] -[features] -default = ["console_error_panic_hook"] - [dependencies] -wasm-bindgen = "0.2.84" - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" } nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" } -serde = { version = "1.0", features = ["derive"] } -serde-wasm-bindgen = "0.4" -console_error_panic_hook = { version = "0.1.7", optional = true } -web-sys = { version = "0.3.69", features = ["console"] } - -[dev-dependencies] -wasm-bindgen-test = "0.3.34" diff --git a/nodes/max/plantarium/box/package.json b/nodes/max/plantarium/box/package.json index 86916c9..69679f8 100644 --- a/nodes/max/plantarium/box/package.json +++ b/nodes/max/plantarium/box/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "wasm-pack build --release --out-name index --no-default-features", + "build": "cargo build --target wasm32-unknown-unknown --release && mkdir -p pkg && cp ../../../../target/wasm32-unknown-unknown/release/box.wasm ./pkg/node.wasm", "dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'" } } diff --git a/nodes/max/plantarium/box/src/lib.rs b/nodes/max/plantarium/box/src/lib.rs index e550888..e4dc8f4 100644 --- a/nodes/max/plantarium/box/src/lib.rs +++ b/nodes/max/plantarium/box/src/lib.rs @@ -1,18 +1,15 @@ -use nodarium_macros::include_definition_file; +use nodarium_macros::nodarium_definition_file; +use nodarium_macros::nodarium_execute; use nodarium_utils::{ - concat_args, encode_float, evaluate_float, geometry::calculate_normals, log, set_panic_hook, + encode_float, evaluate_float, geometry::calculate_normals,log, split_args, wrap_arg, }; -use wasm_bindgen::prelude::*; -include_definition_file!("src/input.json"); +nodarium_definition_file!("src/input.json"); -#[rustfmt::skip] -#[wasm_bindgen] +#[nodarium_execute] pub fn execute(input: &[i32]) -> Vec { - set_panic_hook(); - let args = split_args(input); log!("WASM(cube): input: {:?} -> {:?}", input, args); @@ -22,7 +19,6 @@ pub fn execute(input: &[i32]) -> Vec { let p = encode_float(size); let n = encode_float(-size); - // [[1,3, x, y, z, x, y,z,x,y,z]]; let mut cube_geometry = [ diff --git a/nodes/max/plantarium/box/tests/web.rs b/nodes/max/plantarium/box/tests/web.rs deleted file mode 100644 index de5c1da..0000000 --- a/nodes/max/plantarium/box/tests/web.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Test suite for the Web and headless browsers. - -#![cfg(target_arch = "wasm32")] - -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -wasm_bindgen_test_configure!(run_in_browser); - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); -} diff --git a/nodes/max/plantarium/branch/Cargo.toml b/nodes/max/plantarium/branch/Cargo.toml index e627cf5..b38ac0e 100644 --- a/nodes/max/plantarium/branch/Cargo.toml +++ b/nodes/max/plantarium/branch/Cargo.toml @@ -7,23 +7,6 @@ edition = "2018" [lib] crate-type = ["cdylib", "rlib"] -[features] -default = ["console_error_panic_hook"] - [dependencies] -wasm-bindgen = "0.2.84" - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" } nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" } -serde = { version = "1.0", features = ["derive"] } -serde-wasm-bindgen = "0.4" -console_error_panic_hook = { version = "0.1.7", optional = true } -web-sys = { version = "0.3.69", features = ["console"] } -glam = "0.27.0" - -[dev-dependencies] -wasm-bindgen-test = "0.3.34" diff --git a/nodes/max/plantarium/branch/package.json b/nodes/max/plantarium/branch/package.json index 86916c9..dd1de2c 100644 --- a/nodes/max/plantarium/branch/package.json +++ b/nodes/max/plantarium/branch/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "wasm-pack build --release --out-name index --no-default-features", + "build": "cargo build --target wasm32-unknown-unknown --release && mkdir -p pkg && cp ../../../../target/wasm32-unknown-unknown/release/branch.wasm ./pkg/node.wasm", "dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'" } } diff --git a/nodes/max/plantarium/branch/src/lib.rs b/nodes/max/plantarium/branch/src/lib.rs index 9180467..6f9b60d 100644 --- a/nodes/max/plantarium/branch/src/lib.rs +++ b/nodes/max/plantarium/branch/src/lib.rs @@ -1,20 +1,19 @@ -use nodarium_macros::include_definition_file; +use nodarium_macros::nodarium_definition_file; +use nodarium_macros::nodarium_execute; use nodarium_utils::{ concat_arg_vecs, evaluate_float, evaluate_int, geometry::{ create_path, interpolate_along_path, rotate_vector_by_angle, wrap_path, wrap_path_mut, }, - log, set_panic_hook, split_args, + log, split_args, }; + use std::f32::consts::PI; -use wasm_bindgen::prelude::*; -include_definition_file!("src/input.json"); +nodarium_definition_file!("src/input.json"); -#[wasm_bindgen] +#[nodarium_execute] pub fn execute(input: &[i32]) -> Vec { - set_panic_hook(); - let args = split_args(input); let paths = split_args(args[0]); diff --git a/nodes/max/plantarium/branch/tests/web.rs b/nodes/max/plantarium/branch/tests/web.rs deleted file mode 100644 index de5c1da..0000000 --- a/nodes/max/plantarium/branch/tests/web.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Test suite for the Web and headless browsers. - -#![cfg(target_arch = "wasm32")] - -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -wasm_bindgen_test_configure!(run_in_browser); - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); -} diff --git a/nodes/max/plantarium/float/Cargo.toml b/nodes/max/plantarium/float/Cargo.toml index c1762ed..4c570f6 100644 --- a/nodes/max/plantarium/float/Cargo.toml +++ b/nodes/max/plantarium/float/Cargo.toml @@ -7,21 +7,6 @@ edition = "2018" [lib] crate-type = ["cdylib", "rlib"] -[features] -default = ["console_error_panic_hook"] - [dependencies] -wasm-bindgen = "0.2.84" - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" } nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" } -serde = { version = "1.0", features = ["derive"] } -serde-wasm-bindgen = "0.4" -console_error_panic_hook = { version = "0.1.7", optional = true } - -[dev-dependencies] -wasm-bindgen-test = "0.3.34" diff --git a/nodes/max/plantarium/float/package.json b/nodes/max/plantarium/float/package.json index 86916c9..e2e1fc5 100644 --- a/nodes/max/plantarium/float/package.json +++ b/nodes/max/plantarium/float/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "wasm-pack build --release --out-name index --no-default-features", + "build": "cargo build --target wasm32-unknown-unknown --release && mkdir -p pkg && cp ../../../../target/wasm32-unknown-unknown/release/float.wasm ./pkg/node.wasm", "dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'" } } diff --git a/nodes/max/plantarium/float/src/lib.rs b/nodes/max/plantarium/float/src/lib.rs index 5e6b39d..5d3a67f 100644 --- a/nodes/max/plantarium/float/src/lib.rs +++ b/nodes/max/plantarium/float/src/lib.rs @@ -1,9 +1,9 @@ -use nodarium_macros::include_definition_file; -use wasm_bindgen::prelude::*; +use nodarium_macros::nodarium_definition_file; +use nodarium_macros::nodarium_execute; -include_definition_file!("src/input.json"); +nodarium_definition_file!("src/input.json"); -#[wasm_bindgen] +#[nodarium_execute] pub fn execute(args: &[i32]) -> Vec { args.into() } diff --git a/nodes/max/plantarium/float/tests/web.rs b/nodes/max/plantarium/float/tests/web.rs deleted file mode 100644 index de5c1da..0000000 --- a/nodes/max/plantarium/float/tests/web.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Test suite for the Web and headless browsers. - -#![cfg(target_arch = "wasm32")] - -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -wasm_bindgen_test_configure!(run_in_browser); - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); -} diff --git a/nodes/max/plantarium/gravity/Cargo.toml b/nodes/max/plantarium/gravity/Cargo.toml index 332cbff..a38ae47 100644 --- a/nodes/max/plantarium/gravity/Cargo.toml +++ b/nodes/max/plantarium/gravity/Cargo.toml @@ -7,24 +7,7 @@ edition = "2018" [lib] crate-type = ["cdylib", "rlib"] -[features] -default = ["console_error_panic_hook"] - [dependencies] -wasm-bindgen = "0.2.84" - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" } nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" } -serde = { version = "1.0", features = ["derive"] } -serde-wasm-bindgen = "0.4" -console_error_panic_hook = { version = "0.1.7", optional = true } -web-sys = { version = "0.3.69", features = ["console"] } -noise = "0.9.0" -glam = "0.27.0" - -[dev-dependencies] -wasm-bindgen-test = "0.3.34" +glam = "0.30.10" diff --git a/nodes/max/plantarium/gravity/package.json b/nodes/max/plantarium/gravity/package.json index 86916c9..6ca64a2 100644 --- a/nodes/max/plantarium/gravity/package.json +++ b/nodes/max/plantarium/gravity/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "wasm-pack build --release --out-name index --no-default-features", + "build": "cargo build --target wasm32-unknown-unknown --release && mkdir -p pkg && cp ../../../../target/wasm32-unknown-unknown/release/gravity.wasm ./pkg/node.wasm", "dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'" } } diff --git a/nodes/max/plantarium/gravity/src/lib.rs b/nodes/max/plantarium/gravity/src/lib.rs index be7f892..4453934 100644 --- a/nodes/max/plantarium/gravity/src/lib.rs +++ b/nodes/max/plantarium/gravity/src/lib.rs @@ -1,22 +1,20 @@ use glam::Vec3; -use nodarium_macros::include_definition_file; +use nodarium_macros::nodarium_definition_file; +use nodarium_macros::nodarium_execute; use nodarium_utils::{ concat_args, evaluate_float, evaluate_int, geometry::{wrap_path, wrap_path_mut}, - log, reset_call_count, set_panic_hook, split_args, + log, reset_call_count, split_args, }; -use wasm_bindgen::prelude::*; -include_definition_file!("src/input.json"); +nodarium_definition_file!("src/input.json"); fn lerp_vec3(a: Vec3, b: Vec3, t: f32) -> Vec3 { a + (b - a) * t } -#[wasm_bindgen] +#[nodarium_execute] pub fn execute(input: &[i32]) -> Vec { - set_panic_hook(); - reset_call_count(); let args = split_args(input); diff --git a/nodes/max/plantarium/gravity/tests/web.rs b/nodes/max/plantarium/gravity/tests/web.rs deleted file mode 100644 index de5c1da..0000000 --- a/nodes/max/plantarium/gravity/tests/web.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Test suite for the Web and headless browsers. - -#![cfg(target_arch = "wasm32")] - -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -wasm_bindgen_test_configure!(run_in_browser); - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); -} diff --git a/nodes/max/plantarium/instance/Cargo.toml b/nodes/max/plantarium/instance/Cargo.toml index 69ea1b8..474eeab 100644 --- a/nodes/max/plantarium/instance/Cargo.toml +++ b/nodes/max/plantarium/instance/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "nodarium_instance" +name = "instance" version = "0.1.0" authors = ["Max Richter "] edition = "2018" @@ -7,23 +7,7 @@ edition = "2018" [lib] crate-type = ["cdylib", "rlib"] -[features] -default = ["console_error_panic_hook"] - [dependencies] -wasm-bindgen = "0.2.84" - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" } nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" } -serde = { version = "1.0", features = ["derive"] } -serde-wasm-bindgen = "0.4" -console_error_panic_hook = { version = "0.1.7", optional = true } -web-sys = { version = "0.3.69", features = ["console"] } -glam = "0.27.0" - -[dev-dependencies] -wasm-bindgen-test = "0.3.34" +glam = "0.30.10" diff --git a/nodes/max/plantarium/instance/package.json b/nodes/max/plantarium/instance/package.json index 86916c9..061b805 100644 --- a/nodes/max/plantarium/instance/package.json +++ b/nodes/max/plantarium/instance/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "wasm-pack build --release --out-name index --no-default-features", + "build": "cargo build --target wasm32-unknown-unknown --release && mkdir -p pkg && cp ../../../../target/wasm32-unknown-unknown/release/instance.wasm ./pkg/node.wasm", "dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'" } } diff --git a/nodes/max/plantarium/instance/src/lib.rs b/nodes/max/plantarium/instance/src/lib.rs index 3b7891c..ca98ac9 100644 --- a/nodes/max/plantarium/instance/src/lib.rs +++ b/nodes/max/plantarium/instance/src/lib.rs @@ -1,20 +1,18 @@ use glam::{Mat4, Quat, Vec3}; -use nodarium_macros::include_definition_file; +use nodarium_macros::nodarium_execute; +use nodarium_macros::nodarium_definition_file; use nodarium_utils::{ - concat_args, encode_float, evaluate_float, evaluate_int, + concat_args, evaluate_float, evaluate_int, geometry::{ - calculate_normals, create_instance_data, wrap_geometry_data, wrap_instance_data, wrap_path, + create_instance_data, wrap_geometry_data, wrap_instance_data, wrap_path, }, - log, set_panic_hook, split_args, wrap_arg, + log, split_args, }; -use wasm_bindgen::prelude::*; -include_definition_file!("src/input.json"); +nodarium_definition_file!("src/input.json"); -#[wasm_bindgen] +#[nodarium_execute] pub fn execute(input: &[i32]) -> Vec { - set_panic_hook(); - let args = split_args(input); let mut inputs = split_args(args[0]); log!("WASM(instance): inputs: {:?}", inputs); diff --git a/nodes/max/plantarium/instance/tests/web.rs b/nodes/max/plantarium/instance/tests/web.rs deleted file mode 100644 index de5c1da..0000000 --- a/nodes/max/plantarium/instance/tests/web.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Test suite for the Web and headless browsers. - -#![cfg(target_arch = "wasm32")] - -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -wasm_bindgen_test_configure!(run_in_browser); - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); -} diff --git a/nodes/max/plantarium/math/Cargo.toml b/nodes/max/plantarium/math/Cargo.toml index aac8ae4..7424c08 100644 --- a/nodes/max/plantarium/math/Cargo.toml +++ b/nodes/max/plantarium/math/Cargo.toml @@ -7,17 +7,6 @@ edition = "2018" [lib] crate-type = ["cdylib", "rlib"] -[features] -default = ["console_error_panic_hook"] - [dependencies] -wasm-bindgen = "0.2.84" -serde = { version = "1.0", features = ["derive"] } -serde-wasm-bindgen = "0.4" -console_error_panic_hook = { version = "0.1.7", optional = true } nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" } nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" } -web-sys = { version = "0.3.69", features = ["console"] } - -[dev-dependencies] -wasm-bindgen-test = "0.3.34" diff --git a/nodes/max/plantarium/math/package.json b/nodes/max/plantarium/math/package.json index 86916c9..e63975b 100644 --- a/nodes/max/plantarium/math/package.json +++ b/nodes/max/plantarium/math/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "wasm-pack build --release --out-name index --no-default-features", + "build": "cargo build --target wasm32-unknown-unknown --release && mkdir -p pkg && cp ../../../../target/wasm32-unknown-unknown/release/math.wasm ./pkg/node.wasm", "dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'" } } diff --git a/nodes/max/plantarium/math/src/lib.rs b/nodes/max/plantarium/math/src/lib.rs index c97015f..09b36ac 100644 --- a/nodes/max/plantarium/math/src/lib.rs +++ b/nodes/max/plantarium/math/src/lib.rs @@ -1,12 +1,13 @@ -use nodarium_macros::include_definition_file; -use nodarium_utils::{concat_args, set_panic_hook, split_args}; -use wasm_bindgen::prelude::*; +use nodarium_macros::nodarium_definition_file; +use nodarium_macros::nodarium_execute; +use nodarium_utils::{ + concat_args, split_args +}; -include_definition_file!("src/input.json"); - -#[wasm_bindgen] +#[nodarium_execute] pub fn execute(args: &[i32]) -> Vec { - set_panic_hook(); let args = split_args(args); concat_args(vec![&[0], args[0], args[1], args[2]]) } + +nodarium_definition_file!("src/input.json"); diff --git a/nodes/max/plantarium/math/tests/web.rs b/nodes/max/plantarium/math/tests/web.rs deleted file mode 100644 index de5c1da..0000000 --- a/nodes/max/plantarium/math/tests/web.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Test suite for the Web and headless browsers. - -#![cfg(target_arch = "wasm32")] - -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -wasm_bindgen_test_configure!(run_in_browser); - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); -} diff --git a/nodes/max/plantarium/noise/Cargo.toml b/nodes/max/plantarium/noise/Cargo.toml index 5ddf492..478cb3c 100644 --- a/nodes/max/plantarium/noise/Cargo.toml +++ b/nodes/max/plantarium/noise/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "nodes-noise" +name = "noise" version = "0.1.0" authors = ["Max Richter "] edition = "2018" @@ -7,24 +7,8 @@ edition = "2018" [lib] crate-type = ["cdylib", "rlib"] -[features] -default = ["console_error_panic_hook"] - [dependencies] -wasm-bindgen = "0.2.84" - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" } nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" } -serde = { version = "1.0", features = ["derive"] } -serde-wasm-bindgen = "0.4" -console_error_panic_hook = { version = "0.1.7", optional = true } -web-sys = { version = "0.3.69", features = ["console"] } noise = "0.9.0" -glam = "0.27.0" -[dev-dependencies] -wasm-bindgen-test = "0.3.34" diff --git a/nodes/max/plantarium/noise/package.json b/nodes/max/plantarium/noise/package.json index 86916c9..30b7618 100644 --- a/nodes/max/plantarium/noise/package.json +++ b/nodes/max/plantarium/noise/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "wasm-pack build --release --out-name index --no-default-features", + "build": "cargo build --target wasm32-unknown-unknown --release && mkdir -p pkg && cp ../../../../target/wasm32-unknown-unknown/release/noise.wasm ./pkg/node.wasm", "dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'" } } diff --git a/nodes/max/plantarium/noise/src/lib.rs b/nodes/max/plantarium/noise/src/lib.rs index b405c83..b54f684 100644 --- a/nodes/max/plantarium/noise/src/lib.rs +++ b/nodes/max/plantarium/noise/src/lib.rs @@ -1,21 +1,19 @@ -use nodarium_macros::include_definition_file; +use nodarium_macros::nodarium_definition_file; +use nodarium_macros::nodarium_execute; use nodarium_utils::{ - concat_args, evaluate_float, evaluate_int, evaluate_vec3, geometry::wrap_path_mut, log, - reset_call_count, set_panic_hook, split_args, + concat_args, evaluate_float, evaluate_int, evaluate_vec3, geometry::wrap_path_mut, + reset_call_count, split_args, }; use noise::{HybridMulti, MultiFractal, NoiseFn, OpenSimplex}; -use wasm_bindgen::prelude::*; -include_definition_file!("src/input.json"); +nodarium_definition_file!("src/input.json"); fn lerp(a: f32, b: f32, t: f32) -> f32 { a + t * (b - a) } -#[wasm_bindgen] +#[nodarium_execute] pub fn execute(input: &[i32]) -> Vec { - set_panic_hook(); - reset_call_count(); let args = split_args(input); diff --git a/nodes/max/plantarium/noise/tests/web.rs b/nodes/max/plantarium/noise/tests/web.rs deleted file mode 100644 index de5c1da..0000000 --- a/nodes/max/plantarium/noise/tests/web.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Test suite for the Web and headless browsers. - -#![cfg(target_arch = "wasm32")] - -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -wasm_bindgen_test_configure!(run_in_browser); - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); -} diff --git a/nodes/max/plantarium/output/Cargo.toml b/nodes/max/plantarium/output/Cargo.toml index 2b8546d..010948f 100644 --- a/nodes/max/plantarium/output/Cargo.toml +++ b/nodes/max/plantarium/output/Cargo.toml @@ -7,24 +7,6 @@ edition = "2018" [lib] crate-type = ["cdylib", "rlib"] -[features] -default = ["console_error_panic_hook"] -console_error_panic_hook = ["dep:console_error_panic_hook"] - [dependencies] -wasm-bindgen = "0.2.84" - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. -serde = { version = "1.0", features = ["derive"] } -serde_json = { version = "1.0", default-features = false, features = ["alloc"] } nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" } nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" } -console_error_panic_hook = { version = "0.1.7", optional = true } -web-sys = { version = "0.3.69", features = ["console"] } -glam = "0.27.0" - -[dev-dependencies] -wasm-bindgen-test = "0.3.34" diff --git a/nodes/max/plantarium/output/package.json b/nodes/max/plantarium/output/package.json index 86916c9..4cc2020 100644 --- a/nodes/max/plantarium/output/package.json +++ b/nodes/max/plantarium/output/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "wasm-pack build --release --out-name index --no-default-features", + "build": "cargo build --target wasm32-unknown-unknown --release && mkdir -p pkg && cp ../../../../target/wasm32-unknown-unknown/release/output.wasm ./pkg/node.wasm", "dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'" } } diff --git a/nodes/max/plantarium/output/src/lib.rs b/nodes/max/plantarium/output/src/lib.rs index 402195e..e05828d 100644 --- a/nodes/max/plantarium/output/src/lib.rs +++ b/nodes/max/plantarium/output/src/lib.rs @@ -1,17 +1,15 @@ -use nodarium_macros::include_definition_file; +use nodarium_macros::nodarium_definition_file; +use nodarium_macros::nodarium_execute; use nodarium_utils::{ concat_args, evaluate_int, geometry::{extrude_path, wrap_path}, - log, set_panic_hook, split_args, + log, split_args, }; -use wasm_bindgen::prelude::*; -include_definition_file!("src/inputs.json"); +nodarium_definition_file!("src/inputs.json"); -#[wasm_bindgen] +#[nodarium_execute] pub fn execute(input: &[i32]) -> Vec { - set_panic_hook(); - log!("WASM(output): input: {:?}", input); let args = split_args(input); diff --git a/nodes/max/plantarium/output/tests/web.rs b/nodes/max/plantarium/output/tests/web.rs deleted file mode 100644 index de5c1da..0000000 --- a/nodes/max/plantarium/output/tests/web.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Test suite for the Web and headless browsers. - -#![cfg(target_arch = "wasm32")] - -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -wasm_bindgen_test_configure!(run_in_browser); - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); -} diff --git a/nodes/max/plantarium/random/Cargo.toml b/nodes/max/plantarium/random/Cargo.toml index 219ed0a..7edb88d 100644 --- a/nodes/max/plantarium/random/Cargo.toml +++ b/nodes/max/plantarium/random/Cargo.toml @@ -7,21 +7,7 @@ edition = "2018" [lib] crate-type = ["cdylib", "rlib"] -[features] -default = ["console_error_panic_hook"] [dependencies] -wasm-bindgen = "0.2.84" - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" } nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" } -serde = { version = "1.0", features = ["derive"] } -serde-wasm-bindgen = "0.4" -console_error_panic_hook = { version = "0.1.7", optional = true } - -[dev-dependencies] -wasm-bindgen-test = "0.3.34" diff --git a/nodes/max/plantarium/random/package.json b/nodes/max/plantarium/random/package.json index 86916c9..4fecf10 100644 --- a/nodes/max/plantarium/random/package.json +++ b/nodes/max/plantarium/random/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "wasm-pack build --release --out-name index --no-default-features", + "build": "cargo build --target wasm32-unknown-unknown --release && mkdir -p pkg && cp ../../../../target/wasm32-unknown-unknown/release/random.wasm ./pkg/node.wasm", "dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'" } } diff --git a/nodes/max/plantarium/random/src/lib.rs b/nodes/max/plantarium/random/src/lib.rs index 1d77a36..3937c50 100644 --- a/nodes/max/plantarium/random/src/lib.rs +++ b/nodes/max/plantarium/random/src/lib.rs @@ -1,12 +1,11 @@ -use nodarium_macros::include_definition_file; -use nodarium_utils::{concat_args, set_panic_hook, split_args}; -use wasm_bindgen::prelude::*; +use nodarium_macros::nodarium_definition_file; +use nodarium_macros::nodarium_execute; +use nodarium_utils::{concat_args, split_args}; -include_definition_file!("src/definition.json"); +nodarium_definition_file!("src/definition.json"); -#[wasm_bindgen] +#[nodarium_execute] pub fn execute(args: &[i32]) -> Vec { - set_panic_hook(); let args = split_args(args); concat_args(vec![&[1], args[0], args[1], args[2]]) } diff --git a/nodes/max/plantarium/random/tests/web.rs b/nodes/max/plantarium/random/tests/web.rs deleted file mode 100644 index de5c1da..0000000 --- a/nodes/max/plantarium/random/tests/web.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Test suite for the Web and headless browsers. - -#![cfg(target_arch = "wasm32")] - -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -wasm_bindgen_test_configure!(run_in_browser); - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); -} diff --git a/nodes/max/plantarium/rotate/Cargo.toml b/nodes/max/plantarium/rotate/Cargo.toml index ab87fb1..9b7a219 100644 --- a/nodes/max/plantarium/rotate/Cargo.toml +++ b/nodes/max/plantarium/rotate/Cargo.toml @@ -7,23 +7,8 @@ edition = "2018" [lib] crate-type = ["cdylib", "rlib"] -[features] -default = ["console_error_panic_hook"] - [dependencies] -wasm-bindgen = "0.2.84" - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" } nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" } serde = { version = "1.0", features = ["derive"] } -serde-wasm-bindgen = "0.4" -console_error_panic_hook = { version = "0.1.7", optional = true } -web-sys = { version = "0.3.69", features = ["console"] } -glam = "0.27.0" - -[dev-dependencies] -wasm-bindgen-test = "0.3.34" +glam = "0.30.10" diff --git a/nodes/max/plantarium/rotate/package.json b/nodes/max/plantarium/rotate/package.json index 86916c9..fc6a577 100644 --- a/nodes/max/plantarium/rotate/package.json +++ b/nodes/max/plantarium/rotate/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "wasm-pack build --release --out-name index --no-default-features", + "build": "cargo build --target wasm32-unknown-unknown --release && mkdir -p pkg && cp ../../../../target/wasm32-unknown-unknown/release/rotate.wasm ./pkg/node.wasm", "dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'" } } diff --git a/nodes/max/plantarium/rotate/src/lib.rs b/nodes/max/plantarium/rotate/src/lib.rs index f9ca31f..ad2bd70 100644 --- a/nodes/max/plantarium/rotate/src/lib.rs +++ b/nodes/max/plantarium/rotate/src/lib.rs @@ -1,16 +1,15 @@ use glam::{Mat4, Vec3}; -use nodarium_macros::include_definition_file; +use nodarium_macros::nodarium_definition_file; +use nodarium_macros::nodarium_execute; use nodarium_utils::{ - concat_args, evaluate_float, evaluate_int, geometry::wrap_path_mut, log, set_panic_hook, + concat_args, evaluate_float, evaluate_int, geometry::wrap_path_mut, log, split_args, }; -use wasm_bindgen::prelude::*; -include_definition_file!("src/input.json"); +nodarium_definition_file!("src/input.json"); -#[wasm_bindgen] +#[nodarium_execute] pub fn execute(input: &[i32]) -> Vec { - set_panic_hook(); log!("DEBUG args: {:?}", input); diff --git a/nodes/max/plantarium/rotate/tests/web.rs b/nodes/max/plantarium/rotate/tests/web.rs deleted file mode 100644 index de5c1da..0000000 --- a/nodes/max/plantarium/rotate/tests/web.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Test suite for the Web and headless browsers. - -#![cfg(target_arch = "wasm32")] - -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -wasm_bindgen_test_configure!(run_in_browser); - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); -} diff --git a/nodes/max/plantarium/stem/Cargo.toml b/nodes/max/plantarium/stem/Cargo.toml index 93d8989..6556dc9 100644 --- a/nodes/max/plantarium/stem/Cargo.toml +++ b/nodes/max/plantarium/stem/Cargo.toml @@ -7,23 +7,6 @@ edition = "2018" [lib] crate-type = ["cdylib", "rlib"] -[features] -default = ["console_error_panic_hook"] - [dependencies] -wasm-bindgen = "0.2.84" -serde = { version = "1.0", features = ["derive"] } -serde-wasm-bindgen = "0.4" -console_error_panic_hook = { version = "0.1.7", optional = true } nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" } nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" } -web-sys = { version = "0.3.69", features = ["console"] } - -[dev-dependencies] -wasm-bindgen-test = "0.3.34" - -[package.metadata.wasm-pack.profile.release.wasm-bindgen] -debug-js-glue = true -demangle-name-section = true -dwarf-debug-info = false -omit-default-module-path = true diff --git a/nodes/max/plantarium/stem/package.json b/nodes/max/plantarium/stem/package.json index 86916c9..e22c7b9 100644 --- a/nodes/max/plantarium/stem/package.json +++ b/nodes/max/plantarium/stem/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "wasm-pack build --release --out-name index --no-default-features", + "build": "cargo build --target wasm32-unknown-unknown --release && mkdir -p pkg && cp ../../../../target/wasm32-unknown-unknown/release/stem.wasm ./pkg/node.wasm", "dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'" } } diff --git a/nodes/max/plantarium/stem/src/lib.rs b/nodes/max/plantarium/stem/src/lib.rs index 4838b92..32e57e6 100644 --- a/nodes/max/plantarium/stem/src/lib.rs +++ b/nodes/max/plantarium/stem/src/lib.rs @@ -1,17 +1,15 @@ -use nodarium_macros::include_definition_file; +use nodarium_macros::nodarium_definition_file; +use nodarium_macros::nodarium_execute; use nodarium_utils::{ evaluate_float, evaluate_int, evaluate_vec3, geometry::{create_multiple_paths, wrap_multiple_paths}, - log, reset_call_count, set_panic_hook, split_args, + log, reset_call_count, split_args, }; -use wasm_bindgen::prelude::*; -include_definition_file!("src/input.json"); +nodarium_definition_file!("src/input.json"); -#[wasm_bindgen] +#[nodarium_execute] pub fn execute(input: &[i32]) -> Vec { - set_panic_hook(); - reset_call_count(); let args = split_args(input); diff --git a/nodes/max/plantarium/stem/tests/web.rs b/nodes/max/plantarium/stem/tests/web.rs deleted file mode 100644 index de5c1da..0000000 --- a/nodes/max/plantarium/stem/tests/web.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Test suite for the Web and headless browsers. - -#![cfg(target_arch = "wasm32")] - -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -wasm_bindgen_test_configure!(run_in_browser); - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); -} diff --git a/nodes/max/plantarium/triangle/Cargo.toml b/nodes/max/plantarium/triangle/Cargo.toml index b554ba6..07f78a9 100644 --- a/nodes/max/plantarium/triangle/Cargo.toml +++ b/nodes/max/plantarium/triangle/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "max-plantarium-triangle" +name = "triangle" version = "0.1.0" authors = ["Max Richter "] edition = "2018" @@ -7,22 +7,6 @@ edition = "2018" [lib] crate-type = ["cdylib", "rlib"] -[features] -default = ["console_error_panic_hook"] - [dependencies] -wasm-bindgen = "0.2.84" - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" } nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" } -serde = { version = "1.0", features = ["derive"] } -serde-wasm-bindgen = "0.4" -console_error_panic_hook = { version = "0.1.7", optional = true } -web-sys = { version = "0.3.69", features = ["console"] } - -[dev-dependencies] -wasm-bindgen-test = "0.3.34" diff --git a/nodes/max/plantarium/triangle/package.json b/nodes/max/plantarium/triangle/package.json index 86916c9..77e9f04 100644 --- a/nodes/max/plantarium/triangle/package.json +++ b/nodes/max/plantarium/triangle/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "wasm-pack build --release --out-name index --no-default-features", + "build": "cargo build --target wasm32-unknown-unknown --release && mkdir -p pkg && cp ../../../../target/wasm32-unknown-unknown/release/triangle.wasm ./pkg/node.wasm", "dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'" } } diff --git a/nodes/max/plantarium/triangle/src/lib.rs b/nodes/max/plantarium/triangle/src/lib.rs index 818b4f7..e14533c 100644 --- a/nodes/max/plantarium/triangle/src/lib.rs +++ b/nodes/max/plantarium/triangle/src/lib.rs @@ -1,25 +1,21 @@ -use nodarium_macros::include_definition_file; +use nodarium_macros::nodarium_definition_file; +use nodarium_macros::nodarium_execute; use nodarium_utils::{ - decode_float, encode_float, evaluate_int, set_panic_hook, split_args, wrap_arg, + decode_float, encode_float, evaluate_int, split_args, wrap_arg, log }; -use wasm_bindgen::prelude::*; -use web_sys::console; -include_definition_file!("src/input.json"); +nodarium_definition_file!("src/input.json"); -#[rustfmt::skip] -#[wasm_bindgen] +#[nodarium_execute] pub fn execute(input: &[i32]) -> Vec { - set_panic_hook(); - let args = split_args(input); let size = evaluate_int(args[0]); let decoded = decode_float(size); let negative_size = encode_float(-decoded); - console::log_1(&format!("WASM(triangle): input: {:?} -> {}", args[0],decoded).into()); + log!("WASM(triangle): input: {:?} -> {}", args[0],decoded); // [[1,3, x, y, z, x, y,z,x,y,z]]; wrap_arg(&[ diff --git a/nodes/max/plantarium/triangle/tests/web.rs b/nodes/max/plantarium/triangle/tests/web.rs deleted file mode 100644 index de5c1da..0000000 --- a/nodes/max/plantarium/triangle/tests/web.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Test suite for the Web and headless browsers. - -#![cfg(target_arch = "wasm32")] - -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -wasm_bindgen_test_configure!(run_in_browser); - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); -} diff --git a/nodes/max/plantarium/vec3/Cargo.toml b/nodes/max/plantarium/vec3/Cargo.toml index bb6287d..ef8535e 100644 --- a/nodes/max/plantarium/vec3/Cargo.toml +++ b/nodes/max/plantarium/vec3/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "max-plantarium-vec3" +name = "vec3" version = "0.1.0" authors = ["Max Richter "] edition = "2018" @@ -7,22 +7,8 @@ edition = "2018" [lib] crate-type = ["cdylib", "rlib"] -[features] -default = ["console_error_panic_hook"] - [dependencies] -wasm-bindgen = "0.2.84" - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. nodarium_utils = { version = "0.1.0", path = "../../../../packages/utils" } nodarium_macros = { version = "0.1.0", path = "../../../../packages/macros" } serde = { version = "1.0", features = ["derive"] } -serde-wasm-bindgen = "0.4" -console_error_panic_hook = { version = "0.1.7", optional = true } -web-sys = { version = "0.3.69", features = ["console"] } -[dev-dependencies] -wasm-bindgen-test = "0.3.34" diff --git a/nodes/max/plantarium/vec3/package.json b/nodes/max/plantarium/vec3/package.json index 86916c9..d99c173 100644 --- a/nodes/max/plantarium/vec3/package.json +++ b/nodes/max/plantarium/vec3/package.json @@ -1,6 +1,6 @@ { "scripts": { - "build": "wasm-pack build --release --out-name index --no-default-features", + "build": "cargo build --target wasm32-unknown-unknown --release && mkdir -p pkg && cp ../../../../target/wasm32-unknown-unknown/release/vec3.wasm ./pkg/node.wasm", "dev": "cargo watch -s 'wasm-pack build --dev --out-name index --no-default-features'" } } diff --git a/nodes/max/plantarium/vec3/src/lib.rs b/nodes/max/plantarium/vec3/src/lib.rs index c0ab226..118fd29 100644 --- a/nodes/max/plantarium/vec3/src/lib.rs +++ b/nodes/max/plantarium/vec3/src/lib.rs @@ -1,10 +1,10 @@ -use nodarium_macros::include_definition_file; +use nodarium_macros::nodarium_definition_file; +use nodarium_macros::nodarium_execute; use nodarium_utils::{concat_args, log, split_args}; -use wasm_bindgen::prelude::*; -include_definition_file!("src/input.json"); +nodarium_definition_file!("src/input.json"); -#[wasm_bindgen] +#[nodarium_execute] pub fn execute(input: &[i32]) -> Vec { let args = split_args(input); log!("vec3 input: {:?}", input); diff --git a/nodes/max/plantarium/vec3/tests/web.rs b/nodes/max/plantarium/vec3/tests/web.rs deleted file mode 100644 index de5c1da..0000000 --- a/nodes/max/plantarium/vec3/tests/web.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Test suite for the Web and headless browsers. - -#![cfg(target_arch = "wasm32")] - -extern crate wasm_bindgen_test; -use wasm_bindgen_test::*; - -wasm_bindgen_test_configure!(run_in_browser); - -#[wasm_bindgen_test] -fn pass() { - assert_eq!(1 + 1, 2); -} diff --git a/packages/macros/Cargo.toml b/packages/macros/Cargo.toml index 6ed39ac..f37b0b9 100644 --- a/packages/macros/Cargo.toml +++ b/packages/macros/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/jim-fx/nodes" proc-macro = true [dependencies] -syn = { version = "1.0", features = ["full"] } +syn = { version = "2.0", features = ["full"] } serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0", default-features = false, features = ["alloc"] } quote = "1.0" diff --git a/packages/macros/src/lib.rs b/packages/macros/src/lib.rs index 344a1c0..fb4ef10 100644 --- a/packages/macros/src/lib.rs +++ b/packages/macros/src/lib.rs @@ -5,32 +5,7 @@ use quote::quote; use std::env; use std::fs; use std::path::Path; -use syn::{parse_macro_input, LitStr}; - -#[proc_macro] -pub fn node_definition(input: TokenStream) -> TokenStream { - let input_string = parse_macro_input!(input as LitStr).value(); - - // Validate JSON format - let json: NodeDefinition = match serde_json::from_str(&input_string) { - Ok(json) => json, - Err(e) => panic!("Invalid JSON input: {}", e), - }; - - // Convert the validated JSON back to a pretty-printed string - let formatted_json = serde_json::to_string_pretty(&json).expect("Failed to serialize JSON"); - - // Generate the output function - let expanded = quote! { - #[wasm_bindgen] - pub fn get_definition() -> String { - String::from(#formatted_json) - } - }; - - // Convert the generated code back to a TokenStream - TokenStream::from(expanded) -} +use syn::parse_macro_input; fn add_line_numbers(input: String) -> String { return input @@ -41,39 +16,120 @@ fn add_line_numbers(input: String) -> String { .join("\n"); } -#[proc_macro] -pub fn include_definition_file(input: TokenStream) -> TokenStream { - let file_path = syn::parse_macro_input!(input as syn::LitStr).value(); +#[proc_macro_attribute] +pub fn nodarium_execute(_attr: TokenStream, item: TokenStream) -> TokenStream { + let input_fn = parse_macro_input!(item as syn::ItemFn); + let _fn_name = &input_fn.sig.ident; + let _fn_vis = &input_fn.vis; + let fn_body = &input_fn.block; - // Retrieve the directory containing the Cargo.toml file - let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); - let full_path = Path::new(&project_dir).join(&file_path); + let first_arg_ident = if let Some(syn::FnArg::Typed(pat_type)) = input_fn.sig.inputs.first() { + if let syn::Pat::Ident(pat_ident) = &*pat_type.pat { + &pat_ident.ident + } else { + panic!("Expected a simple identifier for the first argument"); + } + } else { + panic!("The execute function must have at least one argument (the input slice)"); + }; - // Read the JSON file content - let json_content = fs::read_to_string(full_path).unwrap_or_else(|err| { - panic!( - "Failed to read JSON file at '{}/{}': {}", - project_dir, file_path, err - ) - }); - - // Optionally, validate that the content is valid JSON - let _: NodeDefinition = serde_json::from_str(&json_content).unwrap_or_else(|err| { - panic!( - "JSON file contains invalid JSON: \n{} \n{}", - err, - add_line_numbers(json_content.clone()) - ) - }); - - // Generate the function that returns the JSON string + // We create a wrapper that handles the C ABI and pointer math let expanded = quote! { - #[wasm_bindgen] - pub fn get_definition() -> String { - String::from(#json_content) + extern "C" { + fn host_log_panic(ptr: *const u8, len: usize); + fn host_log(ptr: *const u8, len: usize); + } + + fn setup_panic_hook() { + static SET_HOOK: std::sync::Once = std::sync::Once::new(); + SET_HOOK.call_once(|| { + std::panic::set_hook(Box::new(|info| { + let msg = info.to_string(); + unsafe { host_log_panic(msg.as_ptr(), msg.len()); } + })); + }); + } + + #[no_mangle] + pub extern "C" fn __alloc(len: usize) -> *mut i32 { + let mut buf = Vec::with_capacity(len); + let ptr = buf.as_mut_ptr(); + std::mem::forget(buf); + ptr + } + + #[no_mangle] + pub extern "C" fn __free(ptr: *mut i32, len: usize) { + unsafe { + let _ = Vec::from_raw_parts(ptr, 0, len); + } + } + + static mut OUTPUT_BUFFER: Vec = Vec::new(); + + #[no_mangle] + pub extern "C" fn execute(ptr: *const i32, len: usize) -> *mut i32 { + setup_panic_hook(); + // 1. Convert raw pointer to slice + let input = unsafe { core::slice::from_raw_parts(ptr, len) }; + + // 2. Call the logic (which we define below) + let result_data: Vec = internal_logic(input); + + // 3. Use the static buffer for the result + let result_len = result_data.len(); + unsafe { + OUTPUT_BUFFER.clear(); + OUTPUT_BUFFER.reserve(result_len + 1); + OUTPUT_BUFFER.push(result_len as i32); + OUTPUT_BUFFER.extend(result_data); + + OUTPUT_BUFFER.as_mut_ptr() + } + } + + fn internal_logic(#first_arg_ident: &[i32]) -> Vec { + #fn_body + } + }; + + TokenStream::from(expanded) +} + +#[proc_macro] +pub fn nodarium_definition_file(input: TokenStream) -> TokenStream { + let path_lit = syn::parse_macro_input!(input as syn::LitStr); + let file_path = path_lit.value(); + + let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + let full_path = Path::new(&project_dir).join(&file_path); + + let json_content = fs::read_to_string(&full_path).unwrap_or_else(|err| { + panic!("Failed to read JSON file at '{}/{}': {}", project_dir, file_path, err) + }); + + let _: NodeDefinition = serde_json::from_str(&json_content).unwrap_or_else(|err| { + panic!("JSON file contains invalid JSON: \n{} \n{}", err, add_line_numbers(json_content.clone())) + }); + + // We use the span from the input path literal + let bytes = syn::LitByteStr::new(json_content.as_bytes(), path_lit.span()); + let len = json_content.len(); + + let expanded = quote! { + #[link_section = "nodarium_definition"] + static DEFINITION_DATA: [u8; #len] = *#bytes; + + #[no_mangle] + pub extern "C" fn get_definition_ptr() -> *const u8 { + DEFINITION_DATA.as_ptr() + } + + #[no_mangle] + pub extern "C" fn get_definition_len() -> usize { + DEFINITION_DATA.len() } }; - // Convert the generated code back to a TokenStream TokenStream::from(expanded) } diff --git a/packages/registry/src/node-registry-client.ts b/packages/registry/src/node-registry-client.ts index e10d9ce..c034c94 100644 --- a/packages/registry/src/node-registry-client.ts +++ b/packages/registry/src/node-registry-client.ts @@ -13,7 +13,6 @@ export class RemoteNodeRegistry implements NodeRegistry { status: "loading" | "ready" | "error" = "loading"; private nodes: Map = new Map(); - constructor( private url: string, private cache?: AsyncCache, diff --git a/packages/types/Cargo.toml b/packages/types/Cargo.toml index 518d8d0..b8141f2 100644 --- a/packages/types/Cargo.toml +++ b/packages/types/Cargo.toml @@ -4,7 +4,6 @@ version = "0.1.0" edition = "2021" license = "MIT" description = "Types for Nodarium" -website = "https://nodes.max-richter.dev" repository = "https://github.com/jim-fx/nodes" [dependencies] diff --git a/packages/ui/src/lib/app.css b/packages/ui/src/lib/app.css index e96ef2e..ac2b426 100644 --- a/packages/ui/src/lib/app.css +++ b/packages/ui/src/lib/app.css @@ -40,6 +40,30 @@ } +@theme { + --color-neutral-100: #E7E7E7; + --color-neutral-200: #CECECE; + --color-neutral-300: #7C7C7C; + --color-neutral-400: #2D2D2D; + --color-neutral-500: #171717; + --color-neutral-800: #111111; + --color-neutral-900: #060606; + + --color-layer-0: var(--neutral-900); + --color-layer-1: var(--neutral-500); + --color-layer-2: var(--neutral-400); + --color-layer-3: var(--neutral-200); + + --color-active: #ffffff; + --color-selected: #c65a19; + + --color-outline: var(--neutral-400); + --color-connection: #333333; + --color-edge: var(--connection, var(--outline)); + + --color-text-color: var(--neutral-200); +} + html { --neutral-100: #E7E7E7; --neutral-200: #CECECE; diff --git a/packages/utils/Cargo.toml b/packages/utils/Cargo.toml index 5816536..776a455 100644 --- a/packages/utils/Cargo.toml +++ b/packages/utils/Cargo.toml @@ -6,14 +6,11 @@ description = "A collection of utilities for Nodarium" license = "MIT" repository = "https://github.com/jim-fx/nodes" -[features] -default = ["console_error_panic_hook"] +[lib] +crate-type = ["rlib"] [dependencies] -wasm-bindgen = "0.2.92" -web-sys = { version = "0.3.69", features = ["console"] } serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0", default-features = false, features = ["alloc"] } -console_error_panic_hook = { version = "0.1.7", optional = true } -glam = "0.27.0" +glam = "0.30.10" noise = "0.9.0" diff --git a/packages/utils/src/flatTree.ts b/packages/utils/src/flatTree.ts index ac47194..f99cf45 100644 --- a/packages/utils/src/flatTree.ts +++ b/packages/utils/src/flatTree.ts @@ -109,10 +109,12 @@ export function decodeNestedArray(dense: number[] | Int32Array) { } export function splitNestedArray(input: Int32Array) { + let index = 0; const length = input.length; let res: Int32Array[] = []; + let nextBracketIndex = 0; let argStartIndex = 0; let depth = -1; diff --git a/packages/utils/src/geometry/geometry_data.rs b/packages/utils/src/geometry/geometry_data.rs index 3edc965..6ea6324 100644 --- a/packages/utils/src/geometry/geometry_data.rs +++ b/packages/utils/src/geometry/geometry_data.rs @@ -61,7 +61,7 @@ pub fn create_geometry_data(vertex_amount: usize, face_amount: usize) -> Vec GeometryData { +pub fn wrap_geometry_data(geometry: &mut [i32]) -> GeometryData<'_> { // Basic validity checks assert!( geometry.len() > GEOMETRY_HEADER_SIZE, diff --git a/packages/utils/src/geometry/instance_data.rs b/packages/utils/src/geometry/instance_data.rs index ed92519..eaa720a 100644 --- a/packages/utils/src/geometry/instance_data.rs +++ b/packages/utils/src/geometry/instance_data.rs @@ -73,7 +73,7 @@ pub fn create_instance_data( geo } -pub fn wrap_instance_data(instances: &mut [i32]) -> InstanceData { +pub fn wrap_instance_data(instances: &mut [i32]) -> InstanceData<'_> { assert!( instances.len() > INSTANCE_HEADER_SIZE, "Instance vector does not contain enough data for a header." diff --git a/packages/utils/src/geometry/path_data.rs b/packages/utils/src/geometry/path_data.rs index f3de7e9..795c96a 100644 --- a/packages/utils/src/geometry/path_data.rs +++ b/packages/utils/src/geometry/path_data.rs @@ -130,7 +130,7 @@ pub fn create_path(point_amount: usize, depth: i32) -> Vec { path } -pub fn wrap_path(input: &[i32]) -> PathData { +pub fn wrap_path(input: &[i32]) -> PathData<'_> { // Basic validity checks assert!( input.len() > PATH_HEADER_SIZE, diff --git a/packages/utils/src/lib.rs b/packages/utils/src/lib.rs index 90dca23..0bcf629 100644 --- a/packages/utils/src/lib.rs +++ b/packages/utils/src/lib.rs @@ -6,12 +6,22 @@ pub use nodes::reset_call_count; pub use tree::*; pub mod geometry; +extern "C" { + #[cfg(target_arch = "wasm32")] + pub fn host_log(ptr: *const u8, len: usize); +} + #[cfg(debug_assertions)] #[macro_export] macro_rules! log { - ($($arg:tt)*) => {{ - use web_sys::console; - console::log_1(&format!($($arg)*).into()); + ($($t:tt)*) => {{ + let msg = std::format!($($t)*); + #[cfg(target_arch = "wasm32")] + unsafe { + $crate::host_log(msg.as_ptr(), msg.len()); + } + #[cfg(not(target_arch = "wasm32"))] + println!("{}", msg); }} } @@ -23,13 +33,3 @@ macro_rules! log { }}; } -pub fn set_panic_hook() { - // When the `console_error_panic_hook` feature is enabled, we can call the - // `set_panic_hook` function at least once during initialization, and then - // we will get better error messages if our code ever panics. - // - // For more details see - // https://github.com/rustwasm/console_error_panic_hook#readme - #[cfg(feature = "console_error_panic_hook")] - console_error_panic_hook::set_once(); -} diff --git a/packages/utils/src/wasm-wrapper.ts b/packages/utils/src/wasm-wrapper.ts index 0f53e19..6327d73 100644 --- a/packages/utils/src/wasm-wrapper.ts +++ b/packages/utils/src/wasm-wrapper.ts @@ -1,256 +1,55 @@ -//@ts-nocheck -import { NodeDefinition } from "@nodarium/types"; +interface NodariumExports extends WebAssembly.Exports { + memory: WebAssembly.Memory; + execute: (ptr: number, len: number) => number; + __free: (ptr: number, len: number) => void; + __alloc: (len: number) => number; +} -const cachedTextDecoder = new TextDecoder("utf-8", { - ignoreBOM: true, - fatal: true, -}); -const cachedTextEncoder = new TextEncoder(); +export function createWasmWrapper(buffer: ArrayBuffer) { + let exports: NodariumExports; -const encodeString = - typeof cachedTextEncoder.encodeInto === "function" - ? function (arg, view) { - return cachedTextEncoder.encodeInto(arg, view); + const importObject = { + env: { + host_log_panic: (ptr: number, len: number) => { + if (!exports) return; + const view = new Uint8Array(exports.memory.buffer, ptr, len); + console.error("RUST PANIC:", new TextDecoder().decode(view)); + }, + host_log: (ptr: number, len: number) => { + if (!exports) return; + const view = new Uint8Array(exports.memory.buffer, ptr, len); + console.log("RUST:", new TextDecoder().decode(view)); + } } - : function (arg, view) { - const buf = cachedTextEncoder.encode(arg); - view.set(buf); - return { - read: arg.length, - written: buf.length, - }; - }; + }; -function createWrapper() { - let wasm: any; - - let cachedUint8Memory0: Uint8Array | null = null; - let cachedInt32Memory0: Int32Array | null = null; - let cachedUint32Memory0: Uint32Array | null = null; - - const heap = new Array(128).fill(undefined); - heap.push(undefined, null, true, false); - let heap_next = heap.length; - - function getUint8Memory0() { - if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { - cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); - } - return cachedUint8Memory0; - } - - function getInt32Memory0() { - if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { - cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); - } - return cachedInt32Memory0; - } - - function getUint32Memory0() { - if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) { - cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer); - } - return cachedUint32Memory0; - } - - function getStringFromWasm0(ptr: number, len: number) { - return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); - } - - function getObject(idx: number) { - return heap[idx]; - } - - function addHeapObject(obj: any) { - if (heap_next === heap.length) heap.push(heap.length + 1); - const idx = heap_next; - heap_next = heap[idx]; - heap[idx] = obj; - return idx; - } - - let WASM_VECTOR_LEN = 0; - function passArray32ToWasm0( - arg: ArrayLike, - malloc: (arg0: number, arg1: number) => number, - ) { - const ptr = malloc(arg.length * 4, 4) >>> 0; - getUint32Memory0().set(arg, ptr / 4); - WASM_VECTOR_LEN = arg.length; - return ptr; - } - - function getArrayI32FromWasm0(ptr: number, len: number) { - ptr = ptr >>> 0; - return getInt32Memory0().subarray(ptr / 4, ptr / 4 + len); - } - - function dropObject(idx: number) { - if (idx < 132) return; - heap[idx] = heap_next; - heap_next = idx; - } - - function takeObject(idx: number) { - const ret = getObject(idx); - dropObject(idx); - return ret; - } - - function __wbindgen_string_new(arg0: number, arg1: number) { - const ret = getStringFromWasm0(arg0, arg1); - return addHeapObject(ret); - } - - // Additional methods and their internal helpers can also be refactored in a similar manner. - function get_definition() { - let deferred1_0: number; - let deferred1_1: number; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.get_definition(retptr); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred1_0 = r0; - deferred1_1 = r1; - const rawDefinition = getStringFromWasm0(r0, r1); - return JSON.parse(rawDefinition) as NodeDefinition; - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); - } - } + const module = new WebAssembly.Module(buffer); + const instance = new WebAssembly.Instance(module, importObject); + exports = instance.exports as NodariumExports; function execute(args: Int32Array) { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passArray32ToWasm0(args, wasm.__wbindgen_malloc); - const len0 = WASM_VECTOR_LEN; - wasm.execute(retptr, ptr0, len0); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var v2 = getArrayI32FromWasm0(r0, r1).slice(); - wasm.__wbindgen_free(r0, r1 * 4, 4); - return v2; - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); + const inPtr = exports.__alloc(args.length); + new Int32Array(exports.memory.buffer).set(args, inPtr / 4); + + const outPtr = exports.execute(inPtr, args.length); + + const i32Result = new Int32Array(exports.memory.buffer); + const outLen = i32Result[outPtr / 4]; + const out = i32Result.slice(outPtr / 4 + 1, outPtr / 4 + 1 + outLen); + + exports.__free(inPtr, args.length); + + return out; + } + + function get_definition() { + const sections = WebAssembly.Module.customSections(module, "nodarium_definition"); + if (sections.length > 0) { + const decoder = new TextDecoder(); + const jsonString = decoder.decode(sections[0]); + return JSON.parse(jsonString); } } - function passStringToWasm0( - arg: string, - malloc: (arg0: any, arg1: number) => number, - realloc: - | ((arg0: number, arg1: any, arg2: number, arg3: number) => number) - | undefined, - ) { - if (realloc === undefined) { - const buf = cachedTextEncoder.encode(arg); - const ptr = malloc(buf.length, 1) >>> 0; - getUint8Memory0() - .subarray(ptr, ptr + buf.length) - .set(buf); - WASM_VECTOR_LEN = buf.length; - return ptr; - } - - let len = arg.length; - let ptr = malloc(len, 1) >>> 0; - - const mem = getUint8Memory0(); - - let offset = 0; - - for (; offset < len; offset++) { - const code = arg.charCodeAt(offset); - if (code > 0x7f) break; - mem[ptr + offset] = code; - } - - if (offset !== len) { - if (offset !== 0) { - arg = arg.slice(offset); - } - ptr = realloc(ptr, len, (len = offset + arg.length * 3), 1) >>> 0; - const view = getUint8Memory0().subarray(ptr + offset, ptr + len); - const ret = encodeString(arg, view); - - offset += ret.written; - ptr = realloc(ptr, len, offset, 1) >>> 0; - } - - WASM_VECTOR_LEN = offset; - return ptr; - } - - function __wbg_new_abda76e883ba8a5f() { - const ret = new Error(); - return addHeapObject(ret); - } - - function __wbg_stack_658279fe44541cf6(arg0, arg1) { - const ret = getObject(arg1).stack; - const ptr1 = passStringToWasm0( - ret, - wasm.__wbindgen_malloc, - wasm.__wbindgen_realloc, - ); - const len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; - } - - function __wbg_error_f851667af71bcfc6(arg0, arg1) { - let deferred0_0; - let deferred0_1; - try { - deferred0_0 = arg0; - deferred0_1 = arg1; - console.error(getStringFromWasm0(arg0, arg1)); - } finally { - wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); - } - } - - function __wbindgen_object_drop_ref(arg0) { - takeObject(arg0); - } - - function __wbg_log_5bb5f88f245d7762(arg0) { - console.log(getObject(arg0)); - } - - function __wbindgen_throw(arg0, arg1) { - throw new Error(getStringFromWasm0(arg0, arg1)); - } - - return { - setInstance(instance: WebAssembly.Instance) { - wasm = instance.exports; - }, - - exports: { - // Expose other methods that interact with the wasm instance - execute, - get_definition, - }, - - __wbindgen_string_new, - __wbindgen_object_drop_ref, - __wbg_new_abda76e883ba8a5f, - __wbg_error_f851667af71bcfc6, - __wbg_stack_658279fe44541cf6, - __wbg_log_5bb5f88f245d7762, - __wbindgen_throw, - }; -} - -export function createWasmWrapper(wasmBuffer: ArrayBuffer | Uint8Array) { - const wrapper = createWrapper(); - const module = new WebAssembly.Module(wasmBuffer); - const instance = new WebAssembly.Instance(module, { - ["./index_bg.js"]: wrapper, - }); - wrapper.setInstance(instance); - return wrapper.exports; + return { execute, get_definition }; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dbc3f1e..c818d8c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -49,6 +49,9 @@ importers: three: specifier: ^0.182.0 version: 0.182.0 + wabt: + specifier: ^1.0.39 + version: 1.0.39 devDependencies: '@iconify-json/tabler': specifier: ^1.2.26 @@ -2574,6 +2577,10 @@ packages: resolution: {integrity: sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==} engines: {node: '>=18'} + wabt@1.0.39: + resolution: {integrity: sha512-ba+dRL/75VQQY7RkU/CgriGbkoWAfS8TDyUlJfJhJ8KhtXgMl5dhNvoPNUcQ9IWRhW8u41glMSuZeTvsYq2rRg==} + hasBin: true + webgl-sdf-generator@1.1.1: resolution: {integrity: sha512-9Z0JcMTFxeE+b2x1LJTdnaT8rT8aEp7MVxkNwoycNmJWwPdzoXzMh0BjJSh/AEFP+KPYZUli814h8bJZFIZ2jA==} @@ -4930,6 +4937,8 @@ snapshots: xml-name-validator: 5.0.0 optional: true + wabt@1.0.39: {} + webgl-sdf-generator@1.1.1: {} webidl-conversions@7.0.0: