Source code generation policy #994
Replies: 1 comment 1 reply
-
Personally I prefer the out-of-tree approach. But I've been significantly jaded by CMake's handling of such things; where it regularly runs afoul of similar issues with rebuilding and miscompiling. If we are concerned with specific generated code audits e.g. rust files that we manually write our in the build script, then we could experiment auditing this by moving the format string into its own separate file. This file can then be ^^ haven't actually tried this; but I don't see why it wouldn't simply work :) |
Beta Was this translation helpful? Give feedback.
-
We generate code in a few
build.rs
across our various repos. Our current policy has been to generate this code in-tree, allowing us to audit this as part of code reviews in PRs.General guidelines
This policy does go against the common guideline that code generation should be done out-of-tree and never checked into source control. This is also the policy that the
Rust
reference suggests:Why revisit this
Our policy has bitten us recently. Additional code generation was added to
build.rs
, and the generated files were added to thererun-if-changed
pragma (which is perfectly valid). However this caused the build script to always trigger, causing a full recompile each time. This was patched in #991, but I have to admit I still don't fully understand why it was happening. Probably it didn't like a trigger of a generated file; though that feels like it should be allowed to prevent accidental mutation post-generation.Pros/Cons of current policy
Positives:
Negatives:
Beta Was this translation helpful? Give feedback.
All reactions