freetype: update to latest Zig build API
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
8c72c124e2
commit
a2eb384eaf
2 changed files with 72 additions and 52 deletions
|
|
@ -26,9 +26,9 @@ Then in your `build.zig` add:
|
|||
...
|
||||
const freetype = @import("libs/mach-freetype/build.zig");
|
||||
|
||||
pub fn build(b: *Builder) void {
|
||||
pub fn build(b: *Build) void {
|
||||
...
|
||||
exe.addPackage(freetype.pkg);
|
||||
exe.addModule("freetype", freetype.module(b));
|
||||
freetype.link(b, exe, .{});
|
||||
|
||||
// use this option if you are including zlib separately
|
||||
|
|
@ -39,14 +39,14 @@ pub fn build(b: *Builder) void {
|
|||
and optionaly add harfbuzz:
|
||||
|
||||
```zig
|
||||
exe.addPackage(freetype.harfbuzz_pkg);
|
||||
exe.addModule("harfbuzz", freetype.harfbuzzModule(b));
|
||||
freetype.link(b, exe, .{ .harfbuzz = .{} });
|
||||
```
|
||||
|
||||
You can also optionally build brotli compression (for WOFF2 font support):
|
||||
|
||||
```zig
|
||||
exe.addPackage(freetype.pkg);
|
||||
exe.addModule("freetype", freetype.module(b));
|
||||
freetype.link(b, exe, .{ .freetype = .{ .brotli = true } });
|
||||
```
|
||||
|
||||
|
|
@ -65,10 +65,10 @@ Then in your `build.zig` add:
|
|||
const pkgs = @import("deps.zig").pkgs;
|
||||
const freetype = @import("build-freetype");
|
||||
|
||||
pub fn build(b: *Builder) void {
|
||||
pub fn build(b: *Build) void {
|
||||
...
|
||||
|
||||
exe.addPackage(pkgs.freetype);
|
||||
exe.addModule("freetype", pkgs.freetype);
|
||||
freetype.link(b, exe, .{});
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const std = @import("std");
|
||||
const Builder = std.build.Builder;
|
||||
const Build = std.Build;
|
||||
|
||||
const ft_root = sdkPath("/upstream/freetype");
|
||||
const ft_include_path = ft_root ++ "/include";
|
||||
|
|
@ -7,17 +7,20 @@ const hb_root = sdkPath("/upstream/harfbuzz");
|
|||
const hb_include_path = hb_root ++ "/src";
|
||||
const brotli_root = sdkPath("/upstream/brotli");
|
||||
|
||||
pub const pkg = std.build.Pkg{
|
||||
.name = "freetype",
|
||||
.source = .{ .path = sdkPath("/src/main.zig") },
|
||||
.dependencies = &.{},
|
||||
};
|
||||
pub fn module(b: *std.Build) *std.build.Module {
|
||||
return b.createModule(.{
|
||||
.source_file = .{ .path = sdkPath("/src/main.zig") },
|
||||
});
|
||||
}
|
||||
|
||||
pub const harfbuzz_pkg = std.build.Pkg{
|
||||
.name = "harfbuzz",
|
||||
.source = .{ .path = sdkPath("/src/harfbuzz/main.zig") },
|
||||
.dependencies = &.{pkg},
|
||||
};
|
||||
pub fn harfbuzzModule(b: *std.Build) *std.build.Module {
|
||||
return b.createModule(.{
|
||||
.source_file = .{ .path = sdkPath("/src/harfbuzz/main.zig") },
|
||||
.dependencies = &.{
|
||||
.{ .name = "freetype", .module = module(b) },
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
pub const Options = struct {
|
||||
freetype: FreetypeOptions = .{},
|
||||
|
|
@ -37,21 +40,24 @@ pub const HarfbuzzOptions = struct {
|
|||
install_libs: bool = false,
|
||||
};
|
||||
|
||||
pub fn build(b: *std.build.Builder) !void {
|
||||
const mode = b.standardReleaseOptions();
|
||||
pub fn build(b: *std.Build) !void {
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
const target = b.standardTargetOptions(.{});
|
||||
|
||||
const test_step = b.step("test", "Run library tests");
|
||||
test_step.dependOn(&testStep(b, mode, target).step);
|
||||
test_step.dependOn(&testStep(b, optimize, target).step);
|
||||
|
||||
inline for ([_][]const u8{
|
||||
"single-glyph",
|
||||
"glyph-to-svg",
|
||||
}) |example| {
|
||||
const example_exe = b.addExecutable("example-" ++ example, "examples/" ++ example ++ ".zig");
|
||||
example_exe.setBuildMode(mode);
|
||||
example_exe.setTarget(target);
|
||||
example_exe.addPackage(pkg);
|
||||
const example_exe = b.addExecutable(.{
|
||||
.name = "example-" ++ example,
|
||||
.root_source_file = .{ .path = "examples/" ++ example ++ ".zig" },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
example_exe.addModule("freetype", module(b));
|
||||
|
||||
link(b, example_exe, .{});
|
||||
|
||||
|
|
@ -70,11 +76,15 @@ pub fn build(b: *std.build.Builder) !void {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn testStep(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.RunStep {
|
||||
const main_tests = b.addTestExe("freetype-tests", sdkPath("/src/main.zig"));
|
||||
main_tests.setBuildMode(mode);
|
||||
main_tests.setTarget(target);
|
||||
main_tests.addPackage(pkg);
|
||||
pub fn testStep(b: *Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *std.build.RunStep {
|
||||
const main_tests = b.addTest(.{
|
||||
.name = "freetype-tests",
|
||||
.kind = .test_exe,
|
||||
.root_source_file = .{ .path = sdkPath("/src/main.zig") },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
main_tests.addModule("freetype", module(b));
|
||||
link(b, main_tests, .{
|
||||
.freetype = .{
|
||||
.brotli = true,
|
||||
|
|
@ -84,10 +94,14 @@ pub fn testStep(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget
|
|||
main_tests.main_pkg_path = sdkPath("/");
|
||||
main_tests.install();
|
||||
|
||||
const harfbuzz_tests = b.addTestExe("harfbuzz-tests", sdkPath("/src/harfbuzz/main.zig"));
|
||||
harfbuzz_tests.setBuildMode(mode);
|
||||
harfbuzz_tests.setTarget(target);
|
||||
harfbuzz_tests.addPackage(pkg);
|
||||
const harfbuzz_tests = b.addTest(.{
|
||||
.name = "harfbuzz-tests",
|
||||
.kind = .test_exe,
|
||||
.root_source_file = .{ .path = sdkPath("/src/harfbuzz/main.zig") },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
harfbuzz_tests.addModule("freetype", module(b));
|
||||
link(b, harfbuzz_tests, .{
|
||||
.freetype = .{
|
||||
.brotli = true,
|
||||
|
|
@ -102,41 +116,43 @@ pub fn testStep(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget
|
|||
return main_tests_run;
|
||||
}
|
||||
|
||||
pub fn link(b: *Builder, step: *std.build.LibExeObjStep, options: Options) void {
|
||||
pub fn link(b: *Build, step: *std.build.CompileStep, options: Options) void {
|
||||
linkFreetype(b, step, options.freetype);
|
||||
if (options.harfbuzz) |harfbuzz_options|
|
||||
linkHarfbuzz(b, step, harfbuzz_options);
|
||||
}
|
||||
|
||||
pub fn linkFreetype(b: *Builder, step: *std.build.LibExeObjStep, options: FreetypeOptions) void {
|
||||
const ft_lib = buildFreetype(b, step.build_mode, step.target, options);
|
||||
pub fn linkFreetype(b: *Build, step: *std.build.CompileStep, options: FreetypeOptions) void {
|
||||
const ft_lib = buildFreetype(b, step.optimize, step.target, options);
|
||||
step.linkLibrary(ft_lib);
|
||||
step.addIncludePath(ft_include_path);
|
||||
if (options.brotli) {
|
||||
const brotli_lib = buildBrotli(b, step.build_mode, step.target);
|
||||
const brotli_lib = buildBrotli(b, step.optimize, step.target);
|
||||
if (options.install_libs)
|
||||
brotli_lib.install();
|
||||
step.linkLibrary(brotli_lib);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn linkHarfbuzz(b: *Builder, step: *std.build.LibExeObjStep, options: HarfbuzzOptions) void {
|
||||
const hb_lib = buildHarfbuzz(b, step.build_mode, step.target, options);
|
||||
pub fn linkHarfbuzz(b: *Build, step: *std.build.CompileStep, options: HarfbuzzOptions) void {
|
||||
const hb_lib = buildHarfbuzz(b, step.optimize, step.target, options);
|
||||
step.linkLibrary(hb_lib);
|
||||
step.addIncludePath(hb_include_path);
|
||||
}
|
||||
|
||||
pub fn buildFreetype(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget, options: FreetypeOptions) *std.build.LibExeObjStep {
|
||||
pub fn buildFreetype(b: *Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget, options: FreetypeOptions) *std.build.CompileStep {
|
||||
// TODO(build-system): https://github.com/hexops/mach/issues/229#issuecomment-1100958939
|
||||
ensureDependencySubmodule(b.allocator, "upstream") catch unreachable;
|
||||
|
||||
const lib = b.addStaticLibrary("freetype", null);
|
||||
const lib = b.addStaticLibrary(.{
|
||||
.name = "freetype",
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
lib.defineCMacro("FT2_BUILD_LIBRARY", "1");
|
||||
if (options.use_system_zlib) {
|
||||
lib.defineCMacro("FT_CONFIG_OPTION_SYSTEM_ZLIB", "1");
|
||||
}
|
||||
lib.setBuildMode(mode);
|
||||
lib.setTarget(target);
|
||||
lib.linkLibC();
|
||||
lib.addIncludePath(ft_include_path);
|
||||
|
||||
|
|
@ -169,11 +185,13 @@ pub fn buildFreetype(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossT
|
|||
return lib;
|
||||
}
|
||||
|
||||
pub fn buildHarfbuzz(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget, options: HarfbuzzOptions) *std.build.LibExeObjStep {
|
||||
const main_abs = hb_root ++ "/src/harfbuzz.cc";
|
||||
const lib = b.addStaticLibrary("harfbuzz", main_abs);
|
||||
lib.setBuildMode(mode);
|
||||
lib.setTarget(target);
|
||||
pub fn buildHarfbuzz(b: *Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget, options: HarfbuzzOptions) *std.build.CompileStep {
|
||||
const lib = b.addStaticLibrary(.{
|
||||
.name = "harfbuzz",
|
||||
.root_source_file = .{ .path = hb_root ++ "/src/harfbuzz.cc" },
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
lib.linkLibCpp();
|
||||
lib.addIncludePath(hb_include_path);
|
||||
lib.addIncludePath(ft_include_path);
|
||||
|
|
@ -184,10 +202,12 @@ pub fn buildHarfbuzz(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossT
|
|||
return lib;
|
||||
}
|
||||
|
||||
fn buildBrotli(b: *Builder, mode: std.builtin.Mode, target: std.zig.CrossTarget) *std.build.LibExeObjStep {
|
||||
const lib = b.addStaticLibrary("brotli", null);
|
||||
lib.setBuildMode(mode);
|
||||
lib.setTarget(target);
|
||||
fn buildBrotli(b: *Build, optimize: std.builtin.OptimizeMode, target: std.zig.CrossTarget) *std.build.CompileStep {
|
||||
const lib = b.addStaticLibrary(.{
|
||||
.name = "brotli",
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
lib.linkLibC();
|
||||
lib.addIncludePath(brotli_root ++ "/include");
|
||||
lib.addCSourceFiles(brotli_base_sources, &.{});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue