Compare commits

..

4 Commits

Author SHA1 Message Date
79e77c40eb
add github/gitea action
All checks were successful
Generic zig build / build (push) Successful in 12s
2024-04-29 13:23:00 -07:00
1e534201c4
fix ordering of union 2024-04-02 10:57:42 -07:00
6fae461907
fix tests broken in 0a5a08a 2024-04-02 10:53:46 -07:00
melhindi
176817f95f
Fix compilation issues on zig master 2024-04-02 10:23:15 -07:00
3 changed files with 42 additions and 11 deletions

27
.github/workflows/zig-build.yaml vendored Normal file
View File

@ -0,0 +1,27 @@
name: Generic zig build
on:
workflow_dispatch:
push:
branches:
- '*'
- '!zig-develop*'
jobs:
build:
steps:
- uses: actions/checkout@v4
- uses: elerch/setup-zig@v3
with:
version: 0.12.0
- uses: Hanaasagi/zig-action-cache@v1.1.5
- name: Build project
run: zig build
- name: Run tests
run: zig build test --summary all
- name: Notify
uses: elerch/action-notify-ntfy@v2
if: ${{ github.env.GITEA_ACTIONS == 'true' }}
with:
host: ${{ secrets.NTFY_HOST }}
topic: ${{ secrets.NTFY_TOPIC }}
user: ${{ secrets.NTFY_USER }}
password: ${{ secrets.NTFY_PASSWORD }}

View File

@ -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.

View File

@ -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 {
@ -130,8 +133,6 @@ pub const Trait = union(TraitType) {
},
aws_protocol: AwsProtocol,
ec2_query_name: []const u8,
json_name: []const u8,
xml_name: []const u8,
http: struct {
method: []const u8,
uri: []const u8,
@ -141,6 +142,8 @@ pub const Trait = union(TraitType) {
http_label: []const u8,
http_query: []const u8,
http_payload: struct {},
json_name: []const u8,
xml_name: []const u8,
required: struct {},
client_optional: void,
documentation: []const u8,
@ -262,10 +265,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 +277,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 +585,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 +619,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;
@ -887,7 +891,7 @@ fn read_file_to_string(allocator: std.mem.Allocator, file_name: []const u8, max_
return file.readToEndAlloc(allocator, max_bytes);
}
const test_data: []const u8 = @embedFile("test.json");
const intrinsic_type_count: usize = 5; // 5 intrinsic types are added to every model
const intrinsic_type_count: usize = 15; // 15 intrinsic types are added to every model (see shapes() function)
test "parse string" {
const test_string =