@@ -90,6 +90,14 @@ is_linking_libc: bool,
90
90
is_linking_libcpp : bool ,
91
91
vcpkg_bin_path : ? []const u8 = null ,
92
92
93
+ // keep in sync with src/Compilation.zig:RcIncludes
94
+ /// Behavior of automatic detection of include directories when compiling .rc files.
95
+ /// any: Use MSVC if available, fall back to MinGW.
96
+ /// msvc: Use MSVC include paths (must be present on the system).
97
+ /// gnu: Use MinGW include paths (distributed with Zig).
98
+ /// none: Do not use any autodetected include paths.
99
+ rc_includes : enum { any , msvc , gnu , none } = .any ,
100
+
93
101
installed_path : ? []const u8 ,
94
102
95
103
/// Base address for an executable image.
@@ -221,13 +229,34 @@ pub const CSourceFile = struct {
221
229
}
222
230
};
223
231
232
+ pub const RcSourceFile = struct {
233
+ file : LazyPath ,
234
+ /// Any option that rc.exe accepts will work here, with the exception of:
235
+ /// - `/fo`: The output filename is set by the build system
236
+ /// - Any MUI-related option
237
+ /// https://learn.microsoft.com/en-us/windows/win32/menurc/using-rc-the-rc-command-line-
238
+ ///
239
+ /// Implicitly defined options:
240
+ /// /x (ignore the INCLUDE environment variable)
241
+ /// /D_DEBUG or /DNDEBUG depending on the optimization mode
242
+ flags : []const []const u8 = &.{},
243
+
244
+ pub fn dupe (self : RcSourceFile , b : * std.Build ) RcSourceFile {
245
+ return .{
246
+ .file = self .file .dupe (b ),
247
+ .flags = b .dupeStrings (self .flags ),
248
+ };
249
+ }
250
+ };
251
+
224
252
pub const LinkObject = union (enum ) {
225
253
static_path : LazyPath ,
226
254
other_step : * Compile ,
227
255
system_lib : SystemLib ,
228
256
assembly_file : LazyPath ,
229
257
c_source_file : * CSourceFile ,
230
258
c_source_files : * CSourceFiles ,
259
+ win32_resource_file : * RcSourceFile ,
231
260
};
232
261
233
262
pub const SystemLib = struct {
@@ -910,6 +939,18 @@ pub fn addCSourceFile(self: *Compile, source: CSourceFile) void {
910
939
source .file .addStepDependencies (& self .step );
911
940
}
912
941
942
+ pub fn addWin32ResourceFile (self : * Compile , source : RcSourceFile ) void {
943
+ // Only the PE/COFF format has a Resource Table, so for any other target
944
+ // the resource file is just ignored.
945
+ if (self .target .getObjectFormat () != .coff ) return ;
946
+
947
+ const b = self .step .owner ;
948
+ const rc_source_file = b .allocator .create (RcSourceFile ) catch @panic ("OOM" );
949
+ rc_source_file .* = source .dupe (b );
950
+ self .link_objects .append (.{ .win32_resource_file = rc_source_file }) catch @panic ("OOM" );
951
+ source .file .addStepDependencies (& self .step );
952
+ }
953
+
913
954
pub fn setVerboseLink (self : * Compile , value : bool ) void {
914
955
self .verbose_link = value ;
915
956
}
@@ -1358,6 +1399,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1358
1399
try transitive_deps .add (self .link_objects .items );
1359
1400
1360
1401
var prev_has_cflags = false ;
1402
+ var prev_has_rcflags = false ;
1361
1403
var prev_search_strategy : SystemLib.SearchStrategy = .paths_first ;
1362
1404
var prev_preferred_link_mode : std.builtin.LinkMode = .Dynamic ;
1363
1405
@@ -1500,6 +1542,24 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1500
1542
try zig_args .append (b .pathFromRoot (file ));
1501
1543
}
1502
1544
},
1545
+
1546
+ .win32_resource_file = > | rc_source_file | {
1547
+ if (rc_source_file .flags .len == 0 ) {
1548
+ if (prev_has_rcflags ) {
1549
+ try zig_args .append ("-rcflags" );
1550
+ try zig_args .append ("--" );
1551
+ prev_has_rcflags = false ;
1552
+ }
1553
+ } else {
1554
+ try zig_args .append ("-rcflags" );
1555
+ for (rc_source_file .flags ) | arg | {
1556
+ try zig_args .append (arg );
1557
+ }
1558
+ try zig_args .append ("--" );
1559
+ prev_has_rcflags = true ;
1560
+ }
1561
+ try zig_args .append (rc_source_file .file .getPath (b ));
1562
+ },
1503
1563
}
1504
1564
}
1505
1565
@@ -1897,6 +1957,11 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1897
1957
}
1898
1958
}
1899
1959
1960
+ if (self .rc_includes != .any ) {
1961
+ try zig_args .append ("-rcincludes" );
1962
+ try zig_args .append (@tagName (self .rc_includes ));
1963
+ }
1964
+
1900
1965
try addFlag (& zig_args , "valgrind" , self .valgrind_support );
1901
1966
try addFlag (& zig_args , "each-lib-rpath" , self .each_lib_rpath );
1902
1967
0 commit comments