mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
build: build proper metallib for iOS builds
This commit is contained in:
31
build.zig
31
build.zig
@ -1267,29 +1267,18 @@ fn addDeps(
|
|||||||
/// Generate Metal shader library
|
/// Generate Metal shader library
|
||||||
fn addMetallib(
|
fn addMetallib(
|
||||||
b: *std.Build,
|
b: *std.Build,
|
||||||
step_: ?*std.Build.Step.Compile,
|
step: *std.Build.Step.Compile,
|
||||||
) !void {
|
) !void {
|
||||||
// Our static state between runs. We memoize so we only compile
|
const metal_step = MetallibStep.create(b, .{
|
||||||
// the Metal shaders once.
|
.name = "Ghostty",
|
||||||
const MetalState = struct {
|
.target = step.root_module.resolved_target.?,
|
||||||
var generated: ?std.Build.LazyPath = null;
|
.sources = &.{b.path("src/renderer/shaders/cell.metal")},
|
||||||
};
|
});
|
||||||
|
|
||||||
const output = MetalState.generated orelse metal: {
|
metal_step.output.addStepDependencies(&step.step);
|
||||||
const step = MetallibStep.create(b, .{
|
step.root_module.addAnonymousImport("ghostty_metallib", .{
|
||||||
.name = "Ghostty",
|
.root_source_file = metal_step.output,
|
||||||
.sources = &.{b.path("src/renderer/shaders/cell.metal")},
|
});
|
||||||
});
|
|
||||||
|
|
||||||
break :metal step.output;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (step_) |step| {
|
|
||||||
output.addStepDependencies(&step.step);
|
|
||||||
step.root_module.addAnonymousImport("ghostty_metallib", .{
|
|
||||||
.root_source_file = output,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate help files
|
/// Generate help files
|
||||||
|
@ -11,6 +11,9 @@ pub const Options = struct {
|
|||||||
/// The name of the xcframework to create.
|
/// The name of the xcframework to create.
|
||||||
name: []const u8,
|
name: []const u8,
|
||||||
|
|
||||||
|
/// The OS being targeted
|
||||||
|
target: std.Build.ResolvedTarget,
|
||||||
|
|
||||||
/// The Metal source files.
|
/// The Metal source files.
|
||||||
sources: []const LazyPath,
|
sources: []const LazyPath,
|
||||||
};
|
};
|
||||||
@ -21,20 +24,45 @@ output: LazyPath,
|
|||||||
pub fn create(b: *std.Build, opts: Options) *MetallibStep {
|
pub fn create(b: *std.Build, opts: Options) *MetallibStep {
|
||||||
const self = b.allocator.create(MetallibStep) catch @panic("OOM");
|
const self = b.allocator.create(MetallibStep) catch @panic("OOM");
|
||||||
|
|
||||||
|
const sdk = switch (opts.target.result.os.tag) {
|
||||||
|
.macos => "macosx",
|
||||||
|
.ios => "iphoneos",
|
||||||
|
else => @panic("unsupported metallib OS"),
|
||||||
|
};
|
||||||
|
|
||||||
|
const min_version = if (opts.target.query.os_version_min) |v|
|
||||||
|
b.fmt("{}", .{v.semver})
|
||||||
|
else switch (opts.target.result.os.tag) {
|
||||||
|
.macos => "10.14",
|
||||||
|
.ios => "11.0",
|
||||||
|
else => unreachable,
|
||||||
|
};
|
||||||
|
|
||||||
const run_ir = RunStep.create(
|
const run_ir = RunStep.create(
|
||||||
b,
|
b,
|
||||||
b.fmt("metal {s}", .{opts.name}),
|
b.fmt("metal {s}", .{opts.name}),
|
||||||
);
|
);
|
||||||
run_ir.addArgs(&.{ "xcrun", "-sdk", "macosx", "metal", "-o" });
|
run_ir.addArgs(&.{ "xcrun", "-sdk", sdk, "metal", "-o" });
|
||||||
const output_ir = run_ir.addOutputFileArg(b.fmt("{s}.ir", .{opts.name}));
|
const output_ir = run_ir.addOutputFileArg(b.fmt("{s}.ir", .{opts.name}));
|
||||||
run_ir.addArgs(&.{"-c"});
|
run_ir.addArgs(&.{"-c"});
|
||||||
for (opts.sources) |source| run_ir.addFileArg(source);
|
for (opts.sources) |source| run_ir.addFileArg(source);
|
||||||
|
switch (opts.target.result.os.tag) {
|
||||||
|
.ios => run_ir.addArgs(&.{b.fmt(
|
||||||
|
"-mios-version-min={s}",
|
||||||
|
.{min_version},
|
||||||
|
)}),
|
||||||
|
.macos => run_ir.addArgs(&.{b.fmt(
|
||||||
|
"-mmacos-version-min={s}",
|
||||||
|
.{min_version},
|
||||||
|
)}),
|
||||||
|
else => {},
|
||||||
|
}
|
||||||
|
|
||||||
const run_lib = RunStep.create(
|
const run_lib = RunStep.create(
|
||||||
b,
|
b,
|
||||||
b.fmt("metallib {s}", .{opts.name}),
|
b.fmt("metallib {s}", .{opts.name}),
|
||||||
);
|
);
|
||||||
run_lib.addArgs(&.{ "xcrun", "-sdk", "macosx", "metallib", "-o" });
|
run_lib.addArgs(&.{ "xcrun", "-sdk", sdk, "metallib", "-o" });
|
||||||
const output_lib = run_lib.addOutputFileArg(b.fmt("{s}.metallib", .{opts.name}));
|
const output_lib = run_lib.addOutputFileArg(b.fmt("{s}.metallib", .{opts.name}));
|
||||||
run_lib.addFileArg(output_ir);
|
run_lib.addFileArg(output_ir);
|
||||||
run_lib.step.dependOn(&run_ir.step);
|
run_lib.step.dependOn(&run_ir.step);
|
||||||
|
Reference in New Issue
Block a user