From ed9c7ced6c23426c062a46a77f9dead9eb708550 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Tue, 3 Feb 2026 15:42:28 -0800 Subject: [PATCH] add config parameter so consumers can change defaults --- build.zig | 31 ++++++++++++++++++++++++------- build.zig.zon | 4 ---- lambdabuild.zig | 23 ++++++++++++++++++++--- tools/build/build.zig.zon | 4 ++-- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/build.zig b/build.zig index 152d770..d30e36f 100644 --- a/build.zig +++ b/build.zig @@ -107,9 +107,12 @@ fn configureBuildInternal(b: *std.Build, exe: *std.Build.Step.Compile) !void { .target = b.graph.host, .optimize = .ReleaseSafe, }); - try @import("lambdabuild.zig").configureBuild(b, lambda_build_dep, exe); + try @import("lambdabuild.zig").configureBuild(b, lambda_build_dep, exe, .{}); } +/// Re-export LambdaConfig for consumers +pub const LambdaConfig = @import("lambdabuild.zig").Config; + /// Configure Lambda build steps for a Zig project. /// /// This function adds build steps and options for packaging and deploying @@ -127,12 +130,15 @@ fn configureBuildInternal(b: *std.Build, exe: *std.Build.Step.Compile) !void { /// /// ## Build Options /// -/// The following options are added to the build: +/// The following options are added to the build (command-line options override +/// config defaults): /// -/// - `-Dfunction-name=[string]`: Name of the Lambda function (default: "zig-fn") +/// - `-Dfunction-name=[string]`: Name of the Lambda function +/// (default: "zig-fn", or as provided by config parameter) /// - `-Dregion=[string]`: AWS region for deployment and invocation /// - `-Dprofile=[string]`: AWS profile to use for credentials -/// - `-Drole-name=[string]`: IAM role name (default: "lambda_basic_execution") +/// - `-Drole-name=[string]`: IAM role name +/// (default: "lambda_basic_execution", or as provided by config parameter) /// - `-Dpayload=[string]`: JSON payload for invocation (default: "{}") /// - `-Denv-file=[string]`: Path to environment variables file (KEY=VALUE format) /// - `-Dallow-principal=[string]`: AWS service principal to grant invoke permission @@ -155,14 +161,25 @@ fn configureBuildInternal(b: *std.Build, exe: *std.Build.Step.Compile) !void { /// const exe = b.addExecutable(.{ ... }); /// b.installArtifact(exe); /// -/// try lambda_zig.configureBuild(b, lambda_zig_dep, exe); +/// // Use default config (function name defaults to "zig-fn") +/// try lambda_zig.configureBuild(b, lambda_zig_dep, exe, .{}); +/// +/// // Or specify project-level defaults +/// try lambda_zig.configureBuild(b, lambda_zig_dep, exe, .{ +/// .default_function_name = "my-function", +/// }); /// } /// ``` -pub fn configureBuild(b: *std.Build, lambda_zig_dep: *std.Build.Dependency, exe: *std.Build.Step.Compile) !void { +pub fn configureBuild( + b: *std.Build, + lambda_zig_dep: *std.Build.Dependency, + exe: *std.Build.Step.Compile, + config: LambdaConfig, +) !void { // Get lambda_build from the lambda_zig dependency's Build context const lambda_build_dep = lambda_zig_dep.builder.dependency("lambda_build", .{ .target = b.graph.host, .optimize = .ReleaseSafe, }); - try @import("lambdabuild.zig").configureBuild(b, lambda_build_dep, exe); + try @import("lambdabuild.zig").configureBuild(b, lambda_build_dep, exe, config); } diff --git a/build.zig.zon b/build.zig.zon index a31b7f3..51c1e07 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -9,10 +9,6 @@ .lambda_build = .{ .path = "tools/build", }, - .aws = .{ - .url = "git+https://git.lerch.org/lobo/aws-sdk-for-zig#686b18d1f4329e80cf6d9b916eaa0c231333edb9", - .hash = "aws-0.0.1-SbsFcAc3CgCdWfayHWFazNfJBxkzLyU2wOJSj7h4W17-", - }, }, // Specifies the set of files and directories that are included in this package. // Only files and directories listed here are included in the `hash` that diff --git a/lambdabuild.zig b/lambdabuild.zig index 0f56a59..e787f12 100644 --- a/lambdabuild.zig +++ b/lambdabuild.zig @@ -5,6 +5,19 @@ const std = @import("std"); +/// Configuration options for Lambda build integration. +/// +/// These provide project-level defaults that can still be overridden +/// via command-line options (e.g., `-Dfunction-name=...`). +pub const Config = struct { + /// Default function name if not specified via -Dfunction-name. + /// This allows consuming projects to set their own default. + default_function_name: []const u8 = "zig-fn", + + /// Default IAM role name if not specified via -Drole-name. + default_role_name: []const u8 = "lambda_basic_execution", +}; + /// Configure Lambda build steps for a Zig project. /// /// Adds the following build steps: @@ -12,23 +25,27 @@ const std = @import("std"); /// - awslambda_iam: Create/verify IAM role /// - awslambda_deploy: Deploy the function to AWS /// - awslambda_run: Invoke the deployed function +/// +/// The `config` parameter allows setting project-level defaults that can +/// still be overridden via command-line options. pub fn configureBuild( b: *std.Build, lambda_build_dep: *std.Build.Dependency, exe: *std.Build.Step.Compile, + config: Config, ) !void { // Get the lambda-build CLI artifact from the dependency const cli = lambda_build_dep.artifact("lambda-build"); - // Get configuration options - const function_name = b.option([]const u8, "function-name", "Function name for Lambda") orelse "zig-fn"; + // Get configuration options (command-line overrides config defaults) + const function_name = b.option([]const u8, "function-name", "Function name for Lambda") orelse config.default_function_name; const region = b.option([]const u8, "region", "AWS region") orelse null; const profile = b.option([]const u8, "profile", "AWS profile") orelse null; const role_name = b.option( []const u8, "role-name", "IAM role name (default: lambda_basic_execution)", - ) orelse "lambda_basic_execution"; + ) orelse config.default_role_name; const payload = b.option( []const u8, "payload", diff --git a/tools/build/build.zig.zon b/tools/build/build.zig.zon index eb596be..20764b9 100644 --- a/tools/build/build.zig.zon +++ b/tools/build/build.zig.zon @@ -4,8 +4,8 @@ .fingerprint = 0x6e61de08e7e51114, .dependencies = .{ .aws = .{ - .url = "git+https://git.lerch.org/lobo/aws-sdk-for-zig#fd568f26b976e5f84b27261fccd7b5c2fc9a14c0", - .hash = "aws-0.0.1-SbsFcEs5CgDQYOMkJZ14smUrAFVzQaf6G6l1IOYpwrMA", + .url = "git+https://git.lerch.org/lobo/aws-sdk-for-zig#c1df6ef3a6f4eb4eb75608c3cc6488cffc300793", + .hash = "aws-0.0.1-SbsFcC47CgCWY3bwHxku5J4BAohk-6UJZEUX1B0azJ_D", }, }, .paths = .{