Commit 01fc6a05ef

Ryan Liptak <squeek502@hotmail.com>
2023-09-06 08:33:38
Add a standalone test for Windows resource file compilation
1 parent 28f6559
Changed files (7)
test
test/standalone/windows_resources/res/sub/sub.rc
@@ -0,0 +1,1 @@
+2 RCDATA hello.bin
test/standalone/windows_resources/res/hello.bin
@@ -0,0 +1,1 @@
+abcdefg
\ No newline at end of file
test/standalone/windows_resources/res/zig.ico
Binary file
test/standalone/windows_resources/res/zig.rc
@@ -0,0 +1,40 @@
+#define ICO_ID 1
+
+// Nothing from windows.h is used in this .rc file,
+// but it's common to include it within a .rc file
+// so this makes sure that it can be found on
+// all platforms.
+#include "windows.h"
+
+ICO_ID ICON "zig.ico"
+
+1 VERSIONINFO
+ FILEVERSION 1L,0,0,2
+ PRODUCTVERSION 1,0,0,1
+ FILEFLAGSMASK 0x3fL
+ FILEFLAGS 0x1L
+ FILEOS 0x4L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "040904e4"
+        BEGIN
+            VALUE "CompanyName", "Zig"
+            VALUE "FileDescription", "My cool zig program"
+            VALUE "FileVersion", "1.0.0.1"
+            VALUE "InternalName", "zig-ico.exe"
+            VALUE "LegalCopyright", "(c) no one"
+            VALUE "OriginalFilename", "zig-ico.exe"
+            VALUE "ProductName", "Zig but with an icon"
+            VALUE "ProductVersion", "1.0.0.1"
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x409, 1252
+    END
+END
+
+#include "sub/sub.rc"
test/standalone/windows_resources/build.zig
@@ -0,0 +1,33 @@
+const std = @import("std");
+
+pub fn build(b: *std.Build) void {
+    const test_step = b.step("test", "Test it");
+    b.default_step = test_step;
+
+    const native_target: std.zig.CrossTarget = .{};
+    const cross_target = .{
+        .cpu_arch = .x86_64,
+        .os_tag = .windows,
+        .abi = .gnu,
+    };
+
+    add(b, native_target, test_step);
+    add(b, cross_target, test_step);
+}
+
+fn add(b: *std.Build, target: std.zig.CrossTarget, test_step: *std.Build.Step) void {
+    const exe = b.addExecutable(.{
+        .name = "zig_resource_test",
+        .root_source_file = .{ .path = "main.zig" },
+        .target = target,
+        .optimize = .Debug,
+    });
+    exe.addWin32ResourceFile(.{
+        .file = .{ .path = "res/zig.rc" },
+        .flags = &.{"/c65001"}, // UTF-8 code page
+    });
+
+    _ = exe.getEmittedBin();
+
+    test_step.dependOn(&exe.step);
+}
test/standalone/windows_resources/main.zig
@@ -0,0 +1,5 @@
+const std = @import("std");
+
+pub fn main() !void {
+    std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
+}
test/standalone.zig
@@ -194,6 +194,10 @@ pub const build_cases = [_]BuildCase{
         .build_root = "test/standalone/load_dynamic_library",
         .import = @import("standalone/load_dynamic_library/build.zig"),
     },
+    .{
+        .build_root = "test/standalone/windows_resources",
+        .import = @import("standalone/windows_resources/build.zig"),
+    },
     .{
         .build_root = "test/standalone/windows_spawn",
         .import = @import("standalone/windows_spawn/build.zig"),