Skip to content

fix(spec-gen): copy Typst specs into crate so vendored builds succeed - #2

Merged
tvanderstad merged 1 commit into
lockbookfrom
fix/self-contained-typst-specs
Nov 27, 2026
Merged

tvanderstad merged 1 commit into
lockbookfrom
fix/self-contained-typst-specs

Conversation

@tvanderstad

@tvanderstad tvanderstad commented Nov 27, 2026 •

Copy link
Copy Markdown

Why this is needed

Lockbook embeds both MiTeX and Typst inside one native Rust binary, so our fork added TYPST_SPECS to crates/mitex-spec-gen/src/lib.rs to bake MiTeX's three Typst definition files (mod.typ, prelude.typ, and latex/standard.typ) directly into the compiled binary.

Previously, lib.rs pulled those files in with include_str!("../../../packages/mitex/specs/..."), climbing out of the crates/mitex-spec-gen/ crate folder into the repo's top-level packages/mitex/specs/ directory.

That works during normal online Cargo builds (where Cargo clones the entire git repository), but breaks offline/vendored builds like Flathub (flatpak-cargo-generator), cargo vendor, and cargo package. Those tools extract only each Rust crate's own folder (crates/mitex-spec-gen/) into cargo/vendor/mitex-spec-gen/ and leave packages/mitex/specs/ behind, causing the Flathub build to fail with No such file or directory.

What this PR changes

  • Copies the 3 .typ files into crates/mitex-spec-gen/assets/specs/ so everything the crate compiles lives inside its own directory (the same way assets/artifacts/spec/default.json already does).
    • Why the diff is ~1,500 lines: 1,464 of those lines are verbatim copies of mod.typ (12), prelude.typ (230), and latex/standard.typ (1,222). Only 31 lines are Rust changes in src/lib.rs.
    • Why copy instead of move: packages/mitex/specs/ is the source of truth used by the Typst package (packages/mitex/mitex.typ), build.rs in generate mode, mitex-cli, and upstream mitex-rs/mitex. Leaving it in place avoids breaking those paths and keeps merges from upstream clean.
  • Updates TYPST_SPECS in crates/mitex-spec-gen/src/lib.rs to include_str! from ../assets/specs/....
  • Adds a unit test (vendored_typst_specs_match_package) that verifies the crate-local copies match packages/mitex/specs/ byte-for-byte during workspace test runs, so the two copies can't silently drift apart.

Verification

  • cargo test -p mitex-spec-gen --features prebuilt, cargo test -p mitex --features mitex-spec-gen/prebuilt, cargo clippy -p mitex-spec-gen --all-targets --features prebuilt, cargo fmt --check --all, and cargo doc -p mitex-spec-gen --no-deps --features prebuilt (all with RUSTFLAGS="-Dwarnings" and RUSTDOCFLAGS="-Dwarnings").
  • Simulated Flathub's vendored layout by copying only crates/mitex-spec and crates/mitex-spec-gen into a fresh workspace without packages/ and running cargo check and cargo test.

@tvanderstad tvanderstad changed the title fix(spec-gen): keep embedded Typst specs inside crate directory fix(spec-gen): copy Typst specs into crate so vendored builds succeed Nov 27, 2026
@tvanderstad
tvanderstad merged commit 94945f4 into lockbook Nov 27, 2026
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant