diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ea48754..8ce2959 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -19,7 +19,10 @@ jobs: - run: git checkout -B pr_check - run: rustup component add clippy - run: cargo install cargo-release + - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - run: cargo test --verbose -- --nocapture + - run: wasm-pack test --headless --firefox ./adana-script-wasm + - run: wasm-pack test --headless --chrome ./adana-script-wasm - run: cargo clippy --all-targets --all-features -- -D warnings - run: cargo release --no-publish --no-tag --allow-branch pr_check --no-push --dependent-version upgrade minor #- run: cargo publish --dry-run diff --git a/.github/workflows/release-wasm.yml b/.github/workflows/release-wasm.yml new file mode 100644 index 0000000..1532b22 --- /dev/null +++ b/.github/workflows/release-wasm.yml @@ -0,0 +1,47 @@ +name: Release WASM + +on: + push: + tags: + - "**[0-9]+.[0-9]+.[0-9]+*" + +env: + CARGO_TERM_COLOR: always +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + targets: x86_64-unknown-linux-gnu + - name: Build + run: | + curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + wasm-pack build --target web --release --scope nbittich ./adana-script-wasm + wasm-pack pack ./adana-script-wasm/pkg + - name: Upload pkg + uses: actions/upload-artifact@v4 + with: + name: pkg + path: adana-script-wasm/pkg + publish: + runs-on: ubuntu-latest + steps: + - name: Download pkg + uses: actions/download-artifact@v4 + with: + name: pkg + path: pkg + - name: Setup NPM + uses: actions/setup-node@v3 + with: + node-version: "20.x" + registry-url: "https://registry.npmjs.org" + - name: Publish on NPM + run: npm publish pkg/nbittich-adana-script-wasm-${{github.ref_name}}.tgz + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/Cargo.lock b/Cargo.lock index 02a5926..ea04f64 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,6 +72,21 @@ dependencies = [ "strum", ] +[[package]] +name = "adana-script-wasm" +version = "0.16.4" +dependencies = [ + "adana-script", + "adana-script-core", + "bincode", + "console_error_panic_hook", + "serde", + "serde-wasm-bindgen", + "wasm-bindgen", + "wasm-bindgen-test", + "wee_alloc", +] + [[package]] name = "adler" version = "1.0.2" @@ -145,6 +160,12 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + [[package]] name = "bytemuck" version = "1.14.1" @@ -157,6 +178,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + [[package]] name = "cfg-if" version = "1.0.0" @@ -189,6 +216,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[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 1.0.0", + "wasm-bindgen", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -235,7 +272,7 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", ] [[package]] @@ -254,7 +291,7 @@ version = "5.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "hashbrown", "lock_api", "once_cell", @@ -339,7 +376,7 @@ version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e5768da2206272c81ef0b5e951a41862938a6070da63bcea197899942d3b947" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "rustix", "windows-sys 0.52.0", ] @@ -471,7 +508,7 @@ version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "wasi", ] @@ -523,6 +560,15 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" +[[package]] +name = "js-sys" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -541,7 +587,7 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "windows-sys 0.48.0", ] @@ -602,6 +648,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -634,7 +686,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" dependencies = [ "bitflags 1.3.2", - "cfg-if", + "cfg-if 1.0.0", "libc", "memoffset", ] @@ -646,7 +698,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" dependencies = [ "bitflags 2.4.2", - "cfg-if", + "cfg-if 1.0.0", "libc", ] @@ -735,7 +787,7 @@ version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ - "cfg-if", + "cfg-if 1.0.0", "libc", "redox_syscall", "smallvec", @@ -870,7 +922,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02a2d683a4ac90aeef5b1013933f6d977bd37d51ff3f4dad829d4931a7e6be86" dependencies = [ "bitflags 2.4.2", - "cfg-if", + "cfg-if 1.0.0", "clipboard-win 5.0.0", "fd-lock", "home", @@ -902,6 +954,12 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "scopeguard" version = "1.2.0" @@ -917,6 +975,17 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9b713f70513ae1f8d92665bbbbda5c295c2cf1da5542881ae5eefe20c9af132" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "serde_derive" version = "1.0.196" @@ -1100,6 +1169,119 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasm-bindgen" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877b9c3f61ceea0e56331985743b13f3d25c406a7098d45180fb5f09bc19ed97" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" + +[[package]] +name = "wasm-bindgen-test" +version = "0.3.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "143ddeb4f833e2ed0d252e618986e18bfc7b0e52f2d28d77d05b2f045dd8eb61" +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.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5211b7550606857312bba1d978a8ec75692eae187becc5e680444fffc5e6f89" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "web-sys" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wee_alloc" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "memory_units", + "winapi", +] + [[package]] name = "weezl" version = "0.1.8" diff --git a/Cargo.toml b/Cargo.toml index 76f5afd..fdf9609 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "adana-db", "adana-script", "adana-script-core", + "adana-script-wasm", "adana-shell", ] resolver = "2" @@ -21,6 +22,7 @@ license = "MIT" exclude = ["vscode/", "dist/", ".vscode", ".history", ".git", ".github"] [workspace.dependencies] + anyhow = "1.0.79" bincode = "1.3.3" dirs = "5.0.1" # todo maybe replace by the home crate @@ -40,6 +42,12 @@ arboard = "3.3.0" regex = { version = "1.10.3", default-features = false, features = ["std"] } serial_test = "3.0.0" +# wasm +wasm-bindgen = { version = "0.2.91" } +console_error_panic_hook = { version = "0.1.7" } +serde-wasm-bindgen = "0.6.3" +wee_alloc = "0.4.5" +wasm-bindgen-test = "0.3.41" # workspace specific libs adana-script-core = { version = "0.16.4", path = "./adana-script-core" } adana-script = { version = "0.16.4", path = "./adana-script" } @@ -60,11 +68,8 @@ targets = ["x86_64-unknown-linux-gnu"] pr-run-mode = "plan" [profile.release] -opt-level = 'z' # Optimize for size. -lto = true # Link Time Optimization (LTO) -codegen-units = 1 # Set this to 1 to allow for maximum size reduction optimizations: -panic = 'abort' # removes the need for this extra unwinding code. -strip = "symbols" +opt-level = 's' +lto = true # Link Time Optimization (LTO) # The profile that 'cargo dist' will build with [profile.dist] diff --git a/adana-cache-command/release.toml b/adana-cache-command/release.toml new file mode 100644 index 0000000..8f14116 --- /dev/null +++ b/adana-cache-command/release.toml @@ -0,0 +1 @@ +tag = false diff --git a/adana-db/release.toml b/adana-db/release.toml new file mode 100644 index 0000000..8f14116 --- /dev/null +++ b/adana-db/release.toml @@ -0,0 +1 @@ +tag = false diff --git a/adana-script-core/Cargo.toml b/adana-script-core/Cargo.toml index c5f12a8..2c6f2ba 100644 --- a/adana-script-core/Cargo.toml +++ b/adana-script-core/Cargo.toml @@ -15,6 +15,7 @@ exclude.workspace = true [dependencies] anyhow.workspace = true -libloading.workspace = true serde.workspace = true strum.workspace = true +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +libloading.workspace = true diff --git a/adana-script-core/release.toml b/adana-script-core/release.toml new file mode 100644 index 0000000..8f14116 --- /dev/null +++ b/adana-script-core/release.toml @@ -0,0 +1 @@ +tag = false diff --git a/adana-script-core/src/primitive.rs b/adana-script-core/src/primitive.rs index 6511a07..e0d2b3f 100644 --- a/adana-script-core/src/primitive.rs +++ b/adana-script-core/src/primitive.rs @@ -6,7 +6,7 @@ use std::{ sync::{Arc, RwLock}, }; -use anyhow::{Context, Result}; +use anyhow::Result; use serde::{Deserialize, Serialize}; @@ -16,6 +16,9 @@ const MAX_U32_AS_I128: i128 = u32::MAX as i128; #[derive(Debug)] pub struct NativeLibrary { + #[cfg(target_arch = "wasm32")] + _lib: (), + #[cfg(not(target_arch = "wasm32"))] lib: libloading::Library, path: PathBuf, } @@ -23,34 +26,55 @@ pub struct NativeLibrary { pub type NativeFunctionCallResult = anyhow::Result; pub type Compiler = dyn FnMut(Value, BTreeMap) -> NativeFunctionCallResult + Send; + +#[cfg(not(target_arch = "wasm32"))] #[allow(improper_ctypes_definitions)] pub type NativeFunction<'lib> = libloading::Symbol< 'lib, fn(Vec, Box) -> NativeFunctionCallResult, >; + +#[cfg(target_arch = "wasm32")] +pub type NativeFunction = (); + impl NativeLibrary { /// # Safety /// trust me bro + #[cfg(not(target_arch = "wasm32"))] pub unsafe fn new(path: &Path) -> anyhow::Result { let lib = libloading::Library::new(path) .map_err(|e| anyhow::format_err!("could not load lib, {e}"))?; Ok(NativeLibrary { lib, path: path.to_path_buf() }) } + + #[cfg(target_arch = "wasm32")] + pub fn new(_path: &Path) -> anyhow::Result { + Err(anyhow::format_err!("cannot use lib loading in wasm context!")) + } + pub fn get_path(&self) -> &Path { self.path.as_path() } + /// # Safety /// trust me bro - + #[cfg(not(target_arch = "wasm32"))] pub unsafe fn get_function( &self, key: &str, ) -> anyhow::Result { - self.lib.get(key.as_bytes()).context("{key} wasn't found") + let r = self.lib.get(key.as_bytes())?; + Ok(r) } + + #[cfg(target_arch = "wasm32")] + pub fn get_function(&self, _key: &str) -> anyhow::Result { + Err(anyhow::format_err!("cannot use lib loading in wasm context!")) + } + /// # Safety /// trust me bro - + #[cfg(not(target_arch = "wasm32"))] pub unsafe fn call_function( &self, key: &str, @@ -60,6 +84,16 @@ impl NativeLibrary { let fun = self.get_function(key)?; fun(params, compiler) } + + #[cfg(target_arch = "wasm32")] + pub fn call_function( + &self, + _key: &str, + _params: Vec, + _compiler: Box, + ) -> anyhow::Result { + Err(anyhow::format_err!("cannot use lib loading in wasm context!")) + } } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/adana-script-wasm/Cargo.toml b/adana-script-wasm/Cargo.toml new file mode 100644 index 0000000..49b28aa --- /dev/null +++ b/adana-script-wasm/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "adana-script-wasm" +version.workspace = true +authors.workspace = true +description.workspace = true +homepage.workspace = true +repository.workspace = true +readme.workspace = true +rust-version.workspace = true +edition.workspace = true +license.workspace = true +exclude.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +default = ["wee_alloc", "console_error_panic_hook"] + +[dependencies] +wasm-bindgen = { workspace = true } +adana-script.workspace = true +adana-script-core.workspace = true +serde.workspace = true +serde-wasm-bindgen.workspace = true +console_error_panic_hook = { workspace = true, optional = true } +wee_alloc = { workspace = true, optional = true } +bincode.workspace = true + +[dev-dependencies] +wasm-bindgen-test.workspace = true diff --git a/adana-script-wasm/release.toml b/adana-script-wasm/release.toml new file mode 100644 index 0000000..8f14116 --- /dev/null +++ b/adana-script-wasm/release.toml @@ -0,0 +1 @@ +tag = false diff --git a/adana-script-wasm/src/lib.rs b/adana-script-wasm/src/lib.rs new file mode 100644 index 0000000..166ef48 --- /dev/null +++ b/adana-script-wasm/src/lib.rs @@ -0,0 +1,26 @@ +mod utils; +use adana_script_core::primitive::RefPrimitive; +use std::collections::BTreeMap; +use wasm_bindgen::prelude::*; + +#[global_allocator] +static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; + +#[wasm_bindgen] +pub fn compute(script: &str, mem: &mut [u8]) -> Result { + utils::set_panic_hook(); + // wasm memory: + // https://developer.mozilla.org/fr/docs/WebAssembly/JavaScript_interface/Memory + let mut ctx: BTreeMap = if !mem.is_empty() { + bincode::deserialize(mem)? + } else { + BTreeMap::new() + }; + + let result = adana_script::compute(script, &mut ctx, "N/A") + .map_err(|e| e.to_string()) + .map_err(|e| JsError::new(&e))?; + + bincode::serialize_into(mem, &ctx)?; + Ok(serde_wasm_bindgen::to_value(&result)?) +} diff --git a/adana-script-wasm/src/utils.rs b/adana-script-wasm/src/utils.rs new file mode 100644 index 0000000..b1d7929 --- /dev/null +++ b/adana-script-wasm/src/utils.rs @@ -0,0 +1,10 @@ +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/adana-script-wasm/tests/web.rs b/adana-script-wasm/tests/web.rs new file mode 100644 index 0000000..4b95afd --- /dev/null +++ b/adana-script-wasm/tests/web.rs @@ -0,0 +1,27 @@ +//! Test suite for the Web and headless browsers. + +#![cfg(target_arch = "wasm32")] + +extern crate wasm_bindgen_test; + +use adana_script_core::primitive::{Primitive, RefPrimitive}; +use adana_script_wasm::compute; +use std::assert_eq; +use std::collections::BTreeMap; +use wasm_bindgen::JsValue; +use wasm_bindgen_test::*; +wasm_bindgen_test_configure!(run_in_browser); + +#[wasm_bindgen_test] +fn compute_test() { + let mut memory = vec![0; 64]; + let res = compute("x = 1+1", &mut memory).map_err(JsValue::from).unwrap(); + + //wasm_bindgen_test::console_log!("{memory:?}"); + let res: Primitive = serde_wasm_bindgen::from_value(res).unwrap(); + assert_eq!(Primitive::Int(2), res); + let ctx: BTreeMap = + bincode::deserialize(&memory).unwrap(); + assert_eq!(1, ctx.len()); + assert_eq!(Primitive::Int(2), ctx["x"].read().unwrap().clone()); +} diff --git a/adana-script/release.toml b/adana-script/release.toml new file mode 100644 index 0000000..8f14116 --- /dev/null +++ b/adana-script/release.toml @@ -0,0 +1 @@ +tag = false diff --git a/adana-script/src/compute.rs b/adana-script/src/compute.rs index badb829..7aa53a9 100644 --- a/adana-script/src/compute.rs +++ b/adana-script/src/compute.rs @@ -759,33 +759,43 @@ fn compute_recur( //Ok(function(vec![Primitive::String("s".into())])) } else if let Primitive::NativeFunction(key, lib) = function { - if cfg!(test) { - dbg!(&key, &lib); - } - let mut parameters = vec![]; + #[cfg(not(target_arch = "wasm32"))] + { + if cfg!(test) { + dbg!(&key, &lib); + } + let mut parameters = vec![]; - for param in param_values.iter() { - let variable_from_fn_call = - compute_lazy(param.clone(), ctx, shared_lib)?; - parameters.push(variable_from_fn_call); - } - if cfg!(test) { - dbg!(¶meters); - } + for param in param_values.iter() { + let variable_from_fn_call = compute_lazy( + param.clone(), + ctx, + shared_lib, + )?; + parameters.push(variable_from_fn_call); + } + if cfg!(test) { + dbg!(¶meters); + } - let mut scope_ctx = scoped_ctx(ctx)?; + let mut scope_ctx = scoped_ctx(ctx)?; - let slb = shared_lib.as_ref().to_path_buf(); - let fun = move |v, extra_ctx| { - scope_ctx.extend(extra_ctx); - compute_lazy(v, &mut scope_ctx, &slb) - }; - unsafe { - lib.call_function( - key.as_str(), - parameters, - Box::new(fun), - ) + let slb = shared_lib.as_ref().to_path_buf(); + let fun = move |v, extra_ctx| { + scope_ctx.extend(extra_ctx); + compute_lazy(v, &mut scope_ctx, &slb) + }; + unsafe { + lib.call_function( + key.as_str(), + parameters, + Box::new(fun), + ) + } + } + #[cfg(target_arch = "wasm32")] + { + return Ok(Primitive::Error(format!("Loading native function {key} doesn't work in wasm context! {lib:?}"))); } } else { Ok(Primitive::Error(format!( diff --git a/adana-script/src/require_dynamic_lib.rs b/adana-script/src/require_dynamic_lib.rs index 5f6ca30..ba17f84 100644 --- a/adana-script/src/require_dynamic_lib.rs +++ b/adana-script/src/require_dynamic_lib.rs @@ -1,13 +1,14 @@ +#[cfg(not(target_arch = "wasm32"))] const STD_DOWNLOAD_URI: &str = "https://github.com/nbittich/adana-std/releases/download/0.16.1/adana-std.tar.gz"; -use std::{ - path::Path, - process::{Command, Stdio}, -}; +#[cfg(not(target_arch = "wasm32"))] +use std::process::{Command, Stdio}; use adana_script_core::primitive::NativeLibrary; +#[cfg(not(target_arch = "wasm32"))] use anyhow::{anyhow, Context}; +use std::path::Path; pub fn require_dynamic_lib( path: &str, @@ -16,6 +17,17 @@ pub fn require_dynamic_lib( try_from_path(path, shared_lib) } +#[cfg(target_arch = "wasm32")] +fn try_from_path( + _file_path: &str, + _shared_lib: impl AsRef + Copy, +) -> anyhow::Result { + return Err(anyhow::format_err!( + "Cannot load native library in wasm context!" + )); +} + +#[cfg(not(target_arch = "wasm32"))] fn try_from_path( file_path: &str, shared_lib: impl AsRef + Copy, diff --git a/adana-shell/release.toml b/adana-shell/release.toml new file mode 100644 index 0000000..8f14116 --- /dev/null +++ b/adana-shell/release.toml @@ -0,0 +1 @@ +tag = false diff --git a/release.toml b/release.toml new file mode 100644 index 0000000..f5c72be --- /dev/null +++ b/release.toml @@ -0,0 +1,2 @@ +tag-name = "{{version}}" +tag = true