cli: Adapt default Makefile/CMakeLists for repos not storing grammar.json#4646
Merged
ObserverOfTime merged 3 commits intotree-sitter:masterfrom Aug 2, 2025
Merged
cli: Adapt default Makefile/CMakeLists for repos not storing grammar.json#4646ObserverOfTime merged 3 commits intotree-sitter:masterfrom
ObserverOfTime merged 3 commits intotree-sitter:masterfrom
Conversation
…json This is a new version of tree-sitter#4580, to make it easier not to include tree-sitter generated files in grammar repos, as outlined in tree-sitter#930. This makes it possible to run `make` or `cmake --build .` in grammar repos where `grammar.json` hasn't been included, and still get the parser compilation to work. The build scripts still work if `grammar.json` is included.
Member
ObserverOfTime
left a comment
There was a problem hiding this comment.
Please add migrations to init.rs.
Member
Maybe we can use a variable ( |
Contributor
Author
|
I've added migrations and tested them on a couple of grammars with
I don't know how to do that, and am not sure if it's worth it if people need to enable a specific variable for it. I propose to stick with the two-stage generation. People can also edit the Makefile if they prefer a different process, I would say. |
Member
ifdef TS_GENERATE_ALL
$(PARSER): grammar.js
$(TS) generate $^
else
$(SRC_DIR)/grammar.json: grammar.js
$(TS) generate --stage=json $^
$(PARSER): $(SRC_DIR)/grammar.json
$(TS) generate --stage=parser $^
endifSimilarly for CMake, but as you said it's probably not worth it. |
Co-authored-by: ObserverOfTime <chronobserver@disroot.org>
ObserverOfTime
approved these changes
Aug 1, 2025
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 is a new version of #4580, to make it easier not to include tree-sitter generated files in grammar repos, as outlined in #930.
This makes it possible to run
makeorcmake --build .in grammar repos wheregrammar.jsonhasn't been included, and still get the parser compilation to work. The build scripts still work ifgrammar.jsonis included.When
grammar.jsonis present, this gives:When only
grammar.jsis present, this gives:(and similarly for
cmake --build .)I don't know if it's possible to encourage
maketo just runtree-sitter generate grammar.jsin this case, generating all files in one go. The rules with grouped targets seem to be theoretically designed for that, but I couldn't get it to work without overriding the more granular rules. I think it could also work without this feature, as the overhead of starting two processes shouldn't be significant compared to the complexity of the generation work.