diff options
author | Christian Segundo | 2023-07-24 10:28:58 +0200 |
---|---|---|
committer | Christian Segundo | 2023-07-24 10:28:58 +0200 |
commit | f743e05e207046073999ee7234a157359d6a4f57 (patch) | |
tree | 0ceb01ffdcdc3a094e488c28e80c80d89f8309c5 /XCFrameworkStep.zig | |
parent | b02b7f71978a172848322f0671d580e425634916 (diff) | |
download | zmission-master.tar.gz |
Diffstat (limited to 'XCFrameworkStep.zig')
-rw-r--r-- | XCFrameworkStep.zig | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/XCFrameworkStep.zig b/XCFrameworkStep.zig new file mode 100644 index 0000000..36fdbeb --- /dev/null +++ b/XCFrameworkStep.zig @@ -0,0 +1,59 @@ +//! A zig builder step that runs "swift build" in the context of +//! a Swift project managed with SwiftPM. This is primarily meant to build +//! executables currently since that is what we build. +const XCFrameworkStep = @This(); + +const std = @import("std"); +const Step = std.build.Step; +const RunStep = std.build.RunStep; +const FileSource = std.build.FileSource; + +pub const Options = struct { + /// The name of the xcframework to create. + name: []const u8, + + /// The path to write the framework + out_path: []const u8, + + /// Library file (dylib, a) to package. + library: std.build.FileSource, + + /// Path to a directory with the headers. + headers: std.build.FileSource, +}; + +step: *Step, + +pub fn create(b: *std.Build, opts: Options) *XCFrameworkStep { + const self = b.allocator.create(XCFrameworkStep) catch @panic("OOM"); + + // We have to delete the old xcframework first since we're writing + // to a static path. + const run_delete = run: { + const run = RunStep.create(b, b.fmt("xcframework delete {s}", .{opts.name})); + run.has_side_effects = true; + run.addArgs(&.{ "rm", "-rf", opts.out_path }); + break :run run; + }; + + // Then we run xcodebuild to create the framework. + const run_create = run: { + const run = RunStep.create(b, b.fmt("xcframework {s}", .{opts.name})); + run.has_side_effects = true; + run.addArgs(&.{ "xcodebuild", "-create-xcframework" }); + run.addArg("-library"); + run.addFileSourceArg(opts.library); + run.addArg("-headers"); + run.addFileSourceArg(opts.headers); + run.addArg("-output"); + run.addArg(opts.out_path); + break :run run; + }; + run_create.step.dependOn(&run_delete.step); + + self.* = .{ + .step = &run_create.step, + }; + + return self; +} |