extract smithy to separate package
This commit is contained in:
parent
22e39dd6e1
commit
ac07c9300f
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -5,3 +5,5 @@ codegen/codegen
|
||||||
*.tgz
|
*.tgz
|
||||||
service_manifest.zig
|
service_manifest.zig
|
||||||
demo
|
demo
|
||||||
|
src/models/
|
||||||
|
smithy/zig-out/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub fn build(b: *std.build.Builder) void {
|
pub fn build(b: *std.build.Builder) !void {
|
||||||
// Standard target options allows the person running `zig build` to choose
|
// Standard target options allows the person running `zig build` to choose
|
||||||
// what target to build for. Here we do not override the defaults, which
|
// what target to build for. Here we do not override the defaults, which
|
||||||
// means any target is allowed, and the default is native. Other options
|
// means any target is allowed, and the default is native. Other options
|
||||||
|
@ -12,9 +12,22 @@ pub fn build(b: *std.build.Builder) void {
|
||||||
const mode = b.standardReleaseOptions();
|
const mode = b.standardReleaseOptions();
|
||||||
|
|
||||||
const exe = b.addExecutable("codegen", "src/main.zig");
|
const exe = b.addExecutable("codegen", "src/main.zig");
|
||||||
|
exe.addPackagePath("smithy", "../smithy/src/smithy.zig");
|
||||||
exe.setTarget(target);
|
exe.setTarget(target);
|
||||||
exe.setBuildMode(mode);
|
exe.setBuildMode(mode);
|
||||||
exe.override_dest_dir = .{ .Custom = ".." };
|
// This line works as of c5d412268
|
||||||
|
// Earliest nightly is 05b5e49bc on 2021-06-12
|
||||||
|
// https://ziglang.org/builds/zig-linux-x86_64-0.9.0-dev.113+05b5e49bc.tar.xz
|
||||||
|
// exe.override_dest_dir = .{ .Custom = ".." };
|
||||||
|
exe.override_dest_dir = .{ .custom = ".." };
|
||||||
|
|
||||||
|
// Static linkage flag was nonfunctional until 2b2efa24d0855
|
||||||
|
// Did not notice this until 2021-06-28, and that nightly is:
|
||||||
|
// https://ziglang.org/builds/zig-linux-x86_64-0.9.0-dev.321+15a030ef3.tar.xz
|
||||||
|
exe.linkage = .static;
|
||||||
|
|
||||||
|
const is_strip = b.option(bool, "strip", "strip exe") orelse true;
|
||||||
|
exe.strip = !is_strip;
|
||||||
exe.install();
|
exe.install();
|
||||||
|
|
||||||
const run_cmd = exe.run();
|
const run_cmd = exe.run();
|
||||||
|
@ -25,4 +38,22 @@ pub fn build(b: *std.build.Builder) void {
|
||||||
|
|
||||||
const run_step = b.step("run", "Run the app");
|
const run_step = b.step("run", "Run the app");
|
||||||
run_step.dependOn(&run_cmd.step);
|
run_step.dependOn(&run_cmd.step);
|
||||||
|
|
||||||
|
const test_step = b.step("test", "Run library tests");
|
||||||
|
var build_dir = try std.fs.openDirAbsolute(b.build_root, .{});
|
||||||
|
defer build_dir.close();
|
||||||
|
var src_dir = try build_dir.openDir("src", .{ .iterate = true });
|
||||||
|
defer src_dir.close();
|
||||||
|
var iterator = src_dir.iterate();
|
||||||
|
while (try iterator.next()) |entry| {
|
||||||
|
if (std.mem.endsWith(u8, entry.name, ".zig") and
|
||||||
|
!std.mem.eql(u8, entry.name, "main.zig"))
|
||||||
|
{
|
||||||
|
const name = try std.fmt.allocPrint(b.allocator, "src/{s}", .{entry.name});
|
||||||
|
defer b.allocator.free(name);
|
||||||
|
const t = b.addTest(name);
|
||||||
|
t.setBuildMode(mode);
|
||||||
|
test_step.dependOn(&t.step);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const smithy = @import("smithy.zig");
|
const smithy = @import("smithy");
|
||||||
const snake = @import("snake.zig");
|
const snake = @import("snake.zig");
|
||||||
|
|
||||||
pub fn main() anyerror!void {
|
pub fn main() anyerror!void {
|
||||||
|
|
17
smithy/build.zig
Normal file
17
smithy/build.zig
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn build(b: *std.build.Builder) void {
|
||||||
|
// Standard release options allow the person running `zig build` to select
|
||||||
|
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
||||||
|
const mode = b.standardReleaseOptions();
|
||||||
|
|
||||||
|
const lib = b.addStaticLibrary("smithy", "src/smithy.zig");
|
||||||
|
lib.setBuildMode(mode);
|
||||||
|
lib.install();
|
||||||
|
|
||||||
|
var main_tests = b.addTest("src/smithy.zig");
|
||||||
|
main_tests.setBuildMode(mode);
|
||||||
|
|
||||||
|
const test_step = b.step("test", "Run library tests");
|
||||||
|
test_step.dependOn(&main_tests.step);
|
||||||
|
}
|
|
@ -659,7 +659,7 @@ fn read_file_to_string(allocator: *std.mem.Allocator, file_name: []const u8, max
|
||||||
var test_data: ?[]const u8 = null;
|
var test_data: ?[]const u8 = null;
|
||||||
const intrinsic_type_count: usize = 5; // 5 intrinsic types are added to every model
|
const intrinsic_type_count: usize = 5; // 5 intrinsic types are added to every model
|
||||||
|
|
||||||
fn getTestData(allocator: *std.mem.Allocator) []const u8 {
|
fn getTestData(_: *std.mem.Allocator) []const u8 {
|
||||||
if (test_data) |d| return d;
|
if (test_data) |d| return d;
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
test_data = read_file_to_string(&gpa.allocator, "test.json", 150000) catch @panic("could not read test.json");
|
test_data = read_file_to_string(&gpa.allocator, "test.json", 150000) catch @panic("could not read test.json");
|
||||||
|
@ -669,7 +669,7 @@ test "read file" {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
defer if (gpa.deinit()) @panic("leak");
|
defer if (gpa.deinit()) @panic("leak");
|
||||||
const allocator = &gpa.allocator;
|
const allocator = &gpa.allocator;
|
||||||
const test_string = getTestData(allocator);
|
_ = getTestData(allocator);
|
||||||
// test stuff
|
// test stuff
|
||||||
}
|
}
|
||||||
test "parse string" {
|
test "parse string" {
|
Loading…
Reference in New Issue
Block a user