Skip to content

chore: update to latest Zig in master (0.12.0-dev.1695+e4977f3e8) #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 24, 2023
Merged
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
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ RUN git config --global core.autocrlf input

ADD . .

RUN bash ./install-zig.sh 0.12.0-dev.389+61b70778b
RUN bash ./install-zig.sh 0.12.0-dev.1695+e4977f3e8

ENV AGREE=true
ENV AGREE=true
18 changes: 9 additions & 9 deletions bootstrapped-generator/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn main() !void {
const file_buffer = try stdin.readToEndAlloc(allocator, buffer_size);
defer allocator.free(file_buffer);

var request: plugin.CodeGeneratorRequest = try plugin.CodeGeneratorRequest.decode(file_buffer, allocator);
const request: plugin.CodeGeneratorRequest = try plugin.CodeGeneratorRequest.decode(file_buffer, allocator);

var ctx: GenerationContext = GenerationContext{ .req = request };

Expand Down Expand Up @@ -91,7 +91,7 @@ const GenerationContext = struct {
}

fn getOutputList(self: *Self, name: FullName) !*std.ArrayList([]const u8) {
var entry = try self.output_lists.getOrPut(name.buf);
const entry = try self.output_lists.getOrPut(name.buf);

if (!entry.found_existing) {
var list = std.ArrayList([]const u8).init(allocator);
Expand Down Expand Up @@ -138,7 +138,7 @@ const GenerationContext = struct {
if (!std.mem.eql(u8, package.key_ptr.*, name.buf)) {
try list.append(try std.fmt.allocPrint(allocator, "/// import package {?s}\n", .{package.key_ptr.*}));

var optional_pub_directive: []const u8 = if (package.value_ptr.*) "pub const" else "const";
const optional_pub_directive: []const u8 = if (package.value_ptr.*) "pub const" else "const";

try list.append(try std.fmt.allocPrint(allocator, "{s} {!s} = @import(\"{!s}\");\n", .{ optional_pub_directive, self.escapeFqn(package.key_ptr.*), self.resolvePath(name.buf, package.key_ptr.*) }));
}
Expand All @@ -161,7 +161,7 @@ const GenerationContext = struct {
}

pub fn printFileDeclarations(self: *Self, fqn: FullName, file: descriptor.FileDescriptorProto) !void {
var list = try self.getOutputList(fqn);
const list = try self.getOutputList(fqn);

try self.generateEnums(list, fqn, file, file.enum_type);
try self.generateMessages(list, fqn, file, file.message_type);
Expand Down Expand Up @@ -419,8 +419,8 @@ const GenerationContext = struct {

fn generateFieldDescriptor(ctx: *Self, list: *std.ArrayList(string), fqn: FullName, file: descriptor.FileDescriptorProto, message: descriptor.DescriptorProto, field: descriptor.FieldDescriptorProto, is_union: bool) !void {
_ = message;
var name = try ctx.getFieldName(field);
var descStr = try ctx.getFieldTypeDescriptor(fqn, file, field, is_union);
const name = try ctx.getFieldName(field);
const descStr = try ctx.getFieldTypeDescriptor(fqn, file, field, is_union);
const format = " .{s} = fd({?d}, {s}),\n";
try list.append(try std.fmt.allocPrint(allocator, format, .{ name, field.number, descStr }));
}
Expand Down Expand Up @@ -495,7 +495,7 @@ const GenerationContext = struct {
for (m.field.items) |field| {
const f: descriptor.FieldDescriptorProto = field;
if (f.oneof_index orelse -1 == @as(i32, @intCast(i))) {
var name = try ctx.getFieldName(f);
const name = try ctx.getFieldName(f);
try list.append(try std.fmt.allocPrint(allocator, " {?s},\n", .{name}));
}
}
Expand All @@ -509,8 +509,8 @@ const GenerationContext = struct {
for (m.field.items) |field| {
const f: descriptor.FieldDescriptorProto = field;
if (f.oneof_index orelse -1 == @as(i32, @intCast(i))) {
var name = try ctx.getFieldName(f);
var typeStr = try ctx.getFieldType(messageFqn, file, f, true);
const name = try ctx.getFieldName(f);
const typeStr = try ctx.getFieldType(messageFqn, file, f, true);
try list.append(try std.fmt.allocPrint(allocator, " {?s}: {?s},\n", .{ name, typeStr }));
}
}
Expand Down
10 changes: 5 additions & 5 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn build(b: *std.build.Builder) !void {

const test_step = b.step("test", "Run library tests");

var tests = [_]*std.build.LibExeObjStep{
const tests = [_]*std.build.LibExeObjStep{
b.addTest(.{
.name = "protobuf",
.root_source_file = .{ .path = "src/protobuf.zig" },
Expand Down Expand Up @@ -141,7 +141,7 @@ pub const RunProtocStep = struct {
include_directories: []const []const u8,
destination_directory: std.build.FileSource,
generator: *std.build.Step.Compile,
verbose : bool = false, // useful for debugging if you need to know what protoc command is sent
verbose: bool = false, // useful for debugging if you need to know what protoc command is sent

pub const base_id = .protoc;

Expand Down Expand Up @@ -214,7 +214,7 @@ pub const RunProtocStep = struct {
try argv.append(it);
}

if(self.verbose) {
if (self.verbose) {
std.debug.print("Running protoc:", .{});
for (argv.items) |it| {
std.debug.print(" {s}", .{it});
Expand Down Expand Up @@ -452,7 +452,7 @@ fn unzipFile(allocator: std.mem.Allocator, file: []const u8, target_directory: [
}

fn ensureCanDownloadFiles(allocator: std.mem.Allocator) void {
const result = std.ChildProcess.exec(.{
const result = std.ChildProcess.run(.{
.allocator = allocator,
.argv = &.{ "curl", "--version" },
.cwd = sdkPath("/"),
Expand All @@ -471,7 +471,7 @@ fn ensureCanDownloadFiles(allocator: std.mem.Allocator) void {
}

fn ensureCanUnzipFiles(allocator: std.mem.Allocator) void {
const result = std.ChildProcess.exec(.{
const result = std.ChildProcess.run(.{
.allocator = allocator,
.argv = &.{"unzip"},
.cwd = sdkPath("/"),
Expand Down
11 changes: 5 additions & 6 deletions src/protobuf.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const std = @import("std");
const StructField = std.builtin.Type.StructField;
const isSignedInt = std.meta.trait.isSignedInt;
const isIntegral = std.meta.trait.isIntegral;
const Allocator = std.mem.Allocator;
const testing = std.testing;
Expand Down Expand Up @@ -176,7 +175,7 @@ fn append_as_varint(pb: *ArrayList(u8), int: anytype, comptime varint_type: Vari
const type_of_val = @TypeOf(int);
const bitsize = @bitSizeOf(type_of_val);
const val: u64 = blk: {
if (isSignedInt(type_of_val)) {
if (@typeInfo(type_of_val).Int.signedness == .signed) {
switch (varint_type) {
.ZigZagOptimized => {
break :blk @as(u64, @intCast((int >> (bitsize - 1)) ^ (int << 1)));
Expand Down Expand Up @@ -482,7 +481,7 @@ fn dupe_field(original: anytype, comptime field_name: []const u8, comptime ftype
return @field(original, field_name);
},
.List => |list_type| {
var capacity = @field(original, field_name).items.len;
const capacity = @field(original, field_name).items.len;
var list = try @TypeOf(@field(original, field_name)).initCapacity(allocator, capacity);
if (list_type == .SubMessage or list_type == .String) {
for (@field(original, field_name).items) |item| {
Expand All @@ -496,7 +495,7 @@ fn dupe_field(original: anytype, comptime field_name: []const u8, comptime ftype
return list;
},
.PackedList => |_| {
var capacity = @field(original, field_name).items.len;
const capacity = @field(original, field_name).items.len;
var list = try @TypeOf(@field(original, field_name)).initCapacity(allocator, capacity);

for (@field(original, field_name).items) |item| {
Expand Down Expand Up @@ -525,7 +524,7 @@ fn dupe_field(original: anytype, comptime field_name: []const u8, comptime ftype
// and if one matches the actual tagName of the union
if (std.mem.eql(u8, union_field.name, active)) {
// deinit the current value
var value = try dupe_field(union_value, union_field.name, @field(one_of._union_desc, union_field.name).ftype, allocator);
const value = try dupe_field(union_value, union_field.name, @field(one_of._union_desc, union_field.name).ftype, allocator);

return @unionInit(one_of, union_field.name, value);
}
Expand Down Expand Up @@ -920,7 +919,7 @@ fn decode_data(comptime T: type, comptime field_desc: FieldDescriptor, comptime
deinit_field(result, field.name, field_desc.ftype);

// and decode & assign the new value
var value = try decode_value(union_field.type, v.ftype, extracted_data, allocator);
const value = try decode_value(union_field.type, v.ftype, extracted_data, allocator);
@field(result, field.name) = @unionInit(one_of, union_field.name, value);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/leaks.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test "leak in allocated string" {
defer demo.deinit();

// allocate a "dynamic" string
var allocated = try testing.allocator.dupe(u8, "asd");
const allocated = try testing.allocator.dupe(u8, "asd");
// copy the allocated string
demo.field = .{ .field = try protobuf.ManagedString.copy(allocated, testing.allocator) };
// release the allocated string immediately
Expand Down
2 changes: 1 addition & 1 deletion tests/mapbox.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const binary_file = @embedFile("./fixtures/vector_tile.bin");
test "mapbox decoding and re-encoding" {
// we will decode a releaseable copy of the binary file. to ensure that string slices are not
// leaked into final string values
var copied_slice = try testing.allocator.dupe(u8, binary_file);
const copied_slice = try testing.allocator.dupe(u8, binary_file);

// first decode the binary
const decoded = try vector_tile.Tile.decode(copied_slice, testing.allocator);
Expand Down