oxidecomputer / idolatry

An experimental IPC interface definition language for Hubris.
Mozilla Public License 2.0
17 stars 11 forks source link

introduce `Generator` type for configuring codegen #42

Closed hawkw closed 8 months ago

hawkw commented 8 months ago

Currently, all code-generation in Idol is performed by free functions. This is problematic for adding new configuration parameters to the API, as adding an additional parameter to these functions is a breaking change, requiring "every build script in Hubris" to be updated. On the other hand, the current API surface already has a bunch of functions that essentially call another function with one parameter excluded, such as build_server_support and build_restricted_server_support; adding new parameters which are defaulted in this manner gets unwieldy very fast.

Therefore, this commit introduces a Generator type, which serves as a builder pattern for code generation settings. The bodies of the existing free functions have been moved to methods on Generator, with the free functions now being thin wrappers around Generator::default().<the_function>(). This way, we can freely add any number of new configuration options to the Generator struct, without having to worry about breaking all callers of the code generation.

Right now the only parameter configured by Generator is whether or not to run prettyplease formatting on the generated code. In the future, it will also be used to configure automatic counter generation (this change was factored out from PR #41 to make that diff easier to review).