Repository navigation
Split out four new crates - #5302
Merged
Merged
Conversation
Contributor
|
Incredible. Love this |
Member
Author
|
GitHub shows conflicts on all PRs now, but just a |
Dikluwe
pushed a commit
to Dikluwe/typst-crystalline
that referenced
this pull request
Sep 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR splits out four new crates:
typst-library: Most of the code fromtypstmoved here. The crate holds Typst's standard library and all central definitions for the compiler (as these are interwoven with the standard library types). All of its definitions are reexported by thetypstcrate, which has become just a thin wrapper.typst-eval: Moved fromtypst/src/eval.typst-realize: Moved fromtypst/src/realize.rs.typst-layout: Contains code fromtypst/src/layoutandtypst/src/math.The three new eval/realize/layout crates contain primarily behaviour, not types. This behaviour is made available to code in
typst-librarythrough a newRoutinesstruct containing a table of function pointer. This struct is populated in the now very smalltypstcrate which depends on all of the four crates and just puts the pieces together.This set-up of having a central crate with types and surrounding crates with behaviour that are assembled together by one small umbrella crate is very scalable because it makes all the behaviour crates independent from each other, such that they can be compiled in parallel. A very similar design is employed by
rustc.Here's a small diagram, which should make things clear:
The main motivation of this change is developer experience: Compile times for the
typstcrate have gotten pretty bad and rust-analyzer has become rather sluggish. With the new setup, thetypst-librarycrate is still quite big1, but at least a bit smaller. It also won't grow as much as the mono-typst-crate would due to upcoming features like HTML export (which will get its owntypst-htmlcrate). Editingtypst-libraryis still not a great experience, but I suspect the solution here is to optimize the various proc-macros to generate less code.Meanwhile, editing in the new crates is a much nicer experience, with rust-analyzer being quite snappy. Moreover, editing these crates does not trigger recompilation of the exporter crates. (Previously, the test cycle for any change to the layout engine triggered a recompilation of
typst-pdf,typst-svg, andtypst-render.)Footnotes
Splitting
typst-libraryfurther is hard due to the various interactions between all its types. While there are various definitions in it (e.g. data loading functions) that are leafs and not needed by anything else, the boundaries of potentially split-out crates end up being rather arbitrary, so that didn't seem like a durable solution. (I don't want to change the crate structure every week.) The nice thing about just splitting behaviour rather than types is that we can easily resolve cyclid dependencies via the function pointer table. This is not possible types. For what it's worth, many large Rust projects end up with one large core crate surrounded by other crates, so I think we're in good company. ↩