cloudflare fixes
All checks were successful
AWS-Zig Build / build-zig-0.11.0-amd64-host (push) Successful in 1m32s

This commit is contained in:
Emil Lerch 2023-10-20 22:28:38 -07:00
parent 88eb415a1e
commit 0c6a9366f5
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
6 changed files with 14 additions and 15 deletions

View File

@ -73,8 +73,8 @@ fn make(step: *std.Build.Step, prog_node: *std.Progress.Node) !void {
b.allocator,
&client,
self.worker_name,
script,
self.options.wasm_dir orelse ".",
script,
al.writer(),
std.io.getStdErr().writer(),
);

View File

@ -1,22 +1,21 @@
const std = @import("std");
const builtin = @import("builtin");
const CloudflareDeployStep = @import("CloudflareDeployStep");
const CloudflareDeployStep = @import("CloudflareDeployStep.zig");
const script = @embedFile("index.js");
pub fn configureBuild(b: *std.build.Builder, cs: *std.Build.Step.Compile, build_root_src: []const u8) !void {
_ = build_root_src;
pub fn configureBuild(b: *std.build.Builder, cs: *std.Build.Step.Compile, function_name: []const u8) !void {
const deploy_cmd = CloudflareDeployStep.create(
b,
"zigwasi",
function_name,
.{ .path = "index.js" },
.{
.primary_file_data = script,
.wasm_name = .{
.search = "zigout.wasm",
.search = "custom.wasm",
.replace = cs.name,
},
.wasm_dir = b.getInstallDir(.bin, "."),
.wasm_dir = b.getInstallPath(.bin, "."),
},
);
deploy_cmd.step.dependOn(b.getInstallStep());

View File

@ -1,4 +1,4 @@
import zigWasm from "zigout.wasm";
import customWasm from "custom.wasm";
export default {
async fetch(request, _env2, ctx) {
const stdout = new TransformStream();
@ -11,7 +11,7 @@ export default {
});
const wasi = new WASI({
args: [
"./zigout.wasm",
"./custom.wasm",
// In a CLI, the first arg is the name of the exe
"--url=" + request.url,
// this contains the target but is the full url, so we will use a different arg for this
@ -22,7 +22,7 @@ export default {
stdin: request.body,
stdout: stdout.writable
});
const instance = new WebAssembly.Instance(demoWasm, {
const instance = new WebAssembly.Instance(customWasm, {
wasi_snapshot_preview1: wasi.wasiImport
});
ctx.waitUntil(wasi.start(instance));

View File

@ -30,7 +30,7 @@ fn addArgs(allocator: std.mem.Allocator, original: []const u8, args: [][]const u
/// awslambda_deploy depends on iam and package
///
/// iam and package do not have any dependencies
pub fn configureBuild(b: *std.build.Builder, exe: *std.Build.Step.Compile) !void {
pub fn configureBuild(b: *std.build.Builder, exe: *std.Build.Step.Compile, function_name: []const u8) !void {
// The rest of this function is currently reliant on the use of Linux
// system being used to build the lambda function
//
@ -132,7 +132,6 @@ pub fn configureBuild(b: *std.build.Builder, exe: *std.Build.Step.Compile) !void
break :blk try std.fmt.allocPrint(b.allocator, "--role \"$(cat {s})\"", .{iam_role_file});
};
const function_name = b.option([]const u8, "function-name", "Function name for Lambda [zig-fn]") orelse "zig-fn";
const function_name_file = b.getInstallPath(.bin, function_name);
const ifstatement = "if [ ! -f {s} ] || [ {s} -nt {s} ]; then if aws lambda get-function --function-name {s} 2>&1 |grep -q ResourceNotFoundException; then echo not found > /dev/null; {s}; else echo found > /dev/null; {s}; fi; fi";
// The architectures option was introduced in 2.2.43 released 2021-10-01

View File

@ -24,7 +24,7 @@ const runFn = blk: {
switch (build_options.build_type) {
.awslambda => break :blk @import("lambda.zig").run,
.standalone_server => break :blk runStandaloneServer,
.exe_run => break :blk runExe,
.exe_run, .cloudflare => break :blk runExe,
else => @compileError("Provider interface for " ++ @tagName(build_options.build_type) ++ " has not yet been implemented"),
}
};

View File

@ -15,6 +15,7 @@ pub const BuildType = enum {
pub var module_root: ?[]const u8 = null;
pub fn configureBuild(b: *std.Build, cs: *std.Build.Step.Compile) !void {
const function_name = b.option([]const u8, "function-name", "Function name for Lambda [zig-fn]") orelse "zig-fn";
const file_location = try findFileLocation(b);
/////////////////////////////////////////////////////////////////////////
// Add modules
@ -62,10 +63,10 @@ pub fn configureBuild(b: *std.Build, cs: *std.Build.Step.Compile) !void {
});
// Add steps
try @import("lambda_build.zig").configureBuild(b, cs);
try @import("lambda_build.zig").configureBuild(b, cs, function_name);
try @import("standalone_server_build.zig").configureBuild(b, cs);
try @import("flexilib_build.zig").configureBuild(b, cs, file_location);
try @import("cloudflare_build.zig").configureBuild(b, cs, file_location);
try @import("cloudflare_build.zig").configureBuild(b, cs, function_name);
}
/// This function relies on internal implementation of the build runner