centralize module configuration in build.zig
All checks were successful
AWS-Zig Build / build-zig-amd64-host (push) Successful in 7m9s

This commit is contained in:
Emil Lerch 2025-04-30 07:39:42 -07:00
parent a91b2e8ddb
commit 57a7cf3190
Signed by: lobo
GPG key ID: A7B62D657EF764F8

View file

@ -50,10 +50,7 @@ pub fn build(b: *Builder) !void {
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
mod_exe.addImport("smithy", dep_mods.get("smithy").?); configure(mod_exe, dep_mods, true);
mod_exe.addImport("zeit", dep_mods.get("zeit").?);
mod_exe.addImport("json", dep_mods.get("json").?);
mod_exe.addImport("date", dep_mods.get("date").?);
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "demo", .name = "demo",
@ -78,9 +75,7 @@ pub fn build(b: *Builder) !void {
.target = b.graph.host, .target = b.graph.host,
.optimize = if (b.verbose) .Debug else .ReleaseSafe, .optimize = if (b.verbose) .Debug else .ReleaseSafe,
}); });
cg_mod.addImport("smithy", dep_mods.get("smithy").?); configure(cg_mod, dep_mods, false);
cg_mod.addImport("date", dep_mods.get("date").?);
cg_mod.addImport("json", dep_mods.get("json").?);
const cg_exe = b.addExecutable(.{ const cg_exe = b.addExecutable(.{
.name = "codegen", .name = "codegen",
@ -125,10 +120,7 @@ pub fn build(b: *Builder) !void {
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
service_manifest_module.addImport("smithy", dep_mods.get("smithy").?); configure(service_manifest_module, dep_mods, true);
service_manifest_module.addImport("date", dep_mods.get("date").?);
service_manifest_module.addImport("json", dep_mods.get("json").?);
service_manifest_module.addImport("zeit", dep_mods.get("zeit").?);
mod_exe.addImport("service_manifest", service_manifest_module); mod_exe.addImport("service_manifest", service_manifest_module);
@ -138,19 +130,14 @@ pub fn build(b: *Builder) !void {
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
mod_aws.addImport("smithy", dep_mods.get("smithy").?);
mod_aws.addImport("service_manifest", service_manifest_module); mod_aws.addImport("service_manifest", service_manifest_module);
mod_aws.addImport("date", dep_mods.get("date").?); configure(mod_aws, dep_mods, true);
mod_aws.addImport("json", dep_mods.get("json").?);
mod_aws.addImport("zeit", dep_mods.get("zeit").?);
// Expose module to others // Expose module to others
const mod_aws_signing = b.addModule("aws-signing", .{ const mod_aws_signing = b.addModule("aws-signing", .{
.root_source_file = b.path("src/aws_signing.zig"), .root_source_file = b.path("src/aws_signing.zig"),
}); });
mod_aws_signing.addImport("date", dep_mods.get("date").?); configure(mod_aws_signing, dep_mods, false);
mod_aws_signing.addImport("smithy", dep_mods.get("smithy").?);
mod_aws_signing.addImport("json", dep_mods.get("json").?);
// Similar to creating the run step earlier, this exposes a `test` step to // Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request // the `zig build --help` menu, providing a way for the user to request
@ -179,11 +166,8 @@ pub fn build(b: *Builder) !void {
.target = b.resolveTargetQuery(t), .target = b.resolveTargetQuery(t),
.optimize = optimize, .optimize = optimize,
}); });
mod_unit_tests.addImport("smithy", dep_mods.get("smithy").?);
mod_unit_tests.addImport("service_manifest", service_manifest_module); mod_unit_tests.addImport("service_manifest", service_manifest_module);
mod_unit_tests.addImport("date", dep_mods.get("date").?); configure(mod_unit_tests, dep_mods, true);
mod_unit_tests.addImport("zeit", dep_mods.get("zeit").?);
mod_unit_tests.addImport("json", dep_mods.get("json").?);
// Creates a step for unit testing. This only builds the test executable // Creates a step for unit testing. This only builds the test executable
// but does not run it. // but does not run it.
@ -227,6 +211,13 @@ pub fn build(b: *Builder) !void {
} }
} }
fn configure(compile: *std.Build.Module, modules: std.StringHashMap(*std.Build.Module), include_time: bool) void {
compile.addImport("smithy", modules.get("smithy").?);
compile.addImport("date", modules.get("date").?);
compile.addImport("json", modules.get("json").?);
if (include_time) compile.addImport("zeit", modules.get("zeit").?);
}
fn getDependencyModules(b: *std.Build, args: anytype) !std.StringHashMap(*std.Build.Module) { fn getDependencyModules(b: *std.Build, args: anytype) !std.StringHashMap(*std.Build.Module) {
var result = std.StringHashMap(*std.Build.Module).init(b.allocator); var result = std.StringHashMap(*std.Build.Module).init(b.allocator);