From f2d65d4524b60188ef1a7759c31741032453a283 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 17 Aug 2022 11:20:31 -0700 Subject: [PATCH] move freetype into pkg --- build.zig | 6 +- pkg/freetype/build.zig | 109 +++++++++++++++++++++++ {src => pkg}/freetype/c.zig | 0 {src => pkg}/freetype/freetype-zig.h | 0 pkg/freetype/main.zig | 1 + pkg/libuv/build.zig | 10 --- src/font/Face.zig | 2 +- src/font/Family.zig | 2 +- src/freetype/build.zig | 124 --------------------------- 9 files changed, 115 insertions(+), 139 deletions(-) create mode 100644 pkg/freetype/build.zig rename {src => pkg}/freetype/c.zig (100%) rename {src => pkg}/freetype/freetype-zig.h (100%) create mode 100644 pkg/freetype/main.zig delete mode 100644 src/freetype/build.zig diff --git a/build.zig b/build.zig index 07fbfa859..462a26408 100644 --- a/build.zig +++ b/build.zig @@ -3,7 +3,7 @@ const fs = std.fs; 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 freetype = @import("pkg/freetype/build.zig"); const libuv = @import("pkg/libuv/build.zig"); const tracylib = @import("src/tracy/build.zig"); const system_sdk = @import("vendor/mach/glfw/system_sdk.zig"); @@ -130,8 +130,8 @@ fn addDeps( step.addCSourceFile("vendor/glad/src/gl.c", &.{}); // Freetype - const ftlib = try ft.create(b, step.target, step.build_mode, .{}); - ftlib.link(step); + step.addPackage(freetype.pkg); + try freetype.link(b, step); // Glfw step.addPackage(glfw.pkg); diff --git a/pkg/freetype/build.zig b/pkg/freetype/build.zig new file mode 100644 index 000000000..348a405ca --- /dev/null +++ b/pkg/freetype/build.zig @@ -0,0 +1,109 @@ +const std = @import("std"); + +/// Directories with our includes. +const root = thisDir() ++ "../../../vendor/freetype/"; +const include_path = root ++ "include"; +const include_path_self = thisDir(); + +pub const pkg = std.build.Pkg{ + .name = "freetype", + .source = .{ .path = thisDir() ++ "/main.zig" }, +}; + +fn thisDir() []const u8 { + return std.fs.path.dirname(@src().file) orelse "."; +} + +pub fn link(b: *std.build.Builder, step: *std.build.LibExeObjStep) !void { + const lib = try buildFreetype(b, step); + step.linkLibrary(lib); + step.addIncludePath(include_path); + step.addIncludePath(include_path_self); +} + +pub fn buildFreetype( + b: *std.build.Builder, + step: *std.build.LibExeObjStep, +) !*std.build.LibExeObjStep { + const target = step.target; + const lib = b.addStaticLibrary("freetype", null); + lib.setTarget(step.target); + lib.setBuildMode(step.build_mode); + + // Include + lib.addIncludePath(include_path); + + // Link + lib.linkLibC(); + + // 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", + }); + + // C files + lib.addCSourceFiles(srcs, flags.items); + switch (target.getOsTag()) { + .linux => lib.addCSourceFile(root ++ "builds/unix/ftsystem.c", flags.items), + .windows => lib.addCSourceFile(root ++ "builds/windows/ftsystem.c", flags.items), + else => lib.addCSourceFile(root ++ "src/base/ftsystem.c", flags.items), + } + switch (target.getOsTag()) { + .windows => { + lib.addCSourceFile(root ++ "builds/windows/ftdebug.c", flags.items); + lib.addCSourceFile(root ++ "src/base/ftver.c", flags.items); + }, + else => lib.addCSourceFile(root ++ "src/base/ftdebug.c", 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", +}; diff --git a/src/freetype/c.zig b/pkg/freetype/c.zig similarity index 100% rename from src/freetype/c.zig rename to pkg/freetype/c.zig diff --git a/src/freetype/freetype-zig.h b/pkg/freetype/freetype-zig.h similarity index 100% rename from src/freetype/freetype-zig.h rename to pkg/freetype/freetype-zig.h diff --git a/pkg/freetype/main.zig b/pkg/freetype/main.zig new file mode 100644 index 000000000..e66cd7094 --- /dev/null +++ b/pkg/freetype/main.zig @@ -0,0 +1 @@ +pub const c = @import("c.zig"); diff --git a/pkg/libuv/build.zig b/pkg/libuv/build.zig index 9ce738c85..6bcf6fc3c 100644 --- a/pkg/libuv/build.zig +++ b/pkg/libuv/build.zig @@ -157,13 +157,3 @@ pub fn buildLibuv( return lib; } - -pub fn testLibuv( - b: *std.build.Builder, - step: *std.build.LibExeObjStep, -) !*std.build.LibExeObjStep { - const lib = b.addTest(root ++ "src/main.zig"); - lib.setTarget(step.target); - try link(b, step); - return lib; -} diff --git a/src/font/Face.zig b/src/font/Face.zig index d8e3d1b0e..1f370c492 100644 --- a/src/font/Face.zig +++ b/src/font/Face.zig @@ -9,7 +9,7 @@ const std = @import("std"); const assert = std.debug.assert; const testing = std.testing; const Allocator = std.mem.Allocator; -const ftc = @import("../freetype/c.zig"); +const ftc = @import("freetype").c; const Atlas = @import("../Atlas.zig"); const Glyph = @import("font.zig").Glyph; diff --git a/src/font/Family.zig b/src/font/Family.zig index 8a81e21cc..c1d32ff16 100644 --- a/src/font/Family.zig +++ b/src/font/Family.zig @@ -5,7 +5,7 @@ const Family = @This(); const std = @import("std"); const Allocator = std.mem.Allocator; const Atlas = @import("../Atlas.zig"); -const ftc = @import("../freetype/c.zig"); +const ftc = @import("freetype").c; const ftok = ftc.FT_Err_Ok; const Face = @import("font.zig").Face; const Glyph = @import("font.zig").Glyph; diff --git a/src/freetype/build.zig b/src/freetype/build.zig deleted file mode 100644 index 5df314abd..000000000 --- a/src/freetype/build.zig +++ /dev/null @@ -1,124 +0,0 @@ -const std = @import("std"); - -/// This is the type returned by create. -pub const Library = struct { - step: *std.build.LibExeObjStep, - - /// statically link this library into the given step - pub fn link(self: Library, other: *std.build.LibExeObjStep) void { - self.addIncludeDirs(other); - other.linkLibrary(self.step); - } - - /// only add the include dirs to the given step. This is useful if building - /// a static library that you don't want to fully link in the code of this - /// library. - pub fn addIncludeDirs(self: Library, other: *std.build.LibExeObjStep) void { - _ = self; - - // 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); - } -}; - -/// 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 create( - b: *std.build.Builder, - target: std.zig.CrossTarget, - mode: std.builtin.Mode, - opts: Options, -) !Library { - _ = opts; - - const ret = b.addStaticLibrary("freetype", null); - ret.setTarget(target); - ret.setBuildMode(mode); - - var flags = std.ArrayList([]const u8).init(b.allocator); - defer flags.deinit(); - - try flags.appendSlice(&.{ - "-DFT2_BUILD_LIBRARY", - - "-DHAVE_UNISTD_H", - "-DHAVE_FCNTL_H", - }); - - // C files - ret.addCSourceFiles(srcs, flags.items); - switch (target.getOsTag()) { - .linux => ret.addCSourceFile(root() ++ "builds/unix/ftsystem.c", flags.items), - .windows => ret.addCSourceFile(root() ++ "builds/windows/ftsystem.c", flags.items), - else => ret.addCSourceFile(root() ++ "src/base/ftsystem.c", flags.items), - } - switch (target.getOsTag()) { - .windows => { - ret.addCSourceFile(root() ++ "builds/windows/ftdebug.c", flags.items); - ret.addCSourceFile(root() ++ "src/base/ftver.c", flags.items); - }, - else => ret.addCSourceFile(root() ++ "src/base/ftdebug.c", flags.items), - } - - ret.addIncludeDir(include_dir); - ret.linkLibC(); - - return Library{ .step = ret }; -} - -fn root() []const u8 { - return (std.fs.path.dirname(@src().file) orelse unreachable) ++ "/../../vendor/freetype/"; -} - -/// Directories with our includes. -const include_dir = root() ++ "include"; - -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", -};