From 176817f95f5e73f407f9f2e2266d1630c81cc21b Mon Sep 17 00:00:00 2001 From: melhindi Date: Sat, 13 Jan 2024 17:34:41 +0100 Subject: [PATCH] Fix compilation issues on zig master --- build.zig | 4 ++-- src/smithy.zig | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/build.zig b/build.zig index cd35753..a1ebee6 100644 --- a/build.zig +++ b/build.zig @@ -30,9 +30,9 @@ pub fn build(b: *std.Build) void { b.installArtifact(lib); const module = b.addModule("smithy", .{ - .source_file = .{ .path = "src/smithy.zig" }, + .root_source_file = .{ .path = "src/smithy.zig" }, }); - lib.addModule("smithy", module); + lib.root_module.addImport("smithy", module); // Creates a step for unit testing. This only builds the test executable // but does not run it. diff --git a/src/smithy.zig b/src/smithy.zig index ad7121d..593f3f0 100644 --- a/src/smithy.zig +++ b/src/smithy.zig @@ -7,14 +7,16 @@ pub const Smithy = struct { metadata: ModelMetadata, shapes: []ShapeInfo, allocator: std.mem.Allocator, + json_source: std.json.Parsed(std.json.Value), const Self = @This(); - pub fn init(allocator: std.mem.Allocator, version: []const u8, metadata: ModelMetadata, shapeinfo: []ShapeInfo) Smithy { + pub fn init(allocator: std.mem.Allocator, version: []const u8, metadata: ModelMetadata, shapeinfo: []ShapeInfo, json_source: std.json.Parsed(std.json.Value)) Smithy { return .{ .version = version, .metadata = metadata, .shapes = shapeinfo, .allocator = allocator, + .json_source = json_source, }; } pub fn deinit(self: Self) void { @@ -76,6 +78,7 @@ pub const Smithy = struct { } } self.allocator.free(self.shapes); + self.json_source.deinit(); } }; pub const ShapeInfo = struct { @@ -99,6 +102,8 @@ pub const TraitType = enum { aws_auth_sigv4, aws_protocol, ec2_query_name, + json_name, + xml_name, http, http_header, http_label, @@ -262,10 +267,10 @@ pub const AwsProtocol = enum { }; pub fn parse(allocator: std.mem.Allocator, json_model: []const u8) !Smithy { - // construct a parser. We're not copying strings here, but that may - // be a poor decision + // construct a parser. We're not copying strings here + // Instead, we keep the original json string around + // This might be bad if we only need a small fraction of the original json source var vt = try std.json.parseFromSlice(std.json.Value, allocator, json_model, .{}); - defer vt.deinit(); return Smithy.init( allocator, vt.value.object.get("smithy").?.string, @@ -274,6 +279,7 @@ pub fn parse(allocator: std.mem.Allocator, json_model: []const u8) !Smithy { .suppressions = &.{}, }, try shapes(allocator, vt.value.object.get("shapes").?.object), + vt, ); } @@ -581,7 +587,7 @@ fn getShape(allocator: std.mem.Allocator, shape: std.json.Value) SmithyParseErro } fn parseMembers(allocator: std.mem.Allocator, shape: ?std.json.Value) SmithyParseError![]TypeMember { - var rc: []TypeMember = &.{}; + const rc: []TypeMember = &.{}; if (shape == null) return rc; @@ -615,7 +621,7 @@ fn parseTraitsOnly(allocator: std.mem.Allocator, shape: std.json.Value) SmithyPa } fn parseTraits(allocator: std.mem.Allocator, shape: ?std.json.Value) SmithyParseError![]Trait { - var rc: []Trait = &.{}; + const rc: []Trait = &.{}; if (shape == null) return rc;