Remove Plugin, Commit Generated Code #621
Closed
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.
Yes, I know. Committing generated code is not regarded as good practice (and generally I agree).
However, I believe that this situation is not the normal generated-code scenario. Furthermore, there are some other compelling reasons to do it.
TL;DR
The idealist in me loves the plugin, and thinks that it is definitely the right approach.
The pragmatist thinks that until Swift works a bit better, especially on Windows, checking in the generated code is more sensible.
This Time It's Different, Honest
In my mind, the normal scenario is:
Another common argument against checking in generated code is that it has the potential to mess up the diff of otherwise unrelated changes.
This situation is different because:
Other Positive Reasons To Do This
Faster Build Times
Swift doesn't have to check to see if it needs to run the generator each time we build.
Although in theory this check should be fairly fast, and the generator should only run once until you do a clean build, in practice the check seems to take a noticeable amount of time, and a full re-run of the generator seems to happen quite often. This is probably down to bugs in SwiftPM, but we can't fix those 🤷.
Much Faster Windows Build Times
Doing this, we also get around the ugly single-file hack for Windows (due to it not being able to cope with more than 32Kb of arguments to the generator tool).
The Swift 6 toolchain seems to completely die when trying to compile the single-file on Windows.
Removing this makes the Windows library build in a more reasonable time on my machine. I wouldn't say it's fast, but it does actually finish rather than just locking up forever.
Easier Hacking
For what it's worth, this also makes it easier to hack on the generated code. This could be useful for prototyping changes to the generator; rather than having to implement them in the generator, we can just modify a single generated file and test it in isolation.
Avoid SwiftPM Generator Bugs
Like this one, which is a massive PITA: swiftlang/swift-package-manager#7930