bifrucate the service_model module based pre-packaging
All checks were successful
AWS-Zig Build / build-zig-amd64-host (push) Successful in 1m2s

This commit is contained in:
Emil Lerch 2026-01-30 09:38:10 -08:00
parent 615f92c654
commit efdef66fdb
Signed by: lobo
GPG key ID: A7B62D657EF764F8

View file

@ -114,12 +114,41 @@ pub fn build(b: *Builder) !void {
cg.dependOn(&cg_cmd.step); cg.dependOn(&cg_cmd.step);
// Each module will need access to the generated AWS modules. These
// are all imported by service_manifest.zig, which is a generated list
// of services created by the codegen process.
//
// First, we need to check if pre-generated models exist, which only happens
// for packaged distribution.
//
// The idea here is that if we have a packaged distibution (tarball with
// models available, we are pre-generated, do not need the codegen step
// (and in fact do not have that available), and our service_manifest
// module needs to be the pre-packaged file.
//
// If we do not have a packaged distribution, the file will not exist,
// because it is generated by codegen and will live in the zig cache directory,
// so we depend on the codegen step and the service_manifest module will
// be based on the codegen output itself.
//
// Most of this complication comes from the fact that we want to enable
// consuming build.zig files to be able to use the SDK at build time for
// things like code deployments, e.g. https://git.lerch.org/lobo/lambda-zig
const has_pre_generated =
if (b.build_root.handle.access("src/models/service_manifest.zig", .{})) true else |_| false;
// Only depend on codegen if we don't have pre-generated models
if (!has_pre_generated)
exe.step.dependOn(cg); exe.step.dependOn(cg);
// This allows us to have each module depend on the // Use pre-generated models if available, otherwise use codegen output
// generated service manifest. const service_manifest_source: std.Build.LazyPath = if (has_pre_generated)
b.path("src/models/service_manifest.zig")
else
cg_output_dir.path(b, "service_manifest.zig");
const service_manifest_module = b.createModule(.{ const service_manifest_module = b.createModule(.{
.root_source_file = cg_output_dir.path(b, "service_manifest.zig"), .root_source_file = service_manifest_source,
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
@ -179,6 +208,7 @@ pub fn build(b: *Builder) !void {
.filters = test_filters, .filters = test_filters,
}); });
if (!has_pre_generated)
unit_tests.step.dependOn(cg); unit_tests.step.dependOn(cg);
unit_tests.use_llvm = !no_llvm; unit_tests.use_llvm = !no_llvm;
@ -202,6 +232,7 @@ pub fn build(b: *Builder) !void {
.filters = test_filters, .filters = test_filters,
}); });
smoke_test.use_llvm = !no_llvm; smoke_test.use_llvm = !no_llvm;
if (!has_pre_generated)
smoke_test.step.dependOn(cg); smoke_test.step.dependOn(cg);
const run_smoke_test = b.addRunArtifact(smoke_test); const run_smoke_test = b.addRunArtifact(smoke_test);