diff --git a/build.zig b/build.zig index fc944059b..9281489e8 100644 --- a/build.zig +++ b/build.zig @@ -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 diff --git a/pkg/libpng/build.old.zig b/pkg/libpng/build.old.zig new file mode 100644 index 000000000..0e98059ac --- /dev/null +++ b/pkg/libpng/build.old.zig @@ -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", +}; diff --git a/pkg/libpng/build.zig b/pkg/libpng/build.zig index 0e98059ac..f54c06893 100644 --- a/pkg/libpng/build.zig +++ b/pkg/libpng/build.zig @@ -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", }; diff --git a/pkg/libpng/build.zig.zon b/pkg/libpng/build.zig.zon new file mode 100644 index 000000000..ebad1dcb4 --- /dev/null +++ b/pkg/libpng/build.zig.zon @@ -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", + }, + }, +} diff --git a/pkg/zlib/build.old.zig b/pkg/zlib/build.old.zig new file mode 100644 index 000000000..fa2a57acb --- /dev/null +++ b/pkg/zlib/build.old.zig @@ -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", +}; diff --git a/pkg/zlib/build.zig b/pkg/zlib/build.zig index fa2a57acb..de00f4b73 100644 --- a/pkg/zlib/build.zig +++ b/pkg/zlib/build.zig @@ -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", }; diff --git a/pkg/zlib/build.zig.zon b/pkg/zlib/build.zig.zon new file mode 100644 index 000000000..7550da4a3 --- /dev/null +++ b/pkg/zlib/build.zig.zon @@ -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", + }, + }, +}