mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-14 11:35:48 +00:00
build: add ghostty-internal pkg-config modules (shared + static)
This commit is contained in:
@@ -13,6 +13,8 @@ step: *std.Build.Step,
|
||||
/// The final static library file
|
||||
output: std.Build.LazyPath,
|
||||
dsym: ?std.Build.LazyPath,
|
||||
pkg_config: ?std.Build.LazyPath,
|
||||
pkg_config_static: ?std.Build.LazyPath,
|
||||
|
||||
pub fn initStatic(
|
||||
b: *std.Build,
|
||||
@@ -54,6 +56,8 @@ pub fn initStatic(
|
||||
.step = &lib.step,
|
||||
.output = lib.getEmittedBin(),
|
||||
.dsym = null,
|
||||
.pkg_config = null,
|
||||
.pkg_config_static = null,
|
||||
};
|
||||
|
||||
// Create a static lib that contains all our dependencies.
|
||||
@@ -70,6 +74,8 @@ pub fn initStatic(
|
||||
|
||||
// Static libraries cannot have dSYMs because they aren't linked.
|
||||
.dsym = null,
|
||||
.pkg_config = null,
|
||||
.pkg_config_static = null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -146,10 +152,20 @@ pub fn initShared(
|
||||
break :dsymutil output;
|
||||
};
|
||||
|
||||
// pkg-config
|
||||
//
|
||||
// pkg-config's --static only expands Libs.private / Requires.private;
|
||||
// it doesn't change -lghostty into an archive-only reference when
|
||||
// both shared and static libraries are installed. Install a dedicated
|
||||
// static module so consumers can request the archive explicitly.
|
||||
const pcs = pkgConfigFiles(b, deps);
|
||||
|
||||
return .{
|
||||
.step = &lib.step,
|
||||
.output = lib.getEmittedBin(),
|
||||
.dsym = dsymutil,
|
||||
.pkg_config = pcs.shared,
|
||||
.pkg_config_static = pcs.static,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -180,13 +196,31 @@ pub fn initMacOSUniversal(
|
||||
// You can't run dsymutil on a universal binary, you have to
|
||||
// do it on the individual binaries.
|
||||
.dsym = null,
|
||||
.pkg_config = null,
|
||||
.pkg_config_static = null,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn install(self: *const GhosttyLib, name: []const u8) void {
|
||||
const b = self.step.owner;
|
||||
const step = b.getInstallStep();
|
||||
const lib_install = b.addInstallLibFile(self.output, name);
|
||||
b.getInstallStep().dependOn(&lib_install.step);
|
||||
step.dependOn(&lib_install.step);
|
||||
|
||||
if (self.pkg_config) |pc| {
|
||||
step.dependOn(&b.addInstallFileWithDir(
|
||||
pc,
|
||||
.prefix,
|
||||
"share/pkgconfig/ghostty-internal.pc",
|
||||
).step);
|
||||
}
|
||||
if (self.pkg_config_static) |pc| {
|
||||
step.dependOn(&b.addInstallFileWithDir(
|
||||
pc,
|
||||
.prefix,
|
||||
"share/pkgconfig/ghostty-internal-static.pc",
|
||||
).step);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn installHeader(self: *const GhosttyLib) void {
|
||||
@@ -197,3 +231,54 @@ pub fn installHeader(self: *const GhosttyLib) void {
|
||||
);
|
||||
b.getInstallStep().dependOn(&header_install.step);
|
||||
}
|
||||
|
||||
const PkgConfigFiles = struct {
|
||||
shared: std.Build.LazyPath,
|
||||
static: std.Build.LazyPath,
|
||||
};
|
||||
|
||||
fn pkgConfigFiles(
|
||||
b: *std.Build,
|
||||
deps: *const SharedDeps,
|
||||
) PkgConfigFiles {
|
||||
const os_tag = deps.config.target.result.os.tag;
|
||||
const wf = b.addWriteFiles();
|
||||
|
||||
return .{
|
||||
.shared = wf.add("ghostty-internal.pc", b.fmt(
|
||||
\\prefix={s}
|
||||
\\includedir=${{prefix}}/include
|
||||
\\libdir=${{prefix}}/lib
|
||||
\\
|
||||
\\Name: ghostty-internal
|
||||
\\URL: https://github.com/ghostty-org/ghostty
|
||||
\\Description: Ghostty internal library (not for external use)
|
||||
\\Version: {f}
|
||||
\\Cflags: -I${{includedir}}
|
||||
\\Libs: -L${{libdir}} -lghostty
|
||||
\\Libs.private:
|
||||
\\Requires.private:
|
||||
, .{ b.install_prefix, deps.config.version })),
|
||||
.static = wf.add("ghostty-internal-static.pc", b.fmt(
|
||||
\\prefix={s}
|
||||
\\includedir=${{prefix}}/include
|
||||
\\libdir=${{prefix}}/lib
|
||||
\\
|
||||
\\Name: ghostty-internal-static
|
||||
\\URL: https://github.com/ghostty-org/ghostty
|
||||
\\Description: Ghostty internal library, static (not for external use)
|
||||
\\Version: {f}
|
||||
\\Cflags: -I${{includedir}}
|
||||
\\Libs: ${{libdir}}/{s}
|
||||
\\Libs.private:
|
||||
\\Requires.private:
|
||||
, .{ b.install_prefix, deps.config.version, staticLibraryName(os_tag) })),
|
||||
};
|
||||
}
|
||||
|
||||
fn staticLibraryName(os_tag: std.Target.Os.Tag) []const u8 {
|
||||
return if (os_tag == .windows)
|
||||
"ghostty-static.lib"
|
||||
else
|
||||
"libghostty.a";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user