From 3ed6a0217694646e27cc8f2f7191517da0067bc3 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 1 Oct 2023 16:45:39 -0700 Subject: [PATCH] pkg/utf8proc --- build.zig | 38 +++++++++++++---------- build.zig.zon | 1 + pkg/utf8proc/build.old.zig | 55 +++++++++++++++++++++++++++++++++ pkg/utf8proc/build.zig | 63 ++++++++++++++------------------------ pkg/utf8proc/build.zig.zon | 10 ++++++ 5 files changed, 110 insertions(+), 57 deletions(-) create mode 100644 pkg/utf8proc/build.old.zig create mode 100644 pkg/utf8proc/build.zig.zon diff --git a/build.zig b/build.zig index b276b7519..a42fe5742 100644 --- a/build.zig +++ b/build.zig @@ -20,7 +20,6 @@ const libxev = @import("vendor/libxev/build.zig"); const libxml2 = @import("vendor/zig-libxml2/libxml2.zig"); const macos = @import("pkg/macos/build.zig"); const objc = @import("vendor/zig-objc/build.zig"); -const utf8proc = @import("pkg/utf8proc/build.zig"); const tracylib = @import("pkg/tracy/build.zig"); const system_sdk = @import("vendor/mach-glfw/system_sdk.zig"); @@ -29,6 +28,7 @@ const freetype = @import("pkg/freetype/build.old.zig"); const harfbuzz = @import("pkg/harfbuzz/build.old.zig"); const libpng = @import("pkg/libpng/build.old.zig"); const pixman = @import("pkg/pixman/build.old.zig"); +const utf8proc = @import("pkg/utf8proc/build.old.zig"); const zlib = @import("pkg/zlib/build.old.zig"); // Do a comptime Zig version requirement. The required Zig version is @@ -653,20 +653,6 @@ fn addDeps( var static_libs = FileSourceList.init(b.allocator); errdefer static_libs.deinit(); - // Wasm we do manually since it is such a different build. - if (step.target.getCpuArch() == .wasm32) { - // We link this package but its a no-op since Tracy - // never actually WORKS with wasm. - step.addModule("tracy", tracylib.module(b)); - step.addModule("utf8proc", utf8proc.module(b)); - step.addModule("zig-js", js.module(b)); - - // utf8proc - _ = try utf8proc.link(b, step); - - return static_libs; - } - // For dynamic linking, we prefer dynamic linking and to search by // mode first. Mode first will search all paths for a dynamic library // before falling back to static. @@ -696,6 +682,10 @@ fn addDeps( .target = step.target, .optimize = step.optimize, }); + const utf8proc_dep = b.dependency("utf8proc", .{ + .target = step.target, + .optimize = step.optimize, + }); const harfbuzz_dep = b.dependency("harfbuzz", .{ .target = step.target, .optimize = step.optimize, @@ -703,6 +693,20 @@ fn addDeps( .@"enable-coretext" = font_backend.hasCoretext(), }); + // Wasm we do manually since it is such a different build. + if (step.target.getCpuArch() == .wasm32) { + // We link this package but its a no-op since Tracy + // never actually WORKS with wasm. + step.addModule("tracy", tracylib.module(b)); + step.addModule("utf8proc", utf8proc.module(b)); + step.addModule("zig-js", js.module(b)); + + // utf8proc + step.linkLibrary(utf8proc_dep.artifact("utf8proc")); + + return static_libs; + } + // On Linux, we need to add a couple common library paths that aren't // on the standard search list. i.e. GTK is often in /usr/lib/x86_64-linux-gnu // on x86_64. @@ -759,8 +763,8 @@ fn addDeps( } // utf8proc - const utf8proc_step = try utf8proc.link(b, step); - try static_libs.append(utf8proc_step.getEmittedBin()); + step.linkLibrary(utf8proc_dep.artifact("utf8proc")); + try static_libs.append(utf8proc_dep.artifact("utf8proc").getEmittedBin()); // Dynamic link if (!static) { diff --git a/build.zig.zon b/build.zig.zon index b3e20200c..749d6fedc 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -7,6 +7,7 @@ .harfbuzz = .{ .path = "./pkg/harfbuzz" }, .libpng = .{ .path = "./pkg/libpng" }, .pixman = .{ .path = "./pkg/pixman" }, + .utf8proc = .{ .path = "./pkg/utf8proc" }, .zlib = .{ .path = "./pkg/zlib" }, }, } diff --git a/pkg/utf8proc/build.old.zig b/pkg/utf8proc/build.old.zig new file mode 100644 index 000000000..7152766d6 --- /dev/null +++ b/pkg/utf8proc/build.old.zig @@ -0,0 +1,55 @@ +const std = @import("std"); + +/// Directories with our includes. +const root = thisDir() ++ "../../../vendor/utf8proc/"; +const include_path = root; + +pub const include_paths = .{include_path}; + +pub fn module(b: *std.Build) *std.build.Module { + return b.createModule(.{ + .source_file = .{ .path = (comptime thisDir()) ++ "/main.zig" }, + }); +} + +fn thisDir() []const u8 { + return std.fs.path.dirname(@src().file) orelse "."; +} + +pub fn link(b: *std.Build, step: *std.build.LibExeObjStep) !*std.build.LibExeObjStep { + const lib = try buildLib(b, step); + step.linkLibrary(lib); + step.addIncludePath(.{ .path = include_path }); + return lib; +} + +pub fn buildLib( + b: *std.Build, + step: *std.build.LibExeObjStep, +) !*std.build.LibExeObjStep { + const lib = b.addStaticLibrary(.{ + .name = "utf8proc", + .target = step.target, + .optimize = step.optimize, + }); + + // Include + lib.addIncludePath(.{ .path = include_path }); + + // Link + lib.linkLibC(); + + // Compile + var flags = std.ArrayList([]const u8).init(b.allocator); + try flags.append("-DUTF8PROC_EXPORTS"); + defer flags.deinit(); + + // C files + lib.addCSourceFiles(srcs, flags.items); + + return lib; +} + +const srcs = &.{ + root ++ "utf8proc.c", +}; diff --git a/pkg/utf8proc/build.zig b/pkg/utf8proc/build.zig index 7152766d6..2f83d8708 100644 --- a/pkg/utf8proc/build.zig +++ b/pkg/utf8proc/build.zig @@ -1,55 +1,38 @@ const std = @import("std"); -/// Directories with our includes. -const root = thisDir() ++ "../../../vendor/utf8proc/"; -const include_path = root; +pub fn build(b: *std.Build) !void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); -pub const include_paths = .{include_path}; + const upstream = b.dependency("utf8proc", .{}); -pub fn module(b: *std.Build) *std.build.Module { - return b.createModule(.{ - .source_file = .{ .path = (comptime thisDir()) ++ "/main.zig" }, - }); -} - -fn thisDir() []const u8 { - return std.fs.path.dirname(@src().file) orelse "."; -} - -pub fn link(b: *std.Build, step: *std.build.LibExeObjStep) !*std.build.LibExeObjStep { - const lib = try buildLib(b, step); - step.linkLibrary(lib); - step.addIncludePath(.{ .path = include_path }); - return lib; -} - -pub fn buildLib( - b: *std.Build, - step: *std.build.LibExeObjStep, -) !*std.build.LibExeObjStep { const lib = b.addStaticLibrary(.{ .name = "utf8proc", - .target = step.target, - .optimize = step.optimize, + .target = target, + .optimize = optimize, + }); + lib.linkLibC(); + lib.addIncludePath(upstream.path("")); + lib.installHeadersDirectoryOptions(.{ + .source_dir = upstream.path(""), + .install_dir = .header, + .install_subdir = "", + .include_extensions = &.{".h"}, }); - // Include - lib.addIncludePath(.{ .path = include_path }); - - // Link - lib.linkLibC(); - - // Compile var flags = std.ArrayList([]const u8).init(b.allocator); try flags.append("-DUTF8PROC_EXPORTS"); defer flags.deinit(); + for (srcs) |src| { + lib.addCSourceFile(.{ + .file = upstream.path(src), + .flags = flags.items, + }); + } - // C files - lib.addCSourceFiles(srcs, flags.items); - - return lib; + b.installArtifact(lib); } -const srcs = &.{ - root ++ "utf8proc.c", +const srcs: []const []const u8 = &.{ + "utf8proc.c", }; diff --git a/pkg/utf8proc/build.zig.zon b/pkg/utf8proc/build.zig.zon new file mode 100644 index 000000000..a4ecb6ab3 --- /dev/null +++ b/pkg/utf8proc/build.zig.zon @@ -0,0 +1,10 @@ +.{ + .name = "utf8proc", + .version = "2.8.0", + .dependencies = .{ + .utf8proc = .{ + .url = "https://github.com/JuliaStrings/utf8proc/archive/refs/tags/v2.8.0.tar.gz", + .hash = "1220056ce228a8c58f1fa66ab778f5c8965e62f720c1d30603c7d534cb7d8a605ad7", + }, + }, +}