Parse src.cpp rules at build time#61
Conversation
| run: ninja check-rules | ||
| working-directory: build | ||
|
|
||
| - name: Run unit tests |
There was a problem hiding this comment.
this change is weird. ninja should regen the files.
There was a problem hiding this comment.
Right, I will make the change to regen the files on ninja
However, I think it's better to run check-rules before unit tests because it's cheaper and catches the rules errors early
There was a problem hiding this comment.
Now that we run preprocess-{rust,cpp}-rules in ALL, check-rules does not need to delete then re-run preprocess-{rust,cpp}-rules, it can only do git diff
| list(APPEND cpp_rules_ir_outputs ${_out}) | ||
| endforeach() | ||
|
|
||
| add_custom_target("preprocess-cpp-rules" DEPENDS ${cpp_rules_ir_outputs}) |
There was a problem hiding this comment.
add ALL so it runs with the build
There was a problem hiding this comment.
Done. preprocess-cpp-rules has ALL
|
|
||
| add_custom_target("preprocess-cpp-rules" DEPENDS ${cpp_rules_ir_outputs}) | ||
|
|
||
| add_custom_target("preprocess-rust-rules" |
There was a problem hiding this comment.
this needs to be changed to use the same pattern as above, so it runs on build and iff some rust file changed.
There was a problem hiding this comment.
Done. preprocess-rust-rules now has a list on dependent files and runs on all + when a file changes
| USES_TERMINAL | ||
| ) | ||
|
|
||
| add_custom_target("check-rules" |
There was a problem hiding this comment.
move the delete here and call preprocess & then diff.
There was a problem hiding this comment.
Done. check-rules now contains deltee + call preprocess rust/cpp + diff
| ) | ||
|
|
||
| add_custom_target("preprocess-rust-rules" ALL | ||
| DEPENDS ${rust_rules_ir_outputs} install-rust-toolchain) |
There was a problem hiding this comment.
doesn't seem like it needs the rust toolchain here.
Fixes #55
Each src.cpp from the
rules/dir is now parsed at build time, instead of on every invocation of cpp2rust. This gives a 5-8x speedup in running the unit tests in the Github runner. Translating a simple unit test likeassert.cppwent down form 6 seconds to 0.1 seconds.The new
cpp-rule-preprocessorbinary fromcpp2rust/is responsible for parsing onesrc.cppat a time and to generate air_src.jsonin the same dir as thesrc.cppfile. The format of the json file is:f<n> / t<n>: { "to_string": <Mapper::ToString> }.All
src.cppfiles are parsed in parallel, CMakeLists takes care of that. Thecheck-rulestarget is now responsible for parsing the Rust rules and the C++ rules. The IR forsrc.cppis not indexed in git. The IR for the Rust rules remains unchanged.I ported the clang AST matcher form translation_rule.cpp into the new file cpp_rule_preprocessor.cpp. As a result, translation_rule.cpp is only responsible for loading IR JSONs.