Use dependency that is a transitive dep of another one (harfbuzz, freetype)
Hello, I’m trying to render text using harfbuzz and freetype. To do this, I shape the text using harfbuzz which gives me the glyphs I need to render, but to actually render I need to use freetype to get a bitmap. I’m using the allyourcodebase builds, but if I try to include both libraries and use them I get this error:
zig-pkg/harfbuzz-14.1.0-Ip1VAuGZAAC1jdxPHOMPoHyi-50Hm_q4bveaVflELHGw/freetype.zig:1:1: error: file exists in modules 'freetype' and 'freetype0'
zig-pkg/harfbuzz-14.1.0-Ip1VAuGZAAC1jdxPHOMPoHyi-50Hm_q4bveaVflELHGw/freetype.zig:1:1: note: files must belong to only one module
zig-pkg/harfbuzz-14.1.0-Ip1VAuGZAAC1jdxPHOMPoHyi-50Hm_q4bveaVflELHGw/freetype.zig:1:1: note: file is the root of module 'freetype'
zig-pkg/harfbuzz-14.1.0-Ip1VAuGZAAC1jdxPHOMPoHyi-50Hm_q4bveaVflELHGw/freetype.zig:1:1: note: file is the root of module 'freetype0'
From what I unbderstand this is because harfbuzz has a dep on freetype, but I’m not sure what the problem is?
I tried accessing freetype through the harfbuzz import but it’s not pub. Does anyone have any suggestions/explanation?
build.zig:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const harfbuzz = b.dependency("harfbuzz", .{}).module("harfbuzz");
const freetype = b.dependency("freetype", .{}).module("freetype");
const exe = b.addExecutable(.{
.name = "gigi",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
.{ .name = "harfbuzz", .module = harfbuzz },
.{ .name = "freetype", .module = freetype },
},
}),
});
b.installArtifact(exe);
const run_exe = b.addRunArtifact(exe);
const run_step = b.step("run", "Run gigi");
run_step.dependOn(&run_exe.step);
}
build.zig.zon:
.{
.name = .repro_freetype_harfbuzz,
.version = "0.0.1",
.dependencies = .{
.harfbuzz = .{
.url = "git+https://github.com/allyourcodebase/harfbuzz#d055840ecefefcd57f5ddeb2fa8c83fafed1a40b",
.hash = "harfbuzz-14.1.0-Ip1VAuGZAAC1jdxPHOMPoHyi-50Hm_q4bveaVflELHGw",
},
.freetype = .{
.url = "git+https://github.com/allyourcodebase/freetype#884fd2235e6ae1ec4306eda30b3259f20930ed2e",
.hash = "freetype-2.14.3-C3-WdXSKAAB-kHs4qgRoeoFnRkNQn6M_SSlUGZ6ywgBQ",
},
},
.minimum_zig_version = "0.16.0",
.paths = .{""},
.fingerprint = 0x7d8b6d4c3f9364cf,
}
src/main.zig:
const hb = @import("harfbuzz").c;
const ft = @import("freetype");
pub fn main() void {
const text_buffer = hb.hb_buffer_create();
defer hb.hb_buffer_destroy(text_buffer);
const lib = try ft.Library.init();
defer lib.deinit();
}