From 5bd55e0ac3c21a117ab4e5cbdaf479cf4496544d Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Mon, 20 Jul 2026 09:40:13 -0600 Subject: [PATCH] add dlls to everything.zig --- build.zig | 12 ++++++++++++ src/genzig.zig | 13 +++++++++++++ test/api_access.zig | 15 +++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 test/api_access.zig diff --git a/build.zig b/build.zig index 06b67ef..fcebdd8 100644 --- a/build.zig +++ b/build.zig @@ -200,6 +200,18 @@ pub fn build(b: *Build) !void { buildcommon.addExamples(b, optimize, win32, b.path("examples"), if (autoexit) .yes else .no); + { + const api_access_test = b.addTest(.{ + .root_module = b.createModule(.{ + .root_source_file = b.path("test/api_access.zig"), + .target = b.graph.host, + }), + }); + api_access_test.root_module.addImport("win32", win32); + // no need to run, compilation is sufficient + test_step.dependOn(&api_access_test.step); + } + // Exercise the Zig compiler's COM overload handling against the generated // Windows bindings for each arch. Run the exe when the target matches // the host; otherwise just compile-check. diff --git a/src/genzig.zig b/src/genzig.zig index 67ec29b..00d872d 100644 --- a/src/genzig.zig +++ b/src/genzig.zig @@ -511,6 +511,19 @@ fn generateEverythingModule(out_win32_dir: std.fs.Dir, root_module: *Module) !vo \\pub const zig = @import("zig.zig"); \\ )); + { + var dll_names = std.array_list.Managed(StringPool.Val).init(allocator); + defer dll_names.deinit(); + var it = dll_modules.keyIterator(); + while (it.next()) |name| try dll_names.append(name.*); + std.mem.sort(StringPool.Val, dll_names.items, {}, StringPool.asciiLessThanIgnoreCase); + try writer.print("\n// {} dll modules:\n", .{dll_names.items.len}); + for (dll_names.items) |name| { + const dm = dll_modules.get(name).?; + try writer.print("pub const {f} = @import(\"../win32.zig\").{s};\n", .{ name, dm.module.file.?.zig_name }); + } + } + try writer.writeAll("// end of dll modules\n\n"); for (redirects.keys(), redirects.values()) |name, target| switch (target) { .native => |def| try writer.print("pub const {s} = {s};\n", .{ name, def }), diff --git a/test/api_access.zig b/test/api_access.zig new file mode 100644 index 0000000..8c0af78 --- /dev/null +++ b/test/api_access.zig @@ -0,0 +1,15 @@ +const win32 = @import("win32"); + +comptime { + assertHasDecl(win32, "kernel32"); + assertHasDecl(win32.kernel32, "GetLastError"); + + assertHasDecl(win32.everything, "GetLastError"); + assertHasDecl(win32.everything, "kernel32"); + assertHasDecl(win32.everything.kernel32, "GetLastError"); +} + +fn assertHasDecl(comptime T: type, comptime name: []const u8) void { + if (!@hasDecl(T, name)) + @compileError("expected '" ++ @typeName(T) ++ "' to have decl '" ++ name ++ "'"); +}