|
| 1 | +const GhosttyLibVt = @This(); |
| 2 | + |
| 3 | +const std = @import("std"); |
| 4 | +const RunStep = std.Build.Step.Run; |
| 5 | +const Config = @import("Config.zig"); |
| 6 | +const GhosttyZig = @import("GhosttyZig.zig"); |
| 7 | +const SharedDeps = @import("SharedDeps.zig"); |
| 8 | +const LibtoolStep = @import("LibtoolStep.zig"); |
| 9 | +const LipoStep = @import("LipoStep.zig"); |
| 10 | + |
| 11 | +/// The step that generates the file. |
| 12 | +step: *std.Build.Step, |
| 13 | + |
| 14 | +/// The final library file |
| 15 | +output: std.Build.LazyPath, |
| 16 | +dsym: ?std.Build.LazyPath, |
| 17 | + |
| 18 | +pub fn initShared( |
| 19 | + b: *std.Build, |
| 20 | + zig: *const GhosttyZig, |
| 21 | + deps: *const SharedDeps, |
| 22 | +) !GhosttyLibVt { |
| 23 | + const lib = b.addSharedLibrary(.{ |
| 24 | + .name = "ghostty-vt", |
| 25 | + .root_module = zig.vt, |
| 26 | + }); |
| 27 | + |
| 28 | + // Get our debug symbols |
| 29 | + const dsymutil: ?std.Build.LazyPath = dsymutil: { |
| 30 | + if (!deps.config.target.result.os.tag.isDarwin()) { |
| 31 | + break :dsymutil null; |
| 32 | + } |
| 33 | + |
| 34 | + const dsymutil = RunStep.create(b, "dsymutil"); |
| 35 | + dsymutil.addArgs(&.{"dsymutil"}); |
| 36 | + dsymutil.addFileArg(lib.getEmittedBin()); |
| 37 | + dsymutil.addArgs(&.{"-o"}); |
| 38 | + const output = dsymutil.addOutputFileArg("libghostty-vt.dSYM"); |
| 39 | + break :dsymutil output; |
| 40 | + }; |
| 41 | + |
| 42 | + return .{ |
| 43 | + .step = &lib.step, |
| 44 | + .output = lib.getEmittedBin(), |
| 45 | + .dsym = dsymutil, |
| 46 | + }; |
| 47 | +} |
| 48 | + |
| 49 | +pub fn install( |
| 50 | + self: *const GhosttyLibVt, |
| 51 | + step: *std.Build.Step, |
| 52 | + name: []const u8, |
| 53 | +) void { |
| 54 | + const b = self.step.owner; |
| 55 | + const lib_install = b.addInstallLibFile( |
| 56 | + self.output, |
| 57 | + name, |
| 58 | + ); |
| 59 | + step.dependOn(&lib_install.step); |
| 60 | +} |
| 61 | + |
| 62 | +pub fn installHeader( |
| 63 | + self: *const GhosttyLibVt, |
| 64 | + step: *std.Build.Step, |
| 65 | +) void { |
| 66 | + const b = self.step.owner; |
| 67 | + const header_install = b.addInstallHeaderFile( |
| 68 | + b.path("include/ghostty-vt.h"), |
| 69 | + "ghostty-vt.h", |
| 70 | + ); |
| 71 | + step.dependOn(&header_install.step); |
| 72 | +} |
0 commit comments