freetype builds in png support, uses our own zlib

This commit is contained in:
Mitchell Hashimoto
2022-08-20 10:33:57 -07:00
parent 54b0c6cd03
commit 5ae450099d
4 changed files with 39 additions and 9 deletions

View File

@ -145,11 +145,12 @@ fn addDeps(
step.addIncludeDir("vendor/glad/include/"); step.addIncludeDir("vendor/glad/include/");
step.addCSourceFile("vendor/glad/src/gl.c", &.{}); step.addCSourceFile("vendor/glad/src/gl.c", &.{});
// Dependencies of other dependencies
const zlib_step = try zlib.link(b, step); const zlib_step = try zlib.link(b, step);
const libpng_step = try libpng.link(b, step, .{ const libpng_step = try libpng.link(b, step, .{
.zlib = .{ .zlib = .{
.step = zlib_step, .step = zlib_step,
.include = zlib.include_path, .include = &zlib.include_paths,
}, },
}); });
@ -157,7 +158,15 @@ fn addDeps(
step.addPackage(freetype.pkg); step.addPackage(freetype.pkg);
_ = try freetype.link(b, step, .{ _ = try freetype.link(b, step, .{
.libpng = freetype.Options.Libpng{ .libpng = freetype.Options.Libpng{
.enabled = true,
.step = libpng_step, .step = libpng_step,
.include = &libpng.include_paths,
},
.zlib = .{
.enabled = true,
.step = zlib_step,
.include = &zlib.include_paths,
}, },
}); });

View File

@ -16,11 +16,18 @@ fn thisDir() []const u8 {
pub const Options = struct { pub const Options = struct {
libpng: Libpng = .{}, libpng: Libpng = .{},
zlib: Zlib = .{},
pub const Libpng = struct { pub const Libpng = struct {
enabled: bool = false, enabled: bool = false,
step: ?*std.build.LibExeObjStep = null, step: ?*std.build.LibExeObjStep = null,
include: ?[]const u8 = null, include: ?[]const []const u8 = null,
};
pub const Zlib = struct {
enabled: bool = false,
step: ?*std.build.LibExeObjStep = null,
include: ?[]const []const u8 = null,
}; };
}; };
@ -57,8 +64,17 @@ pub fn buildFreetype(
else else
lib.linkSystemLibrary("libpng"); lib.linkSystemLibrary("libpng");
if (opt.libpng.include) |dir| if (opt.libpng.include) |dirs|
lib.addIncludePath(dir); for (dirs) |dir| lib.addIncludePath(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(dir);
} }
// Compile // Compile
@ -71,7 +87,8 @@ pub fn buildFreetype(
"-DHAVE_UNISTD_H", "-DHAVE_UNISTD_H",
"-DHAVE_FCNTL_H", "-DHAVE_FCNTL_H",
}); });
if (opt.libpng.enabled) try flags.append("-DFT_CONFIG_OPTION_USE_PNG"); 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 // C files
lib.addCSourceFiles(srcs, flags.items); lib.addCSourceFiles(srcs, flags.items);

View File

@ -5,6 +5,8 @@ const root = thisDir() ++ "../../../vendor/libpng/";
const include_path = root; const include_path = root;
const include_path_pnglibconf = thisDir(); const include_path_pnglibconf = thisDir();
pub const include_paths = .{ include_path, include_path_pnglibconf };
pub const pkg = std.build.Pkg{ pub const pkg = std.build.Pkg{
.name = "libpng", .name = "libpng",
.source = .{ .path = thisDir() ++ "/main.zig" }, .source = .{ .path = thisDir() ++ "/main.zig" },
@ -19,7 +21,7 @@ pub const Options = struct {
pub const Zlib = struct { pub const Zlib = struct {
step: ?*std.build.LibExeObjStep = null, step: ?*std.build.LibExeObjStep = null,
include: ?[]const u8 = null, include: ?[]const []const u8 = null,
}; };
}; };
@ -59,8 +61,8 @@ pub fn buildLib(
else else
lib.linkSystemLibrary("z"); lib.linkSystemLibrary("z");
if (opt.zlib.include) |dir| if (opt.zlib.include) |dirs|
lib.addIncludePath(dir); for (dirs) |dir| lib.addIncludePath(dir);
// Compile // Compile
var flags = std.ArrayList([]const u8).init(b.allocator); var flags = std.ArrayList([]const u8).init(b.allocator);

View File

@ -2,7 +2,9 @@ const std = @import("std");
/// Directories with our includes. /// Directories with our includes.
const root = thisDir() ++ "../../../vendor/zlib/"; const root = thisDir() ++ "../../../vendor/zlib/";
pub const include_path = root; const include_path = root;
pub const include_paths = .{include_path};
pub const pkg = std.build.Pkg{ pub const pkg = std.build.Pkg{
.name = "zlib", .name = "zlib",