summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 01:01:25 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitcfedacb6d8c1e194575d5b5c62d2a724bdf2add6 (patch)
treef2166d353f374beebb6beac08dbd02c77da3d5fc /src
parent10115489f8988cf6a649707202a51757708883a2 (diff)
downloadsketchbook-cfedacb6d8c1e194575d5b5c62d2a724bdf2add6.tar.gz
sketchbook-cfedacb6d8c1e194575d5b5c62d2a724bdf2add6.zip
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 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src')
-rw-r--r--src/anim/typst.zig10
1 files changed, 8 insertions, 2 deletions
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) {