Use mach-freetype with the package manager and update zig version to 0.12.0-dev.163+6780a6bbf

This commit is contained in:
IntegratedQuantum 2023-08-24 09:47:13 +02:00
parent 840d62177c
commit 7d4d110b03
5 changed files with 42 additions and 18 deletions

3
.gitmodules vendored
View File

@ -1,6 +1,3 @@
[submodule "mach-freetype"]
path = mach-freetype
url = https://github.com/hexops/mach-freetype
[submodule "portaudio"]
path = portaudio
url = git@github.com:PortAudio/portaudio.git

View File

@ -1,5 +1,4 @@
const std = @import("std");
const freetype = @import("mach-freetype/build.zig");
pub fn build(b: *std.build.Builder) !void {
// Standard target options allows the person running `zig build` to choose
@ -13,11 +12,11 @@ pub fn build(b: *std.build.Builder) !void {
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "Cubyzig",
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = .{.path = "src/main.zig"},
.target = target,
.optimize = optimize,
});
exe.addIncludePath("include");
exe.addIncludePath(.{.path = "include"});
exe.linkLibC();
{ // compile glfw from source:
if(target.getOsTag() == .windows) {
@ -44,10 +43,10 @@ pub fn build(b: *std.build.Builder) !void {
}
}
{ // compile portaudio from source:
exe.addIncludePath("portaudio/include");
exe.addIncludePath("portaudio/src/common");
exe.addIncludePath(.{.path = "portaudio/include"});
exe.addIncludePath(.{.path = "portaudio/src/common"});
exe.addCSourceFiles(&[_][]const u8 {
"portaudio/src/common/pa_allocation.c",
"portaudio/src/common/pa_allocation.c",
"portaudio/src/common/pa_converters.c",
"portaudio/src/common/pa_cpuload.c",
"portaudio/src/common/pa_debugprint.c",
@ -61,7 +60,7 @@ pub fn build(b: *std.build.Builder) !void {
if(target.getOsTag() == .windows) {
// windows:
exe.addCSourceFiles(&[_][]const u8 {"portaudio/src/os/win/pa_win_coinitialize.c", "portaudio/src/os/win/pa_win_hostapis.c", "portaudio/src/os/win/pa_win_util.c", "portaudio/src/os/win/pa_win_waveformat.c", "portaudio/src/os/win/pa_win_wdmks_utils.c", "portaudio/src/os/win/pa_x86_plain_converters.c", }, &[_][]const u8{"-g", "-O3", "-DPA_USE_WASAPI"});
exe.addIncludePath("portaudio/src/os/win");
exe.addIncludePath(.{.path = "portaudio/src/os/win"});
exe.linkSystemLibrary("ole32");
exe.linkSystemLibrary("winmm");
exe.linkSystemLibrary("uuid");
@ -70,7 +69,7 @@ pub fn build(b: *std.build.Builder) !void {
} else if(target.getOsTag() == .linux) {
// unix:
exe.addCSourceFiles(&[_][]const u8 {"portaudio/src/os/unix/pa_unix_hostapis.c", "portaudio/src/os/unix/pa_unix_util.c"}, &[_][]const u8{"-g", "-O3", "-DPA_USE_ALSA"});
exe.addIncludePath("portaudio/src/os/unix");
exe.addIncludePath(.{.path = "portaudio/src/os/unix"});
// ALSA:
exe.addCSourceFiles(&[_][]const u8 {"portaudio/src/hostapi/alsa/pa_linux_alsa.c"}, &[_][]const u8{"-g", "-O3"});
exe.linkSystemLibrary("asound");
@ -81,11 +80,18 @@ pub fn build(b: *std.build.Builder) !void {
exe.addCSourceFiles(&[_][]const u8{"lib/glad.c", "lib/stb_image.c", "lib/stb_image_write.c", "lib/stb_vorbis.c"}, &[_][]const u8{"-g", "-O3"});
exe.addAnonymousModule("gui", .{.source_file = .{.path = "src/gui/gui.zig"}});
exe.addAnonymousModule("server", .{.source_file = .{.path = "src/server/server.zig"}});
const harfbuzzModule = freetype.harfbuzzModule(b);
const freetypeModule = harfbuzzModule.dependencies.get("freetype").?;
exe.addModule("harfbuzz", harfbuzzModule);
exe.addModule("freetype", freetypeModule);
freetype.link(b, exe, .{ .harfbuzz = .{} });
@import("mach_freetype").brotli_import_path = "mach_freetype.freetype.brotli";
@import("mach_freetype").freetype_import_path = "mach_freetype.freetype";
const mach_freetype_dep = b.dependency("mach_freetype", .{
.target = target,
.optimize = optimize,
});
exe.addModule("freetype", mach_freetype_dep.module("mach-freetype"));
exe.addModule("harfbuzz", mach_freetype_dep.module("mach-harfbuzz"));
@import("mach_freetype").linkFreetype(b, optimize, target, exe);
@import("mach_freetype").linkHarfbuzz(b, optimize, target, exe);
//exe.strip = true; // Improves compile-time
//exe.sanitize_thread = true;
b.installArtifact(exe);

22
build.zig.zon Normal file
View File

@ -0,0 +1,22 @@
.{
.name = "Cubyzig",
.version = "0.0.0",
.dependencies = .{
.mach_freetype = .{
.url = "https://pkg.machengine.org/mach-freetype/de94b3a5fa14b717936a8881c7e7966d544bf4d0.tar.gz",
.hash = "1220b1c6027993ca41ea5a3a62b16de2f6689092205c39508af4de3e9cfec0bb7607",
},
.freetype = .{
.url = "https://pkg.machengine.org/freetype/835d7f07c605eec021911c671f0dad2b25ee5a30.tar.gz",
.hash = "122093dd7a4c91fcad6d44601f879a2d7d66700cdf8a2053e4ffdbfb26cd1b597a18",
},
.brotli = .{
.url = "https://pkg.machengine.org/brotli/b574788e32438f543ee552beec8bc70b05a465c2.tar.gz",
.hash = "122054602e178b287f13ed7b37c4bd54eb50af88dc2f9d9ba9e3c084fb4175f298a1",
},
.harfbuzz = .{
.url = "https://pkg.machengine.org/harfbuzz/616fc99a8408309da7ce07aa43de2eb634b0bc19.tar.gz",
.hash = "12206659398359bd48edbdcc5cf610ccff2b7af04a93acc946197a444bbe6ad34061",
},
},
}

@ -1 +0,0 @@
Subproject commit 3365aadd69674eeed497f0bf6ca535e64f4937a9

View File

@ -576,7 +576,7 @@ pub const TextBuffer = struct {
buffer.setDirection(.ltr);
buffer.setScript(.common);
buffer.setLanguage(harfbuzz.Language.getDefault());
harfbuzz.hb_shape(TextRendering.harfbuzzFont.handle, buffer.handle, null, 0);
TextRendering.harfbuzzFont.shape(buffer, null);
const glyphInfos = buffer.getGlyphInfos();
const glyphPositions = buffer.getGlyphPositions().?;