Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified examples/generated/source_sync/example.pdf
Binary file not shown.
27 changes: 27 additions & 0 deletions typst/private/tests/simple/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("//typst:typst.bzl", "typst")

filegroup(
Expand Down Expand Up @@ -29,3 +30,29 @@ build_test(
":simple",
],
)

# Determinism test: two separate targets from the same source must produce
# byte-identical PDFs (SOURCE_DATE_EPOCH=0 is set by default).
typst(
name = "deterministic_a",
src = "simple.typ",
data = [
":frown",
":smile",
],
)

typst(
name = "deterministic_b",
src = "simple.typ",
data = [
":frown",
":smile",
],
)

diff_test(
name = "deterministic_test",
file1 = ":deterministic_a",
file2 = ":deterministic_b",
)
15 changes: 12 additions & 3 deletions typst/private/typst.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ def _typst_impl(ctx):
_rlocationpath(src, ctx.workspace_name),
))

env = {"SOURCE_DATE_EPOCH": "0"}
env.update(ctx.attr.env)

ctx.actions.run(
mnemonic = "TypstC",
executable = toolchain_info.process_wrapper,
arguments = [args],
outputs = [pdf_outfile],
tools = toolchain_info.all_files,
inputs = depset([ctx.file.src] + ctx.files.data),
env = env,
)

return [
Expand All @@ -48,16 +52,21 @@ def _typst_impl(ctx):
]

typst = rule(
doc = "TODO",
doc = "Compile a Typst document to PDF.",
implementation = _typst_impl,
attrs = {
"data": attr.label_list(
doc = "TODO",
doc = "Additional data dependencies (images, templates, etc.).",
allow_files = True,
mandatory = False,
),
"env": attr.string_dict(
doc = "Additional environment variables for the typst compiler action. " +
"SOURCE_DATE_EPOCH=0 is set by default for deterministic output. " +
"Override with a different value to opt out.",
),
"src": attr.label(
doc = "TODO",
doc = "The .typ source file to compile.",
allow_single_file = [".typ"],
mandatory = True,
),
Expand Down
Loading