authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-09-17 13:09:16-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2023-09-17 13:09:16-07:00
log471f279cd621cef7c826fe27f1f8d0c585cc76e2
treec82e6464d5f39a5b08f48472eff9f776ff8ef413
parent0168ed7bf1c7fc5010fa82eaf33ed1b3af817709

Fix rc preprocessing when using the MinGW includes and targeting the GNU abi

Also update the standalone test so that this failure would have been detected on any host system.

2 files changed, 23 insertions(+), 3 deletions(-)

src/Compilation.zig+13
......@@ -4513,6 +4513,19 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
45134513 "-fms-compatibility", // Allow things like "header.h" to be resolved relative to the 'root' .rc file, among other things
45144514 "-DRC_INVOKED", // https://learn.microsoft.com/en-us/windows/win32/menurc/predefined-macros
45154515 });
4516 // Using -fms-compatibility and targeting the gnu abi interact in a strange way:
4517 // - Targeting the GNU abi stops _MSC_VER from being defined
4518 // - Passing -fms-compatibility stops __GNUC__ from being defined
4519 // Neither being defined is a problem for things like things like MinGW's
4520 // vadefs.h, which will fail during preprocessing if neither are defined.
4521 // So, when targeting the GNU abi, we need to force __GNUC__ to be defined.
4522 //
4523 // TODO: This is a workaround that should be removed if possible.
4524 if (comp.getTarget().isGnu()) {
4525 // This is the same default gnuc version that Clang uses:
4526 // https://github.com/llvm/llvm-project/blob/4b5366c9512aa273a5272af1d833961e1ed156e7/clang/lib/Driver/ToolChains/Clang.cpp#L6738
4527 try argv.append("-fgnuc-version=4.2.1");
4528 }
45164529 for (options.extra_include_paths.items) |extra_include_path| {
45174530 try argv.append("--include-directory");
45184531 try argv.append(extra_include_path);
test/standalone/windows_resources/build.zig+10-3
......@@ -11,11 +11,14 @@ pub fn build(b: *std.Build) void {
1111 .abi = .gnu,
1212 };
1313
14 add(b, native_target, test_step);
15 add(b, cross_target, test_step);
14 add(b, native_target, .any, test_step);
15 add(b, cross_target, .any, test_step);
16
17 add(b, native_target, .gnu, test_step);
18 add(b, cross_target, .gnu, test_step);
1619}
1720
18fn add(b: *std.Build, target: std.zig.CrossTarget, test_step: *std.Build.Step) void {
21fn add(b: *std.Build, target: std.zig.CrossTarget, rc_includes: enum { any, gnu }, test_step: *std.Build.Step) void {
1922 const exe = b.addExecutable(.{
2023 .name = "zig_resource_test",
2124 .root_source_file = .{ .path = "main.zig" },
......@@ -26,6 +29,10 @@ fn add(b: *std.Build, target: std.zig.CrossTarget, test_step: *std.Build.Step) v
2629 .file = .{ .path = "res/zig.rc" },
2730 .flags = &.{"/c65001"}, // UTF-8 code page
2831 });
32 exe.rc_includes = switch (rc_includes) {
33 .any => .any,
34 .gnu => .gnu,
35 };
2936
3037 _ = exe.getEmittedBin();
3138