2021-06-30 16:37:14 +00:00
|
|
|
const std = @import("std");
|
|
|
|
const builtin = @import("builtin");
|
2021-04-27 18:24:01 +00:00
|
|
|
const Builder = @import("std").build.Builder;
|
|
|
|
|
2021-06-30 16:37:14 +00:00
|
|
|
pub fn build(b: *Builder) !void {
|
2021-04-27 18:24:01 +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.
|
2023-08-04 23:40:24 +00:00
|
|
|
const optimize = b.standardOptimizeOption(.{});
|
2021-04-27 18:24:01 +00:00
|
|
|
|
2023-08-04 23:40:24 +00:00
|
|
|
const exe = b.addExecutable(.{
|
|
|
|
.name = "demo",
|
|
|
|
.root_source_file = .{ .path = "src/main.zig" },
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
|
|
|
const smithy_dep = b.dependency("smithy", .{
|
|
|
|
// These are the arguments to the dependency. It expects a target and optimization level.
|
|
|
|
.target = target,
|
|
|
|
.optimize = optimize,
|
|
|
|
});
|
|
|
|
exe.addModule("smithy", smithy_dep.module("smithy"));
|
|
|
|
// TODO: Smithy needs to be in a different repo
|
2021-06-30 16:37:14 +00:00
|
|
|
// https://github.com/ziglang/zig/issues/855
|
2023-08-04 23:40:24 +00:00
|
|
|
// exe.addModulePath("smithy", "smithy/src/smithy.zig");
|
2021-06-12 20:40:23 +00:00
|
|
|
|
2022-02-09 06:36:36 +00:00
|
|
|
if (target.getOs().tag != .macos) exe.linkage = .static;
|
2021-06-09 23:18:01 +00:00
|
|
|
|
2023-08-04 23:40:24 +00:00
|
|
|
// Strip is controlled by optimize options
|
|
|
|
// exe.strip = b.option(bool, "strip", "strip exe [true]") orelse true;
|
2022-01-11 05:49:59 +00:00
|
|
|
|
2023-08-04 23:40:24 +00:00
|
|
|
const run_cmd = b.addRunArtifact(exe);
|
2021-04-27 18:24:01 +00:00
|
|
|
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:37:14 +00:00
|
|
|
|
2023-08-05 20:11:30 +00:00
|
|
|
// TODO: Proper testing
|
2021-06-30 18:09:30 +00:00
|
|
|
|
2022-05-28 22:14:27 +00:00
|
|
|
var codegen: ?*std.build.Step = null;
|
2023-08-04 17:06:54 +00:00
|
|
|
if (target.getOs().tag == .linux and false) {
|
2022-01-11 05:49:59 +00:00
|
|
|
// TODO: Support > linux with RunStep
|
|
|
|
// std.build.RunStep.create(null,null).cwd(std.fs.path.resolve(b.build_root, "codegen")).addArgs(...)
|
2022-05-28 22:14:27 +00:00
|
|
|
codegen = b.step("gen", "Generate zig service code from smithy models");
|
|
|
|
const cg = codegen.?;
|
|
|
|
cg.dependOn(&b.addSystemCommand(&.{ "/bin/sh", "-c", "cd codegen && zig build" }).step);
|
2022-01-11 05:49:59 +00:00
|
|
|
|
|
|
|
// This can probably be triggered instead by GitRepoStep cloning the repo
|
|
|
|
// with models
|
2021-07-23 21:05:26 +00:00
|
|
|
// Since codegen binary is built every time, if it's newer than our
|
|
|
|
// service manifest we know it needs to be regenerated. So this step
|
|
|
|
// will remove the service manifest if codegen has been touched, thereby
|
|
|
|
// triggering the re-gen
|
2022-05-28 22:14:27 +00:00
|
|
|
cg.dependOn(&b.addSystemCommand(&.{
|
2021-07-23 21:05:26 +00:00
|
|
|
"/bin/sh", "-c",
|
|
|
|
\\ [ ! -f src/models/service_manifest.zig ] || \
|
2022-05-28 22:14:27 +00:00
|
|
|
\\ [ $(find codegen -type f -newer src/models/service_manifest.zig -print -quit |wc -c) = '0' ] || \
|
2021-07-23 21:05:26 +00:00
|
|
|
\\ rm src/models/service_manifest.zig
|
|
|
|
}).step);
|
2022-05-28 22:14:27 +00:00
|
|
|
cg.dependOn(&b.addSystemCommand(&.{
|
2021-06-30 18:09:30 +00:00
|
|
|
"/bin/sh", "-c",
|
|
|
|
\\ mkdir -p src/models/ && \
|
|
|
|
\\ [ -f src/models/service_manifest.zig ] || \
|
|
|
|
\\ ( cd codegen/models && ../codegen *.json && mv *.zig ../../src/models )
|
|
|
|
}).step);
|
2022-05-28 22:14:27 +00:00
|
|
|
exe.step.dependOn(cg);
|
2021-06-30 18:09:30 +00:00
|
|
|
}
|
2021-06-30 18:13:12 +00:00
|
|
|
|
2023-08-04 23:40:24 +00:00
|
|
|
b.installArtifact(exe);
|
2022-01-11 05:49:59 +00:00
|
|
|
}
|