build compiles at least

This commit is contained in:
Mitchell Hashimoto
2023-03-24 19:39:50 -07:00
parent b5441dbb5b
commit 5dc98da9a0
6 changed files with 75 additions and 168 deletions

View File

@@ -4,8 +4,8 @@ const LibtoolStep = @This();
const std = @import("std");
const Step = std.build.Step;
const RunStep = std.build.RunStep;
const FileSource = std.build.FileSource;
const GeneratedFile = std.build.GeneratedFile;
pub const Options = struct {
/// The name of this step.
@@ -19,47 +19,26 @@ pub const Options = struct {
sources: []FileSource,
};
step: Step,
builder: *std.Build,
/// The step to depend on.
step: *Step,
/// Resulting binary
out_path: GeneratedFile,
/// The output file from the libtool run.
output: FileSource,
/// See Options
name: []const u8,
out_name: []const u8,
sources: []FileSource,
/// Run libtool against a list of library files to combine into a single
/// static library.
pub fn create(b: *std.Build, opts: Options) *LibtoolStep {
const self = b.allocator.create(LibtoolStep) catch @panic("OOM");
const run_step = RunStep.create(b, b.fmt("libtool {s}", .{opts.name}));
run_step.addArgs(&.{ "libtool", "-static", "-o" });
const output = run_step.addOutputFileArg(opts.out_name);
for (opts.sources) |source| run_step.addFileSourceArg(source);
pub fn create(builder: *std.Build, opts: Options) *LibtoolStep {
const self = builder.allocator.create(LibtoolStep) catch @panic("OOM");
self.* = .{
.step = Step.init(.custom, builder.fmt("lipo {s}", .{opts.name}), builder.allocator, make),
.builder = builder,
.name = opts.name,
.out_path = .{ .step = &self.step },
.out_name = opts.out_name,
.sources = opts.sources,
.step = &run_step.step,
.output = output,
};
return self;
}
fn make(step: *Step) !void {
const self = @fieldParentPtr(LibtoolStep, "step", step);
// We use a RunStep here to ease our configuration.
const run = std.build.RunStep.create(self.builder, self.builder.fmt(
"libtool {s}",
.{self.name},
));
run.addArgs(&.{
"libtool",
"-static",
"-o",
});
try run.argv.append(.{ .output = .{
.generated_file = &self.out_path,
.basename = self.out_name,
} });
for (self.sources) |source| run.addFileSourceArg(source);
try run.step.make();
}

View File

@@ -4,8 +4,8 @@ const LipoStep = @This();
const std = @import("std");
const Step = std.build.Step;
const RunStep = std.build.RunStep;
const FileSource = std.build.FileSource;
const GeneratedFile = std.build.GeneratedFile;
pub const Options = struct {
/// The name of the xcframework to create.
@@ -19,46 +19,24 @@ pub const Options = struct {
input_b: FileSource,
};
step: Step,
builder: *std.build.Builder,
step: *Step,
/// Resulting binary
out_path: GeneratedFile,
output: FileSource,
/// See Options
name: []const u8,
out_name: []const u8,
input_a: FileSource,
input_b: FileSource,
pub fn create(b: *std.Build, opts: Options) *LipoStep {
const self = b.allocator.create(LipoStep) catch @panic("OOM");
const run_step = RunStep.create(b, b.fmt("lipo {s}", .{opts.name}));
run_step.addArgs(&.{ "lipo", "-create", "-output" });
const output = run_step.addOutputFileArg(opts.out_name);
run_step.addFileSourceArg(opts.input_a);
run_step.addFileSourceArg(opts.input_b);
pub fn create(builder: *std.build.Builder, opts: Options) *LipoStep {
const self = builder.allocator.create(LipoStep) catch @panic("OOM");
self.* = .{
.step = Step.init(.custom, builder.fmt("lipo {s}", .{opts.name}), builder.allocator, make),
.builder = builder,
.name = opts.name,
.out_path = .{ .step = &self.step },
.out_name = opts.out_name,
.input_a = opts.input_a,
.input_b = opts.input_b,
.step = &run_step.step,
.output = output,
};
return self;
}
fn make(step: *Step) !void {
const self = @fieldParentPtr(LipoStep, "step", step);
// We use a RunStep here to ease our configuration.
const run = std.build.RunStep.create(self.builder, self.builder.fmt(
"lipo {s}",
.{self.name},
));
run.addArgs(&.{ "lipo", "-create", "-output" });
try run.argv.append(.{ .output = .{
.generated_file = &self.out_path,
.basename = self.out_name,
} });
run.addFileSourceArg(self.input_a);
run.addFileSourceArg(self.input_b);
try run.step.make();
}

View File

@@ -5,7 +5,8 @@ const XCFrameworkStep = @This();
const std = @import("std");
const Step = std.build.Step;
const GeneratedFile = std.build.GeneratedFile;
const RunStep = std.build.RunStep;
const FileSource = std.build.FileSource;
pub const Options = struct {
/// The name of the xcframework to create.
@@ -21,61 +22,38 @@ pub const Options = struct {
headers: std.build.FileSource,
};
step: Step,
builder: *std.build.Builder,
step: *Step,
/// See Options
name: []const u8,
out_path: []const u8,
library: std.build.FileSource,
headers: std.build.FileSource,
pub fn create(b: *std.Build, opts: Options) *XCFrameworkStep {
const self = b.allocator.create(XCFrameworkStep) catch @panic("OOM");
pub fn create(builder: *std.build.Builder, opts: Options) *XCFrameworkStep {
const self = builder.allocator.create(XCFrameworkStep) catch @panic("OOM");
self.* = .{
.step = Step.init(.custom, builder.fmt(
"xcframework {s}",
.{opts.name},
), builder.allocator, make),
.builder = builder,
.name = opts.name,
.out_path = opts.out_path,
.library = opts.library,
.headers = opts.headers,
// 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;
};
return self;
}
fn make(step: *Step) !void {
const self = @fieldParentPtr(XCFrameworkStep, "step", step);
// TODO: use the zig cache system when it is in the stdlib
// https://github.com/ziglang/zig/pull/14571
const output_path = self.out_path;
// We use a RunStep here to ease our configuration.
{
const run = std.build.RunStep.create(self.builder, self.builder.fmt(
"xcframework delete {s}",
.{self.name},
));
run.condition = .always;
run.addArgs(&.{ "rm", "-rf", output_path });
try run.step.make();
}
{
const run = std.build.RunStep.create(self.builder, self.builder.fmt(
"xcframework {s}",
.{self.name},
));
run.condition = .always;
// 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(self.library);
run.addFileSourceArg(opts.library);
run.addArg("-headers");
run.addFileSourceArg(self.headers);
run.addFileSourceArg(opts.headers);
run.addArg("-output");
run.addArg(output_path);
try run.step.make();
}
run.addArg(opts.out_path);
break :run run;
};
run_create.step.dependOn(&run_delete.step);
self.* = .{
.step = &run_create.step,
};
return self;
}