mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-29 10:33:57 +00:00
build: ghostty lib, framework, build into app
This commit is contained in:
78
src/build/XCFrameworkStep.zig
Normal file
78
src/build/XCFrameworkStep.zig
Normal file
@@ -0,0 +1,78 @@
|
||||
//! 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 GeneratedFile = std.build.GeneratedFile;
|
||||
|
||||
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,
|
||||
builder: *std.build.Builder,
|
||||
|
||||
/// See Options
|
||||
name: []const u8,
|
||||
out_path: []const u8,
|
||||
library: std.build.FileSource,
|
||||
headers: std.build.FileSource,
|
||||
|
||||
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,
|
||||
};
|
||||
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.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.addArgs(&.{
|
||||
"xcodebuild", "-create-xcframework",
|
||||
"-library", self.library.getPath(self.builder),
|
||||
"-headers", self.headers.getPath(self.builder),
|
||||
"-output", output_path,
|
||||
});
|
||||
try run.step.make();
|
||||
}
|
||||
}
|
||||
11
src/main_c.zig
Normal file
11
src/main_c.zig
Normal file
@@ -0,0 +1,11 @@
|
||||
// This is the main file for the C API. The C API is used to embed Ghostty
|
||||
// within other applications. Depending on the build settings some APIs
|
||||
// may not be available (i.e. embedding into macOS exposes various Metal
|
||||
// support).
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
// We're just testing right now.
|
||||
export fn ghostty_hello() u64 {
|
||||
return 42;
|
||||
}
|
||||
Reference in New Issue
Block a user