zig icon indicating copy to clipboard operation
zig copied to clipboard

Add support for compiling .rc files into Windows .res files

Open leximayfield opened this issue 6 years ago • 5 comments

I tried to compile an old Win32 C program with a build.zig and didn't see an obvious happy path to compile an .rc file into a .res file and add it to the build. These seem to be somewhat common in Win32 projects, so I think that if the intention is to support gradually converting Win32 C programs to Zig, being able to easily compile resource files and add them to the target should be part of that.

LLVM comes with llvm-rc, and it worked for me, but unlike windres and whatever the MSVC resource compiler is, llvm-rc doesn't run the preprocessor against the source file, so a preprocessing step with clang -E is also necessary. However, once you get a .res file out of it, it can be added to the build with addObjectFile.

leximayfield avatar Nov 16 '19 17:11 leximayfield

For now (0.5.0+652efe38b), using addObjectFile breaks debugging in Visual Studio Code with C/C++ (ms-vscode.cpptools) extension. I am not sure why, but I'll be happy to provide any information.

adontz avatar Feb 21 '20 21:02 adontz

LLVM has a mostly complete RC compiler that we could port to Zig and improve compatiblity https://github.com/llvm/llvm-project/tree/master/llvm/tools/llvm-rc

mlarouche avatar Feb 21 '20 21:02 mlarouche

There are some free standalone editors (http://www.resedit.net/, http://angusj.com/resourcehacker/) so just being able to compile rc files will be good enough experience.

adontz avatar Feb 22 '20 08:02 adontz

The typical tool for this is binutils' windres. There's a port of that to llvm's separate tools here: https://github.com/mstorsjo/llvm-mingw/blob/master/wrappers/windres-wrapper.c . It essentially pipes llvm-rc to llvm-cvtres. Having something like that available as a zig subcommand would allow zig to be used as a drop-in compiler suite for win32 C development and more.

zx2c4 avatar Feb 18 '21 23:02 zx2c4

I've started working on this here: https://github.com/squeek502/resinator

squeek502 avatar Nov 01 '22 21:11 squeek502