diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79f419d..ad72086 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ concurrency: cancel-in-progress: true env: - ZIG_VERSION: 0.16.0 + ZIG_VERSION: 0.17.0 jobs: build-test: diff --git a/build.zig b/build.zig index a083ca8..7e045b1 100644 --- a/build.zig +++ b/build.zig @@ -52,10 +52,21 @@ pub fn build(b: *std.Build) void { lib.installHeader(snappy_stubs_public_h.getOutputFile(), "snappy-stubs-public.h"); b.installArtifact(lib); + const translate_c = b.addTranslateC(.{ + .root_source_file = upstream.path("snappy-c.h"), + .target = target, + .optimize = optimize, + }); + translate_c.addIncludePath(upstream.path(".")); + translate_c.addConfigHeader(snappy_stubs_public_h); + const module = b.addModule("snappy", .{ .root_source_file = b.path("src/snappy.zig"), .target = target, .optimize = optimize, + .imports = &.{ + .{ .name = "c", .module = translate_c.createModule() }, + }, }); module.linkLibrary(lib); diff --git a/build.zig.zon b/build.zig.zon index f97836e..002aead 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -2,7 +2,7 @@ .name = .snappy, .version = "0.1.0", .fingerprint = 0xcbfb5fb8aa1a809f, - .minimum_zig_version = "0.16.0", + .minimum_zig_version = "0.17.0", .dependencies = .{ .snappy = .{ .url = "git+https://github.com/google/snappy#6f99459b5b837fa18abb1be317d3ac868530f384", diff --git a/src/frame.zig b/src/frame.zig index 8c379f1..b8ea9a4 100644 --- a/src/frame.zig +++ b/src/frame.zig @@ -57,7 +57,7 @@ pub fn compress(allocator: std.mem.Allocator, bytes: []const u8) CompressError![ const chunk_type: ChunkType = if (use_compressed) .compressed else .uncompressed; const frame_size = payload.len + 4; - var header: [4]u8 = .{ @intFromEnum(chunk_type), 0, 0, 0 }; + var header: [4]u8 = .{ @backingInt(chunk_type), 0, 0, 0 }; std.mem.writeInt(u24, header[1..4], @intCast(frame_size), .little); try out.appendSlice(allocator, &header); @@ -88,7 +88,7 @@ pub fn uncompress(allocator: std.mem.Allocator, bytes: []const u8) UncompressErr while (slice.len > 0) { if (slice.len < 4) break; - const chunk_type: ChunkType = @enumFromInt(slice[0]); + const chunk_type: ChunkType = @fromBackingInt(slice[0]); const frame_size: usize = @intCast(std.mem.readInt(u24, slice[1..4], .little)); const frame = slice[4 .. 4 + frame_size]; @@ -131,7 +131,7 @@ pub fn uncompress(allocator: std.mem.Allocator, bytes: []const u8) UncompressErr /// Masked CRC32C hash used by the Snappy framing format. fn crc(b: []const u8) u32 { - const c = std.hash.crc.Crc32Iscsi; + const c = std.hash.crc.@"CRC-32/ISCSI"; const hash = c.hash(b); return @as(u32, hash >> 15 | hash << 17) +% 0xa282ead8; } diff --git a/src/raw.zig b/src/raw.zig index 7b22e4f..e72cf83 100644 --- a/src/raw.zig +++ b/src/raw.zig @@ -1,6 +1,4 @@ -const c = @cImport({ - @cInclude("snappy-c.h"); -}); +const c = @import("c"); pub const Error = error{ invalid_input,