Add an opt-in to write the generated lexer and parser to obj - #255
Merged
Merged
Conversation
MSBuild only honours FileWrites under the output or intermediate folder, so the registration that was meant to let `dotnet clean` remove the generated .fs and .fsi never took effect: by default they land next to the grammar, outside both folders. FsLexYaccOutputToIntermediate=true now defaults FsLexOutputFolder and FsYaccOutputFolder to IntermediateOutputPath, so clean removes the generated sources and they stay out of the source tree. Projects reference them as $(FsLexOutputFolder)Lexer.fs and $(FsYaccOutputFolder)Parser.fs(i). Because every existing project references Parser.fs next to Parser.fsy, this is opt-in for now and becomes the default in the next major version. The defaults are resolved at evaluation time so the properties can be used in Compile items, which requires the targets to be imported after the SDK targets, as the NuGet package does. A project that imports the targets file from its body would otherwise get Compile items that silently point next to the grammar, so FsLexYaccCheckOutputFolders fails the build with an error that explains the cause and the fix. JsonLexAndYaccExample opts in to cover the new mode, and imports the SDK explicitly so the targets evaluate the way a package consumer sees them. LexAndYaccMiniProject keeps the default so both modes stay covered. Release as 12.2.0. Closes fsprojects#247
|
You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool. What Enabling Code Scanning Means:
For more information about GitHub Code Scanning, check out the documentation. |
baronfel
approved these changes
Sep 24, 2026
baronfel
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, and as we discussed I would just go ahead and change defaults to emit the files to the Intermediate locations. MSBuild Targets are (by convention) expected to not pollute the source tree because it can lead to circularity and all kinds of fun, subtle issues during the build.
MSBuild targets are expected to stay out of the source tree, since writing there invites circularity and subtle build issues. FsLexOutputFolder and FsYaccOutputFolder now default to IntermediateOutputPath, so the generated .fs and .fsi stay out of the source tree and `dotnet clean` removes them. FsLexYaccOutputToIntermediate=false keeps the previous behaviour of writing them next to the grammar. A project written for the old default compiles Parser.fs next to Parser.fsy. After the upgrade that copy is no longer regenerated, so the build would silently keep compiling a stale file. FsLexYaccCheckOutputFolders now fails the build in that case and explains how to reference the generated files or opt out. Its existing error for importing the targets before the SDK now also points at the opt-out. JsonLexAndYaccExample covers the new default and LexAndYaccMiniProject opts out, so both modes stay covered. Release as 13.0.0.
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.
MSBuild only honours FileWrites under the output or intermediate folder, so the registration that was meant to let
dotnet cleanremove the generated .fs and .fsi never took effect: by default they land next to the grammar, outside both folders.FsLexYaccOutputToIntermediate=true now defaults FsLexOutputFolder and FsYaccOutputFolder to IntermediateOutputPath, so clean removes the generated sources and they stay out of the source tree. Projects reference them as$(FsLexOutputFolder)Lexer.fs and $ (FsYaccOutputFolder)Parser.fs(i). Because every existing project references Parser.fs next to Parser.fsy, this is opt-in for now and becomes the default in the next major version.
The defaults are resolved at evaluation time so the properties can be used in Compile items, which requires the targets to be imported after the SDK targets, as the NuGet package does. A project that imports the targets file from its body would otherwise get Compile items that silently point next to the grammar, so FsLexYaccCheckOutputFolders fails the build with an error that explains the cause and the fix.
JsonLexAndYaccExample opts in to cover the new mode, and imports the SDK explicitly so the targets evaluate the way a package consumer sees them. LexAndYaccMiniProject keeps the default so both modes stay covered.
Release as 12.2.0.
Closes #247