pkg/utf8proc

This commit is contained in:
Mitchell Hashimoto
2023-10-01 16:45:39 -07:00
parent 5d52a94792
commit 3ed6a02176
5 changed files with 110 additions and 57 deletions

View File

@@ -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",
};

View File

@@ -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",
};

View File

@@ -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",
},
},
}