more cross-platform
All checks were successful
AWS-Zig Build / build-zig-0.11.0-amd64-host (push) Successful in 3m39s

This commit is contained in:
Emil Lerch 2024-02-24 15:48:18 -08:00
parent 7d6829cf17
commit 25f92b741d
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
3 changed files with 37 additions and 18 deletions

View File

@ -33,8 +33,14 @@ jobs:
ln -s /usr/local/zig-linux-${ARCH}-${ZIG_VERSION}/zig /usr/local/bin/zig ln -s /usr/local/zig-linux-${ARCH}-${ZIG_VERSION}/zig /usr/local/bin/zig
- name: Run tests - name: Run tests
run: zig build test --verbose run: zig build test --verbose
- name: Build example - name: Build other platforms
run: ( cd example && zig build ) # Make sure example builds 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 # - name: Sign
# id: sign # id: sign
# uses: https://git.lerch.org/lobo/action-hsm-sign@v1 # uses: https://git.lerch.org/lobo/action-hsm-sign@v1

View File

@ -1,11 +1,11 @@
const std = @import("std"); const std = @import("std");
const universal_lambda = @import("universal_lambda_build"); 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{ const test_targets = [_]std.zig.CrossTarget{
.{}, // native .{}, // 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, // .cpu_arch = .x86_64,
// .os_tag = .linux, // .os_tag = .linux,
@ -18,6 +18,7 @@ const test_targets = [_]std.zig.CrossTarget{
// .cpu_arch = .riscv64, // .cpu_arch = .riscv64,
// .os_tag = .linux, // .os_tag = .linux,
// }, // },
// will not work
// .{ // .{
// .cpu_arch = .arm, // .cpu_arch = .arm,
// .os_tag = .linux, // .os_tag = .linux,
@ -96,23 +97,37 @@ pub fn build(b: *std.Build) !void {
try universal_lambda.configureBuild(b, exe); try universal_lambda.configureBuild(b, exe);
const aws_dep = b.dependency("aws", .{ const exe_aws_dep = b.dependency("aws", .{
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
const aws_signing_module = aws_dep.module("aws-signing"); const exe_aws_signing_module = exe_aws_dep.module("aws-signing");
const sqlite_dep = b.dependency("sqlite", .{ const exe_sqlite_dep = b.dependency("sqlite", .{
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
.use_bundled = true, .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 // 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
// running the unit tests. // running the unit tests.
const test_step = b.step("test", "Run unit tests"); const test_step = b.step("test", "Run unit tests");
for (test_targets) |t| { 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 // Creates a step for unit testing. This only builds the test executable
// but does not run it. // but does not run it.
const unit_tests = b.addTest(.{ const unit_tests = b.addTest(.{
@ -127,12 +142,10 @@ pub fn build(b: *std.Build) !void {
test_step.dependOn(&run_unit_tests.step); test_step.dependOn(&run_unit_tests.step);
for (&[_]*std.Build.Step.Compile{ exe, unit_tests }) |cs| { unit_tests.addModule("aws-signing", aws_signing_module);
cs.addModule("aws-signing", aws_signing_module); unit_tests.addModule("sqlite", sqlite_module);
cs.addModule("sqlite", sqlite_module); unit_tests.addIncludePath(.{ .path = "c" });
cs.addIncludePath(.{ .path = "c" }); unit_tests.linkLibrary(sqlite_dep.artifact("sqlite"));
cs.linkLibrary(sqlite_dep.artifact("sqlite"));
}
} }
var creds_step = b.step("generate_credentials", "Generate credentials for access_keys.csv"); var creds_step = b.step("generate_credentials", "Generate credentials for access_keys.csv");

View File

@ -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 { pub fn handler(allocator: std.mem.Allocator, event_data: []const u8, context: universal_lambda_interface.Context) ![]const u8 {
const builtin = @import("builtin"); 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) if (builtin.os.tag == .linux and builtin.mode == .Debug)
rss = std.os.getrusage(std.os.rusage.SELF); rss = std.os.getrusage(std.os.rusage.SELF);
defer if (builtin.os.tag == .linux and builtin.mode == .Debug) { // and debug mode) { 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, .headers = headers,
}; };
const auth_bypass = 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 const is_authenticated = auth_bypass or
signing.verify(allocator, request, body_reader, getCreds) catch |err| { signing.verify(allocator, request, body_reader, getCreds) catch |err| {
if (std.mem.eql(u8, "AuthorizationHeaderMissing", @errorName(err))) { if (std.mem.eql(u8, "AuthorizationHeaderMissing", @errorName(err))) {