Skip to content

Commit 83052a8

Browse files
committedOct 26, 2024
add stub WASM plugin
1 parent b69ddfa commit 83052a8

File tree

8 files changed

+104
-1
lines changed

8 files changed

+104
-1
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/

‎Cargo.lock

+55
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[workspace]
2+
resolver = "2"
3+
4+
members = [
5+
"plugin",
6+
]
7+
8+
[profile.release]
9+
lto = true # Enable link-time optimization
10+
strip = true # Strip symbols from binary*
11+
opt-level = 'z' # Optimize for size
12+
codegen-units = 1 # Reduce number of codegen units to increase optimizations
13+
panic = 'abort' # Abort on panic

‎Justfile

+6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ doc:
1616

1717
# run test suite
1818
test *args:
19+
cargo test
1920
typst-test run {{ args }}
2021

2122
# update test cases
2223
update *args:
2324
typst-test update {{ args }}
2425

26+
# build the parser WASM plugin
27+
plugin:
28+
cargo build --release --target wasm32-unknown-unknown
29+
cp target/wasm32-unknown-unknown/release/parser.wasm src/
30+
2531
# package the library into the specified destination folder
2632
package target:
2733
./scripts/package "{{target}}"

‎plugin/Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "parser"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["cdylib"]
8+
9+
[dependencies]
10+
wasm-minimal-protocol = "0.1.0"

‎plugin/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#[cfg(target_arch = "wasm32")]
2+
use wasm_minimal_protocol::wasm_func;
3+
4+
#[cfg(target_arch = "wasm32")]
5+
wasm_minimal_protocol::initiate_protocol!();
6+
7+
#[cfg_attr(target_arch = "wasm32", wasm_func)]
8+
pub fn concatenate(arg1: &[u8], arg2: &[u8]) -> Vec<u8> {
9+
[arg1, arg2].concat()
10+
}

‎src/lib.typ

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#let _p = plugin("parser.wasm")
2+
3+
14
/// The identity function
25
///
36
/// #example(mode: "markup", ```typ
@@ -7,4 +10,9 @@
710
///
811
/// - x (any): some parameter
912
/// -> any
10-
#let id(x) = x
13+
#let id(x) = {
14+
let foo = "foo"
15+
let foofoo = str(_p.concatenate(bytes(foo), bytes(foo)))
16+
assert.eq(foofoo, foo * 2)
17+
x
18+
}

‎src/parser.wasm

15.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.