Last active
September 11, 2024 16:00
-
-
Save peterhellberg/bfabcabbc07d2202bc3de445299d90dc to your computer and use it in GitHub Desktop.
A WebAssembly plugin for Typst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const std = @import("std"); | |
| pub fn build(b: *std.Build) void { | |
| const target = b.resolveTargetQuery(.{ | |
| .cpu_arch = .wasm32, | |
| .os_tag = .freestanding, | |
| }); | |
| const hello = b.addExecutable(.{ | |
| .name = "hello", | |
| .root_source_file = b.path("hello.zig"), | |
| .target = target, | |
| .optimize = .ReleaseSmall, | |
| .strip = true, | |
| }); | |
| hello.entry = .disabled; | |
| hello.rdynamic = true; | |
| b.installArtifact(hello); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #set page(width: 10cm, height: 10cm) | |
| #set text(font: "Inter") | |
| == A WebAssembly plugin for Typst | |
| #line(length: 100%) | |
| #emph[Typst is capable of interfacing with plugins compiled to WebAssembly.] | |
| #line(length: 100%) | |
| #let wasm = plugin("zig-out/bin/hello.wasm") | |
| #let resp = str(wasm.hello()) | |
| #eval(resp, mode: "markup") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const std = @import("std"); | |
| const allocator = std.heap.page_allocator; | |
| export fn hello() i32 { | |
| const message = "*Hello* from `hello.wasm` written in Zig!"; | |
| wasm_minimal_protocol_send_result_to_host(message.ptr, message.len); | |
| return 0; | |
| } | |
| // === | |
| // Functions for the protocol | |
| extern "typst_env" fn wasm_minimal_protocol_send_result_to_host(ptr: [*]const u8, len: usize) void; | |
| extern "typst_env" fn wasm_minimal_protocol_write_args_to_buffer(ptr: [*]u8) void; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note
Typst is a new markup-based typesetting system that is designed to be as powerful as LaTeX while being much easier to learn and use.
Links