Build system: Allow specifying Win32 resource include paths using LazyPath

Adds an `include_paths` field to RcSourceFile that takes a slice of LazyPaths. The paths are resolved and subsequently appended to the -rcflags as `/I <resolved path>`.

This fixes an accidental regression from https://github.com/ziglang/zig/pull/19174. Before that PR, all Win32 resource compilation would inherit the CC flags (via `addCCArgs`), which included things like include directories. After that PR, though, that is no longer the case.

However, this commit intentionally does not restore the previous behavior (inheriting the C include paths). Instead, each .rc file will need to have its include paths specified directly and the include paths only apply to one particular resource script. This allows more fine-grained control and has less potentially surprising behavior (at the cost of some convenience).

Closes #19605
This commit is contained in:
Ryan Liptak
2024-05-02 18:57:34 -07:00
committed by Andrew Kelley
parent f2110b0c0d
commit ddde99bdfa
4 changed files with 29 additions and 5 deletions

View File

@@ -10,11 +10,13 @@ pub fn build(b: *std.Build) void {
.abi = .gnu,
});
add(b, b.host, .any, test_step);
add(b, target, .any, test_step);
const generated_h_step = b.addWriteFile("generated.h", "#define GENERATED_DEFINE \"foo\"");
add(b, b.host, .gnu, test_step);
add(b, target, .gnu, test_step);
add(b, b.host, .any, test_step, generated_h_step);
add(b, target, .any, test_step, generated_h_step);
add(b, b.host, .gnu, test_step, generated_h_step);
add(b, target, .gnu, test_step, generated_h_step);
}
fn add(
@@ -22,6 +24,7 @@ fn add(
target: std.Build.ResolvedTarget,
rc_includes: enum { any, gnu },
test_step: *std.Build.Step,
generated_h_step: *std.Build.Step.WriteFile,
) void {
const exe = b.addExecutable(.{
.name = "zig_resource_test",
@@ -32,6 +35,9 @@ fn add(
exe.addWin32ResourceFile(.{
.file = b.path("res/zig.rc"),
.flags = &.{"/c65001"}, // UTF-8 code page
.include_paths = &.{
.{ .generated = &generated_h_step.generated_directory },
},
});
exe.rc_includes = switch (rc_includes) {
.any => .any,

View File

@@ -1,3 +1,7 @@
// This include file is generated via build.zig, and it #defines GENERATED_DEFINE
#include "generated.h"
FOO RCDATA { GENERATED_DEFINE }
#define ICO_ID 1
// Nothing from windows.h is used in this .rc file,