75 lines
2.4 KiB
Zig
75 lines
2.4 KiB
Zig
const std = @import("std");
|
|
|
|
pub fn build(b: *std.Build) !void {
|
|
// Default to aarch64-linux for Lambda Graviton deployment
|
|
const target = b.standardTargetOptions(.{
|
|
.default_target = .{
|
|
.cpu_arch = .aarch64,
|
|
.os_tag = .linux,
|
|
},
|
|
});
|
|
const optimize = b.standardOptimizeOption(.{});
|
|
|
|
// Get lambda-zig dependency
|
|
const lambda_zig_dep = b.dependency("lambda_zig", .{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
|
|
// Get controlr dependency for rinnai module
|
|
const controlr_dep = b.dependency("controlr", .{
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
|
|
// Create the main module
|
|
const main_module = b.createModule(.{
|
|
.root_source_file = b.path("src/main.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
|
|
// Add lambda_runtime import
|
|
main_module.addImport("lambda_runtime", lambda_zig_dep.module("lambda_runtime"));
|
|
// Add rinnai import from controlr
|
|
main_module.addImport("rinnai", controlr_dep.module("rinnai"));
|
|
|
|
// Create executable
|
|
const exe = b.addExecutable(.{
|
|
.name = "bootstrap", // Lambda requires the executable to be named "bootstrap"
|
|
.root_module = main_module,
|
|
});
|
|
|
|
b.installArtifact(exe);
|
|
|
|
// Create a step to package for Lambda
|
|
const package_step = b.step("package", "Package for AWS Lambda (arm64) deployment");
|
|
|
|
// After installing, create a zip
|
|
const install_step = b.getInstallStep();
|
|
|
|
// Add a system command to create zip (requires zip to be installed)
|
|
const zip_cmd = b.addSystemCommand(&.{
|
|
"zip", "-j", "function.zip", "zig-out/bin/bootstrap",
|
|
});
|
|
zip_cmd.step.dependOn(install_step);
|
|
package_step.dependOn(&zip_cmd.step);
|
|
|
|
// Test step - reuses the same target query, tests run via emulation or on native arm64
|
|
const test_module = b.createModule(.{
|
|
.root_source_file = b.path("src/main.zig"),
|
|
.target = target,
|
|
.optimize = optimize,
|
|
});
|
|
test_module.addImport("lambda_runtime", lambda_zig_dep.module("lambda_runtime"));
|
|
test_module.addImport("rinnai", controlr_dep.module("rinnai"));
|
|
|
|
const main_tests = b.addTest(.{
|
|
.name = "test",
|
|
.root_module = test_module,
|
|
});
|
|
|
|
const run_main_tests = b.addRunArtifact(main_tests);
|
|
const test_step = b.step("test", "Run unit tests");
|
|
test_step.dependOn(&run_main_tests.step);
|
|
}
|