Skip to content

Commit 1c618cf

Browse files
authored
Zig 0.16 (#2)
* initial zig 0.16 migration * build * 0.4 * missed io param * fix example ---------
1 parent 6520260 commit 1c618cf

14 files changed

Lines changed: 403 additions & 181 deletions

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
- name: Setup Zig
4646
uses: mlugg/setup-zig@v2
4747
with:
48-
version: 0.15.1
48+
version: 0.16.0
4949

5050
- name: Run tests
5151
run: zig build test --summary all

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ xwin --accept-license splat --output ~/.xwin
145145

146146
If you don't have Cargo, [install Rust](https://rustup.rs/) or grab a prebuilt binary from the [releases page](https://github.com/Jake-Shadle/xwin/releases).
147147

148+
**Debug CRT:** xwin only includes release CRT libraries. If you get linker errors about `MSVCRTD.lib`, create a symlink:
149+
150+
```bash
151+
ln -s ~/.xwin/crt/lib/x86_64/msvcrt.lib ~/.xwin/crt/lib/x86_64/MSVCRTD.lib
152+
```
153+
148154
Once set up, `zig build` auto-detects `~/.xwin` and cross-compiles.
149155

150156
## Dependencies

ZIG_0.16_MIGRATION.md

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
# Zig 0.16 Migration Guide
2+
3+
This document describes the changes required to migrate zigxll from Zig 0.14/0.15 to Zig 0.16.
4+
5+
## build.zig Changes
6+
7+
### Compile Step Methods Moved to root_module
8+
9+
Methods that were on `*std.Build.Step.Compile` have moved to `compile.root_module`:
10+
11+
```zig
12+
// Old (0.14/0.15)
13+
xll.addIncludePath(b.path("excel/include"));
14+
xll.addLibraryPath(b.path("excel/lib"));
15+
xll.addCSourceFiles(.{ .root = b.path("src"), .files = &.{"file.c"} });
16+
xll.linkLibC();
17+
xll.linkSystemLibrary("user32");
18+
19+
// New (0.16)
20+
xll.root_module.addIncludePath(b.path("excel/include"));
21+
xll.root_module.addLibraryPath(b.path("excel/lib"));
22+
xll.root_module.addCSourceFiles(.{ .root = b.path("src"), .files = &.{"file.c"} });
23+
xll.root_module.link_libc = true;
24+
xll.root_module.linkSystemLibrary("user32", .{});
25+
```
26+
27+
### Environment Variables
28+
29+
```zig
30+
// Old
31+
const home = std.process.getEnvVarOwned(b.allocator, "HOME") catch return;
32+
33+
// New
34+
const home = b.graph.environ_map.get("HOME") orelse return;
35+
```
36+
37+
### Filesystem Access
38+
39+
```zig
40+
// Old
41+
var dir = std.fs.openDirAbsolute(path, .{}) catch return;
42+
dir.close();
43+
44+
// New
45+
std.Io.Dir.accessAbsolute(b.graph.io, path, .{}) catch return;
46+
```
47+
48+
### Path Joining
49+
50+
```zig
51+
// Old
52+
const path = std.fs.path.join(allocator, &.{ home, ".xwin" }) catch return;
53+
54+
// New
55+
const path = std.Io.Dir.path.join(allocator, &.{ home, ".xwin" }) catch return;
56+
```
57+
58+
### File Reading
59+
60+
```zig
61+
// Old
62+
const bytes = dir.handle.readFileAlloc(allocator, sub_path, max_size) catch ...;
63+
64+
// New (requires io parameter, sub_path before allocator, Io.Limit for max_size)
65+
const bytes = dir.handle.readFileAlloc(b.graph.io, sub_path, allocator, std.Io.Limit.limited(max_size)) catch ...;
66+
```
67+
68+
### Directory Operations
69+
70+
```zig
71+
// Old
72+
var dir = std.fs.cwd().openDir(path, .{ .iterate = true }) catch ...;
73+
defer dir.close();
74+
var it = dir.iterate();
75+
while (it.next() catch ...) |entry| { ... }
76+
77+
// New (cwd() takes no args, openDir/close/next require io parameter)
78+
var dir = std.Io.Dir.cwd().openDir(b.graph.io, path, .{ .iterate = true }) catch ...;
79+
defer dir.close(b.graph.io);
80+
var it = dir.iterate();
81+
while (it.next(b.graph.io) catch ...) |entry| { ... }
82+
```
83+
84+
### captureStdOut
85+
86+
```zig
87+
// Old
88+
const output = run.captureStdOut();
89+
90+
// New (requires options struct)
91+
const output = run.captureStdOut(.{});
92+
```
93+
94+
## Source File Changes
95+
96+
### Mutex API
97+
98+
`std.Thread.Mutex` has been replaced with `std.Io.Mutex`, which requires an `Io` instance for lock/unlock operations:
99+
100+
```zig
101+
// Old
102+
var mutex: std.Thread.Mutex = .{};
103+
mutex.lock();
104+
defer mutex.unlock();
105+
106+
// New
107+
var mutex: std.Io.Mutex = std.Io.Mutex.init;
108+
const io = std.Options.debug_io;
109+
mutex.lock(io) catch {};
110+
defer mutex.unlock(io);
111+
```
112+
113+
### ArrayListUnmanaged Initialization
114+
115+
```zig
116+
// Old
117+
var list = std.ArrayListUnmanaged(u8){};
118+
119+
// New
120+
var list: std.ArrayListUnmanaged(u8) = .empty;
121+
```
122+
123+
### ArrayList API Changes
124+
125+
The `writer()` method has been removed from ArrayList. Use ArrayList methods directly:
126+
127+
```zig
128+
// Old
129+
var buf = std.ArrayListUnmanaged(u8){};
130+
errdefer buf.deinit(allocator);
131+
const writer = buf.writer(allocator);
132+
try writer.writeAll("hello");
133+
try writer.writeByte('|');
134+
try writer.print("{d}", .{42});
135+
return buf.toOwnedSlice(allocator);
136+
137+
// New (use ArrayList methods directly, allocator passed to each method)
138+
var buf: std.ArrayList(u8) = .empty;
139+
errdefer buf.deinit(allocator);
140+
try buf.appendSlice(allocator, "hello");
141+
try buf.append(allocator, '|');
142+
try buf.print(allocator, "{d}", .{42});
143+
return buf.toOwnedSlice(allocator);
144+
```
145+
146+
Note: `std.ArrayList` in 0.16 is now the unmanaged version (formerly `ArrayListUnmanaged`).
147+
The managed version is `std.array_list.Managed` but is deprecated.
148+
149+
### Thread.sleep Removed
150+
151+
`std.Thread.sleep` has been removed. For Windows targets, use the Win32 API directly
152+
(this is what `std.Thread.sleep` called internally anyway):
153+
154+
```zig
155+
// Old
156+
std.Thread.sleep(2 * std.time.ns_per_s);
157+
158+
// New (Windows) - use kernel32.Sleep (milliseconds)
159+
const kernel32 = struct {
160+
extern "kernel32" fn Sleep(dwMilliseconds: u32) callconv(.winapi) void;
161+
};
162+
kernel32.Sleep(2000); // 2 seconds
163+
164+
// Or use the zigxll helper:
165+
xll.async_infra.sleepMs(2000);
166+
```
167+
168+
### Windows Types Removed
169+
170+
`std.os.windows.HRESULT` has been removed. Define locally:
171+
172+
```zig
173+
// Old
174+
pub const HRESULT = std.os.windows.HRESULT;
175+
176+
// New
177+
pub const HRESULT = i32;
178+
```
179+
180+
## Cross-Compilation (xwin) Workaround
181+
182+
Zig 0.16 may request `MSVCRTD.lib` (debug CRT) even in release builds when cross-compiling to Windows. The xwin SDK only includes release libraries.
183+
184+
**Workaround:** Create a symlink from the release library:
185+
186+
```bash
187+
ln -sf ~/.xwin/crt/lib/x86_64/msvcrt.lib ~/.xwin/crt/lib/x86_64/MSVCRTD.lib
188+
```
189+
190+
## Reference
191+
192+
- [Zig 0.16.0 Release Notes](https://ziglang.org/download/0.16.0/release-notes.html)

0 commit comments

Comments
 (0)