zig rc
: Add COFF object file creation for CMake cross-compilation use case
#22813
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.
This is a fully optional PR that addresses a use case that will only be temporarily supported, since all
resinator
code and thezig rc
subcommand is likely to be removed when Windows resource compilation becomes a build system thing (see #22522 for context).Is what's described below worth the temporary addition of an extra thousand+ lines of code?
Note: This only touches files within
lib/compiler/resinator
In #22522 I said:
However, I didn't realize at the time that this only works because of the
-G Ninja
part. When not using Ninja as the generator, CMake adds a workaround for 'very long lists of object files' where it takes all object files and runs them throughar
to combine them into one archive:https://github.com/Kitware/CMake/blob/4a11fd8dde745789f66d6500412d7f56607e9218/Modules/Platform/Windows-GNU.cmake#L141-L158
This is a problem for the Windows resource use-case, because
ar
doesn't know how to deal with.res
files and so this object combining step fails with:Only the linker knows what to do with .res files (since it has its own
.res
->.obj
('cvtres') conversion mechanism). So, when using Ninja: this object file combining step is skipped, and the .res file gets passed to the linker and everyone is happy.When CMake thinks that it's using
windres
as the Windows resource compiler, it will pass-O coff
to windres which causes it to output a COFF object file instead of a.res
file, which means that thear
step can succeed because it's only working on actual object files.This commit gives
zig rc
the ability to output COFF object files directly whenever/:output-format coff
is provided as an argument. This effectively matches what happens when CMake useswindres
for resource compilation, but requires the argument to be provided explicitly.So, after this change, the following CMake cross-compilation use case will work, even when not using Ninja as the generator: