diff --git a/.gitmodules b/.gitmodules index b1120c041..89a90e84a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,3 +22,6 @@ [submodule "vendor/utf8proc"] path = vendor/utf8proc url = https://github.com/JuliaStrings/utf8proc.git +[submodule "vendor/harfbuzz"] + path = vendor/harfbuzz + url = https://github.com/harfbuzz/harfbuzz.git diff --git a/build.zig b/build.zig index 08f93e2a6..b2abfa4f5 100644 --- a/build.zig +++ b/build.zig @@ -4,6 +4,7 @@ const Builder = std.build.Builder; const LibExeObjStep = std.build.LibExeObjStep; const glfw = @import("vendor/mach/glfw/build.zig"); const freetype = @import("pkg/freetype/build.zig"); +const harfbuzz = @import("pkg/harfbuzz/build.zig"); const libuv = @import("pkg/libuv/build.zig"); const libpng = @import("pkg/libpng/build.zig"); const utf8proc = @import("pkg/utf8proc/build.zig"); @@ -156,6 +157,7 @@ fn addDeps( ) !void { // We always need the Zig packages step.addPackage(freetype.pkg); + step.addPackage(harfbuzz.pkg); step.addPackage(glfw.pkg); step.addPackage(libuv.pkg); step.addPackage(utf8proc.pkg); @@ -185,6 +187,7 @@ fn addDeps( step.addIncludePath(freetype.include_path_self); step.linkSystemLibrary("bzip2"); step.linkSystemLibrary("freetype2"); + step.linkSystemLibrary("harfbuzz"); step.linkSystemLibrary("libpng"); step.linkSystemLibrary("libuv"); step.linkSystemLibrary("zlib"); @@ -201,7 +204,7 @@ fn addDeps( }); // Freetype - _ = try freetype.link(b, step, .{ + const freetype_step = try freetype.link(b, step, .{ .libpng = freetype.Options.Libpng{ .enabled = true, .step = libpng_step, @@ -215,8 +218,17 @@ fn addDeps( }, }); + // Harfbuzz + _ = try harfbuzz.link(b, step, .{ + .freetype = .{ + .enabled = true, + .step = freetype_step, + .include = &freetype.include_paths, + }, + }); + // Libuv - var libuv_step = try libuv.link(b, step); + const libuv_step = try libuv.link(b, step); system_sdk.include(b, libuv_step, .{}); } } diff --git a/nix/devshell.nix b/nix/devshell.nix index 1577471a9..532c4c58c 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -17,6 +17,7 @@ , bzip2 , fontconfig , freetype +, harfbuzz , libpng , libGL , libuv @@ -35,6 +36,7 @@ let ] ++ lib.optionals stdenv.isLinux [ bzip2 freetype + harfbuzz libpng libuv zlib @@ -71,6 +73,7 @@ in mkShell rec { ] ++ lib.optionals stdenv.isLinux [ bzip2 freetype + harfbuzz libpng libuv zlib diff --git a/pkg/freetype/build.zig b/pkg/freetype/build.zig index 4e7816a59..5c35ae9be 100644 --- a/pkg/freetype/build.zig +++ b/pkg/freetype/build.zig @@ -5,6 +5,8 @@ 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 const pkg = std.build.Pkg{ .name = "freetype", .source = .{ .path = thisDir() ++ "/main.zig" }, diff --git a/pkg/harfbuzz/build.zig b/pkg/harfbuzz/build.zig new file mode 100644 index 000000000..e110729b8 --- /dev/null +++ b/pkg/harfbuzz/build.zig @@ -0,0 +1,94 @@ +const std = @import("std"); + +/// Directories with our includes. +const root = thisDir() ++ "../../../vendor/harfbuzz/"; +const include_path = root ++ "include"; + +pub const include_paths = .{include_path}; + +pub const pkg = std.build.Pkg{ + .name = "harfbuzz", + .source = .{ .path = thisDir() ++ "/main.zig" }, +}; + +fn thisDir() []const u8 { + return std.fs.path.dirname(@src().file) orelse "."; +} + +pub const Options = struct { + freetype: Freetype = .{}, + + pub const Freetype = struct { + enabled: bool = false, + step: ?*std.build.LibExeObjStep = null, + include: ?[]const []const u8 = null, + }; +}; + +pub fn link( + b: *std.build.Builder, + step: *std.build.LibExeObjStep, + opt: Options, +) !*std.build.LibExeObjStep { + const lib = try buildHarfbuzz(b, step, opt); + step.linkLibrary(lib); + step.addIncludePath(include_path); + return lib; +} + +pub fn buildHarfbuzz( + b: *std.build.Builder, + step: *std.build.LibExeObjStep, + opt: Options, +) !*std.build.LibExeObjStep { + const lib = b.addStaticLibrary("harfbuzz", null); + lib.setTarget(step.target); + lib.setBuildMode(step.build_mode); + + // Include + lib.addIncludePath(include_path); + + // Link + lib.linkLibC(); + lib.linkLibCpp(); + if (opt.freetype.enabled) { + if (opt.freetype.step) |freetype| + lib.linkLibrary(freetype) + else + lib.linkSystemLibrary("freetype2"); + + if (opt.freetype.include) |dirs| + for (dirs) |dir| lib.addIncludePath(dir); + } + + // Compile + var flags = std.ArrayList([]const u8).init(b.allocator); + defer flags.deinit(); + + try flags.appendSlice(&.{ + "-DHAVE_UNISTD_H", + "-DHAVE_SYS_MMAN_H", + "-DHAVE_STDBOOL_H", + + // We always have pthread + "-DHAVE_PTHREAD=1", + }); + if (opt.freetype.enabled) try flags.appendSlice(&.{ + "-DHAVE_FREETYPE=1", + + // Let's just assume a new freetype + "-DHAVE_FT_GET_VAR_BLEND_COORDINATES=1", + "-DHAVE_FT_SET_VAR_BLEND_COORDINATES=1", + "-DHAVE_FT_DONE_MM_VAR=1", + "-DHAVE_FT_GET_TRANSFORM=1", + }); + + // C files + lib.addCSourceFiles(srcs, flags.items); + + return lib; +} + +const srcs = &.{ + root ++ "src/harfbuzz.cc", +}; diff --git a/pkg/harfbuzz/main.zig b/pkg/harfbuzz/main.zig new file mode 100644 index 000000000..1f40f6a44 --- /dev/null +++ b/pkg/harfbuzz/main.zig @@ -0,0 +1 @@ +// Todo! diff --git a/vendor/harfbuzz b/vendor/harfbuzz new file mode 160000 index 000000000..9e4ae09fe --- /dev/null +++ b/vendor/harfbuzz @@ -0,0 +1 @@ +Subproject commit 9e4ae09fe76e0ab908095940c880b4ded94c1e18