From 668debd29de0d5380a18313a3c7f63bc5006f97e Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Fri, 6 Oct 2023 11:48:19 -0700 Subject: [PATCH] initial WASI support --- .gitea/workflows/build.yaml | 1 + src/lambda_build.zig | 2 +- src/universal_lambda.zig | 9 +++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 6bf3b8b..9bde2e4 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -23,6 +23,7 @@ jobs: - run: ln -s /usr/local/zig-linux-${ARCH}-${ZIG_VERSION}/zig /usr/local/bin/zig - run: zig build test - run: zig build test -Dtarget=arm-linux # we want to know we can build for 32 bit + - run: zig build test -Dtarget=wasm32-wasi # downstream needs this for CF workers - name: Notify uses: https://git.lerch.org/lobo/action-notify-ntfy@v2 if: always() diff --git a/src/lambda_build.zig b/src/lambda_build.zig index bb0891d..41225a0 100644 --- a/src/lambda_build.zig +++ b/src/lambda_build.zig @@ -103,7 +103,7 @@ pub fn configureBuild(b: *std.build.Builder, exe: *std.Build.Step.Compile) !void const iam_role_file = b.getInstallPath(.bin, "iam_role"); if (!fileExists(iam_role_file)) { - std.debug.print("file does not exist", .{}); + // std.debug.print("file does not exist", .{}); // Our cache file does not exist on disk, so we'll create/get the role // arn using the AWS CLI and dump to disk here const ifstatement_fmt = diff --git a/src/universal_lambda.zig b/src/universal_lambda.zig index 7df29ac..2848167 100644 --- a/src/universal_lambda.zig +++ b/src/universal_lambda.zig @@ -5,9 +5,14 @@ pub const HandlerFn = *const fn (std.mem.Allocator, []const u8, Context) anyerro const log = std.log.scoped(.universal_lambda); -// TODO: Should this be union? +const FakeResponse = struct { + request: struct { + target: []const u8, + headers: std.http.Headers, + }, +}; pub const Context = union(enum) { - web_request: *std.http.Server.Response, + web_request: if (build_options.build_type == .exe_run) *FakeResponse else *std.http.Server.Response, flexilib: struct { request: flexilib.ZigRequest, response: flexilib.ZigResponse,