diff --git a/AGENT.md b/AGENT.md index 2d58d04..4b35fe4 100644 --- a/AGENT.md +++ b/AGENT.md @@ -230,8 +230,7 @@ defer result.free(allocator); // 释放内存 ### 5.1 支持的 Zig 版本 -- ✅ **完全支持**:Zig 0.14.x, 0.15.x -- ⚠️ **部分支持**:Zig 0.16 (nightly) +- ✅ **完全支持**:Zig 0.14.x, 0.15.x, 0.16.0 ### 5.2 关键差异点 diff --git a/CLAUDE.md b/CLAUDE.md index c0b1379..2bf90f1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -28,7 +28,7 @@ zig build docs - ArrayList API changes in Zig 0.15+ (allocator parameter required for methods) - ArrayList initialization changes in Zig 0.16 (`std.ArrayList(T){}` removed, use `initCapacity`) - Build system API differences between versions - - `std.time.Timer` removed in 0.16 (replaced with platform-specific timing in benchmarks) + - `std.time.Timer` removed in 0.16 (benchmarks use `std.Io.Clock.awake` instead) - `std.heap.GeneralPurposeAllocator` removed in 0.16 (replaced with `page_allocator`) - `std.io.fixedBufferStream` removed in 0.16 (compat layer provides `BufferStream`) @@ -82,4 +82,4 @@ Tests use Zig's built-in testing framework. The test suite in `src/test.zig` cov ## CI/CD -GitHub Actions workflow tests against multiple Zig versions (0.14.0, 0.15.1, nightly) to ensure compatibility. \ No newline at end of file +GitHub Actions workflow tests against multiple Zig versions (0.14.1, 0.15.1, 0.16.0, and master) to ensure compatibility. diff --git a/README.md b/README.md index 48df6f3..39eed3a 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,12 @@ This library is tested and optimized for all major platforms and architectures: | 0.13 and older | 0.0.6 | Legacy support | | 0.14.0 | Current | ✅ Fully supported | | 0.15.x | Current | ✅ Fully supported | -| 0.16.0-dev (nightly) | Current | ✅ Supported with compatibility layer | +| 0.16.0 | Current | ✅ Supported with compatibility layer | > **Note:** For Zig 0.13 and older versions, please use version `0.0.6` of this library. > **Note:** Zig 0.16+ removes `std.io.FixedBufferStream`, but this library provides a compatibility layer to maintain the same API across all supported versions. -For Zig `0.14.0`, `0.15.x`, and `0.16.0-dev`, follow these steps: +For Zig `0.14.0`, `0.15.x`, and `0.16.0`, follow these steps: 1. **Add as a dependency:** Add the library to your `build.zig.zon` file. You can fetch a specific commit or branch. diff --git a/README_CN.md b/README_CN.md index 090ac58..4472507 100644 --- a/README_CN.md +++ b/README_CN.md @@ -47,12 +47,12 @@ Zig 编程语言的 MessagePack 实现。此库提供了一种简单高效的方 | 0.13 及更早版本 | 0.0.6 | 旧版支持 | | 0.14.0 | 当前版本 | ✅ 完全支持 | | 0.15.x | 当前版本 | ✅ 完全支持 | -| 0.16.0-dev (nightly) | 当前版本 | ✅ 通过兼容层支持 | +| 0.16.0 | 当前版本 | ✅ 通过兼容层支持 | > **注意**: 对于 Zig 0.13 及更早版本,请使用本库的 `0.0.6` 版本。 > **注意**: Zig 0.16+ 移除了 `std.io.FixedBufferStream`,但本库提供了兼容层以在所有支持的版本中维持相同的 API。 -对于 Zig `0.14.0`、`0.15.x` 和 `0.16.0-dev` 版本,请按以下步骤操作: +对于 Zig `0.14.0`、`0.15.x` 和 `0.16.0` 版本,请按以下步骤操作: 1. **添加为依赖项**: 将库添加到您的 `build.zig.zon` 文件中。您可以获取特定的提交或分支。 diff --git a/src/bench.zig b/src/bench.zig index 84c9e01..59996f9 100644 --- a/src/bench.zig +++ b/src/bench.zig @@ -17,24 +17,18 @@ const pack = msgpack.Pack( ); const is_zig_16 = builtin.zig_version.minor >= 16; +const BenchRuntime = if (is_zig_16) struct { + var io: ?std.Io = null; +} else struct {}; -/// Get monotonic time in nanoseconds (cross-platform) +/// Get monotonic time in nanoseconds on Zig 0.16+. fn getTimeNs() u64 { - if (builtin.os.tag == .windows) { - const w = std.os.windows; - var counter: w.LARGE_INTEGER = undefined; - _ = w.ntdll.RtlQueryPerformanceCounter(&counter); - var freq: w.LARGE_INTEGER = undefined; - _ = w.ntdll.RtlQueryPerformanceFrequency(&freq); - const ns = std.time.ns_per_s; - const c: u64 = @bitCast(counter); - const f: u64 = @bitCast(freq); - return @intCast(@divTrunc(@as(u128, c) * ns, @as(u128, f))); - } else if (builtin.os.tag != .windows) { - var ts: std.c.timespec = undefined; - _ = std.c.clock_gettime(std.c.CLOCK.MONOTONIC, &ts); - return @as(u64, @intCast(ts.tv_sec)) * std.time.ns_per_s + @as(u64, @intCast(ts.tv_nsec)); - } else @compileError("unsupported OS for benchmark"); + if (is_zig_16) { + const io = BenchRuntime.io orelse @panic("benchmark runtime io is not initialized"); + return @intCast(std.Io.Clock.awake.now(io).nanoseconds); + } + + unreachable; } /// Benchmark timer helper @@ -962,7 +956,7 @@ fn runBenchmarks() !void { const BenchEntry = if (is_zig_16) struct { pub fn main(init: std.process.Init) !void { - _ = &init; + BenchRuntime.io = init.io; try runBenchmarks(); } } else struct {