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 libxev = @import("vendor/libxev/build.zig");
const libxml2 = @import("vendor/zig-libxml2/libxml2.zig");
const libpng = @import("pkg/libpng/build.zig");
const macos = @import("pkg/macos/build.zig");
const objc = @import("vendor/zig-objc/build.zig");
const pixman = @import("pkg/pixman/build.zig");
const utf8proc = @import("pkg/utf8proc/build.zig");
const zlib = @import("pkg/zlib/build.zig");
const tracylib = @import("pkg/tracy/build.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
// 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

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");
/// Directories with our includes.
const root = thisDir() ++ "../../../vendor/libpng/";
const include_path = root;
const include_path_pnglibconf = thisDir();
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
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(.{
.name = "png",
.target = step.target,
.optimize = step.optimize,
.target = target,
.optimize = 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");
const zlib_dep = b.dependency("zlib", .{ .target = target, .optimize = optimize });
lib.linkLibrary(zlib_dep.artifact("z"));
lib.addIncludePath(upstream.path(""));
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);
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",
});
for (srcs) |src| {
lib.addCSourceFile(.{
.file = upstream.path(src),
.flags = flags.items,
});
}
// C files
lib.addCSourceFiles(srcs, flags.items);
lib.installHeader("pnglibconf.h", "pnglibconf.h");
lib.installHeadersDirectoryOptions(.{
.source_dir = upstream.path(""),
.install_dir = .header,
.install_subdir = "",
.include_extensions = &.{".h"},
});
return lib;
b.installArtifact(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",
const srcs: []const []const u8 = &.{
"png.c",
"pngerror.c",
"pngget.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");
/// Directories with our includes.
const root = thisDir() ++ "../../../vendor/zlib/";
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("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(.{
.name = "z",
.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);
defer flags.deinit();
try flags.appendSlice(&.{
"-DHAVE_SYS_TYPES_H",
"-DHAVE_STDINT_H",
"-DHAVE_STDDEF_H",
"-DZ_HAVE_UNISTD_H",
});
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 ++ "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",
const srcs: []const []const u8 = &.{
"adler32.c",
"compress.c",
"crc32.c",
"deflate.c",
"gzclose.c",
"gzlib.c",
"gzread.c",
"gzwrite.c",
"inflate.c",
"infback.c",
"inftrees.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",
},
},
}