zig/lib
Ryan Liptak a502301b5e zig rc: Add COFF object file creation for CMake cross-compilation use case
In #22522 I said:

> RC="zig rc" will now work in combination with zig cc and CMake. Here's an example of cross-compiling a simple Windows GUI CMake project
>
>    $ RC="zig rc" CC="zig cc --target=x86_64-windows-gnu" cmake .. -DCMAKE_SYSTEM_NAME=Windows -G Ninja

However, I didn't realize that the time that this only works because of the `-G Ninja` part. When not using Ninja as the build tool, CMake adds a workaround for 'very long lists of object files' where it takes all object files and runs them through `ar` to combine them into one archive:

4a11fd8dde/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:

    unknown file type: foo.rc.res

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.

Note: When CMake thinks that its 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 the `ar` 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 when `/:output-format coff` is provided as an argument. This effectively matches what happens when CMake uses `windres` 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:

    RC="zig rc /:output-format coff" CC="zig cc --target=x86_64-windows-gnu" cmake .. -DCMAKE_SYSTEM_NAME=Windows
2025-02-22 21:21:30 -05:00
..
compiler zig rc: Add COFF object file creation for CMake cross-compilation use case 2025-02-22 21:21:30 -05:00
compiler_rt zig build fmt 2025-02-22 17:09:20 -08:00
docs zig build fmt 2025-02-22 17:09:20 -08:00
fuzzer/web Replace deprecated default initializations with decl literals 2024-09-12 16:01:23 +01:00
include zig cc: Remove headers related to GPU offload. 2024-12-16 04:36:57 +01:00
init fuzzer: write inputs to shared memory before running 2025-02-11 13:39:20 -08:00
libc musl: Fix typo in m68k clone() assembly. 2025-02-22 08:13:44 +01:00
libcxx libcxx: Update to LLVM 19.1.0. 2024-09-19 18:20:22 -07:00
libcxxabi libcxxabi: Update to LLVM 19. 2024-09-19 18:20:21 -07:00
libunwind libunwind: Fix compilation for the x32 ABI. 2024-11-18 17:43:54 +01:00
std std.heap.DebugAllocator: default wasm to 64K page size 2025-02-22 21:06:00 -05:00
tsan tsan: Update to LLVM 19.1.0. 2024-09-24 23:58:21 -07:00
c.zig c: Include Os.Tag.other in the list of freestanding OSs. 2024-11-08 14:56:55 +01:00
compiler_rt.zig x86_64: rewrite scalar and vector int @divTrunc 2025-02-15 03:45:21 -05:00
fuzzer.zig fix -fsanitize-coverage-trace-pc-guard and fuzzer support for C compile units 2025-02-21 06:06:26 +01:00
zig.h zig.h: Add new zig_gcc macro to indicate GCC. 2025-02-16 00:21:51 +01:00