move freetype into pkg

This commit is contained in:
Mitchell Hashimoto
2022-08-17 11:20:31 -07:00
parent b2192ea8f7
commit f2d65d4524
9 changed files with 115 additions and 139 deletions

View File

@ -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);

109
pkg/freetype/build.zig Normal file
View File

@ -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",
};

1
pkg/freetype/main.zig Normal file
View File

@ -0,0 +1 @@
pub const c = @import("c.zig");

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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",
};