Skip to content
Open
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
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ Autogenerated Zig bindings for Win32 using https://github.com/marlersoft/win32js

## How to generate the Windows Zig bindings

First, clone the zigwin32 repo from the root of this repository to provide a location for the generated files:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these changes to the README are correct. Here's how you could build zigwin32gen from scratch:

$ git clone https://github.com/marlersoft/zigwin32gen
$ cd zigwin32gen
$ git clone https://github.com/marlersoft/zigwin32
# NOTE if you forget to run the command above, the error message will explain you haven't cloned the zigwin32 repo
$ zig build -Dfetch
# Adding the -Dfetch will cause the build to fetch the win32json repo for you (the error message you get explains this)

Lately I've been realizing that requiring the -Dfetch option for dependencies is a bit annoying, maybe I'll change it so it's not required.

First, clone the win32json repo:

```
git clone https://github.com/marlersoft/zigwin32
git clone https://github.com/marlersoft/win32json -b 15.0.2-preview dep/win32json
```

Second, create a empty "zigwin32" directory:

```
mkdir zigwin32
```

Then run the following command to generate the latest bindings:
Expand Down
2 changes: 1 addition & 1 deletion examples/basewin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn BaseWindow(comptime DERIVED_TYPE: type) type { return struct {
.cbWndExtra = 0,
.hInstance = win32.GetModuleHandle(null),
.hIcon = null,
.hCursor = null,
.hCursor = win32.LoadCursor(null,win32.IDC_ARROW),
.hbrBackground = null,
// TODO: autogen bindings don't allow for null, should win32metadata allow Option for fields? Or should all strings allow NULL?
.lpszMenuName = L("Placeholder"),
Expand Down
2 changes: 1 addition & 1 deletion examples/helloworld-window.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub export fn wWinMain(hInstance: HINSTANCE, _: ?HINSTANCE, pCmdLine: [*:0]u16,
.cbWndExtra = 0,
.hInstance = hInstance,
.hIcon = null,
.hCursor = null,
.hCursor = win32.LoadCursor(null,win32.IDC_ARROW),
.hbrBackground = null,
// TODO: this field is not marked as options so we can't use null atm
.lpszMenuName = L("Some Menu Name"),
Expand Down
8 changes: 4 additions & 4 deletions src/genzig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ const fail_allocator = std.mem.Allocator{
};
const fail_allocator_vtable = std.mem.Allocator.VTable{
.alloc = failAllocatorAlloc,
.resize = std.mem.Allocator.noResize,
.free = std.mem.Allocator.noFree,
.resize = std.mem.Allocator.NoResize(anyopaque).noResize,
.free = std.mem.Allocator.NoOpFree(anyopaque).noOpFree,
};
fn failAllocatorAlloc(_: *anyopaque, n: usize, alignment: u8, ra: usize) ?[*]u8 {
fn failAllocatorAlloc(_: *anyopaque, n: usize, alignment: u29, _: u29, ra: usize) error{OutOfMemory}![]u8 {
_ = n;
_ = alignment;
_ = ra;
return null;
return error.OutOfMemory;
}
const empty_json_object_map = json.ObjectMap {
.ctx = .{ },
Expand Down
2 changes: 1 addition & 1 deletion src/zig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub usingnamespace switch (unicode_mode) {

pub const Arch = enum { X86, X64, Arm64 };
pub const arch: Arch = switch (builtin.target.cpu.arch) {
.x86 => .X86,
.i386 => .X86,
.x86_64 => .X64,
.arm, .armeb => .Arm64,
else => @compileError("unable to determine win32 arch"),
Expand Down