Add --with-conditional to wrap single-file output in a preprocessor conditional#772
Merged
tannergooding merged 1 commit intoJul 14, 2026
Conversation
…onditional Wraps single-file C# output in a leading '#if <symbol>' and trailing '#endif' so consumers that can't conditionally exclude files at the project level (e.g. Unity) can generate variants and select one via a build symbol. XML output is unaffected. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.
There's no way today to wrap a generated file in a preprocessor conditional.
--headerFileprepends a fixed header, but nothing emits a leading#if/trailing#endif.This adds
--with-conditional <symbol>/-wcondwhich wraps single-file C# output in a leading#if <symbol>and a trailing#endif:The motivating scenario (#365) is Unity, where files can't be conditionally excluded at the project level, so the consumer generates each struct variant separately and selects one via a build symbol. XML output is intentionally unaffected.
Scoped to single-file C# output on purpose, which is exactly the run-once-per-variant flow in the issue. Wrapping multi-file output is a larger design — you'd want the symbol to vary per file (a remap), where-as a single global symbol is trivial. Left as a follow-up if someone actually needs the multi-file variant.
Adds a golden test (
ConditionalOutputTest).Fixes #365