aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorRyan Liptak <squeek502@hotmail.com>2023-09-11 23:05:48 -0700
committerRyan Liptak <squeek502@hotmail.com>2023-09-17 03:09:58 -0700
commit0168ed7bf1c7fc5010fa82eaf33ed1b3af817709 (patch)
tree8b5491dde63f2cae8a53db61f1a6be777cb19fa8 /src/main.zig
parent4fac7a5263b9b14f63d2459f795ac9d2eee51c85 (diff)
downloadzig-0168ed7bf1c7fc5010fa82eaf33ed1b3af817709.tar.gz
zig-0168ed7bf1c7fc5010fa82eaf33ed1b3af817709.zip
rc compilation: Use MSVC includes if present, fallback to mingw
The include directories used when preprocessing .rc files are now separate from the target, and by default will use the system MSVC include paths if the MSVC + Windows SDK are present, otherwise it will fall back to the MinGW includes distributed with Zig. This default behavior can be overridden by the `-rcincludes` option (possible values: any (the default), msvc, gnu, or none). This behavior is useful because Windows resource files may `#include` files that only exist with in the MSVC include dirs (e.g. in `<MSVC install directory>/atlmfc/include` which can contain other .rc files, images, icons, cursors, etc). So, by defaulting to the `any` behavior (MSVC if present, MinGW fallback), users will by default get behavior that is most-likely-to-work. It also should be okay that the include directories used when compiling .rc files differ from the include directories used when compiling the main binary, since the .res format is not dependent on anything ABI-related. The only relevant differences would be things like `#define` constants being different values in the MinGW headers vs the MSVC headers, but any such differences would likely be a MinGW bug.
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
index f08e8f6433..2913ac2ea2 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -473,6 +473,11 @@ const usage_build_generic =
\\ --libc [file] Provide a file which specifies libc paths
\\ -cflags [flags] -- Set extra flags for the next positional C source files
\\ -rcflags [flags] -- Set extra flags for the next positional .rc source files
+ \\ -rcincludes=[type] Set the type of includes to use when compiling .rc source files
+ \\ any (default) Use msvc if available, fall back to gnu
+ \\ msvc Use msvc include paths (must be present on the system)
+ \\ gnu Use mingw include paths (distributed with Zig)
+ \\ none Do not use any autodetected include paths
\\
\\Link Options:
\\ -l[lib], --library [lib] Link against system library (only if actually used)
@@ -927,6 +932,7 @@ fn buildOutputType(
var symbol_wrap_set: std.StringArrayHashMapUnmanaged(void) = .{};
var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena);
var rc_source_files = std.ArrayList(Compilation.RcSourceFile).init(arena);
+ var rc_includes: Compilation.RcIncludes = .any;
var res_files = std.ArrayList(Compilation.LinkObject).init(arena);
var link_objects = std.ArrayList(Compilation.LinkObject).init(arena);
var framework_dirs = std.ArrayList([]const u8).init(arena);
@@ -1046,6 +1052,10 @@ fn buildOutputType(
if (mem.eql(u8, next_arg, "--")) break;
try extra_cflags.append(next_arg);
}
+ } else if (mem.eql(u8, arg, "-rcincludes")) {
+ rc_includes = parseRcIncludes(args_iter.nextOrFatal());
+ } else if (mem.startsWith(u8, arg, "-rcincludes=")) {
+ rc_includes = parseRcIncludes(arg["-rcincludes=".len..]);
} else if (mem.eql(u8, arg, "-rcflags")) {
extra_rcflags.shrinkRetainingCapacity(0);
while (true) {
@@ -3369,6 +3379,7 @@ fn buildOutputType(
.symbol_wrap_set = symbol_wrap_set,
.c_source_files = c_source_files.items,
.rc_source_files = rc_source_files.items,
+ .rc_includes = rc_includes,
.link_objects = link_objects.items,
.framework_dirs = framework_dirs.items,
.frameworks = resolved_frameworks.items,
@@ -6532,3 +6543,8 @@ fn accessFrameworkPath(
return false;
}
+
+fn parseRcIncludes(arg: []const u8) Compilation.RcIncludes {
+ return std.meta.stringToEnum(Compilation.RcIncludes, arg) orelse
+ fatal("unsupported rc includes type: '{s}'", .{arg});
+}