diff --git a/build.zig b/build.zig index 2614fee9d..48cb6d5a5 100644 --- a/build.zig +++ b/build.zig @@ -145,11 +145,12 @@ fn addDeps( step.addIncludeDir("vendor/glad/include/"); step.addCSourceFile("vendor/glad/src/gl.c", &.{}); + // Dependencies of other dependencies const zlib_step = try zlib.link(b, step); const libpng_step = try libpng.link(b, step, .{ .zlib = .{ .step = zlib_step, - .include = zlib.include_path, + .include = &zlib.include_paths, }, }); @@ -157,7 +158,15 @@ fn addDeps( step.addPackage(freetype.pkg); _ = try freetype.link(b, step, .{ .libpng = freetype.Options.Libpng{ + .enabled = true, .step = libpng_step, + .include = &libpng.include_paths, + }, + + .zlib = .{ + .enabled = true, + .step = zlib_step, + .include = &zlib.include_paths, }, }); diff --git a/pkg/freetype/build.zig b/pkg/freetype/build.zig index 4a407ea73..b85bf4a7f 100644 --- a/pkg/freetype/build.zig +++ b/pkg/freetype/build.zig @@ -16,11 +16,18 @@ fn thisDir() []const u8 { pub const Options = struct { libpng: Libpng = .{}, + zlib: Zlib = .{}, pub const Libpng = struct { enabled: bool = false, 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 lib.linkSystemLibrary("libpng"); - if (opt.libpng.include) |dir| - lib.addIncludePath(dir); + if (opt.libpng.include) |dirs| + 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 @@ -71,7 +87,8 @@ pub fn buildFreetype( "-DHAVE_UNISTD_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 lib.addCSourceFiles(srcs, flags.items); diff --git a/pkg/libpng/build.zig b/pkg/libpng/build.zig index 2edc66248..8d6950e1a 100644 --- a/pkg/libpng/build.zig +++ b/pkg/libpng/build.zig @@ -5,6 +5,8 @@ const root = thisDir() ++ "../../../vendor/libpng/"; const include_path = root; const include_path_pnglibconf = thisDir(); +pub const include_paths = .{ include_path, include_path_pnglibconf }; + pub const pkg = std.build.Pkg{ .name = "libpng", .source = .{ .path = thisDir() ++ "/main.zig" }, @@ -19,7 +21,7 @@ pub const Options = struct { pub const Zlib = struct { step: ?*std.build.LibExeObjStep = null, - include: ?[]const u8 = null, + include: ?[]const []const u8 = null, }; }; @@ -59,8 +61,8 @@ pub fn buildLib( else lib.linkSystemLibrary("z"); - if (opt.zlib.include) |dir| - lib.addIncludePath(dir); + if (opt.zlib.include) |dirs| + for (dirs) |dir| lib.addIncludePath(dir); // Compile var flags = std.ArrayList([]const u8).init(b.allocator); diff --git a/pkg/zlib/build.zig b/pkg/zlib/build.zig index 17a5c86e1..6ca3c9a25 100644 --- a/pkg/zlib/build.zig +++ b/pkg/zlib/build.zig @@ -2,7 +2,9 @@ const std = @import("std"); /// Directories with our includes. 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{ .name = "zlib",