From dd95f727ec785ba288fd874fb8b1c3a9b182db95 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 6 Mar 2025 07:23:00 -0800 Subject: [PATCH] build: add libintl for macOS builds --- build.zig.zon | 1 + pkg/libintl/build.zig | 14 ++++++++++++-- pkg/libintl/build.zig.zon | 2 ++ src/build/SharedDeps.zig | 11 +++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index 76142b4aa..4e69cb393 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -63,6 +63,7 @@ .gtk4_layer_shell = .{ .path = "./pkg/gtk4-layer-shell" }, .harfbuzz = .{ .path = "./pkg/harfbuzz" }, .highway = .{ .path = "./pkg/highway" }, + .libintl = .{ .path = "./pkg/libintl" }, .libpng = .{ .path = "./pkg/libpng" }, .macos = .{ .path = "./pkg/macos" }, .oniguruma = .{ .path = "./pkg/oniguruma" }, diff --git a/pkg/libintl/build.zig b/pkg/libintl/build.zig index 410587c46..bf2e14150 100644 --- a/pkg/libintl/build.zig +++ b/pkg/libintl/build.zig @@ -359,6 +359,12 @@ pub fn build(b: *std.Build) !void { lib.addIncludePath(b.path("")); lib.addIncludePath(upstream.path("gettext-runtime/intl")); lib.addIncludePath(upstream.path("gettext-runtime/intl/gnulib-lib")); + + if (target.result.isDarwin()) { + const apple_sdk = @import("apple_sdk"); + try apple_sdk.addPaths(b, &lib.root_module); + } + lib.addConfigHeader(config); lib.addCSourceFiles(.{ .root = upstream.path("gettext-runtime/intl"), @@ -389,12 +395,16 @@ const srcs: []const []const u8 = &.{ "localealias.c", "log.c", "ngettext.c", - "osdep.c", "plural-exp.c", "plural.c", - "printf.c", "setlocale.c", "textdomain.c", "version.c", "compat.c", + + // Not needed for macOS, but we might need them for other platforms. + // If we expand this to support other platforms, we should uncomment + // these. + // "osdep.c", + // "printf.c", }; diff --git a/pkg/libintl/build.zig.zon b/pkg/libintl/build.zig.zon index e5f630726..216bf1bbb 100644 --- a/pkg/libintl/build.zig.zon +++ b/pkg/libintl/build.zig.zon @@ -7,5 +7,7 @@ .url = "https://deps.files.ghostty.org/gettext-0.24.tar.gz", .hash = "1220f870c853529233ea64a108acaaa81f8d06d7ff4b66c76930be7d78d508aff7a2", }, + + .apple_sdk = .{ .path = "../apple-sdk" }, }, } diff --git a/src/build/SharedDeps.zig b/src/build/SharedDeps.zig index d592aee70..28eb7fa68 100644 --- a/src/build/SharedDeps.zig +++ b/src/build/SharedDeps.zig @@ -381,6 +381,17 @@ pub fn add( if (self.config.renderer == .opengl) { step.linkFramework("OpenGL"); } + + // Apple platforms do not include libc libintl so we bundle it. + // This is LGPL but since our source code is open source we are + // in compliance with the LGPL since end users can modify this + // build script to replace the bundled libintl with their own. + const libintl_dep = b.dependency("libintl", .{ + .target = target, + .optimize = optimize, + }); + step.linkLibrary(libintl_dep.artifact("intl")); + try static_libs.append(libintl_dep.artifact("intl").getEmittedBin()); } // cimgui