Skip to content

Commit

Permalink
render runtime crates from templates dynamically (#962)
Browse files Browse the repository at this point in the history
Closes #863

- The entirety of "runtime" codegen is now following a strict MVC model,
and the source code is rendered from the same model object. We should be
able to further improve/refactor this model object in #638
- Complex model construction can be strongly-typed in Rust, while
rendering is left to templates, as they are much easier to read and
modify, and also have powerful macros/imports/callbacks, etc...
- I also (partially) improved the DX when working with templates in
terminal, by rendering their errors as an `ariadne` report, with
best-guess source location in the template. A temporary workaround
waiting for Keats/tera#885
- Now both stubs and output crates are rendered from the same source
templates, removing a few internal hacks and the need for
`![allow(dead_code)]` and `![allow(unused)]` everywhere (will follow up
on this cleanup separately).
- We no longer have to maintain explicit paths and copy files around in
the code generator. All templates generate their output file relative to
their location, which means we can split and refactor code into as many
templates/sub-modules as needed, following standard rust idioms.
  • Loading branch information
OmarTawfik authored May 14, 2024
1 parent 66ed102 commit 874039b
Show file tree
Hide file tree
Showing 193 changed files with 3,273 additions and 1,805 deletions.
47 changes: 39 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ members = [
"crates/codegen/language/internal_macros",
"crates/codegen/language/macros",
"crates/codegen/language/tests",
"crates/codegen/parser/generator",
"crates/codegen/parser/runtime",
"crates/codegen/runtime/cargo",
"crates/codegen/runtime/generator",
"crates/codegen/runtime/node_addon",
"crates/codegen/runtime/npm",
"crates/codegen/spec",
"crates/codegen/testing",

"crates/infra/cli",
"crates/infra/utils",

Expand Down Expand Up @@ -47,10 +50,13 @@ codegen_language_definition = { path = "crates/codegen/language/definition" }
codegen_language_internal_macros = { path = "crates/codegen/language/internal_macros" }
codegen_language_macros = { path = "crates/codegen/language/macros" }
codegen_language_tests = { path = "crates/codegen/language/tests" }
codegen_parser_generator = { path = "crates/codegen/parser/generator" }
codegen_parser_runtime = { path = "crates/codegen/parser/runtime" }
codegen_runtime_cargo = { path = "crates/codegen/runtime/cargo" }
codegen_runtime_generator = { path = "crates/codegen/runtime/generator" }
codegen_runtime_node_addon = { path = "crates/codegen/runtime/node_addon" }
codegen_runtime_npm = { path = "crates/codegen/runtime/npm" }
codegen_spec = { path = "crates/codegen/spec" }
codegen_testing = { path = "crates/codegen/testing" }

infra_cli = { path = "crates/infra/cli" }
infra_utils = { path = "crates/infra/utils" }

Expand Down
1 change: 0 additions & 1 deletion crates/codegen/language/tests/src/fail/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ fn run_trybuild() {
let tests = FileWalker::from_directory(crate_dir)
.find(["src/fail/**/test.rs"])
.unwrap()
.into_iter()
.collect::<Vec<_>>();

assert!(!tests.is_empty(), "No tests found.");
Expand Down
11 changes: 0 additions & 11 deletions crates/codegen/parser/generator/src/lib.rs

This file was deleted.

36 changes: 0 additions & 36 deletions crates/codegen/parser/generator/src/typescript_generator.rs

This file was deleted.

27 changes: 0 additions & 27 deletions crates/codegen/parser/runtime/src/lib.rs

This file was deleted.

This file was deleted.

Loading

0 comments on commit 874039b

Please sign in to comment.