diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index c16a765..3fba22d 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -33,8 +33,14 @@ jobs: ln -s /usr/local/zig-linux-${ARCH}-${ZIG_VERSION}/zig /usr/local/bin/zig - name: Run tests run: zig build test --verbose - - name: Build example - run: ( cd example && zig build ) # Make sure example builds + - name: Build other platforms + run: | + zig build -Dtarget=aarch64-macos + zig build -Dtarget=x86_64-macos + zig build -Dtarget=x86_64-windows + zig build -Dtarget=aarch64-linux + zig build -Dtarget=riscv64-linux + zig build -Dtarget=x86_64-linux # - name: Sign # id: sign # uses: https://git.lerch.org/lobo/action-hsm-sign@v1 diff --git a/build.zig b/build.zig index 04eba9d..cd78f10 100644 --- a/build.zig +++ b/build.zig @@ -1,11 +1,11 @@ const std = @import("std"); const universal_lambda = @import("universal_lambda_build"); +// This seems to fail for some reason. zig-sqlite does a lot of messing with +// the target. So instead, we will handle this in the CI/CD system at the +// command line const test_targets = [_]std.zig.CrossTarget{ .{}, // native - - // We seem to have compile erros with the rest, all due to sqlite - // I believe either zig+c files or zig-sqlite is not super cross-target friendly // .{ // .cpu_arch = .x86_64, // .os_tag = .linux, @@ -18,6 +18,7 @@ const test_targets = [_]std.zig.CrossTarget{ // .cpu_arch = .riscv64, // .os_tag = .linux, // }, + // will not work // .{ // .cpu_arch = .arm, // .os_tag = .linux, @@ -96,23 +97,37 @@ pub fn build(b: *std.Build) !void { try universal_lambda.configureBuild(b, exe); - const aws_dep = b.dependency("aws", .{ + const exe_aws_dep = b.dependency("aws", .{ .target = target, .optimize = optimize, }); - const aws_signing_module = aws_dep.module("aws-signing"); - const sqlite_dep = b.dependency("sqlite", .{ + const exe_aws_signing_module = exe_aws_dep.module("aws-signing"); + const exe_sqlite_dep = b.dependency("sqlite", .{ .target = target, .optimize = optimize, .use_bundled = true, }); - const sqlite_module = sqlite_dep.module("sqlite"); - + const exe_sqlite_module = exe_sqlite_dep.module("sqlite"); + exe.addModule("aws-signing", exe_aws_signing_module); + exe.addModule("sqlite", exe_sqlite_module); + exe.addIncludePath(.{ .path = "c" }); + exe.linkLibrary(exe_sqlite_dep.artifact("sqlite")); // 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 // running the unit tests. const test_step = b.step("test", "Run unit tests"); for (test_targets) |t| { + const aws_dep = b.dependency("aws", .{ + .target = t, + .optimize = optimize, + }); + const aws_signing_module = aws_dep.module("aws-signing"); + const sqlite_dep = b.dependency("sqlite", .{ + .target = t, + .optimize = optimize, + .use_bundled = true, + }); + const sqlite_module = sqlite_dep.module("sqlite"); // Creates a step for unit testing. This only builds the test executable // but does not run it. const unit_tests = b.addTest(.{ @@ -127,12 +142,10 @@ pub fn build(b: *std.Build) !void { test_step.dependOn(&run_unit_tests.step); - for (&[_]*std.Build.Step.Compile{ exe, unit_tests }) |cs| { - cs.addModule("aws-signing", aws_signing_module); - cs.addModule("sqlite", sqlite_module); - cs.addIncludePath(.{ .path = "c" }); - cs.linkLibrary(sqlite_dep.artifact("sqlite")); - } + unit_tests.addModule("aws-signing", aws_signing_module); + unit_tests.addModule("sqlite", sqlite_module); + unit_tests.addIncludePath(.{ .path = "c" }); + unit_tests.linkLibrary(sqlite_dep.artifact("sqlite")); } var creds_step = b.step("generate_credentials", "Generate credentials for access_keys.csv"); diff --git a/src/main.zig b/src/main.zig index e363691..73b8d60 100644 --- a/src/main.zig +++ b/src/main.zig @@ -25,7 +25,7 @@ pub fn main() !u8 { pub fn handler(allocator: std.mem.Allocator, event_data: []const u8, context: universal_lambda_interface.Context) ![]const u8 { const builtin = @import("builtin"); - var rss: std.os.rusage = undefined; + var rss: if (builtin.os.tag == .linux) std.os.rusage else usize = undefined; if (builtin.os.tag == .linux and builtin.mode == .Debug) rss = std.os.getrusage(std.os.rusage.SELF); defer if (builtin.os.tag == .linux and builtin.mode == .Debug) { // and debug mode) { @@ -122,7 +122,7 @@ fn authenticateUser(allocator: std.mem.Allocator, context: universal_lambda_inte .headers = headers, }; const auth_bypass = - @import("builtin").mode == .Debug and try std.process.hasEnvVar(allocator, "DEBUG_AUTHN_BYPASS"); + @import("builtin").os.tag == .linux and @import("builtin").mode == .Debug and try std.process.hasEnvVar(allocator, "DEBUG_AUTHN_BYPASS"); const is_authenticated = auth_bypass or signing.verify(allocator, request, body_reader, getCreds) catch |err| { if (std.mem.eql(u8, "AuthorizationHeaderMissing", @errorName(err))) {