From 0581221c11cf32dce48abc5b950d974e570afb0d Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Wed, 8 May 2024 16:05:41 -0700 Subject: [PATCH] make it heavy handed, but not THAT heavy handed... --- build.zig | 7 ++----- src/CloudflareDeployStep.zig | 8 ++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/build.zig b/build.zig index 206fde6..6e3f3ca 100644 --- a/build.zig +++ b/build.zig @@ -47,7 +47,7 @@ pub fn build(b: *std.Build) void { 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, // 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 { - 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 wasm_name = try std.fmt.allocPrint(b.allocator, "{s}.wasm", .{cs.name}); 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, }, .wasm_dir = b.getInstallPath(.bin, "."), + .compile_target = cs, }, ); deploy_cmd.step.dependOn(b.getInstallStep()); diff --git a/src/CloudflareDeployStep.zig b/src/CloudflareDeployStep.zig index e06e5fb..dbed8be 100644 --- a/src/CloudflareDeployStep.zig +++ b/src/CloudflareDeployStep.zig @@ -23,6 +23,9 @@ pub const Options = struct { /// When set, the directory specified will be used rather than the current directory wasm_dir: ?[]const u8 = null, + + /// Compilation target for this step + compile_target: *std.Build.Step.Compile, }; pub fn create( @@ -53,6 +56,11 @@ fn make(step: *std.Build.Step, prog_node: *std.Progress.Node) !void { const b = step.owner; 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 }; try client.initDefaultProxies(b.allocator); defer client.deinit();