aws-sdk-for-zig/codegen/build.zig

60 lines
2.3 KiB
Zig
Raw Normal View History

2021-05-30 01:17:45 +00:00
const std = @import("std");
2021-06-30 16:05:21 +00:00
pub fn build(b: *std.build.Builder) !void {
2021-05-30 01:17:45 +00:00
// Standard target options allows the person running `zig build` to choose
// 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
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const exe = b.addExecutable("codegen", "src/main.zig");
2021-06-30 16:05:21 +00:00
exe.addPackagePath("smithy", "../smithy/src/smithy.zig");
2021-05-30 01:17:45 +00:00
exe.setTarget(target);
exe.setBuildMode(mode);
2021-06-30 16:05:21 +00:00
// 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;
2021-05-30 01:17:45 +00:00
exe.install();
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
2021-06-30 16:05:21 +00:00
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);
}
}
2021-05-30 01:17:45 +00:00
}