ghostty/pkg/pixman/build.zig
2022-11-24 10:21:27 -08:00

142 lines
3.7 KiB
Zig

const std = @import("std");
const builtin = @import("builtin");
/// Directories with our includes.
const root = thisDir() ++ "../../../vendor/pixman/";
const include_path = root ++ "pixman/";
const include_path_self = thisDir();
pub const include_paths = .{ include_path, include_path_self };
pub const pkg = std.build.Pkg{
.name = "pixman",
.source = .{ .path = thisDir() ++ "/main.zig" },
};
fn thisDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}
pub const Options = struct {};
pub fn build(b: *std.build.Builder) !void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const tests = b.addTestExe("pixman-test", "main.zig");
tests.setBuildMode(mode);
tests.setTarget(target);
_ = try link(b, tests, .{});
tests.install();
const test_step = b.step("test", "Run tests");
const tests_run = tests.run();
test_step.dependOn(&tests_run.step);
}
pub fn link(
b: *std.build.Builder,
step: *std.build.LibExeObjStep,
opt: Options,
) !*std.build.LibExeObjStep {
const lib = try buildPixman(b, step, opt);
step.linkLibrary(lib);
step.addIncludePath(include_path);
step.addIncludePath(include_path_self);
return lib;
}
pub fn buildPixman(
b: *std.build.Builder,
step: *std.build.LibExeObjStep,
opt: Options,
) !*std.build.LibExeObjStep {
_ = opt;
const target = step.target;
const lib = b.addStaticLibrary("pixman", null);
lib.setTarget(step.target);
lib.setBuildMode(step.build_mode);
// Include
lib.addIncludePath(include_path);
lib.addIncludePath(include_path_self);
// Link
lib.linkLibC();
if (!target.isWindows()) {
lib.linkSystemLibrary("pthread");
}
// Compile
var flags = std.ArrayList([]const u8).init(b.allocator);
defer flags.deinit();
try flags.appendSlice(&.{
"-DHAVE_SIGACTION=1",
"-DHAVE_ALARM=1",
"-DHAVE_MPROTECT=1",
"-DHAVE_GETPAGESIZE=1",
"-DHAVE_MMAP=1",
"-DHAVE_GETISAX=1",
"-DHAVE_GETTIMEOFDAY=1",
"-DHAVE_FENV_H=1",
"-DHAVE_SYS_MMAN_H=1",
"-DHAVE_UNISTD_H=1",
"-DSIZEOF_LONG=8",
"-DPACKAGE=foo",
// There is ubsan
"-fno-sanitize=undefined",
"-fno-sanitize-trap=undefined",
});
if (!target.isWindows()) {
try flags.appendSlice(&.{
"-DHAVE_PTHREADS=1",
"-DHAVE_POSIX_MEMALIGN=1",
});
}
// C files
lib.addCSourceFiles(srcs, flags.items);
return lib;
}
const srcs = &.{
root ++ "pixman/pixman.c",
root ++ "pixman/pixman-access.c",
root ++ "pixman/pixman-access-accessors.c",
root ++ "pixman/pixman-bits-image.c",
root ++ "pixman/pixman-combine32.c",
root ++ "pixman/pixman-combine-float.c",
root ++ "pixman/pixman-conical-gradient.c",
root ++ "pixman/pixman-filter.c",
root ++ "pixman/pixman-x86.c",
root ++ "pixman/pixman-mips.c",
root ++ "pixman/pixman-arm.c",
root ++ "pixman/pixman-ppc.c",
root ++ "pixman/pixman-edge.c",
root ++ "pixman/pixman-edge-accessors.c",
root ++ "pixman/pixman-fast-path.c",
root ++ "pixman/pixman-glyph.c",
root ++ "pixman/pixman-general.c",
root ++ "pixman/pixman-gradient-walker.c",
root ++ "pixman/pixman-image.c",
root ++ "pixman/pixman-implementation.c",
root ++ "pixman/pixman-linear-gradient.c",
root ++ "pixman/pixman-matrix.c",
root ++ "pixman/pixman-noop.c",
root ++ "pixman/pixman-radial-gradient.c",
root ++ "pixman/pixman-region16.c",
root ++ "pixman/pixman-region32.c",
root ++ "pixman/pixman-solid-fill.c",
root ++ "pixman/pixman-timer.c",
root ++ "pixman/pixman-trap.c",
root ++ "pixman/pixman-utils.c",
};