codegen: revert build to mostly stock, update to 0.11

This commit is contained in:
Emil Lerch 2023-08-14 15:24:46 -07:00
parent 2d977b03a4
commit 6b97fed499
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
4 changed files with 67 additions and 41 deletions

View File

@ -1,5 +1,8 @@
const std = @import("std"); const std = @import("std");
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
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
@ -7,53 +10,65 @@ pub fn build(b: *std.build.Builder) !void {
// for restricting supported target set are available. // for restricting supported target set are available.
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
// Standard release options allow the person running `zig build` to select // Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
const mode = b.standardReleaseOptions(); // set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable("codegen", "src/main.zig"); const exe = b.addExecutable(.{
exe.addPackagePath("smithy", "../smithy/src/smithy.zig"); .name = "codegen",
exe.setTarget(target); .root_source_file = .{ .path = "src/main.zig" },
exe.setBuildMode(mode); .target = target,
// This line works as of c5d412268 .optimize = optimize,
// 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 const smithy_dep = b.dependency("smithy", .{
// Did not notice this until 2021-06-28, and that nightly is: .target = target,
// https://ziglang.org/builds/zig-linux-x86_64-0.9.0-dev.321+15a030ef3.tar.xz .optimize = optimize,
exe.linkage = .static; });
exe.addModule("smithy", smithy_dep.module("smithy"));
const is_strip = b.option(bool, "strip", "strip exe") orelse true; // This declares intent for the executable to be installed into the
exe.strip = !is_strip; // standard location when the user invokes the "install" step (the default
exe.install(); // step when running `zig build`).
b.installArtifact(exe);
const run_cmd = exe.run(); // This *creates* a Run step in the build graph, to be executed when another
// step is evaluated that depends on it. The next line below will establish
// such a dependency.
const run_cmd = b.addRunArtifact(exe);
// By making the run step depend on the install step, it will be run from the
// installation directory rather than directly from within the cache directory.
// This is not necessary, however, if the application depends on other installed
// files, this ensures they will be present and in the expected location.
run_cmd.step.dependOn(b.getInstallStep()); run_cmd.step.dependOn(b.getInstallStep());
// This allows the user to pass arguments to the application in the build
// command itself, like this: `zig build run -- arg1 arg2 etc`
if (b.args) |args| { if (b.args) |args| {
run_cmd.addArgs(args); run_cmd.addArgs(args);
} }
// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build run`
// This will evaluate the `run` step rather than the default, which is "install".
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"); // Creates a step for unit testing. This only builds the test executable
var src_dir = try std.fs.openDirAbsolute(b.build_root, .{}); // but does not run it.
defer src_dir.close(); const unit_tests = b.addTest(.{
var iterable = try src_dir.openIterableDir(".", .{}); .root_source_file = .{ .path = "src/main.zig" },
defer iterable.close(); .target = target,
var iterator = iterable.iterate(); .optimize = optimize,
while (try iterator.next()) |entry| { });
if (std.mem.endsWith(u8, entry.name, ".zig") and
!std.mem.eql(u8, entry.name, "main.zig")) const run_unit_tests = b.addRunArtifact(unit_tests);
{
const name = try std.fmt.allocPrint(b.allocator, "src/{s}", .{entry.name}); // Similar to creating the run step earlier, this exposes a `test` step to
defer b.allocator.free(name); // the `zig build --help` menu, providing a way for the user to request
const t = b.addTest(name); // running the unit tests.
t.setBuildMode(mode); const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&t.step); test_step.dependOn(&run_unit_tests.step);
}
}
} }

11
codegen/build.zig.zon Normal file
View File

@ -0,0 +1,11 @@
.{
.name = "aws-zig-codegen",
.version = "0.0.1",
.dependencies = .{
.smithy = .{
.url = "https://git.lerch.org/lobo/smithy/archive/41b61745d25a65817209dd5dddbb5f9b66896a99.tar.gz",
.hash = "122087deb0ae309b2258d59b40d82fe5921fdfc35b420bb59033244851f7f276fa34",
},
},
}

View File

@ -19,7 +19,7 @@ pub fn serializeMap(map: anytype, key: []const u8, options: anytype, out_stream:
try out_stream.writeByte('{'); try out_stream.writeByte('{');
if (options.whitespace) |_| if (options.whitespace) |_|
try out_stream.writeByte('\n'); try out_stream.writeByte('\n');
for (map) |tag, i| { for (map, 0..) |tag, i| {
if (tag.key == null or tag.value == null) continue; if (tag.key == null or tag.value == null) continue;
// TODO: Deal with escaping and general "json.stringify" the values... // TODO: Deal with escaping and general "json.stringify" the values...
if (child_options.whitespace) |ws| if (child_options.whitespace) |ws|
@ -100,8 +100,8 @@ fn outputUnicodeEscape(
assert(codepoint <= 0x10FFFF); assert(codepoint <= 0x10FFFF);
// To escape an extended character that is not in the Basic Multilingual Plane, // To escape an extended character that is not in the Basic Multilingual Plane,
// the character is represented as a 12-character sequence, encoding the UTF-16 surrogate pair. // the character is represented as a 12-character sequence, encoding the UTF-16 surrogate pair.
const high = @intCast(u16, (codepoint - 0x10000) >> 10) + 0xD800; const high = @as(u16, @intCast((codepoint - 0x10000) >> 10)) + 0xD800;
const low = @intCast(u16, codepoint & 0x3FF) + 0xDC00; const low = @as(u16, @intCast(codepoint & 0x3FF)) + 0xDC00;
try out_stream.writeAll("\\u"); try out_stream.writeAll("\\u");
try std.fmt.formatIntValue(high, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream); try std.fmt.formatIntValue(high, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream);
try out_stream.writeAll("\\u"); try out_stream.writeAll("\\u");

View File

@ -72,7 +72,7 @@ fn isAcronymChar(char: u8) bool {
fn isAscii(codepoint: ?u21) !?u8 { fn isAscii(codepoint: ?u21) !?u8 {
if (codepoint) |cp| { if (codepoint) |cp| {
if (cp > 0xff) return error.UnicodeNotSupported; if (cp > 0xff) return error.UnicodeNotSupported;
return @truncate(u8, cp); return @as(u8, @truncate(cp));
} }
return null; return null;
} }