Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions src/genzig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
15 changes: 15 additions & 0 deletions test/api_access.zig
Original file line number Diff line number Diff line change
@@ -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 ++ "'");
}
Loading