aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-04-29 22:30:04 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2026-04-29 22:30:04 +0200
commit78f399521661c82e45e627bbbdc8ce4daa9e5207 (patch)
tree2671aa93feb01956aded5cef1e725f9aff4aa3a9
parent77ccdd8559383c25fc59fbcba38117102e5657b5 (diff)
style(typst): move in lib folder
-rw-r--r--build.zig42
-rw-r--r--lib/typst/.gitignore (renamed from typst/.gitignore)0
-rw-r--r--lib/typst/Cargo.lock (renamed from typst/Cargo.lock)0
-rw-r--r--lib/typst/Cargo.toml (renamed from typst/Cargo.toml)0
-rw-r--r--lib/typst/README.md (renamed from typst/README.md)0
-rw-r--r--lib/typst/example.c (renamed from typst/example.c)0
-rw-r--r--lib/typst/src/lib.rs (renamed from typst/src/lib.rs)0
-rw-r--r--lib/typst/src/world.rs (renamed from typst/src/world.rs)0
-rw-r--r--lib/typst/typdown_typst.h (renamed from typst/typdown_typst.h)0
-rw-r--r--src/paragraph.zig5
-rw-r--r--src/testing.zig2
11 files changed, 36 insertions, 13 deletions
diff --git a/build.zig b/build.zig
index 6782207..f23ae35 100644
--- a/build.zig
+++ b/build.zig
@@ -1,14 +1,20 @@
const std = @import("std");
+const TYPST = "lib/typst";
+const TYPST_DEBUG = TYPST ++ "/target/debug";
+const TYPST_RELEASE = TYPST ++ "/target/release";
+
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
+ const install = b.getInstallStep();
+
// build typst module
const build_typst = b.addSystemCommand(&[_][]const u8{
"cargo", "build",
});
- build_typst.setCwd(b.path("typst/"));
+ build_typst.setCwd(b.path(TYPST));
if (optimize != .Debug) build_typst.addArg("--release");
const mod = b.addModule("typdown", .{
@@ -17,17 +23,18 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});
if (!target.result.isWasiLibC()) mod.link_libc = true;
- // link typst module during build
- mod.addIncludePath(b.path("typst"));
- mod.addLibraryPath(if (optimize == .Debug) b.path("typst/target/debug/") else b.path("typst/target/release/"));
if (optimize != .Debug) mod.strip = true;
+ // find typst module
+ mod.addIncludePath(b.path(TYPST));
+ mod.addLibraryPath(if (optimize == .Debug) b.path(TYPST_DEBUG) else b.path(TYPST_RELEASE));
const lib = b.addLibrary(.{
.name = "typdown",
.linkage = .static,
.root_module = mod,
+ .use_llvm = true, // zig internal backend crashes during linking (for 0.15.2)
});
- // link typst module to build
+ // link typst module
lib.linkSystemLibrary("typdown_typst");
const installed_lib = b.addInstallArtifact(lib, .{});
@@ -49,22 +56,37 @@ pub fn build(b: *std.Build) void {
example.root_module.linkLibrary(lib);
example.root_module.addIncludePath(b.path("include"));
- b.getInstallStep().dependOn(&installed_lib.step);
+ install.dependOn(&installed_lib.step);
+
+ const fmt = b.addFmt(.{
+ .paths = &.{
+ "src/",
+ "build.zig",
+ "build.zig.zon",
+ },
+ .check = true,
+ });
+ install.dependOn(&fmt.step);
+ const test_step = b.step("test", "Run tests");
const mod_tests = b.addTest(.{
.root_module = mod,
.use_llvm = true, // zig internal backend crashes during linking (for 0.15.2)
});
+
+ const options = b.addOptions();
+ const short = b.option(bool, "short", "skip long tests") orelse false;
+ options.addOption(bool, "short", short);
+ mod_tests.root_module.addOptions("config", options);
+
const run_mod_tests = b.addRunArtifact(mod_tests);
generateSVG(b, &run_mod_tests.step) catch |err| run_mod_tests.step.addError("{}\n", .{err}) catch unreachable;
- run_mod_tests.step.dependOn(b.getInstallStep());
-
- const test_step = b.step("test", "Run tests");
+ run_mod_tests.step.dependOn(install);
test_step.dependOn(&run_mod_tests.step);
const examples_step = b.step("examples", "Run examples");
const example_run = b.addRunArtifact(example);
- example_run.step.dependOn(b.getInstallStep());
+ example_run.step.dependOn(install);
examples_step.dependOn(&example_run.step);
const check = b.step("check", "Check if foo compiles");
diff --git a/typst/.gitignore b/lib/typst/.gitignore
index 695217d..695217d 100644
--- a/typst/.gitignore
+++ b/lib/typst/.gitignore
diff --git a/typst/Cargo.lock b/lib/typst/Cargo.lock
index 3ce45b7..3ce45b7 100644
--- a/typst/Cargo.lock
+++ b/lib/typst/Cargo.lock
diff --git a/typst/Cargo.toml b/lib/typst/Cargo.toml
index dc7eb97..dc7eb97 100644
--- a/typst/Cargo.toml
+++ b/lib/typst/Cargo.toml
diff --git a/typst/README.md b/lib/typst/README.md
index 6e2530f..6e2530f 100644
--- a/typst/README.md
+++ b/lib/typst/README.md
diff --git a/typst/example.c b/lib/typst/example.c
index 39e7a06..39e7a06 100644
--- a/typst/example.c
+++ b/lib/typst/example.c
diff --git a/typst/src/lib.rs b/lib/typst/src/lib.rs
index 5c2ee0d..5c2ee0d 100644
--- a/typst/src/lib.rs
+++ b/lib/typst/src/lib.rs
diff --git a/typst/src/world.rs b/lib/typst/src/world.rs
index c2fe7c7..c2fe7c7 100644
--- a/typst/src/world.rs
+++ b/lib/typst/src/world.rs
diff --git a/typst/typdown_typst.h b/lib/typst/typdown_typst.h
index 755314a..755314a 100644
--- a/typst/typdown_typst.h
+++ b/lib/typst/typdown_typst.h
diff --git a/src/paragraph.zig b/src/paragraph.zig
index ce2d123..5b13cf2 100644
--- a/src/paragraph.zig
+++ b/src/paragraph.zig
@@ -41,6 +41,7 @@ pub fn parseLine(alloc: Allocator, l: *Lexer) Error!Element {
}
fn doTestMath(parent: Allocator, t: []const u8, v: []const u8) !void {
+ if (@import("config").short) return;
var arena = std.heap.ArenaAllocator.init(parent);
defer arena.deinit();
var alloc = arena.allocator();
@@ -54,10 +55,10 @@ fn doTestMath(parent: Allocator, t: []const u8, v: []const u8) !void {
var v_iter = std.mem.splitSequence(u8, v, " ");
while (g_iter.next()) |g_it| {
const v_it = v_iter.next() orelse break :brk false;
- if ((std.mem.startsWith(u8, g_it, "xlink:href=") and std.mem.startsWith(u8, g_it, "xlink:href")) or
+ if ((std.mem.startsWith(u8, g_it, "xlink:href=") and std.mem.startsWith(u8, g_it, "xlink:href")) or
(std.mem.startsWith(u8, g_it, "id=") and std.mem.startsWith(u8, v_it, "id="))) continue;
if (!std.mem.eql(u8, g_it, v_it)) {
- std.debug.print("not the same: {s} vs {s}", .{g_it, v_it});
+ std.debug.print("not the same: {s} vs {s}", .{ g_it, v_it });
break :brk false;
}
}
diff --git a/src/testing.zig b/src/testing.zig
index 4ed071f..21fb4fd 100644
--- a/src/testing.zig
+++ b/src/testing.zig
@@ -14,7 +14,7 @@ pub fn do(comptime parse: fn (Allocator, *Lexer) parser.Error!Element, parent: A
const g = try p.renderHTML(alloc);
defer alloc.free(g);
std.testing.expect(std.mem.eql(u8, g, v)) catch |err| {
- std.debug.print("got: {s}\nwanted: {s}\n", .{g, v});
+ std.debug.print("got: {s}\nwanted: {s}\n", .{ g, v });
return err;
};
}