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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concurrency:
cancel-in-progress: true

env:
ZIG_VERSION: 0.16.0
ZIG_VERSION: 0.17.0

jobs:
build-test:
Expand Down
11 changes: 11 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/frame.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions src/raw.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const c = @cImport({
@cInclude("snappy-c.h");
});
const c = @import("c");

pub const Error = error{
invalid_input,
Expand Down