This commit is contained in:
yuzu 2024-11-04 20:39:37 -05:00
parent 5d231649a9
commit d4613bb2ca
12 changed files with 47 additions and 88 deletions

0
.zig-cache/h/timestamp Normal file
View File

View File

@ -0,0 +1,2 @@
pub const packages = struct {};
pub const root_deps: []const struct { []const u8, []const u8 } = &.{};

Binary file not shown.

Binary file not shown.

View File

@ -1,37 +1,30 @@
const std = @import("std");
const zlib = @import("zlib.zig");
pub fn build(b: *std.build.Builder) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
pub fn build(b: *std.Build) void {
// Modules available to downstream dependencies
_ = b.addModule("zlib", .{
.source_file = .{ .path = (comptime thisDir()) ++ "/src/main.zig" },
const zlib = b.addModule("zlib", .{
.root_source_file = b.path("src/main.zig"),
.link_libc = true,
});
const lib = zlib.create(b, target, optimize);
b.installArtifact(lib.step);
const srcs = &.{
"zlib/adler32.c",
"zlib/compress.c",
"zlib/crc32.c",
"zlib/deflate.c",
"zlib/gzclose.c",
"zlib/gzlib.c",
"zlib/gzread.c",
"zlib/gzwrite.c",
"zlib/inflate.c",
"zlib/infback.c",
"zlib/inftrees.c",
"zlib/inffast.c",
"zlib/trees.c",
"zlib/uncompr.c",
"zlib/zutil.c",
};
const tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
});
lib.link(tests, .{});
const test_step = b.step("test", "Run tests");
test_step.dependOn(&tests.step);
const bin = b.addExecutable(.{
.name = "example1",
.root_source_file = .{ .path = "example/example1.zig" },
.target = target,
.optimize = optimize,
});
lib.link(bin, .{ .import_name = "zlib" });
b.installArtifact(bin);
}
/// Path to the directory with the build.zig.
fn thisDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse unreachable;
zlib.addCSourceFiles(.{ .files = srcs, .flags = &.{"-std=c89"} });
zlib.addIncludePath(b.path("zlib/"));
}

11
build.zig.zon Normal file
View File

@ -0,0 +1,11 @@
.{
.name = "zlib",
.version = "0.1.0",
.dependencies = .{},
.paths = .{
"readme.md",
"build.zig",
"build.zig.zon",
"src",
},
}

View File

View File

@ -0,0 +1,11 @@
pub const packages = struct {
pub const @"1220d624669f633ebe6c7afaba1a702c05c4c8e55a57b77a4d0d6ab1e3da07db11e2" = struct {
pub const build_root = "/home/rain/.cache/zig/p/1220d624669f633ebe6c7afaba1a702c05c4c8e55a57b77a4d0d6ab1e3da07db11e2";
pub const build_zig = @import("1220d624669f633ebe6c7afaba1a702c05c4c8e55a57b77a4d0d6ab1e3da07db11e2");
pub const deps: []const struct { []const u8, []const u8 } = &.{};
};
};
pub const root_deps: []const struct { []const u8, []const u8 } = &.{
.{ "zlib", "1220d624669f633ebe6c7afaba1a702c05c4c8e55a57b77a4d0d6ab1e3da07db11e2" },
};

View File

@ -1,58 +0,0 @@
const std = @import("std");
const Self = @This();
fn root() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}
const root_path = root() ++ "/";
const package_path = root_path ++ "src/main.zig";
pub const include_dir = root_path ++ "zlib";
pub const Options = struct {
import_name: ?[]const u8 = null,
};
pub const Library = struct {
step: *std.build.LibExeObjStep,
pub fn link(self: Library, other: *std.build.LibExeObjStep, opts: Options) void {
other.addIncludePath(.{ .path = include_dir });
other.linkLibrary(self.step);
if (opts.import_name) |import_name|
other.addAnonymousModule(
import_name,
.{ .source_file = .{ .path = package_path } },
);
}
};
pub fn create(b: *std.build.Builder, target: std.zig.CrossTarget, optimize: std.builtin.OptimizeMode) Library {
const ret = b.addStaticLibrary(.{
.name = "z",
.target = target,
.optimize = optimize,
});
ret.linkLibC();
ret.addCSourceFiles(.{ .files = srcs, .flags = &.{"-std=c89"} });
return Library{ .step = ret };
}
const srcs = &.{
root_path ++ "zlib/adler32.c",
root_path ++ "zlib/compress.c",
root_path ++ "zlib/crc32.c",
root_path ++ "zlib/deflate.c",
root_path ++ "zlib/gzclose.c",
root_path ++ "zlib/gzlib.c",
root_path ++ "zlib/gzread.c",
root_path ++ "zlib/gzwrite.c",
root_path ++ "zlib/inflate.c",
root_path ++ "zlib/infback.c",
root_path ++ "zlib/inftrees.c",
root_path ++ "zlib/inffast.c",
root_path ++ "zlib/trees.c",
root_path ++ "zlib/uncompr.c",
root_path ++ "zlib/zutil.c",
};