Skip to content

Commit 6f5e9e1

Browse files
committed
docs: update Zig 0.16.0 as stable and fix benchmark timing
1 parent b1ba240 commit 6f5e9e1

5 files changed

Lines changed: 18 additions & 25 deletions

File tree

AGENT.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ defer result.free(allocator); // 释放内存
230230

231231
### 5.1 支持的 Zig 版本
232232

233-
-**完全支持**:Zig 0.14.x, 0.15.x
234-
- ⚠️ **部分支持**:Zig 0.16 (nightly)
233+
-**完全支持**:Zig 0.14.x, 0.15.x, 0.16.0
235234

236235
### 5.2 关键差异点
237236

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ zig build docs
2828
- ArrayList API changes in Zig 0.15+ (allocator parameter required for methods)
2929
- ArrayList initialization changes in Zig 0.16 (`std.ArrayList(T){}` removed, use `initCapacity`)
3030
- Build system API differences between versions
31-
- `std.time.Timer` removed in 0.16 (replaced with platform-specific timing in benchmarks)
31+
- `std.time.Timer` removed in 0.16 (benchmarks use `std.Io.Clock.awake` instead)
3232
- `std.heap.GeneralPurposeAllocator` removed in 0.16 (replaced with `page_allocator`)
3333
- `std.io.fixedBufferStream` removed in 0.16 (compat layer provides `BufferStream`)
3434

@@ -82,4 +82,4 @@ Tests use Zig's built-in testing framework. The test suite in `src/test.zig` cov
8282

8383
## CI/CD
8484

85-
GitHub Actions workflow tests against multiple Zig versions (0.14.0, 0.15.1, nightly) to ensure compatibility.
85+
GitHub Actions workflow tests against multiple Zig versions (0.14.1, 0.15.1, 0.16.0, and master) to ensure compatibility.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ This library is tested and optimized for all major platforms and architectures:
4747
| 0.13 and older | 0.0.6 | Legacy support |
4848
| 0.14.0 | Current | ✅ Fully supported |
4949
| 0.15.x | Current | ✅ Fully supported |
50-
| 0.16.0-dev (nightly) | Current | ✅ Supported with compatibility layer |
50+
| 0.16.0 | Current | ✅ Supported with compatibility layer |
5151

5252
> **Note:** For Zig 0.13 and older versions, please use version `0.0.6` of this library.
5353
> **Note:** Zig 0.16+ removes `std.io.FixedBufferStream`, but this library provides a compatibility layer to maintain the same API across all supported versions.
5454
55-
For Zig `0.14.0`, `0.15.x`, and `0.16.0-dev`, follow these steps:
55+
For Zig `0.14.0`, `0.15.x`, and `0.16.0`, follow these steps:
5656

5757
1. **Add as a dependency:**
5858
Add the library to your `build.zig.zon` file. You can fetch a specific commit or branch.

README_CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ Zig 编程语言的 MessagePack 实现。此库提供了一种简单高效的方
4747
| 0.13 及更早版本 | 0.0.6 | 旧版支持 |
4848
| 0.14.0 | 当前版本 | ✅ 完全支持 |
4949
| 0.15.x | 当前版本 | ✅ 完全支持 |
50-
| 0.16.0-dev (nightly) | 当前版本 | ✅ 通过兼容层支持 |
50+
| 0.16.0 | 当前版本 | ✅ 通过兼容层支持 |
5151

5252
> **注意**: 对于 Zig 0.13 及更早版本,请使用本库的 `0.0.6` 版本。
5353
> **注意**: Zig 0.16+ 移除了 `std.io.FixedBufferStream`,但本库提供了兼容层以在所有支持的版本中维持相同的 API。
5454
55-
对于 Zig `0.14.0``0.15.x``0.16.0-dev` 版本,请按以下步骤操作:
55+
对于 Zig `0.14.0``0.15.x``0.16.0` 版本,请按以下步骤操作:
5656

5757
1. **添加为依赖项**:
5858
将库添加到您的 `build.zig.zon` 文件中。您可以获取特定的提交或分支。

src/bench.zig

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,18 @@ const pack = msgpack.Pack(
1717
);
1818

1919
const is_zig_16 = builtin.zig_version.minor >= 16;
20+
const BenchRuntime = if (is_zig_16) struct {
21+
var io: ?std.Io = null;
22+
} else struct {};
2023

21-
/// Get monotonic time in nanoseconds (cross-platform)
24+
/// Get monotonic time in nanoseconds on Zig 0.16+.
2225
fn getTimeNs() u64 {
23-
if (builtin.os.tag == .windows) {
24-
const w = std.os.windows;
25-
var counter: w.LARGE_INTEGER = undefined;
26-
_ = w.ntdll.RtlQueryPerformanceCounter(&counter);
27-
var freq: w.LARGE_INTEGER = undefined;
28-
_ = w.ntdll.RtlQueryPerformanceFrequency(&freq);
29-
const ns = std.time.ns_per_s;
30-
const c: u64 = @bitCast(counter);
31-
const f: u64 = @bitCast(freq);
32-
return @intCast(@divTrunc(@as(u128, c) * ns, @as(u128, f)));
33-
} else if (builtin.os.tag != .windows) {
34-
var ts: std.c.timespec = undefined;
35-
_ = std.c.clock_gettime(std.c.CLOCK.MONOTONIC, &ts);
36-
return @as(u64, @intCast(ts.tv_sec)) * std.time.ns_per_s + @as(u64, @intCast(ts.tv_nsec));
37-
} else @compileError("unsupported OS for benchmark");
26+
if (is_zig_16) {
27+
const io = BenchRuntime.io orelse @panic("benchmark runtime io is not initialized");
28+
return @intCast(std.Io.Clock.awake.now(io).nanoseconds);
29+
}
30+
31+
unreachable;
3832
}
3933

4034
/// Benchmark timer helper
@@ -962,7 +956,7 @@ fn runBenchmarks() !void {
962956

963957
const BenchEntry = if (is_zig_16) struct {
964958
pub fn main(init: std.process.Init) !void {
965-
_ = &init;
959+
BenchRuntime.io = init.io;
966960
try runBenchmarks();
967961
}
968962
} else struct {

0 commit comments

Comments
 (0)