make it heavy handed, but not THAT heavy handed...
All checks were successful
Generic zig build / build (push) Successful in 1m32s

This commit is contained in:
Emil Lerch 2024-05-08 16:05:41 -07:00
parent 1eea692a24
commit 0581221c11
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
2 changed files with 10 additions and 5 deletions

View File

@ -47,7 +47,7 @@ pub fn build(b: *std.Build) void {
run_cmd.addArgs(args); run_cmd.addArgs(args);
} }
const deploy_cmd = CloudflareDeployStep.create(b, "zigwasi", .{ .path = "index.js" }, .{}); const deploy_cmd = CloudflareDeployStep.create(b, "zigwasi", .{ .path = "index.js" }, .{ .compile_target = exe });
// This creates a build step. It will be visible in the `zig build --help` menu, // This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build run` // and can be selected like this: `zig build run`
@ -78,10 +78,6 @@ pub fn build(b: *std.Build) void {
} }
pub fn configureBuild(b: *std.Build, cs: *std.Build.Step.Compile, function_name: []const u8) !void { pub fn configureBuild(b: *std.Build, cs: *std.Build.Step.Compile, function_name: []const u8) !void {
if (cs.rootModuleTarget().os.tag != .wasi) {
std.log.err("Error: Cloudflare builds require compilation with -Dtarget=wasm32-wasi", .{});
return error.WasiCompilationRequired;
}
const script = @embedFile("index.js"); const script = @embedFile("index.js");
const wasm_name = try std.fmt.allocPrint(b.allocator, "{s}.wasm", .{cs.name}); const wasm_name = try std.fmt.allocPrint(b.allocator, "{s}.wasm", .{cs.name});
const deploy_cmd = CloudflareDeployStep.create( const deploy_cmd = CloudflareDeployStep.create(
@ -95,6 +91,7 @@ pub fn configureBuild(b: *std.Build, cs: *std.Build.Step.Compile, function_name:
.replace = wasm_name, .replace = wasm_name,
}, },
.wasm_dir = b.getInstallPath(.bin, "."), .wasm_dir = b.getInstallPath(.bin, "."),
.compile_target = cs,
}, },
); );
deploy_cmd.step.dependOn(b.getInstallStep()); deploy_cmd.step.dependOn(b.getInstallStep());

View File

@ -23,6 +23,9 @@ pub const Options = struct {
/// When set, the directory specified will be used rather than the current directory /// When set, the directory specified will be used rather than the current directory
wasm_dir: ?[]const u8 = null, wasm_dir: ?[]const u8 = null,
/// Compilation target for this step
compile_target: *std.Build.Step.Compile,
}; };
pub fn create( pub fn create(
@ -53,6 +56,11 @@ fn make(step: *std.Build.Step, prog_node: *std.Progress.Node) !void {
const b = step.owner; const b = step.owner;
const self = @as(*CloudflareDeployStep, @fieldParentPtr("step", step)); const self = @as(*CloudflareDeployStep, @fieldParentPtr("step", step));
if (self.options.compile_target.rootModuleTarget().os.tag != .wasi) {
std.log.err("Error: Cloudflare builds require compilation with -Dtarget=wasm32-wasi", .{});
return error.WasiCompilationRequired;
}
var client = std.http.Client{ .allocator = b.allocator }; var client = std.http.Client{ .allocator = b.allocator };
try client.initDefaultProxies(b.allocator); try client.initDefaultProxies(b.allocator);
defer client.deinit(); defer client.deinit();