No description
  • Rust 98.7%
  • Shell 1.3%
Find a file
Tin Švagelj 9561989444
Restructure project to allow inclusion in other projects
Signed-off-by: Tin Švagelj <tin.svagelj@live.com>
2024-10-17 11:07:19 +02:00
.githooks Deny rustdoc warnings in pre-push script, and fix a doc comment 2023-09-25 10:11:23 +02:00
crates Restructure project to allow inclusion in other projects 2024-10-17 11:07:19 +02:00
examples Use assert.eq instead of assert 2023-09-25 10:04:12 +02:00
.gitignore initial commit 2023-06-19 17:37:47 +02:00
Cargo.lock Update the wast dependency, and lower the minimum dependencies for the protocol 2023-09-21 16:35:04 +02:00
Cargo.toml Restructure project to allow inclusion in other projects 2024-10-17 11:07:19 +02:00
CONTRIBUTING.md Add contribution instructions 2023-09-21 16:40:42 +02:00
LICENSE Create LICENSE 2023-07-16 08:23:07 +02:00
README.md Restructure project to allow inclusion in other projects 2024-10-17 11:07:19 +02:00

wasm-minimal-protocol

A minimal protocol to write typst plugins.

Note that plugins require typst version 0.8 or more.

You want to write a plugin

A plugin can be written in Rust, C, Zig, or any language than compiles to WebAssembly.

Rust plugins can use this crate to automatically implement the protocol with a macro:

// Rust file
use wasm_minimal_protocol::*;

initiate_protocol!();

#[wasm_func]
pub fn hello() -> Vec<u8> {
    b"Hello from wasm!!!".to_vec()
}
// Typst file
#let p = plugin("/path/to/plugin.wasm")
#assert.eq(str(p.hello()), "Hello from wasm!!!")

For other languages, the protocol is described at https://typst.app/docs/reference/foundations/plugin/. You should also take a look at this repository's examples.

Examples

See the example for your language:

If you have all the required dependencies, you may build all examples by running cargo test.

wasi-stub

The runtime used by typst do not allow the plugin to import any function (beside the ones used by the protocol). In particular, if your plugin is compiled for WASI, it will not be able to be loaded by typst.

To get around that, you can use wasi-stub. It will detect all WASI-related imports, and replace them by stubs that do nothing.

If you are compiling C code with emcc, stubbing is almost certainly required.