mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
pkg/freetype
This commit is contained in:
@ -16,7 +16,6 @@ const Version = @import("src/build/Version.zig");
|
||||
|
||||
const glfw = @import("vendor/mach-glfw/build.zig");
|
||||
const fontconfig = @import("pkg/fontconfig/build.zig");
|
||||
const freetype = @import("pkg/freetype/build.zig");
|
||||
const harfbuzz = @import("pkg/harfbuzz/build.zig");
|
||||
const js = @import("vendor/zig-js/build.zig");
|
||||
const libxev = @import("vendor/libxev/build.zig");
|
||||
@ -28,6 +27,7 @@ const utf8proc = @import("pkg/utf8proc/build.zig");
|
||||
const tracylib = @import("pkg/tracy/build.zig");
|
||||
const system_sdk = @import("vendor/mach-glfw/system_sdk.zig");
|
||||
|
||||
const freetype = @import("pkg/freetype/build.old.zig");
|
||||
const libpng = @import("pkg/libpng/build.old.zig");
|
||||
const zlib = @import("pkg/zlib/build.old.zig");
|
||||
|
||||
|
172
pkg/freetype/build.old.zig
Normal file
172
pkg/freetype/build.old.zig
Normal file
@ -0,0 +1,172 @@
|
||||
const std = @import("std");
|
||||
|
||||
/// Directories with our includes.
|
||||
const root = thisDir() ++ "../../../vendor/freetype/";
|
||||
const include_path = root ++ "include";
|
||||
pub const include_path_self = thisDir();
|
||||
|
||||
pub const include_paths = .{ include_path, include_path_self };
|
||||
|
||||
pub fn module(b: *std.Build) *std.build.Module {
|
||||
return b.createModule(.{
|
||||
.source_file = .{ .path = (comptime thisDir()) ++ "/main.zig" },
|
||||
});
|
||||
}
|
||||
|
||||
fn thisDir() []const u8 {
|
||||
return std.fs.path.dirname(@src().file) orelse ".";
|
||||
}
|
||||
|
||||
pub const Options = struct {
|
||||
libpng: Libpng = .{},
|
||||
zlib: Zlib = .{},
|
||||
|
||||
pub const Libpng = struct {
|
||||
enabled: bool = false,
|
||||
step: ?*std.build.LibExeObjStep = null,
|
||||
include: ?[]const []const u8 = null,
|
||||
};
|
||||
|
||||
pub const Zlib = struct {
|
||||
enabled: bool = false,
|
||||
step: ?*std.build.LibExeObjStep = null,
|
||||
include: ?[]const []const u8 = null,
|
||||
};
|
||||
};
|
||||
|
||||
pub fn link(
|
||||
b: *std.Build,
|
||||
step: *std.build.LibExeObjStep,
|
||||
opt: Options,
|
||||
) !*std.build.LibExeObjStep {
|
||||
const lib = try buildFreetype(b, step, opt);
|
||||
step.linkLibrary(lib);
|
||||
step.addIncludePath(.{ .path = include_path });
|
||||
step.addIncludePath(.{ .path = include_path_self });
|
||||
return lib;
|
||||
}
|
||||
|
||||
pub fn buildFreetype(
|
||||
b: *std.Build,
|
||||
step: *std.build.LibExeObjStep,
|
||||
opt: Options,
|
||||
) !*std.build.LibExeObjStep {
|
||||
const target = step.target;
|
||||
const lib = b.addStaticLibrary(.{
|
||||
.name = "freetype",
|
||||
.target = target,
|
||||
.optimize = step.optimize,
|
||||
});
|
||||
|
||||
// Include
|
||||
lib.addIncludePath(.{ .path = include_path });
|
||||
|
||||
// Link
|
||||
lib.linkLibC();
|
||||
if (opt.libpng.enabled) {
|
||||
if (opt.libpng.step) |libpng|
|
||||
lib.linkLibrary(libpng)
|
||||
else
|
||||
lib.linkSystemLibrary("libpng");
|
||||
|
||||
if (opt.libpng.include) |dirs|
|
||||
for (dirs) |dir| lib.addIncludePath(.{ .path = dir });
|
||||
}
|
||||
if (opt.zlib.enabled) {
|
||||
if (opt.zlib.step) |zlib|
|
||||
lib.linkLibrary(zlib)
|
||||
else
|
||||
lib.linkSystemLibrary("z");
|
||||
|
||||
if (opt.zlib.include) |dirs|
|
||||
for (dirs) |dir| lib.addIncludePath(.{ .path = dir });
|
||||
}
|
||||
|
||||
// Compile
|
||||
var flags = std.ArrayList([]const u8).init(b.allocator);
|
||||
defer flags.deinit();
|
||||
|
||||
try flags.appendSlice(&.{
|
||||
"-DFT2_BUILD_LIBRARY",
|
||||
|
||||
"-DHAVE_UNISTD_H",
|
||||
"-DHAVE_FCNTL_H",
|
||||
|
||||
"-fno-sanitize=undefined",
|
||||
});
|
||||
if (opt.libpng.enabled) try flags.append("-DFT_CONFIG_OPTION_USE_PNG=1");
|
||||
if (opt.zlib.enabled) try flags.append("-DFT_CONFIG_OPTION_SYSTEM_ZLIB=1");
|
||||
|
||||
// C files
|
||||
lib.addCSourceFiles(srcs, flags.items);
|
||||
switch (target.getOsTag()) {
|
||||
.linux => lib.addCSourceFile(.{
|
||||
.file = .{ .path = root ++ "builds/unix/ftsystem.c" },
|
||||
.flags = flags.items,
|
||||
}),
|
||||
.windows => lib.addCSourceFile(.{
|
||||
.file = .{ .path = root ++ "builds/windows/ftsystem.c" },
|
||||
.flags = flags.items,
|
||||
}),
|
||||
else => lib.addCSourceFile(.{
|
||||
.file = .{ .path = root ++ "src/base/ftsystem.c" },
|
||||
.flags = flags.items,
|
||||
}),
|
||||
}
|
||||
switch (target.getOsTag()) {
|
||||
.windows => {
|
||||
lib.addCSourceFiles(&.{
|
||||
root ++ "builds/windows/ftdebug.c",
|
||||
}, flags.items);
|
||||
},
|
||||
else => lib.addCSourceFile(.{
|
||||
.file = .{ .path = root ++ "src/base/ftdebug.c" },
|
||||
.flags = flags.items,
|
||||
}),
|
||||
}
|
||||
|
||||
return lib;
|
||||
}
|
||||
|
||||
const srcs = &.{
|
||||
root ++ "src/autofit/autofit.c",
|
||||
root ++ "src/base/ftbase.c",
|
||||
root ++ "src/base/ftbbox.c",
|
||||
root ++ "src/base/ftbdf.c",
|
||||
root ++ "src/base/ftbitmap.c",
|
||||
root ++ "src/base/ftcid.c",
|
||||
root ++ "src/base/ftfstype.c",
|
||||
root ++ "src/base/ftgasp.c",
|
||||
root ++ "src/base/ftglyph.c",
|
||||
root ++ "src/base/ftgxval.c",
|
||||
root ++ "src/base/ftinit.c",
|
||||
root ++ "src/base/ftmm.c",
|
||||
root ++ "src/base/ftotval.c",
|
||||
root ++ "src/base/ftpatent.c",
|
||||
root ++ "src/base/ftpfr.c",
|
||||
root ++ "src/base/ftstroke.c",
|
||||
root ++ "src/base/ftsynth.c",
|
||||
root ++ "src/base/fttype1.c",
|
||||
root ++ "src/base/ftwinfnt.c",
|
||||
root ++ "src/bdf/bdf.c",
|
||||
root ++ "src/bzip2/ftbzip2.c",
|
||||
root ++ "src/cache/ftcache.c",
|
||||
root ++ "src/cff/cff.c",
|
||||
root ++ "src/cid/type1cid.c",
|
||||
root ++ "src/gzip/ftgzip.c",
|
||||
root ++ "src/lzw/ftlzw.c",
|
||||
root ++ "src/pcf/pcf.c",
|
||||
root ++ "src/pfr/pfr.c",
|
||||
root ++ "src/psaux/psaux.c",
|
||||
root ++ "src/pshinter/pshinter.c",
|
||||
root ++ "src/psnames/psnames.c",
|
||||
root ++ "src/raster/raster.c",
|
||||
root ++ "src/sdf/sdf.c",
|
||||
root ++ "src/sfnt/sfnt.c",
|
||||
root ++ "src/smooth/smooth.c",
|
||||
root ++ "src/svg/svg.c",
|
||||
root ++ "src/truetype/truetype.c",
|
||||
root ++ "src/type1/type1.c",
|
||||
root ++ "src/type42/type42.c",
|
||||
root ++ "src/winfonts/winfnt.c",
|
||||
};
|
@ -1,172 +1,129 @@
|
||||
const std = @import("std");
|
||||
|
||||
/// Directories with our includes.
|
||||
const root = thisDir() ++ "../../../vendor/freetype/";
|
||||
const include_path = root ++ "include";
|
||||
pub const include_path_self = thisDir();
|
||||
pub fn build(b: *std.Build) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
const libpng_enabled = b.option(bool, "enable-libpng", "Build libpng") orelse false;
|
||||
|
||||
pub const include_paths = .{ include_path, include_path_self };
|
||||
const upstream = b.dependency("freetype", .{});
|
||||
|
||||
pub fn module(b: *std.Build) *std.build.Module {
|
||||
return b.createModule(.{
|
||||
.source_file = .{ .path = (comptime thisDir()) ++ "/main.zig" },
|
||||
});
|
||||
}
|
||||
|
||||
fn thisDir() []const u8 {
|
||||
return std.fs.path.dirname(@src().file) orelse ".";
|
||||
}
|
||||
|
||||
pub const Options = struct {
|
||||
libpng: Libpng = .{},
|
||||
zlib: Zlib = .{},
|
||||
|
||||
pub const Libpng = struct {
|
||||
enabled: bool = false,
|
||||
step: ?*std.build.LibExeObjStep = null,
|
||||
include: ?[]const []const u8 = null,
|
||||
};
|
||||
|
||||
pub const Zlib = struct {
|
||||
enabled: bool = false,
|
||||
step: ?*std.build.LibExeObjStep = null,
|
||||
include: ?[]const []const u8 = null,
|
||||
};
|
||||
};
|
||||
|
||||
pub fn link(
|
||||
b: *std.Build,
|
||||
step: *std.build.LibExeObjStep,
|
||||
opt: Options,
|
||||
) !*std.build.LibExeObjStep {
|
||||
const lib = try buildFreetype(b, step, opt);
|
||||
step.linkLibrary(lib);
|
||||
step.addIncludePath(.{ .path = include_path });
|
||||
step.addIncludePath(.{ .path = include_path_self });
|
||||
return lib;
|
||||
}
|
||||
|
||||
pub fn buildFreetype(
|
||||
b: *std.Build,
|
||||
step: *std.build.LibExeObjStep,
|
||||
opt: Options,
|
||||
) !*std.build.LibExeObjStep {
|
||||
const target = step.target;
|
||||
const lib = b.addStaticLibrary(.{
|
||||
.name = "freetype",
|
||||
.target = target,
|
||||
.optimize = step.optimize,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
// Include
|
||||
lib.addIncludePath(.{ .path = include_path });
|
||||
|
||||
// Link
|
||||
lib.linkLibC();
|
||||
if (opt.libpng.enabled) {
|
||||
if (opt.libpng.step) |libpng|
|
||||
lib.linkLibrary(libpng)
|
||||
else
|
||||
lib.linkSystemLibrary("libpng");
|
||||
lib.addIncludePath(upstream.path("include"));
|
||||
|
||||
if (opt.libpng.include) |dirs|
|
||||
for (dirs) |dir| lib.addIncludePath(.{ .path = dir });
|
||||
}
|
||||
if (opt.zlib.enabled) {
|
||||
if (opt.zlib.step) |zlib|
|
||||
lib.linkLibrary(zlib)
|
||||
else
|
||||
lib.linkSystemLibrary("z");
|
||||
|
||||
if (opt.zlib.include) |dirs|
|
||||
for (dirs) |dir| lib.addIncludePath(.{ .path = dir });
|
||||
// Dependencies
|
||||
const zlib_dep = b.dependency("zlib", .{ .target = target, .optimize = optimize });
|
||||
lib.linkLibrary(zlib_dep.artifact("z"));
|
||||
if (libpng_enabled) {
|
||||
const libpng_dep = b.dependency("libpng", .{ .target = target, .optimize = optimize });
|
||||
lib.linkLibrary(libpng_dep.artifact("png"));
|
||||
}
|
||||
|
||||
// Compile
|
||||
var flags = std.ArrayList([]const u8).init(b.allocator);
|
||||
defer flags.deinit();
|
||||
|
||||
try flags.appendSlice(&.{
|
||||
"-DFT2_BUILD_LIBRARY",
|
||||
|
||||
"-DFT_CONFIG_OPTION_SYSTEM_ZLIB=1",
|
||||
|
||||
"-DHAVE_UNISTD_H",
|
||||
"-DHAVE_FCNTL_H",
|
||||
|
||||
"-fno-sanitize=undefined",
|
||||
});
|
||||
if (opt.libpng.enabled) try flags.append("-DFT_CONFIG_OPTION_USE_PNG=1");
|
||||
if (opt.zlib.enabled) try flags.append("-DFT_CONFIG_OPTION_SYSTEM_ZLIB=1");
|
||||
if (libpng_enabled) try flags.append("-DFT_CONFIG_OPTION_USE_PNG=1");
|
||||
|
||||
for (srcs) |src| {
|
||||
lib.addCSourceFile(.{
|
||||
.file = upstream.path(src),
|
||||
.flags = flags.items,
|
||||
});
|
||||
}
|
||||
|
||||
// C files
|
||||
lib.addCSourceFiles(srcs, flags.items);
|
||||
switch (target.getOsTag()) {
|
||||
.linux => lib.addCSourceFile(.{
|
||||
.file = .{ .path = root ++ "builds/unix/ftsystem.c" },
|
||||
.file = upstream.path("builds/unix/ftsystem.c"),
|
||||
.flags = flags.items,
|
||||
}),
|
||||
.windows => lib.addCSourceFile(.{
|
||||
.file = .{ .path = root ++ "builds/windows/ftsystem.c" },
|
||||
.file = upstream.path("builds/windows/ftsystem.c"),
|
||||
.flags = flags.items,
|
||||
}),
|
||||
else => lib.addCSourceFile(.{
|
||||
.file = .{ .path = root ++ "src/base/ftsystem.c" },
|
||||
.file = upstream.path("src/base/ftsystem.c"),
|
||||
.flags = flags.items,
|
||||
}),
|
||||
}
|
||||
switch (target.getOsTag()) {
|
||||
.windows => {
|
||||
lib.addCSourceFiles(&.{
|
||||
root ++ "builds/windows/ftdebug.c",
|
||||
}, flags.items);
|
||||
lib.addCSourceFile(.{
|
||||
.file = upstream.path("builds/windows/ftdebug.c"),
|
||||
.flags = flags.items,
|
||||
});
|
||||
lib.addWin32ResourceFile(.{
|
||||
.file = upstream.path("src/base/ftver.rc"),
|
||||
});
|
||||
},
|
||||
else => lib.addCSourceFile(.{
|
||||
.file = .{ .path = root ++ "src/base/ftdebug.c" },
|
||||
.file = upstream.path("src/base/ftdebug.c"),
|
||||
.flags = flags.items,
|
||||
}),
|
||||
}
|
||||
|
||||
return lib;
|
||||
lib.installHeader("freetype-zig.h", "freetype-zig.h");
|
||||
lib.installHeadersDirectoryOptions(.{
|
||||
.source_dir = upstream.path("include"),
|
||||
.install_dir = .header,
|
||||
.install_subdir = "",
|
||||
.include_extensions = &.{".h"},
|
||||
});
|
||||
|
||||
b.installArtifact(lib);
|
||||
}
|
||||
|
||||
const srcs = &.{
|
||||
root ++ "src/autofit/autofit.c",
|
||||
root ++ "src/base/ftbase.c",
|
||||
root ++ "src/base/ftbbox.c",
|
||||
root ++ "src/base/ftbdf.c",
|
||||
root ++ "src/base/ftbitmap.c",
|
||||
root ++ "src/base/ftcid.c",
|
||||
root ++ "src/base/ftfstype.c",
|
||||
root ++ "src/base/ftgasp.c",
|
||||
root ++ "src/base/ftglyph.c",
|
||||
root ++ "src/base/ftgxval.c",
|
||||
root ++ "src/base/ftinit.c",
|
||||
root ++ "src/base/ftmm.c",
|
||||
root ++ "src/base/ftotval.c",
|
||||
root ++ "src/base/ftpatent.c",
|
||||
root ++ "src/base/ftpfr.c",
|
||||
root ++ "src/base/ftstroke.c",
|
||||
root ++ "src/base/ftsynth.c",
|
||||
root ++ "src/base/fttype1.c",
|
||||
root ++ "src/base/ftwinfnt.c",
|
||||
root ++ "src/bdf/bdf.c",
|
||||
root ++ "src/bzip2/ftbzip2.c",
|
||||
root ++ "src/cache/ftcache.c",
|
||||
root ++ "src/cff/cff.c",
|
||||
root ++ "src/cid/type1cid.c",
|
||||
root ++ "src/gzip/ftgzip.c",
|
||||
root ++ "src/lzw/ftlzw.c",
|
||||
root ++ "src/pcf/pcf.c",
|
||||
root ++ "src/pfr/pfr.c",
|
||||
root ++ "src/psaux/psaux.c",
|
||||
root ++ "src/pshinter/pshinter.c",
|
||||
root ++ "src/psnames/psnames.c",
|
||||
root ++ "src/raster/raster.c",
|
||||
root ++ "src/sdf/sdf.c",
|
||||
root ++ "src/sfnt/sfnt.c",
|
||||
root ++ "src/smooth/smooth.c",
|
||||
root ++ "src/svg/svg.c",
|
||||
root ++ "src/truetype/truetype.c",
|
||||
root ++ "src/type1/type1.c",
|
||||
root ++ "src/type42/type42.c",
|
||||
root ++ "src/winfonts/winfnt.c",
|
||||
const srcs: []const []const u8 = &.{
|
||||
"src/autofit/autofit.c",
|
||||
"src/base/ftbase.c",
|
||||
"src/base/ftbbox.c",
|
||||
"src/base/ftbdf.c",
|
||||
"src/base/ftbitmap.c",
|
||||
"src/base/ftcid.c",
|
||||
"src/base/ftfstype.c",
|
||||
"src/base/ftgasp.c",
|
||||
"src/base/ftglyph.c",
|
||||
"src/base/ftgxval.c",
|
||||
"src/base/ftinit.c",
|
||||
"src/base/ftmm.c",
|
||||
"src/base/ftotval.c",
|
||||
"src/base/ftpatent.c",
|
||||
"src/base/ftpfr.c",
|
||||
"src/base/ftstroke.c",
|
||||
"src/base/ftsynth.c",
|
||||
"src/base/fttype1.c",
|
||||
"src/base/ftwinfnt.c",
|
||||
"src/bdf/bdf.c",
|
||||
"src/bzip2/ftbzip2.c",
|
||||
"src/cache/ftcache.c",
|
||||
"src/cff/cff.c",
|
||||
"src/cid/type1cid.c",
|
||||
"src/gzip/ftgzip.c",
|
||||
"src/lzw/ftlzw.c",
|
||||
"src/pcf/pcf.c",
|
||||
"src/pfr/pfr.c",
|
||||
"src/psaux/psaux.c",
|
||||
"src/pshinter/pshinter.c",
|
||||
"src/psnames/psnames.c",
|
||||
"src/raster/raster.c",
|
||||
"src/sdf/sdf.c",
|
||||
"src/sfnt/sfnt.c",
|
||||
"src/smooth/smooth.c",
|
||||
"src/svg/svg.c",
|
||||
"src/truetype/truetype.c",
|
||||
"src/type1/type1.c",
|
||||
"src/type42/type42.c",
|
||||
"src/winfonts/winfnt.c",
|
||||
};
|
||||
|
13
pkg/freetype/build.zig.zon
Normal file
13
pkg/freetype/build.zig.zon
Normal file
@ -0,0 +1,13 @@
|
||||
.{
|
||||
.name = "freetype",
|
||||
.version = "2.13.2",
|
||||
.dependencies = .{
|
||||
.freetype = .{
|
||||
.url = "https://github.com/freetype/freetype/archive/refs/tags/VER-2-13-2.tar.gz",
|
||||
.hash = "1220b81f6ecfb3fd222f76cf9106fecfa6554ab07ec7fdc4124b9bb063ae2adf969d",
|
||||
},
|
||||
|
||||
.libpng = .{ .path = "../libpng" },
|
||||
.zlib = .{ .path = "../zlib" },
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user