pkg/libpng, pkg/zlib use package manager

This commit is contained in:
Mitchell Hashimoto
2023-10-01 11:25:18 -07:00
parent a75403990a
commit 6e2b7c607e
7 changed files with 280 additions and 132 deletions

View File

@ -21,15 +21,16 @@ const harfbuzz = @import("pkg/harfbuzz/build.zig");
const js = @import("vendor/zig-js/build.zig"); const js = @import("vendor/zig-js/build.zig");
const libxev = @import("vendor/libxev/build.zig"); const libxev = @import("vendor/libxev/build.zig");
const libxml2 = @import("vendor/zig-libxml2/libxml2.zig"); const libxml2 = @import("vendor/zig-libxml2/libxml2.zig");
const libpng = @import("pkg/libpng/build.zig");
const macos = @import("pkg/macos/build.zig"); const macos = @import("pkg/macos/build.zig");
const objc = @import("vendor/zig-objc/build.zig"); const objc = @import("vendor/zig-objc/build.zig");
const pixman = @import("pkg/pixman/build.zig"); const pixman = @import("pkg/pixman/build.zig");
const utf8proc = @import("pkg/utf8proc/build.zig"); const utf8proc = @import("pkg/utf8proc/build.zig");
const zlib = @import("pkg/zlib/build.zig");
const tracylib = @import("pkg/tracy/build.zig"); const tracylib = @import("pkg/tracy/build.zig");
const system_sdk = @import("vendor/mach-glfw/system_sdk.zig"); const system_sdk = @import("vendor/mach-glfw/system_sdk.zig");
const libpng = @import("pkg/libpng/build.old.zig");
const zlib = @import("pkg/zlib/build.old.zig");
// Do a comptime Zig version requirement. The required Zig version is // Do a comptime Zig version requirement. The required Zig version is
// somewhat arbitrary: it is meant to be a version that we feel works well, // somewhat arbitrary: it is meant to be a version that we feel works well,
// but we liberally update it. In the future, we'll be more careful about // but we liberally update it. In the future, we'll be more careful about

102
pkg/libpng/build.old.zig Normal file
View File

@ -0,0 +1,102 @@
const std = @import("std");
/// Directories with our includes.
const root = thisDir() ++ "../../../vendor/libpng/";
const include_path = root;
const include_path_pnglibconf = thisDir();
pub const include_paths = .{ include_path, include_path_pnglibconf };
pub const pkg = std.build.Pkg{
.name = "libpng",
.source = .{ .path = thisDir() ++ "/main.zig" },
};
fn thisDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}
pub const Options = struct {
zlib: Zlib = .{},
pub const Zlib = struct {
step: ?*std.build.LibExeObjStep = null,
include: ?[]const []const u8 = null,
};
};
pub fn link(
b: *std.Build,
step: *std.build.LibExeObjStep,
opt: Options,
) !*std.build.LibExeObjStep {
const lib = try buildLib(b, step, opt);
step.linkLibrary(lib);
step.addIncludePath(.{ .path = include_path });
return lib;
}
pub fn buildLib(
b: *std.Build,
step: *std.build.LibExeObjStep,
opt: Options,
) !*std.build.LibExeObjStep {
const target = step.target;
const lib = b.addStaticLibrary(.{
.name = "png",
.target = step.target,
.optimize = step.optimize,
});
// Include
lib.addIncludePath(.{ .path = include_path });
lib.addIncludePath(.{ .path = include_path_pnglibconf });
// Link
lib.linkLibC();
if (target.isLinux()) {
lib.linkSystemLibrary("m");
}
if (opt.zlib.step) |zlib|
lib.linkLibrary(zlib)
else
lib.linkSystemLibrary("z");
if (opt.zlib.include) |dirs|
for (dirs) |dir| lib.addIncludePath(.{ .path = dir });
// Compile
var flags = std.ArrayList([]const u8).init(b.allocator);
defer flags.deinit();
try flags.appendSlice(&.{
"-DPNG_ARM_NEON_OPT=0",
"-DPNG_POWERPC_VSX_OPT=0",
"-DPNG_INTEL_SSE_OPT=0",
"-DPNG_MIPS_MSA_OPT=0",
});
// C files
lib.addCSourceFiles(srcs, flags.items);
return lib;
}
const srcs = &.{
root ++ "png.c",
root ++ "pngerror.c",
root ++ "pngget.c",
root ++ "pngmem.c",
root ++ "pngpread.c",
root ++ "pngread.c",
root ++ "pngrio.c",
root ++ "pngrtran.c",
root ++ "pngrutil.c",
root ++ "pngset.c",
root ++ "pngtrans.c",
root ++ "pngwio.c",
root ++ "pngwrite.c",
root ++ "pngwtran.c",
root ++ "pngwutil.c",
};

View File

@ -1,102 +1,66 @@
const std = @import("std"); const std = @import("std");
/// Directories with our includes. pub fn build(b: *std.Build) !void {
const root = thisDir() ++ "../../../vendor/libpng/"; const target = b.standardTargetOptions(.{});
const include_path = root; const optimize = b.standardOptimizeOption(.{});
const include_path_pnglibconf = thisDir();
pub const include_paths = .{ include_path, include_path_pnglibconf }; const upstream = b.dependency("libpng", .{});
pub const pkg = std.build.Pkg{
.name = "libpng",
.source = .{ .path = thisDir() ++ "/main.zig" },
};
fn thisDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}
pub const Options = struct {
zlib: Zlib = .{},
pub const Zlib = struct {
step: ?*std.build.LibExeObjStep = null,
include: ?[]const []const u8 = null,
};
};
pub fn link(
b: *std.Build,
step: *std.build.LibExeObjStep,
opt: Options,
) !*std.build.LibExeObjStep {
const lib = try buildLib(b, step, opt);
step.linkLibrary(lib);
step.addIncludePath(.{ .path = include_path });
return lib;
}
pub fn buildLib(
b: *std.Build,
step: *std.build.LibExeObjStep,
opt: Options,
) !*std.build.LibExeObjStep {
const target = step.target;
const lib = b.addStaticLibrary(.{ const lib = b.addStaticLibrary(.{
.name = "png", .name = "png",
.target = step.target, .target = target,
.optimize = step.optimize, .optimize = optimize,
}); });
// Include
lib.addIncludePath(.{ .path = include_path });
lib.addIncludePath(.{ .path = include_path_pnglibconf });
// Link
lib.linkLibC(); lib.linkLibC();
if (target.isLinux()) { if (target.isLinux()) {
lib.linkSystemLibrary("m"); lib.linkSystemLibrary("m");
} }
if (opt.zlib.step) |zlib| const zlib_dep = b.dependency("zlib", .{ .target = target, .optimize = optimize });
lib.linkLibrary(zlib) lib.linkLibrary(zlib_dep.artifact("z"));
else lib.addIncludePath(upstream.path(""));
lib.linkSystemLibrary("z"); lib.addIncludePath(.{ .path = "" });
if (opt.zlib.include) |dirs|
for (dirs) |dir| lib.addIncludePath(.{ .path = dir });
// Compile
var flags = std.ArrayList([]const u8).init(b.allocator); var flags = std.ArrayList([]const u8).init(b.allocator);
defer flags.deinit(); defer flags.deinit();
try flags.appendSlice(&.{ try flags.appendSlice(&.{
"-DPNG_ARM_NEON_OPT=0", "-DPNG_ARM_NEON_OPT=0",
"-DPNG_POWERPC_VSX_OPT=0", "-DPNG_POWERPC_VSX_OPT=0",
"-DPNG_INTEL_SSE_OPT=0", "-DPNG_INTEL_SSE_OPT=0",
"-DPNG_MIPS_MSA_OPT=0", "-DPNG_MIPS_MSA_OPT=0",
}); });
for (srcs) |src| {
// C files lib.addCSourceFile(.{
lib.addCSourceFiles(srcs, flags.items); .file = upstream.path(src),
.flags = flags.items,
return lib; });
} }
const srcs = &.{ lib.installHeader("pnglibconf.h", "pnglibconf.h");
root ++ "png.c", lib.installHeadersDirectoryOptions(.{
root ++ "pngerror.c", .source_dir = upstream.path(""),
root ++ "pngget.c", .install_dir = .header,
root ++ "pngmem.c", .install_subdir = "",
root ++ "pngpread.c", .include_extensions = &.{".h"},
root ++ "pngread.c", });
root ++ "pngrio.c",
root ++ "pngrtran.c", b.installArtifact(lib);
root ++ "pngrutil.c", }
root ++ "pngset.c",
root ++ "pngtrans.c", const srcs: []const []const u8 = &.{
root ++ "pngwio.c", "png.c",
root ++ "pngwrite.c", "pngerror.c",
root ++ "pngwtran.c", "pngget.c",
root ++ "pngwutil.c", "pngmem.c",
"pngpread.c",
"pngread.c",
"pngrio.c",
"pngrtran.c",
"pngrutil.c",
"pngset.c",
"pngtrans.c",
"pngwio.c",
"pngwrite.c",
"pngwtran.c",
"pngwutil.c",
}; };

14
pkg/libpng/build.zig.zon Normal file
View File

@ -0,0 +1,14 @@
.{
.name = "libpng",
.version = "1.6.40",
.dependencies = .{
.libpng = .{
.url = "https://github.com/glennrp/libpng/archive/refs/tags/v1.6.40.tar.gz",
.hash = "12203d2722e3af6f9556503b114c25fe3eead528a93f5f26eefcb187a460d1548e07",
},
.zlib = .{
.path = "../zlib",
},
},
}

74
pkg/zlib/build.old.zig Normal file
View File

@ -0,0 +1,74 @@
const std = @import("std");
/// Directories with our includes.
const root = thisDir() ++ "../../../vendor/zlib/";
const include_path = root;
pub const include_paths = .{include_path};
pub const pkg = std.build.Pkg{
.name = "zlib",
.source = .{ .path = thisDir() ++ "/main.zig" },
};
fn thisDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}
pub fn link(b: *std.build.Builder, 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.Builder,
step: *std.build.LibExeObjStep,
) !*std.build.LibExeObjStep {
const lib = b.addStaticLibrary(.{
.name = "z",
.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);
defer flags.deinit();
try flags.appendSlice(&.{
"-DHAVE_SYS_TYPES_H",
"-DHAVE_STDINT_H",
"-DHAVE_STDDEF_H",
"-DZ_HAVE_UNISTD_H",
});
// C files
lib.addCSourceFiles(srcs, flags.items);
return lib;
}
const srcs = &.{
root ++ "adler32.c",
root ++ "compress.c",
root ++ "crc32.c",
root ++ "deflate.c",
root ++ "gzclose.c",
root ++ "gzlib.c",
root ++ "gzread.c",
root ++ "gzwrite.c",
root ++ "inflate.c",
root ++ "infback.c",
root ++ "inftrees.c",
root ++ "inffast.c",
root ++ "trees.c",
root ++ "uncompr.c",
root ++ "zutil.c",
};

View File

@ -1,74 +1,57 @@
const std = @import("std"); const std = @import("std");
/// Directories with our includes. pub fn build(b: *std.Build) !void {
const root = thisDir() ++ "../../../vendor/zlib/"; const target = b.standardTargetOptions(.{});
const include_path = root; const optimize = b.standardOptimizeOption(.{});
pub const include_paths = .{include_path}; const upstream = b.dependency("zlib", .{});
pub const pkg = std.build.Pkg{
.name = "zlib",
.source = .{ .path = thisDir() ++ "/main.zig" },
};
fn thisDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}
pub fn link(b: *std.build.Builder, 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.Builder,
step: *std.build.LibExeObjStep,
) !*std.build.LibExeObjStep {
const lib = b.addStaticLibrary(.{ const lib = b.addStaticLibrary(.{
.name = "z", .name = "z",
.target = step.target, .target = target,
.optimize = step.optimize, .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); var flags = std.ArrayList([]const u8).init(b.allocator);
defer flags.deinit(); defer flags.deinit();
try flags.appendSlice(&.{ try flags.appendSlice(&.{
"-DHAVE_SYS_TYPES_H", "-DHAVE_SYS_TYPES_H",
"-DHAVE_STDINT_H", "-DHAVE_STDINT_H",
"-DHAVE_STDDEF_H", "-DHAVE_STDDEF_H",
"-DZ_HAVE_UNISTD_H", "-DZ_HAVE_UNISTD_H",
}); });
for (srcs) |src| {
// C files lib.addCSourceFile(.{
lib.addCSourceFiles(srcs, flags.items); .file = upstream.path(src),
.flags = flags.items,
return lib; });
} }
const srcs = &.{ b.installArtifact(lib);
root ++ "adler32.c", }
root ++ "compress.c",
root ++ "crc32.c", const srcs: []const []const u8 = &.{
root ++ "deflate.c", "adler32.c",
root ++ "gzclose.c", "compress.c",
root ++ "gzlib.c", "crc32.c",
root ++ "gzread.c", "deflate.c",
root ++ "gzwrite.c", "gzclose.c",
root ++ "inflate.c", "gzlib.c",
root ++ "infback.c", "gzread.c",
root ++ "inftrees.c", "gzwrite.c",
root ++ "inffast.c", "inflate.c",
root ++ "trees.c", "infback.c",
root ++ "uncompr.c", "inftrees.c",
root ++ "zutil.c", "inffast.c",
"trees.c",
"uncompr.c",
"zutil.c",
}; };

10
pkg/zlib/build.zig.zon Normal file
View File

@ -0,0 +1,10 @@
.{
.name = "zlib",
.version = "1.3.0",
.dependencies = .{
.zlib = .{
.url = "https://github.com/madler/zlib/archive/refs/tags/v1.3.tar.gz",
.hash = "12207d353609d95cee9da7891919e6d9582e97b7aa2831bd50f33bf523a582a08547",
},
},
}