From db8a6359db92b7ce176da20e833ed5848d1e63e9 Mon Sep 17 00:00:00 2001 From: Nordine Bittich Date: Sun, 8 Dec 2024 14:41:21 +0100 Subject: [PATCH] use lol_alloc --- .github/workflows/release-wasm.yml | 52 ++++++++++++++++++++++++++++++ Cargo.lock | 19 +++++++++++ Cargo.toml | 1 + rdfa-wasm/Cargo.toml | 3 +- rdfa-wasm/src/lib.rs | 6 +++- 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release-wasm.yml diff --git a/.github/workflows/release-wasm.yml b/.github/workflows/release-wasm.yml new file mode 100644 index 0000000..5b1e3bf --- /dev/null +++ b/.github/workflows/release-wasm.yml @@ -0,0 +1,52 @@ +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 nodejs --release --scope nbittich ./rdfa-wasm + wasm-pack pack ./rdfa-wasm/pkg + + - name: Upload pkg + uses: actions/upload-artifact@v4 + with: + name: pkg + path: rdfa-wasm/pkg + publish: + needs: build + 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@v4 + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + with: + node-version: "20.x" + registry-url: "https://registry.npmjs.org" + - name: Publish on NPM + run: | + cd pkg + npm install + npm publish --access public diff --git a/Cargo.lock b/Cargo.lock index 50cdf7d..73c21b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -650,6 +650,15 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +[[package]] +name = "lol_alloc" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83e5106554cabc97552dcadf54f57560ae6af3276652f82ca2be06120dc4c5dc" +dependencies = [ + "spin", +] + [[package]] name = "mac" version = "0.1.1" @@ -895,6 +904,7 @@ dependencies = [ "console_error_panic_hook", "getrandom", "graph-rdfa-processor", + "lol_alloc", "wasm-bindgen", ] @@ -1091,6 +1101,15 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + [[package]] name = "stable_deref_trait" version = "1.2.0" diff --git a/Cargo.toml b/Cargo.toml index 8fe47c9..9885650 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ test-case = "3.3.1" env_logger = "0.11.5" tortank = "0.24.2" wasm-bindgen = "0.2.99" +lol_alloc = "0.4.1" [profile.release] opt-level = 'z' # Optimize for size. lto = true # Link Time Optimization (LTO) diff --git a/rdfa-wasm/Cargo.toml b/rdfa-wasm/Cargo.toml index 4898d77..b2a70d2 100644 --- a/rdfa-wasm/Cargo.toml +++ b/rdfa-wasm/Cargo.toml @@ -10,7 +10,7 @@ edition.workspace = true license.workspace = true [features] -default = ["console_error_panic_hook"] +default = ["console_error_panic_hook","lol_alloc"] [lib] @@ -22,3 +22,4 @@ graph-rdfa-processor.workspace = true [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen.workspace = true console_error_panic_hook = { workspace = true, optional = true } +lol_alloc={workspace=true,optional=true} diff --git a/rdfa-wasm/src/lib.rs b/rdfa-wasm/src/lib.rs index 3c2e680..5983e2b 100644 --- a/rdfa-wasm/src/lib.rs +++ b/rdfa-wasm/src/lib.rs @@ -1,8 +1,12 @@ #![cfg(target_arch = "wasm32")] mod utils; use graph_rdfa_processor::RdfaGraph; +use lol_alloc::{AssumeSingleThreaded, FreeListAllocator}; use wasm_bindgen::prelude::*; - +// SAFETY: This application is single threaded, so using AssumeSingleThreaded is allowed. +#[global_allocator] +static ALLOCATOR: AssumeSingleThreaded = + unsafe { AssumeSingleThreaded::new(FreeListAllocator::new()) }; #[wasm_bindgen] pub fn html_to_rdfa(html: &str, base: &str, well_known_prefix: &str) -> String { utils::set_panic_hook();