From efdef66fdbb2500d33a79a0b8d1855dd1bb20d56 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Fri, 30 Jan 2026 09:38:10 -0800 Subject: [PATCH] bifrucate the service_model module based pre-packaging --- build.zig | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/build.zig b/build.zig index ab5a576..0501c49 100644 --- a/build.zig +++ b/build.zig @@ -114,12 +114,41 @@ pub fn build(b: *Builder) !void { cg.dependOn(&cg_cmd.step); - exe.step.dependOn(cg); + // 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); + + // Use pre-generated models if available, otherwise use codegen output + 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"); - // This allows us to have each module depend on the - // generated service manifest. 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, .optimize = optimize, }); @@ -179,7 +208,8 @@ pub fn build(b: *Builder) !void { .filters = test_filters, }); - unit_tests.step.dependOn(cg); + if (!has_pre_generated) + unit_tests.step.dependOn(cg); unit_tests.use_llvm = !no_llvm; const run_unit_tests = b.addRunArtifact(unit_tests); @@ -202,7 +232,8 @@ pub fn build(b: *Builder) !void { .filters = test_filters, }); smoke_test.use_llvm = !no_llvm; - smoke_test.step.dependOn(cg); + if (!has_pre_generated) + smoke_test.step.dependOn(cg); const run_smoke_test = b.addRunArtifact(smoke_test);