Skip to content

Commit fcd9c4c

Browse files
committed
windows: Add support for Zig's builtin rc compiler
1 parent a3437c4 commit fcd9c4c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

docs/markdown/snippets/zig-rc.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Added support for Zig's builtin Windows Resource Compiler
2+
3+
Using `zig rc` as `windres` no longer triggers the error `Could not determine
4+
type of Windows resource compiler`.
5+
6+
Note: Zig 0.14.1 and later have modified their CLI for Meson compatibility, so
7+
this change is only relevant when using `zig rc` versions earlier than 0.14.1.

mesonbuild/modules/windows.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def _find_resource_compiler(self, state: 'ModuleState') -> T.Tuple[ExternalProgr
8686
raise MesonException('Could not find Windows resource compiler')
8787

8888
for (arg, match, rc_type) in [
89+
# Zig >=0.14.1 is also matched by the regex below.
8990
('/?', '^.*Microsoft.*Resource Compiler.*$', ResourceCompilerType.rc),
9091
('/?', 'LLVM Resource Converter.*$', ResourceCompilerType.rc),
9192
('--version', '^.*GNU windres.*$', ResourceCompilerType.windres),
@@ -98,7 +99,15 @@ def _find_resource_compiler(self, state: 'ModuleState') -> T.Tuple[ExternalProgr
9899
self._rescomp = (rescomp, rc_type)
99100
break
100101
else:
101-
raise MesonException('Could not determine type of Windows resource compiler')
102+
# Zig <0.14.1 prints its info to stderr, so we'll handle it separately.
103+
_, _, e = mesonlib.Popen_safe(rescomp.get_command() + ['/?'])
104+
# The string below should be indicative of a resinator rc compiler
105+
# (which includes zig rc).
106+
if re.search('^Supported Win32 RC Options:$', e, re.MULTILINE):
107+
mlog.log('Windows resource compiler: Zig <0.14.1/restinator Resource Compiler')
108+
self._rescomp = (rescomp, ResourceCompilerType.rc)
109+
else:
110+
raise MesonException('Could not determine type of Windows resource compiler')
102111

103112
return self._rescomp
104113

0 commit comments

Comments
 (0)