diff --git a/build.zig b/build.zig index 258b83b14..e7bc9f2f3 100644 --- a/build.zig +++ b/build.zig @@ -3,6 +3,7 @@ const Builder = std.build.Builder; const LibExeObjStep = std.build.LibExeObjStep; const glfw = @import("vendor/mach/glfw/build.zig"); const ft = @import("src/freetype/build.zig"); +const ftgl = @import("src/freetype-gl/build.zig"); pub fn build(b: *std.build.Builder) !void { const target = b.standardTargetOptions(.{}); @@ -16,6 +17,7 @@ pub fn build(b: *std.build.Builder) !void { exe.addCSourceFile("src/gb_math.c", &.{}); exe.addPackagePath("glfw", "vendor/mach/glfw/src/main.zig"); glfw.link(b, exe, .{}); + try ftgl.link(exe, b, target, mode, .{}); exe.linkSystemLibrary("epoxy"); diff --git a/src/freetype-gl/build.zig b/src/freetype-gl/build.zig new file mode 100644 index 000000000..a2ae812cc --- /dev/null +++ b/src/freetype-gl/build.zig @@ -0,0 +1,68 @@ +const std = @import("std"); +const ft = @import("../freetype/build.zig"); + +/// Compile-time options for the library. These mostly correspond to +/// options exposed by the native build system used by the library. +pub const Options = struct {}; + +/// Create this library. This is the primary API users of build.zig should +/// use to link this library to their application. On the resulting Library, +/// call the link function and given your own application step. +pub fn link( + exe: *std.build.LibExeObjStep, + b: *std.build.Builder, + target: std.zig.CrossTarget, + mode: std.builtin.Mode, + opts: Options, +) !void { + _ = opts; + + const ret = b.addStaticLibrary("freetype-gl", null); + ret.setTarget(target); + ret.setBuildMode(mode); + + var flags = std.ArrayList([]const u8).init(b.allocator); + defer flags.deinit(); + // try flags.appendSlice(&.{}); + + // C files + ret.addCSourceFiles(srcs, flags.items); + ret.addIncludeDir(root()); + ret.linkLibC(); + + // For config.h + ret.addIncludeDir(thisDir()); + + // Dependencies + ret.linkSystemLibrary("gl"); + const ftstep = try ft.create(b, target, mode, .{}); + ftstep.addIncludeDirs(ret); + + exe.addIncludeDir(root()); + exe.linkLibrary(ret); +} + +fn root() []const u8 { + return (std.fs.path.dirname(@src().file) orelse unreachable) ++ "/../../vendor/freetype-gl/"; +} + +fn thisDir() []const u8 { + return (std.fs.path.dirname(@src().file) orelse unreachable) ++ "/"; +} + +const srcs = &.{ + root() ++ "distance-field.c", + root() ++ "edtaa3func.c", + root() ++ "platform.c", + root() ++ "text-buffer.c", + root() ++ "texture-atlas.c", + root() ++ "texture-font.c", + root() ++ "utf8-utils.c", + root() ++ "ftgl-utils.c", + root() ++ "vector.c", + root() ++ "vertex-attribute.c", + + // optional stuff we don't need + // root() ++ "font-manager.c", + // root() ++ "vertex-buffer.c", +}; diff --git a/src/freetype-gl/config.h b/src/freetype-gl/config.h new file mode 100644 index 000000000..98d4946aa --- /dev/null +++ b/src/freetype-gl/config.h @@ -0,0 +1 @@ +// Purposely empty! This is just here so that freetype-gl will build. diff --git a/src/freetype/build.zig b/src/freetype/build.zig index da3ac95f7..5df314abd 100644 --- a/src/freetype/build.zig +++ b/src/freetype/build.zig @@ -7,7 +7,6 @@ pub const Library = struct { /// statically link this library into the given step pub fn link(self: Library, other: *std.build.LibExeObjStep) void { self.addIncludeDirs(other); - other.addIncludeDir(include_dir); other.linkLibrary(self.step); } @@ -19,6 +18,7 @@ pub const Library = struct { // We need to add this directory to the include path for the final // app so that we can access "freetype-zig.h". + other.addIncludeDir(include_dir); other.addIncludeDir(std.fs.path.dirname(@src().file) orelse unreachable); } };