From cfedacb6d8c1e194575d5b5c62d2a724bdf2add6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 01:01:25 -0300 Subject: anim: Typst runs with / as its root, so a source can name any file The Typst step ran in .zig-cache/typst with Typst's default root, the directory of the file it compiles, so a source could name no file but one in the cache: #image("/home/me/manual.pdf", page: 31) failed with "would escape the project root". It now runs with --root /, which makes an absolute path in a source the file's own path; relative paths still resolve in the cache, as before. Why / and not the build root: the file a scene names (a manual, a paper) lives where its owner keeps it, outside any project, and a copy or link under the project is one jj add away from being committed. / is safe in that Typst only reads what a source names, and a scene's sources are its author's code, compiled by a build that can already read and run anything. The cache is still keyed by preamble and source alone: a file changed in place keeps its old SVG until its cache entry goes (typst.zig says so). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- src/anim/typst.zig | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/anim/typst.zig b/src/anim/typst.zig index d9df734..05a0d4e 100644 --- a/src/anim/typst.zig +++ b/src/anim/typst.zig @@ -50,12 +50,18 @@ pub fn generate(comptime SceneFile: type, comptime sources: []const []const u8, try out.writeFile(io, .{ .sub_path = "typst.zig", .data = module }); } -/// Runs `typst compile` on `preamble ++ source` and caches the SVG. +/// Runs `typst compile` on `preamble ++ source` and caches the SVG. The +/// root is `/`, so an absolute path in a source is the file's own path +/// (`#image("/home/me/manual.pdf", page: 31)`) and a relative one is +/// in the cache. Typst only reads what a source names, and a scene's +/// sources are its author's code, built by a build that can already read +/// anything. A file named this way is not part of the cache key: changed +/// in place, it keeps its old SVG until its entry in the cache goes. fn compile(gpa: std.mem.Allocator, io: std.Io, cache: std.Io.Dir, name: []const u8, preamble: []const u8, source: []const u8) ![]const u8 { const typ = try std.fmt.allocPrint(gpa, "{s}.typ", .{name}); try cache.writeFile(io, .{ .sub_path = typ, .data = try std.mem.concat(gpa, u8, &.{ preamble, "\n", source, "\n" }) }); const result = try std.process.run(gpa, io, .{ - .argv = &.{ "typst", "compile", "--format", "svg", typ, name }, + .argv = &.{ "typst", "compile", "--root", "/", "--format", "svg", typ, name }, .cwd = .{ .dir = cache }, }); if (result.term != .exited or result.term.exited != 0) { -- cgit v1.3