authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-02 15:51:41 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-02 15:53:46 -07:00
log21683f9329aa22ed8a2d0e3cdff48a398521b65c
tree89f8b0910f0be90c8f0dd16132aea8c1a6d7d5bd
parent53130967cc11bb69e4eee56844ae6a6e8fbcdd74

upgrade to Zig 0.12.0


18 files changed, 286 insertions(+), 308 deletions(-)

.github/workflows/nightly.yml+1-1
......@@ -26,7 +26,7 @@ jobs:
2626 - name: Setup Zig
2727 uses: goto-bus-stop/setup-zig@v2
2828 with:
29 version: "0.11.0"
29 version: "0.12.0"
3030
3131 - run: zig version
3232 - run: zig env
.github/workflows/push.yml+1-1
......@@ -19,7 +19,7 @@ jobs:
1919 - name: Setup Zig
2020 uses: goto-bus-stop/setup-zig@v2
2121 with:
22 version: "0.11.0"
22 version: "0.12.0"
2323
2424 - run: zig version
2525 - run: zig env
README.md+1-1
......@@ -16,7 +16,7 @@ A package manager for the Zig programming language.
1616- https://github.com/nektro/zigmod/releases
1717
1818## Built With
19- Zig master (at least `0.11.0`)
19- Zig master (at least `0.12.0`)
2020- See [`zig.mod`](./zig.mod) and [`zigmod.lock`](./zigmod.lock)
2121
2222### Build from Source
build.zig+10-5
......@@ -3,22 +3,27 @@ const string = []const u8;
33const builtin = @import("builtin");
44const deps = @import("./deps.zig");
55
6pub fn build(b: *std.build.Builder) void {
6pub fn build(b: *std.Build) void {
77 const target = b.standardTargetOptions(.{});
88 const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug;
99 const use_full_name = b.option(bool, "use-full-name", "") orelse false;
10 const with_arch_os = b.fmt("-{s}-{s}", .{ @tagName(target.cpu_arch orelse builtin.cpu.arch), @tagName(target.os_tag orelse builtin.os.tag) });
10 const with_arch_os = b.fmt("-{s}-{s}", .{ @tagName(target.result.cpu.arch), @tagName(target.result.os.tag) });
1111 const exe_name = b.fmt("{s}{s}", .{ "zigmod", if (use_full_name) with_arch_os else "" });
12 const exe = b.addExecutable(.{ .name = exe_name, .root_source_file = .{ .path = "src/main.zig" }, .target = target, .optimize = mode });
12 const exe = b.addExecutable(.{
13 .name = exe_name,
14 .root_source_file = .{ .path = "src/main.zig" },
15 .target = target,
16 .optimize = mode,
17 });
1318 const tag = b.option(string, "tag", "") orelse "dev";
1419 const strip = b.option(bool, "strip", "Build without debug info.") orelse false;
1520
1621 const exe_options = b.addOptions();
17 exe.addOptions("build_options", exe_options);
22 exe.root_module.addImport("build_options", exe_options.createModule());
1823 exe_options.addOption(string, "version", tag);
1924
2025 deps.addAllTo(exe);
21 exe.strip = strip;
26 exe.root_module.strip = strip;
2227 b.installArtifact(exe);
2328
2429 const run_cmd = b.addRunArtifact(exe);
deps.zig+106-105
......@@ -1,19 +1,18 @@
11// zig fmt: off
22const std = @import("std");
33const builtin = @import("builtin");
4const ModuleDependency = std.build.ModuleDependency;
54const string = []const u8;
65
76pub const GitExactStep = struct {
8 step: std.build.Step,
9 builder: *std.build.Builder,
7 step: std.Build.Step,
8 builder: *std.Build,
109 url: string,
1110 commit: string,
1211
13 pub fn create(b: *std.build.Builder, url: string, commit: string) *GitExactStep {
12 pub fn create(b: *std.Build, url: string, commit: string) *GitExactStep {
1413 var result = b.allocator.create(GitExactStep) catch @panic("memory");
1514 result.* = GitExactStep{
16 .step = std.build.Step.init(.{
15 .step = std.Build.Step.init(.{
1716 .id = .custom,
1817 .name = b.fmt("git clone {s} @ {s}", .{ url, commit }),
1918 .owner = b,
......@@ -30,11 +29,11 @@ pub const GitExactStep = struct {
3029 const repopath = b.fmt("{s}/zigmod/deps/git/{s}/{s}", .{ b.cache_root.path.?, urlpath, commit });
3130 flip(std.fs.cwd().access(repopath, .{})) catch return result;
3231
33 var clonestep = std.build.RunStep.create(b, "clone");
32 var clonestep = std.Build.Step.Run.create(b, "clone");
3433 clonestep.addArgs(&.{ "git", "clone", "-q", "--progress", url, repopath });
3534 result.step.dependOn(&clonestep.step);
3635
37 var checkoutstep = std.build.RunStep.create(b, "checkout");
36 var checkoutstep = std.Build.Step.Run.create(b, "checkout");
3837 checkoutstep.addArgs(&.{ "git", "-C", repopath, "checkout", "-q", commit });
3938 result.step.dependOn(&checkoutstep.step);
4039 checkoutstep.step.dependOn(&clonestep.step);
......@@ -42,35 +41,35 @@ pub const GitExactStep = struct {
4241 return result;
4342 }
4443
45 fn make(step: *std.build.Step, prog_node: *std.Progress.Node) !void {
44 fn make(step: *std.Build.Step, prog_node: *std.Progress.Node) !void {
4645 _ = step;
4746 _ = prog_node;
4847 }
4948};
5049
51pub fn fetch(exe: *std.build.LibExeObjStep) void {
50pub fn fetch(exe: *std.Build.Step.Compile) void {
5251 const b = exe.step.owner;
5352 inline for (comptime std.meta.declarations(package_data)) |decl| {
54 const path = &@field(package_data, decl.name).entry;
55 const root = if (@field(package_data, decl.name).store) |_| b.cache_root.path.? else ".";
56 if (path.* != null) path.* = b.fmt("{s}/zigmod/deps{s}", .{ root, path.*.? });
53 const path = &@field(package_data, decl.name).entry;
54 const root = if (@field(package_data, decl.name).store) |_| b.cache_root.path.? else ".";
55 if (path.* != null) path.* = b.fmt("{s}/zigmod/deps{s}", .{ root, path.*.? });
5756 }
58 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/marlersoft/zigwin32", "6777f1db221d0cb50322842f558f03e3c3a4099f").step);
59 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/arqv-ini", "ddbe89bb0d9085e939bcbc713caeb2b7cf852bae").step);
60 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/iguanaTLS", "f5c7c3fe880c5a23fbcdc21dfcb83c2776931f40").step);
61 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zfetch", "f51277414a2309f776fb79f3d55f26e37f9a54da").step);
62 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-ansi", "ac607e4e7ac36d46cc67c8786262578330543a36").step);
57 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/marlersoft/zigwin32", "c778640d3dc153e900fbe37e2816b5176af3c802").step);
58 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/arqv-ini", "38a018ad3a19d5b4663a5364d2d31271f250846b").step);
59 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/iguanaTLS", "4dc8850883b49e4a452871298788b06b1af9fe24").step);
60 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zfetch", "863be236188e5f24d16554f9dcd7df96dd254a13").step);
61 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-ansi", "c3e439f86b0484e4428f38c4d8b07b7b5ae1634b").step);
6362 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-detect-license", "3ff57d0681b7bd7f8ca9bd092afa0b4bfe2f1afd").step);
64 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-extras", "05f0e90a185cb04a09b96f686dffc6375c420e9b").step);
65 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "5cc2a5565d04fe2c0085f0d6818590e800d9dcf7").step);
66 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-leven", "550cabd5a18ace5e67761bc5b867c10e926f4314").step);
67 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "c9b8cbf3565675a056ad4e9b57cb4f84020e7680").step);
68 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses-text", "3c07c6e4eb0965dafd0b029c632f823631b3169c").step);
63 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-extras", "74f0ddb0a4dfa7921739b88cc381951a6b6e73ce").step);
64 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "9e1d873db79e9ffa6ae6e06bd372428c9be85d97").step);
65 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-leven", "e548b0bcc7b6f34f636c0b6b905928d31254c54d").step);
66 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "f46d9f774df929885eef66c733a1e2a46bf16aec").step);
67 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses-text", "b01e5a2dffcc564bddd8f514fe64bab9b5c52572").step);
6968 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-range", "4b2f12808aa09be4b27a163efc424dd4e0415992").step);
70 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-time", "12fad367a5282827aad7e12f0e9cd36f672c4010").step);
69 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-time", "ba546bbf2e8438c9b2325f36f392c9d95b432e8e").step);
7170 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-yaml", "0d17fb99cba338aedc1abac12d78d5e5f04f0b6b").step);
72 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/truemedian/hzzp", "92e6072d8a385d8b08fdcae3ae2021fe5293528f").step);
73 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/ziglibs/known-folders", "855473062efac722624737f1adc56f9c0dd92017").step);
71 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/truemedian/hzzp", "a7f03a1e652abe8c89b376d090cec50acb0d2a1a").step);
72 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/ziglibs/known-folders", "0ad514dcfb7525e32ae349b9acc0a53976f3a9fa").step);
7473 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/yaml/libyaml", "2c891fc7a770e8ba2fec34fc6b545c672beb37e6").step);
7574}
7675
......@@ -86,48 +85,17 @@ fn flip(foo: anytype) !void {
8685 return error.ExpectedError;
8786}
8887
89pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
88pub fn addAllTo(exe: *std.Build.Step.Compile) void {
9089 checkMinZig(builtin.zig_version, exe);
9190 fetch(exe);
92 const b = exe.step.owner;
9391 @setEvalBranchQuota(1_000_000);
9492 for (packages) |pkg| {
95 const moddep = pkg.zp(b);
96 exe.addModule(moddep.name, moddep.module);
97 }
98 addAllLibrariesTo(exe);
99}
100
101pub fn addAllLibrariesTo(exe: *std.build.LibExeObjStep) void {
102 const b = exe.step.owner;
103 var llc = false;
104 var vcpkg = false;
105 inline for (comptime std.meta.declarations(package_data)) |decl| {
106 const pkg = @as(Package, @field(package_data, decl.name));
107 const root = if (pkg.store) |st| b.fmt("{s}/zigmod/deps/{s}", .{ b.cache_root.path.?, st }) else ".";
108 for (pkg.system_libs) |item| {
109 exe.linkSystemLibrary(item);
110 llc = true;
111 }
112 for (pkg.frameworks) |item| {
113 if (!builtin.target.isDarwin()) @panic(exe.step.owner.fmt("a dependency is attempting to link to the framework {s}, which is only possible under Darwin", .{item}));
114 exe.linkFramework(item);
115 llc = true;
116 }
117 for (pkg.c_include_dirs) |item| {
118 exe.addIncludePath(.{.path = b.fmt("{s}/{s}", .{ root, item })});
119 llc = true;
120 }
121 for (pkg.c_source_files) |item| {
122 exe.addCSourceFile(.{ .file = .{ .path = b.fmt("{s}/{s}", .{ root, item }) }, .flags = pkg.c_source_flags });
123 llc = true;
124 }
125 vcpkg = vcpkg or pkg.vcpkg;
93 const module = pkg.module(exe);
94 exe.root_module.addImport(pkg.name, module);
12695 }
127 if (llc) exe.linkLibC();
128 if (builtin.os.tag == .windows and vcpkg) exe.addVcpkgPaths(.static) catch |err| @panic(@errorName(err));
12996}
13097
98var link_lib_c = false;
13199pub const Package = struct {
132100 name: string = "",
133101 entry: ?string = null,
......@@ -138,69 +106,102 @@ pub const Package = struct {
138106 c_source_flags: []const string = &.{},
139107 system_libs: []const string = &.{},
140108 frameworks: []const string = &.{},
141 vcpkg: bool = false,
142 module: ?ModuleDependency = null,
109 module_memo: ?*std.Build.Module = null,
143110
144 pub fn zp(self: *Package, b: *std.build.Builder) ModuleDependency {
145 var temp: [100]ModuleDependency = undefined;
146 for (self.deps, 0..) |item, i| {
147 temp[i] = item.zp(b);
111 pub fn module(self: *Package, exe: *std.Build.Step.Compile) *std.Build.Module {
112 if (self.module_memo) |cached| {
113 return cached;
148114 }
149 if (self.module) |mod| {
150 return mod;
115 const b = exe.step.owner;
116
117 const result = b.createModule(.{});
118 const dummy_library = b.addStaticLibrary(.{
119 .name = "dummy",
120 .target = exe.root_module.resolved_target orelse b.host,
121 .optimize = exe.root_module.optimize.?,
122 });
123 if (self.entry) |capture| {
124 result.root_source_file = .{ .path = capture };
125 }
126 for (self.deps) |item| {
127 const module_dep = item.module(exe);
128 if (module_dep.root_source_file != null) {
129 result.addImport(item.name, module_dep);
130 }
131 for (module_dep.include_dirs.items) |jtem| {
132 switch (jtem) {
133 .path => result.addIncludePath(jtem.path),
134 .path_system, .path_after, .framework_path, .framework_path_system, .other_step, .config_header_step => {},
135 }
136 }
137 }
138 for (self.c_include_dirs) |item| {
139 result.addIncludePath(.{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) });
140 dummy_library.addIncludePath(.{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) });
141 link_lib_c = true;
142 }
143 for (self.c_source_files) |item| {
144 dummy_library.addCSourceFile(.{ .file = .{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) }, .flags = self.c_source_flags });
145 }
146 for (self.system_libs) |item| {
147 dummy_library.linkSystemLibrary(item);
151148 }
152 const result = ModuleDependency{
153 .name = self.name,
154 .module = b.createModule(.{
155 .source_file = .{ .path = self.entry.? },
156 .dependencies = b.allocator.dupe(ModuleDependency, temp[0..self.deps.len]) catch @panic("oom"),
157 }),
158 };
159 self.module = result;
149 for (self.frameworks) |item| {
150 dummy_library.linkFramework(item);
151 }
152 if (self.c_source_files.len > 0 or self.system_libs.len > 0 or self.frameworks.len > 0) {
153 dummy_library.linkLibC();
154 exe.root_module.linkLibrary(dummy_library);
155 link_lib_c = true;
156 }
157 if (link_lib_c) {
158 result.link_libc = true;
159 }
160 self.module_memo = result;
160161 return result;
161162 }
162163};
163164
164fn checkMinZig(current: std.SemanticVersion, exe: *std.build.LibExeObjStep) void {
165 const min = std.SemanticVersion.parse("0.11.0") catch return;
165fn checkMinZig(current: std.SemanticVersion, exe: *std.Build.Step.Compile) void {
166 const min = std.SemanticVersion.parse("0.12.0") catch return;
166167 if (current.order(min).compare(.lt)) @panic(exe.step.owner.fmt("Your Zig version v{} does not meet the minimum build requirement of v{}", .{current, min}));
167168}
168169
169170pub const package_data = struct {
170171 pub var _o6ogpor87xc2 = Package{
171 .store = "/git/github.com/marlersoft/zigwin32/6777f1db221d0cb50322842f558f03e3c3a4099f",
172 .store = "/git/github.com/marlersoft/zigwin32/c778640d3dc153e900fbe37e2816b5176af3c802",
172173 .name = "win32",
173 .entry = "/git/github.com/marlersoft/zigwin32/6777f1db221d0cb50322842f558f03e3c3a4099f/win32.zig",
174 .entry = "/git/github.com/marlersoft/zigwin32/c778640d3dc153e900fbe37e2816b5176af3c802/win32.zig",
174175 };
175176 pub var _u7sysdckdymi = Package{
176 .store = "/git/github.com/nektro/arqv-ini/ddbe89bb0d9085e939bcbc713caeb2b7cf852bae",
177 .store = "/git/github.com/nektro/arqv-ini/38a018ad3a19d5b4663a5364d2d31271f250846b",
177178 .name = "ini",
178 .entry = "/git/github.com/nektro/arqv-ini/ddbe89bb0d9085e939bcbc713caeb2b7cf852bae/src/ini.zig",
179 .entry = "/git/github.com/nektro/arqv-ini/38a018ad3a19d5b4663a5364d2d31271f250846b/src/ini.zig",
179180 };
180181 pub var _csbnipaad8n7 = Package{
181 .store = "/git/github.com/nektro/iguanaTLS/f5c7c3fe880c5a23fbcdc21dfcb83c2776931f40",
182 .store = "/git/github.com/nektro/iguanaTLS/4dc8850883b49e4a452871298788b06b1af9fe24",
182183 .name = "iguanaTLS",
183 .entry = "/git/github.com/nektro/iguanaTLS/f5c7c3fe880c5a23fbcdc21dfcb83c2776931f40/src/main.zig",
184 .entry = "/git/github.com/nektro/iguanaTLS/4dc8850883b49e4a452871298788b06b1af9fe24/src/main.zig",
184185 };
185186 pub var _s84v9o48ucb0 = Package{
186 .store = "/git/github.com/nektro/zig-ansi/ac607e4e7ac36d46cc67c8786262578330543a36",
187 .store = "/git/github.com/nektro/zig-ansi/c3e439f86b0484e4428f38c4d8b07b7b5ae1634b",
187188 .name = "ansi",
188 .entry = "/git/github.com/nektro/zig-ansi/ac607e4e7ac36d46cc67c8786262578330543a36/src/lib.zig",
189 .entry = "/git/github.com/nektro/zig-ansi/c3e439f86b0484e4428f38c4d8b07b7b5ae1634b/src/lib.zig",
189190 };
190191 pub var _f7dubzb7cyqe = Package{
191 .store = "/git/github.com/nektro/zig-extras/05f0e90a185cb04a09b96f686dffc6375c420e9b",
192 .store = "/git/github.com/nektro/zig-extras/74f0ddb0a4dfa7921739b88cc381951a6b6e73ce",
192193 .name = "extras",
193 .entry = "/git/github.com/nektro/zig-extras/05f0e90a185cb04a09b96f686dffc6375c420e9b/src/lib.zig",
194 .entry = "/git/github.com/nektro/zig-extras/74f0ddb0a4dfa7921739b88cc381951a6b6e73ce/src/lib.zig",
194195 };
195196 pub var _0npcrzfdlrvk = Package{
196 .store = "/git/github.com/nektro/zig-licenses/c9b8cbf3565675a056ad4e9b57cb4f84020e7680",
197 .store = "/git/github.com/nektro/zig-licenses/f46d9f774df929885eef66c733a1e2a46bf16aec",
197198 .name = "licenses",
198 .entry = "/git/github.com/nektro/zig-licenses/c9b8cbf3565675a056ad4e9b57cb4f84020e7680/src/lib.zig",
199 .entry = "/git/github.com/nektro/zig-licenses/f46d9f774df929885eef66c733a1e2a46bf16aec/src/lib.zig",
199200 };
200201 pub var _pt88y5d80m25 = Package{
201 .store = "/git/github.com/nektro/zig-licenses-text/3c07c6e4eb0965dafd0b029c632f823631b3169c",
202 .store = "/git/github.com/nektro/zig-licenses-text/b01e5a2dffcc564bddd8f514fe64bab9b5c52572",
202203 .name = "licenses-text",
203 .entry = "/git/github.com/nektro/zig-licenses-text/3c07c6e4eb0965dafd0b029c632f823631b3169c/src/lib.zig",
204 .entry = "/git/github.com/nektro/zig-licenses-text/b01e5a2dffcc564bddd8f514fe64bab9b5c52572/src/lib.zig",
204205 };
205206 pub var _tnj3qf44tpeq = Package{
206207 .store = "/git/github.com/nektro/zig-range/4b2f12808aa09be4b27a163efc424dd4e0415992",
......@@ -208,15 +209,15 @@ pub const package_data = struct {
208209 .entry = "/git/github.com/nektro/zig-range/4b2f12808aa09be4b27a163efc424dd4e0415992/src/lib.zig",
209210 };
210211 pub var _c1xirp1ota5p = Package{
211 .store = "/git/github.com/nektro/zig-inquirer/5cc2a5565d04fe2c0085f0d6818590e800d9dcf7",
212 .store = "/git/github.com/nektro/zig-inquirer/9e1d873db79e9ffa6ae6e06bd372428c9be85d97",
212213 .name = "inquirer",
213 .entry = "/git/github.com/nektro/zig-inquirer/5cc2a5565d04fe2c0085f0d6818590e800d9dcf7/src/lib.zig",
214 .entry = "/git/github.com/nektro/zig-inquirer/9e1d873db79e9ffa6ae6e06bd372428c9be85d97/src/lib.zig",
214215 .deps = &[_]*Package{ &_s84v9o48ucb0, &_tnj3qf44tpeq },
215216 };
216217 pub var _96h80ezrvj7i = Package{
217 .store = "/git/github.com/nektro/zig-leven/550cabd5a18ace5e67761bc5b867c10e926f4314",
218 .store = "/git/github.com/nektro/zig-leven/e548b0bcc7b6f34f636c0b6b905928d31254c54d",
218219 .name = "leven",
219 .entry = "/git/github.com/nektro/zig-leven/550cabd5a18ace5e67761bc5b867c10e926f4314/src/lib.zig",
220 .entry = "/git/github.com/nektro/zig-leven/e548b0bcc7b6f34f636c0b6b905928d31254c54d/src/lib.zig",
220221 .deps = &[_]*Package{ &_tnj3qf44tpeq },
221222 };
222223 pub var _2ovav391ivak = Package{
......@@ -226,32 +227,32 @@ pub const package_data = struct {
226227 .deps = &[_]*Package{ &_pt88y5d80m25, &_96h80ezrvj7i },
227228 };
228229 pub var _iecwp4b3bsfm = Package{
229 .store = "/git/github.com/nektro/zig-time/12fad367a5282827aad7e12f0e9cd36f672c4010",
230 .store = "/git/github.com/nektro/zig-time/ba546bbf2e8438c9b2325f36f392c9d95b432e8e",
230231 .name = "time",
231 .entry = "/git/github.com/nektro/zig-time/12fad367a5282827aad7e12f0e9cd36f672c4010/time.zig",
232 .entry = "/git/github.com/nektro/zig-time/ba546bbf2e8438c9b2325f36f392c9d95b432e8e/time.zig",
232233 .deps = &[_]*Package{ &_f7dubzb7cyqe },
233234 };
234235 pub var _g982zq6e8wsv = Package{
235236 .store = "/git/github.com/nektro/zig-yaml/0d17fb99cba338aedc1abac12d78d5e5f04f0b6b",
236237 .name = "yaml",
237238 .entry = "/git/github.com/nektro/zig-yaml/0d17fb99cba338aedc1abac12d78d5e5f04f0b6b/yaml.zig",
238 .deps = &[_]*Package{ &_f7dubzb7cyqe },
239 .deps = &[_]*Package{ &_8mdbh0zuneb0, &_f7dubzb7cyqe },
239240 };
240241 pub var _9k24gimke1an = Package{
241 .store = "/git/github.com/truemedian/hzzp/92e6072d8a385d8b08fdcae3ae2021fe5293528f",
242 .store = "/git/github.com/truemedian/hzzp/a7f03a1e652abe8c89b376d090cec50acb0d2a1a",
242243 .name = "hzzp",
243 .entry = "/git/github.com/truemedian/hzzp/92e6072d8a385d8b08fdcae3ae2021fe5293528f/src/main.zig",
244 .entry = "/git/github.com/truemedian/hzzp/a7f03a1e652abe8c89b376d090cec50acb0d2a1a/src/main.zig",
244245 };
245246 pub var _ejw82j2ipa0e = Package{
246 .store = "/git/github.com/nektro/zfetch/f51277414a2309f776fb79f3d55f26e37f9a54da",
247 .store = "/git/github.com/nektro/zfetch/863be236188e5f24d16554f9dcd7df96dd254a13",
247248 .name = "zfetch",
248 .entry = "/git/github.com/nektro/zfetch/f51277414a2309f776fb79f3d55f26e37f9a54da/src/main.zig",
249 .entry = "/git/github.com/nektro/zfetch/863be236188e5f24d16554f9dcd7df96dd254a13/src/main.zig",
249250 .deps = &[_]*Package{ &_9k24gimke1an, &_csbnipaad8n7 },
250251 };
251252 pub var _2ta738wrqbaq = Package{
252 .store = "/git/github.com/ziglibs/known-folders/855473062efac722624737f1adc56f9c0dd92017",
253 .store = "/git/github.com/ziglibs/known-folders/0ad514dcfb7525e32ae349b9acc0a53976f3a9fa",
253254 .name = "known-folders",
254 .entry = "/git/github.com/ziglibs/known-folders/855473062efac722624737f1adc56f9c0dd92017/known-folders.zig",
255 .entry = "/git/github.com/ziglibs/known-folders/0ad514dcfb7525e32ae349b9acc0a53976f3a9fa/known-folders.zig",
255256 };
256257 pub var _89ujp8gq842x = Package{
257258 .name = "zigmod",
docs/README.md+1-1
......@@ -10,7 +10,7 @@ The rest of this documentation will assume you already have Zig installed.
1010
1111As Zig is still in development itself, if you plan to contribute to Zigmod you will need a master download of Zig. Those can be obtained from https://ziglang.org/download/#release-master.
1212
13The earliest Zig release this Zigmod was verified to work with is `0.11.0`.
13The earliest Zig release this Zigmod was verified to work with is `0.12.0`.
1414
1515## Download
1616You may download a precompiled binary from https://github.com/nektro/zigmod/releases or build the project from source.
docs/deps.zig.md+1-6
......@@ -15,10 +15,6 @@ A helper function to automatically pull in dependencies, purely from the `zig bu
1515- Type: `pub fn (exe: *std.build.LibExeObjStep) void`
1616A helper function to add all of the packages, C files, and system libraries to the passed exectuable. It will also automatically link libC in the event that any C files are found in the dependency tree.
1717
18### `addAllLibrariesTo`
19- Type: `pub fn (exe: *std.build.LibExeObjStep) void`
20A helper function called by `addAllTo` that adds the C files and libraries.
21
2218### `Package`
2319```zig
2420pub const Package = struct {
......@@ -29,7 +25,6 @@ pub const Package = struct {
2925 c_source_flags: []const string = &.{},
3026 system_libs: []const string = &.{},
3127 frameworks: []const string = &.{},
32 vcpkg: bool = false,
3328};
3429```
3530
......@@ -43,7 +38,7 @@ This is a an array of all of the items in `package_data`, but only contains the
4338
4439### `pkgs`
4540- Type: `struct<NAME, Package>`
46This is a struct that associates the package name to the relavant `Package`. The only packages listed are the dependencies of the root project.
41This is a struct that associates the package name to the relavant `Package`. The only packages listed are the dependencies of the root project.
4742
4843### `imports`
4944- Type: `struct<NAME, @import(main)>`
docs/zig.mod.md-10
......@@ -58,11 +58,6 @@ Similar to `dependencies` but will only get added to the project if the current
5858- Type: `string`
5959Parsed as a `std.SemanticVersion`, this attribute refers to the minimum compatible Zig version for this package/application and will cause `zig build` to panic if violated.
6060
61#### `vcpkg`
62- Type: `bool`
63- Example: `true`|any
64This attribute is a flag to call `try exe.addVcpkgPaths(.static);` when on Windows. Likely used in conjunction with adding system libraries/C code. `true` is the only value that will enable this flag.
65
6661----
6762
6863### Dep Object
......@@ -124,10 +119,5 @@ This attribute specifies a way to filter when the dependency will be generated i
124119- Example: `true`|any
125120This attribute is a manual override for having an external repo that contains no Zig or C code but other files be managed through Zigmod and `deps.zig`. `true` is the only value that will enable this flag.
126121
127#### Dep `vcpkg`
128- Type: `string`
129- Example: `true`|any
130This attribute is a flag to call `try exe.addVcpkgPaths(.static);` when on Windows. Likely used in conjunction with adding system libraries/C code. `true` is the only value that will enable this flag.
131
132122#### Dep Overrides
133123There are a number of fields you can add to a `Dep` object that will override it's top-level value. This is most useful in the case where a project you want to use does not have a `zigmod.yml` manifest. You can then use overrides to define the values for them. The only top-level value you can not override is `dependencies`.
src/cmd/fetch.zig+73-77
......@@ -52,94 +52,89 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
5252 try w.writeAll("const std = @import(\"std\");\n");
5353 try w.writeAll("const builtin = @import(\"builtin\");\n");
5454 try w.writeAll("const string = []const u8;\n");
55 try w.writeAll("const ModuleDependency = std.build.ModuleDependency;\n");
5655 try w.writeAll("\n");
5756 try w.print("pub const cache = \"{}\";\n", .{std.zig.fmtEscapes(cachepath)});
5857 try w.writeAll("\n");
5958 try w.writeAll(
60 \\pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
59 \\pub fn addAllTo(exe: *std.Build.Step.Compile) void {
6160 \\ checkMinZig(builtin.zig_version, exe);
62 \\ const b = exe.step.owner;
6361 \\ @setEvalBranchQuota(1_000_000);
6462 \\ for (packages) |pkg| {
65 \\ const moddep = pkg.zp(b);
66 \\ exe.addModule(moddep.name, moddep.module);
63 \\ const module = pkg.module(exe);
64 \\ exe.root_module.addImport(pkg.import.?[0], module);
6765 \\ }
68 \\ addAllLibrariesTo(exe);
69 \\}
70 \\
71 \\pub fn addAllLibrariesTo(exe: *std.build.LibExeObjStep) void {
72 \\ const b = exe.step.owner;
73 \\ var llc = false;
74 \\ var vcpkg = false;
75 \\ inline for (comptime std.meta.declarations(package_data)) |decl| {
76 \\ const pkg = @as(Package, @field(package_data, decl.name));
77 \\ for (pkg.system_libs) |item| {
78 \\ exe.linkSystemLibrary(item);
79 \\ llc = true;
80 \\ }
81 \\ for (pkg.frameworks) |item| {
82 \\ if (!builtin.target.isDarwin()) @panic(b.fmt("a dependency is attempting to link to the framework {s}, which is only possible under Darwin", .{item}));
83 \\ exe.linkFramework(item);
84 \\ llc = true;
85 \\ }
86 \\ for (pkg.c_include_dirs) |item| {
87 \\ exe.addIncludePath(.{.path = b.fmt("{s}/{s}", .{ @field(dirs, decl.name), item })});
88 \\ llc = true;
89 \\ }
90 \\ for (pkg.c_source_files) |item| {
91 \\ exe.addCSourceFile(.{ .file = .{ .path = b.fmt("{s}/{s}", .{ @field(dirs, decl.name), item }) }, .flags = pkg.c_source_flags });
92 \\ llc = true;
93 \\ }
94 \\ vcpkg = vcpkg or pkg.vcpkg;
95 \\ }
96 \\ if (llc) exe.linkLibC();
97 \\ if (builtin.os.tag == .windows and vcpkg) exe.addVcpkgPaths(.static) catch |err| @panic(@errorName(err));
9866 \\}
9967 \\
68 \\var link_lib_c = false;
10069 \\pub const Package = struct {
10170 \\ directory: string,
102 \\ pkg: ?Pkg = null,
71 \\ import: ?struct { string, std.Build.LazyPath } = null,
72 \\ dependencies: []const *Package,
10373 \\ c_include_dirs: []const string = &.{},
10474 \\ c_source_files: []const string = &.{},
10575 \\ c_source_flags: []const string = &.{},
10676 \\ system_libs: []const string = &.{},
10777 \\ frameworks: []const string = &.{},
108 \\ vcpkg: bool = false,
109 \\ module: ?ModuleDependency = null,
78 \\ module_memo: ?*std.Build.Module = null,
11079 \\
111 \\ pub fn zp(self: *Package, b: *std.build.Builder) ModuleDependency {
112 \\ var temp: [100]ModuleDependency = undefined;
113 \\ const pkg = self.pkg.?;
114 \\ for (pkg.dependencies, 0..) |item, i| {
115 \\ temp[i] = item.zp(b);
80 \\ pub fn module(self: *Package, exe: *std.Build.Step.Compile) *std.Build.Module {
81 \\ if (self.module_memo) |cached| {
82 \\ return cached;
83 \\ }
84 \\ const b = exe.step.owner;
85 \\ const result = b.createModule(.{});
86 \\ const dummy_library = b.addStaticLibrary(.{
87 \\ .name = "dummy",
88 \\ .target = exe.root_module.resolved_target orelse b.host,
89 \\ .optimize = exe.root_module.optimize.?,
90 \\ });
91 \\ if (self.import) |capture| {
92 \\ result.root_source_file = capture[1];
93 \\ }
94 \\ for (self.dependencies) |item| {
95 \\ const module_dep = item.module(exe);
96 \\ if (module_dep.root_source_file != null) {
97 \\ result.addImport(item.import.?[0], module_dep);
98 \\ }
99 \\ for (module_dep.include_dirs.items) |jtem| {
100 \\ switch (jtem) {
101 \\ .path => result.addIncludePath(jtem.path),
102 \\ .path_system, .path_after, .framework_path, .framework_path_system, .other_step, .config_header_step => {},
103 \\ }
104 \\ }
105 \\ }
106 \\ for (self.c_include_dirs) |item| {
107 \\ result.addIncludePath(b.path(b.fmt("{s}/{s}", .{ self.directory, item })));
108 \\ dummy_library.addIncludePath(b.path(b.fmt("{s}/{s}", .{ self.directory, item })));
109 \\ link_lib_c = true;
110 \\ }
111 \\ for (self.c_source_files) |item| {
112 \\ dummy_library.addCSourceFile(.{ .file = b.path(b.fmt("{s}/{s}", .{ self.directory, item })), .flags = self.c_source_flags });
116113 \\ }
117 \\ if (self.module) |mod| {
118 \\ return mod;
114 \\ for (self.system_libs) |item| {
115 \\ dummy_library.linkSystemLibrary(item);
119116 \\ }
120 \\ const result = ModuleDependency{
121 \\ .name = pkg.name,
122 \\ .module = b.createModule(.{
123 \\ .source_file = pkg.source,
124 \\ .dependencies = b.allocator.dupe(ModuleDependency, temp[0..pkg.dependencies.len]) catch @panic("oom"),
125 \\ }),
126 \\ };
127 \\ self.module = result;
117 \\ for (self.frameworks) |item| {
118 \\ dummy_library.linkFramework(item);
119 \\ }
120 \\ if (self.c_source_files.len > 0 or self.system_libs.len > 0 or self.frameworks.len > 0) {
121 \\ dummy_library.linkLibC();
122 \\ exe.root_module.linkLibrary(dummy_library);
123 \\ link_lib_c = true;
124 \\ }
125 \\ if (link_lib_c) {
126 \\ result.link_libc = true;
127 \\ }
128 \\ self.module_memo = result;
128129 \\ return result;
129130 \\ }
130131 \\};
131132 \\
132 \\pub const Pkg = struct {
133 \\ name: string,
134 \\ source: std.build.FileSource,
135 \\ dependencies: []const *Package,
136 \\};
137 \\
138133 \\
139134 );
140135
141136 try w.print(
142 \\fn checkMinZig(current: std.SemanticVersion, exe: *std.build.LibExeObjStep) void {{
137 \\fn checkMinZig(current: std.SemanticVersion, exe: *std.Build.Step.Compile) void {{
143138 \\ const min = std.SemanticVersion.parse("{?}") catch return;
144139 \\ if (current.order(min).compare(.lt)) @panic(exe.step.owner.fmt("Your Zig version v{{}} does not meet the minimum build requirement of v{{}}", .{{current, min}}));
145140 \\}}
......@@ -148,7 +143,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
148143 , .{top_module.minZigVersion()});
149144
150145 try w.writeAll("pub const dirs = struct {\n");
151 try print_dirs(w, list.items);
146 try print_dirs(w, list.items, alloc);
152147 try w.writeAll("};\n\n");
153148
154149 try w.writeAll("pub const package_data = struct {\n");
......@@ -215,7 +210,7 @@ fn diff_lockfile(alloc: std.mem.Allocator) !void {
215210 while (try r.readUntilDelimiterOrEofAlloc(alloc, '\n', max)) |line| {
216211 if (line[0] == ' ') continue;
217212 if (line[0] == '-') try rems.append(line[1..]);
218 if (line[0] == '+') if (line[1] == '2') continue else try adds.append(line[1..]);
213 if (line[0] == '+') if (line[1] == '2') break else try adds.append(line[1..]);
219214 }
220215
221216 var changes = std.StringHashMap(DiffChange).init(alloc);
......@@ -287,13 +282,18 @@ fn diff_printchange(comptime testt: string, comptime replacement: string, item:
287282 return false;
288283}
289284
290fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module) !void {
285fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module, alloc: std.mem.Allocator) !void {
291286 for (list) |mod| {
292287 if (mod.type == .system_lib or mod.type == .framework) continue;
293288 if (std.mem.eql(u8, mod.id, "root")) {
294289 try w.writeAll(" pub const _root = \"\";\n");
295290 continue;
296291 }
292 if (std.mem.eql(u8, mod.clean_path, "../..")) {
293 const cwd_realpath = try std.fs.cwd().realpathAlloc(alloc, ".");
294 try w.print(" pub const _{s} = \"{}\";\n", .{ mod.short_id(), std.zig.fmtEscapes(cwd_realpath) });
295 continue;
296 }
297297 try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), std.zig.fmtEscapes(mod.clean_path) });
298298 }
299299}
......@@ -327,23 +327,22 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
327327 });
328328 if (mod.main.len > 0 and !std.mem.eql(u8, mod.id, "root")) {
329329 try w.print(
330 \\ .pkg = Pkg{{ .name = "{s}", .source = .{{ .path = dirs._{s} ++ "/{s}" }}, .dependencies =
330 \\ .import = .{{ "{s}", .{{ .path = dirs._{s} ++ "/{s}" }} }},
331 \\
331332 , .{
332333 mod.name,
333334 mod.short_id(),
334335 mod.main,
335336 });
336 if (mod.has_no_zig_deps()) {
337 try w.writeAll(" &.{} },\n");
338 } else {
339 try w.writeAll(" &.{");
340 for (mod.deps, 0..) |moddep, j| {
341 if (moddep.main.len == 0) continue;
342 try w.print(" &_{s}", .{moddep.id[0..12]});
343 if (j != mod.deps.len - 1) try w.writeAll(",");
344 }
345 try w.writeAll(" } },\n");
337 }
338 {
339 try w.writeAll(" .dependencies =");
340 try w.writeAll(" &.{");
341 for (mod.deps, 0..) |moddep, j| {
342 try w.print(" &_{s}", .{moddep.id[0..12]});
343 if (j != mod.deps.len - 1) try w.writeAll(",");
346344 }
345 try w.writeAll(" },\n");
347346 }
348347 if (mod.c_include_dirs.len > 0) {
349348 try w.writeAll(" .c_include_dirs = &.{");
......@@ -387,9 +386,6 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
387386 }
388387 try w.writeAll(" },\n");
389388 }
390 if (mod.vcpkg) {
391 try w.writeAll(" .vcpkg = true,\n");
392 }
393389 try w.writeAll(" };\n");
394390
395391 try done.append(mod);
src/cmd/generate.zig+67-70
......@@ -41,20 +41,19 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
4141 try w.writeAll("// zig fmt: off\n");
4242 try w.writeAll("const std = @import(\"std\");\n");
4343 try w.writeAll("const builtin = @import(\"builtin\");\n");
44 try w.writeAll("const ModuleDependency = std.build.ModuleDependency;\n");
4544 try w.writeAll("const string = []const u8;\n");
4645 try w.writeAll("\n");
4746 try w.writeAll(
4847 \\pub const GitExactStep = struct {
49 \\ step: std.build.Step,
50 \\ builder: *std.build.Builder,
48 \\ step: std.Build.Step,
49 \\ builder: *std.Build,
5150 \\ url: string,
5251 \\ commit: string,
5352 \\
54 \\ pub fn create(b: *std.build.Builder, url: string, commit: string) *GitExactStep {
53 \\ pub fn create(b: *std.Build, url: string, commit: string) *GitExactStep {
5554 \\ var result = b.allocator.create(GitExactStep) catch @panic("memory");
5655 \\ result.* = GitExactStep{
57 \\ .step = std.build.Step.init(.{
56 \\ .step = std.Build.Step.init(.{
5857 \\ .id = .custom,
5958 \\ .name = b.fmt("git clone {s} @ {s}", .{ url, commit }),
6059 \\ .owner = b,
......@@ -71,11 +70,11 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
7170 \\ const repopath = b.fmt("{s}/zigmod/deps/git/{s}/{s}", .{ b.cache_root.path.?, urlpath, commit });
7271 \\ flip(std.fs.cwd().access(repopath, .{})) catch return result;
7372 \\
74 \\ var clonestep = std.build.RunStep.create(b, "clone");
73 \\ var clonestep = std.Build.Step.Run.create(b, "clone");
7574 \\ clonestep.addArgs(&.{ "git", "clone", "-q", "--progress", url, repopath });
7675 \\ result.step.dependOn(&clonestep.step);
7776 \\
78 \\ var checkoutstep = std.build.RunStep.create(b, "checkout");
77 \\ var checkoutstep = std.Build.Step.Run.create(b, "checkout");
7978 \\ checkoutstep.addArgs(&.{ "git", "-C", repopath, "checkout", "-q", commit });
8079 \\ result.step.dependOn(&checkoutstep.step);
8180 \\ checkoutstep.step.dependOn(&clonestep.step);
......@@ -85,18 +84,18 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
8584 \\ return result;
8685 \\ }
8786 \\
88 \\ fn make(step: *std.build.Step, prog_node: *std.Progress.Node) !void {
87 \\ fn make(step: *std.Build.Step, prog_node: *std.Progress.Node) !void {
8988 \\ _ = step;
9089 \\ _ = prog_node;
9190 \\ }
9291 \\};
9392 \\
94 \\pub fn fetch(exe: *std.build.LibExeObjStep) void {
93 \\pub fn fetch(exe: *std.Build.Step.Compile) void {
9594 \\ const b = exe.step.owner;
9695 \\ inline for (comptime std.meta.declarations(package_data)) |decl| {
97 \\ const path = &@field(package_data, decl.name).entry;
98 \\ const root = if (@field(package_data, decl.name).store) |_| b.cache_root.path.? else ".";
99 \\ if (path.* != null) path.* = b.fmt("{s}/zigmod/deps{s}", .{ root, path.*.? });
96 \\ const path = &@field(package_data, decl.name).entry;
97 \\ const root = if (@field(package_data, decl.name).store) |_| b.cache_root.path.? else ".";
98 \\ if (path.* != null) path.* = b.fmt("{s}/zigmod/deps{s}", .{ root, path.*.? });
10099 \\ }
101100 \\
102101 );
......@@ -125,48 +124,17 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
125124 \\ return error.ExpectedError;
126125 \\}
127126 \\
128 \\pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
127 \\pub fn addAllTo(exe: *std.Build.Step.Compile) void {
129128 \\ checkMinZig(builtin.zig_version, exe);
130129 \\ fetch(exe);
131 \\ const b = exe.step.owner;
132130 \\ @setEvalBranchQuota(1_000_000);
133131 \\ for (packages) |pkg| {
134 \\ const moddep = pkg.zp(b);
135 \\ exe.addModule(moddep.name, moddep.module);
136 \\ }
137 \\ addAllLibrariesTo(exe);
138 \\}
139 \\
140 \\pub fn addAllLibrariesTo(exe: *std.build.LibExeObjStep) void {
141 \\ const b = exe.step.owner;
142 \\ var llc = false;
143 \\ var vcpkg = false;
144 \\ inline for (comptime std.meta.declarations(package_data)) |decl| {
145 \\ const pkg = @as(Package, @field(package_data, decl.name));
146 \\ const root = if (pkg.store) |st| b.fmt("{s}/zigmod/deps/{s}", .{ b.cache_root.path.?, st }) else ".";
147 \\ for (pkg.system_libs) |item| {
148 \\ exe.linkSystemLibrary(item);
149 \\ llc = true;
150 \\ }
151 \\ for (pkg.frameworks) |item| {
152 \\ if (!builtin.target.isDarwin()) @panic(exe.step.owner.fmt("a dependency is attempting to link to the framework {s}, which is only possible under Darwin", .{item}));
153 \\ exe.linkFramework(item);
154 \\ llc = true;
155 \\ }
156 \\ for (pkg.c_include_dirs) |item| {
157 \\ exe.addIncludePath(.{.path = b.fmt("{s}/{s}", .{ root, item })});
158 \\ llc = true;
159 \\ }
160 \\ for (pkg.c_source_files) |item| {
161 \\ exe.addCSourceFile(.{ .file = .{ .path = b.fmt("{s}/{s}", .{ root, item }) }, .flags = pkg.c_source_flags });
162 \\ llc = true;
163 \\ }
164 \\ vcpkg = vcpkg or pkg.vcpkg;
132 \\ const module = pkg.module(exe);
133 \\ exe.root_module.addImport(pkg.name, module);
165134 \\ }
166 \\ if (llc) exe.linkLibC();
167 \\ if (builtin.os.tag == .windows and vcpkg) exe.addVcpkgPaths(.static) catch |err| @panic(@errorName(err));
168135 \\}
169136 \\
137 \\var link_lib_c = false;
170138 \\pub const Package = struct {
171139 \\ name: string = "",
172140 \\ entry: ?string = null,
......@@ -177,25 +145,58 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
177145 \\ c_source_flags: []const string = &.{},
178146 \\ system_libs: []const string = &.{},
179147 \\ frameworks: []const string = &.{},
180 \\ vcpkg: bool = false,
181 \\ module: ?ModuleDependency = null,
148 \\ module_memo: ?*std.Build.Module = null,
182149 \\
183 \\ pub fn zp(self: *Package, b: *std.build.Builder) ModuleDependency {
184 \\ var temp: [100]ModuleDependency = undefined;
185 \\ for (self.deps, 0..) |item, i| {
186 \\ temp[i] = item.zp(b);
150 \\ pub fn module(self: *Package, exe: *std.Build.Step.Compile) *std.Build.Module {
151 \\ if (self.module_memo) |cached| {
152 \\ return cached;
187153 \\ }
188 \\ if (self.module) |mod| {
189 \\ return mod;
154 \\ const b = exe.step.owner;
155 \\
156 \\ const result = b.createModule(.{});
157 \\ const dummy_library = b.addStaticLibrary(.{
158 \\ .name = "dummy",
159 \\ .target = exe.root_module.resolved_target orelse b.host,
160 \\ .optimize = exe.root_module.optimize.?,
161 \\ });
162 \\ if (self.entry) |capture| {
163 \\ result.root_source_file = .{ .path = capture };
164 \\ }
165 \\ for (self.deps) |item| {
166 \\ const module_dep = item.module(exe);
167 \\ if (module_dep.root_source_file != null) {
168 \\ result.addImport(item.name, module_dep);
169 \\ }
170 \\ for (module_dep.include_dirs.items) |jtem| {
171 \\ switch (jtem) {
172 \\ .path => result.addIncludePath(jtem.path),
173 \\ .path_system, .path_after, .framework_path, .framework_path_system, .other_step, .config_header_step => {},
174 \\ }
175 \\ }
176 \\ }
177 \\ for (self.c_include_dirs) |item| {
178 \\ result.addIncludePath(.{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) });
179 \\ dummy_library.addIncludePath(.{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) });
180 \\ link_lib_c = true;
181 \\ }
182 \\ for (self.c_source_files) |item| {
183 \\ dummy_library.addCSourceFile(.{ .file = .{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) }, .flags = self.c_source_flags });
184 \\ }
185 \\ for (self.system_libs) |item| {
186 \\ dummy_library.linkSystemLibrary(item);
190187 \\ }
191 \\ const result = ModuleDependency{
192 \\ .name = self.name,
193 \\ .module = b.createModule(.{
194 \\ .source_file = .{ .path = self.entry.? },
195 \\ .dependencies = b.allocator.dupe(ModuleDependency, temp[0..self.deps.len]) catch @panic("oom"),
196 \\ }),
197 \\ };
198 \\ self.module = result;
188 \\ for (self.frameworks) |item| {
189 \\ dummy_library.linkFramework(item);
190 \\ }
191 \\ if (self.c_source_files.len > 0 or self.system_libs.len > 0 or self.frameworks.len > 0) {
192 \\ dummy_library.linkLibC();
193 \\ exe.root_module.linkLibrary(dummy_library);
194 \\ link_lib_c = true;
195 \\ }
196 \\ if (link_lib_c) {
197 \\ result.link_libc = true;
198 \\ }
199 \\ self.module_memo = result;
199200 \\ return result;
200201 \\ }
201202 \\};
......@@ -204,7 +205,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
204205 );
205206
206207 try w.print(
207 \\fn checkMinZig(current: std.SemanticVersion, exe: *std.build.LibExeObjStep) void {{
208 \\fn checkMinZig(current: std.SemanticVersion, exe: *std.Build.Step.Compile) void {{
208209 \\ const min = std.SemanticVersion.parse("{?}") catch return;
209210 \\ if (current.order(min).compare(.lt)) @panic(exe.step.owner.fmt("Your Zig version v{{}} does not meet the minimum build requirement of v{{}}", .{{current, min}}));
210211 \\}}
......@@ -273,7 +274,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
273274 , .{
274275 mod.short_id(),
275276 });
276 var fixed_path = if (std.mem.startsWith(u8, mod.clean_path, "v/")) mod.clean_path[2..std.mem.lastIndexOfScalar(u8, mod.clean_path, '/').?] else mod.clean_path;
277 const fixed_path = if (std.mem.startsWith(u8, mod.clean_path, "v/")) mod.clean_path[2..std.mem.lastIndexOfScalar(u8, mod.clean_path, '/').?] else mod.clean_path;
277278 switch (mod.type) {
278279 .system_lib, .framework => {},
279280 .local => {},
......@@ -285,10 +286,9 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
285286 try w.print(" .name = \"{s}\",\n", .{mod.name});
286287 try w.print(" .entry = \"/{}/{s}/{s}\",\n", .{ std.zig.fmtEscapes(fixed_path), try mod.pin(alloc, cachepath), mod.main });
287288
288 if (!mod.has_no_zig_deps()) {
289 if (mod.deps.len != 0) {
289290 try w.writeAll(" .deps = &[_]*Package{");
290291 for (mod.deps, 0..) |moddep, j| {
291 if (moddep.main.len == 0) continue;
292292 try w.print(" &_{s}", .{moddep.id[0..12]});
293293 if (j != mod.deps.len - 1) try w.writeAll(",");
294294 }
......@@ -337,9 +337,6 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
337337 }
338338 try w.writeAll(" },\n");
339339 }
340 if (mod.vcpkg) {
341 try w.writeAll(" .vcpkg = true,\n");
342 }
343340 try w.writeAll(" };\n");
344341
345342 try done.append(mod);
src/common.zig+6-9
......@@ -54,7 +54,6 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO
5454 .yaml = m.yaml,
5555 .dep = null,
5656 .min_zig_version = m.min_zig_version,
57 .vcpkg = m.vcpkg,
5857 };
5958}
6059
......@@ -85,7 +84,6 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, dtype: zigmod.Dep.Type,
8584 .yaml = m.yaml,
8685 .dep = null,
8786 .min_zig_version = m.min_zig_version,
88 .vcpkg = m.vcpkg,
8987 };
9088}
9189
......@@ -153,7 +151,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
153151 defer pvd.close();
154152 try pvd.deleteTree(".git");
155153 }
156 var pvd = try std.fs.cwd().openIterableDir(pv, .{});
154 var pvd = try std.fs.cwd().openDir(pv, .{ .iterate = true });
157155 defer pvd.close();
158156 try setTreeReadOnly(pvd, options.alloc);
159157 return pv;
......@@ -190,7 +188,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
190188 try d.type.pull(options.alloc, d.path, pv);
191189 if (try u.validate_hash(options.alloc, d.version, file_path)) {
192190 try std.fs.cwd().deleteFile(file_path);
193 var pvd = try std.fs.cwd().openIterableDir(pv, .{});
191 var pvd = try std.fs.cwd().openDir(pv, .{ .iterate = true });
194192 defer pvd.close();
195193 try setTreeReadOnly(pvd, options.alloc);
196194 return pv;
......@@ -243,7 +241,6 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
243241 .dep = d.*,
244242 .for_build = d.for_build,
245243 .min_zig_version = null,
246 .vcpkg = false,
247244 };
248245 },
249246 else => {
......@@ -297,7 +294,7 @@ pub fn gen_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std.
297294 defer map.deinit();
298295
299296 for (dirs) |dir_path| {
300 const dir = try mdir.openIterableDir(dir_path, .{});
297 const dir = try mdir.openDir(dir_path, .{ .iterate = true });
301298 var walker = try dir.walk(alloc);
302299 defer walker.deinit();
303300 while (try walker.next()) |p| {
......@@ -377,13 +374,13 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str
377374 return list.toOwnedSlice();
378375}
379376
380fn setTreeReadOnly(idir: std.fs.IterableDir, alloc: std.mem.Allocator) !void {
381 var walker = try idir.walk(alloc);
377fn setTreeReadOnly(dir: std.fs.Dir, alloc: std.mem.Allocator) !void {
378 var walker = try dir.walk(alloc);
382379 defer walker.deinit();
383380
384381 while (try walker.next()) |entry| {
385382 if (entry.kind != .file) continue;
386 var file = try idir.dir.openFile(entry.path, .{});
383 var file = try dir.openFile(entry.path, .{});
387384 defer file.close();
388385 var metadata = try file.metadata();
389386 var perms = metadata.permissions();
src/main.zig+2-2
......@@ -56,7 +56,7 @@ pub fn main() !void {
5656 for (args[1..]) |item| {
5757 try sub_cmd_args.append(item);
5858 }
59 const result = std.ChildProcess.exec(.{ .allocator = gpa, .argv = sub_cmd_args.items }) catch |e| switch (e) {
59 const result = std.ChildProcess.run(.{ .allocator = gpa, .argv = sub_cmd_args.items }) catch |e| switch (e) {
6060 else => |ee| return ee,
6161 error.FileNotFound => {
6262 fail("unknown command \"{s}\" for \"zigmod\"", .{args[0]});
......@@ -75,7 +75,7 @@ const ansi_reset = "\x1B[39m";
7575pub fn assert(ok: bool, comptime fmt: string, args: anytype) void {
7676 if (!ok) {
7777 std.debug.print(ansi_red ++ fmt ++ ansi_reset ++ "\n", args);
78 std.os.exit(1);
78 std.process.exit(1);
7979 }
8080}
8181
src/util/dep.zig-1
......@@ -27,7 +27,6 @@ pub const Dep = struct {
2727 yaml: ?yaml.Mapping,
2828 deps: []zigmod.Dep,
2929 keep: bool = false,
30 vcpkg: bool = false,
3130 for_build: bool = false,
3231 parent_id: string,
3332
src/util/funcs.zig+4-4
......@@ -19,7 +19,7 @@ const ansi_reset = "\x1B[39m";
1919pub fn assert(ok: bool, comptime fmt: string, args: anytype) void {
2020 if (!ok) {
2121 std.debug.print(ansi_red ++ fmt ++ ansi_reset ++ "\n", args);
22 std.os.exit(1);
22 std.process.exit(1);
2323 }
2424}
2525
......@@ -47,13 +47,13 @@ pub fn split(alloc: std.mem.Allocator, in: string, delim: string) ![]string {
4747}
4848
4949pub fn file_list(alloc: std.mem.Allocator, dpath: string) ![]const string {
50 var dir = try std.fs.cwd().openIterableDir(dpath, .{});
50 var dir = try std.fs.cwd().openDir(dpath, .{ .iterate = true });
5151 defer dir.close();
5252 return try extras.fileList(alloc, dir);
5353}
5454
55pub fn run_cmd_raw(alloc: std.mem.Allocator, dir: ?string, args: []const string) !std.ChildProcess.ExecResult {
56 return std.ChildProcess.exec(.{ .allocator = alloc, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch (e) {
55pub fn run_cmd_raw(alloc: std.mem.Allocator, dir: ?string, args: []const string) !std.ChildProcess.RunResult {
56 return std.ChildProcess.run(.{ .allocator = alloc, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch (e) {
5757 error.FileNotFound => {
5858 u.fail("\"{s}\" command not found", .{args[0]});
5959 },
src/util/modfile.zig-3
......@@ -28,7 +28,6 @@ pub const ModFile = struct {
2828 rootdeps: []zigmod.Dep,
2929 builddeps: []zigmod.Dep,
3030 min_zig_version: ?std.SemanticVersion,
31 vcpkg: bool,
3231
3332 pub fn openFile(dir: std.fs.Dir, ops: std.fs.File.OpenFlags) !std.fs.File {
3433 return dir.openFile("zig.mod", ops) catch |err| switch (err) {
......@@ -75,7 +74,6 @@ pub const ModFile = struct {
7574 .rootdeps = try dep_list_by_name(alloc, mapping, &.{ "dev_dependencies", "root_dependencies" }, false),
7675 .builddeps = try dep_list_by_name(alloc, mapping, &.{ "dev_dependencies", "build_dependencies" }, true),
7776 .min_zig_version = std.SemanticVersion.parse(mapping.get_string("min_zig_version") orelse "") catch null,
78 .vcpkg = std.mem.eql(u8, "true", mapping.get_string("vcpkg") orelse ""),
7977 };
8078 }
8179
......@@ -137,7 +135,6 @@ pub const ModFile = struct {
137135 .yaml = item.mapping,
138136 .deps = try dep_list_by_name(alloc, item.mapping, &.{"dependencies"}, for_build),
139137 .keep = std.mem.eql(u8, "true", item.mapping.get_string("keep") orelse ""),
140 .vcpkg = std.mem.eql(u8, "true", item.mapping.get_string("vcpkg") orelse ""),
141138 .for_build = for_build,
142139 .parent_id = mapping.get_string("id") orelse "",
143140 });
src/util/module.zig-2
......@@ -27,7 +27,6 @@ pub const Module = struct {
2727 dep: ?zigmod.Dep,
2828 for_build: bool = false,
2929 min_zig_version: ?std.SemanticVersion,
30 vcpkg: bool,
3130
3231 pub fn from(alloc: std.mem.Allocator, dep: zigmod.Dep, cachepath: string, options: *common.CollectOptions) !Module {
3332 var moddeps = std.ArrayList(Module).init(alloc);
......@@ -54,7 +53,6 @@ pub const Module = struct {
5453 .dep = dep,
5554 .for_build = dep.for_build,
5655 .min_zig_version = null,
57 .vcpkg = dep.vcpkg,
5856 };
5957 }
6058
zig.mod+5-2
......@@ -3,7 +3,7 @@ name: zigmod
33main: src/lib.zig
44license: MIT
55description: A package manager for the Zig programming language.
6min_zig_version: 0.11.0
6min_zig_version: 0.12.0
77dependencies:
88 - src: git https://github.com/nektro/zig-yaml
99 - src: git https://github.com/nektro/zig-ansi
......@@ -18,7 +18,10 @@ dependencies:
1818
1919root_dependencies:
2020 - src: git https://github.com/marlersoft/zigwin32
21 id: zg4wbiyyfn2fdpmia0jjh2d5k0xb7v1l7zn3xcyv
21 id: o6ogpor87xc23o863qaqfciqqdnt48nlj0395dk1xt4m9b34
2222 keep: true
23 name: win32
24 main: win32.zig
25 license: MIT
2326 - src: git https://github.com/nektro/zig-extras
2427 - src: git https://github.com/nektro/zig-ansi
zigmod.lock+8-8
......@@ -1,18 +1,18 @@
112
22git https://github.com/marlersoft/zigwin32 commit-c778640d3dc153e900fbe37e2816b5176af3c802
3git https://github.com/nektro/arqv-ini commit-ddbe89bb0d9085e939bcbc713caeb2b7cf852bae
4git https://github.com/nektro/iguanaTLS commit-f5c7c3fe880c5a23fbcdc21dfcb83c2776931f40
5git https://github.com/nektro/zfetch commit-478031843703fef875ca347898208c01869c7c9d
6git https://github.com/nektro/zig-ansi commit-407a70207ee818f6920096f40779e3fb52db49b0
3git https://github.com/nektro/arqv-ini commit-38a018ad3a19d5b4663a5364d2d31271f250846b
4git https://github.com/nektro/iguanaTLS commit-4dc8850883b49e4a452871298788b06b1af9fe24
5git https://github.com/nektro/zfetch commit-863be236188e5f24d16554f9dcd7df96dd254a13
6git https://github.com/nektro/zig-ansi commit-c3e439f86b0484e4428f38c4d8b07b7b5ae1634b
77git https://github.com/nektro/zig-detect-license commit-3ff57d0681b7bd7f8ca9bd092afa0b4bfe2f1afd
8git https://github.com/nektro/zig-extras commit-c95c2301565603856ff6fcaecaa63bdcdd689bc1
8git https://github.com/nektro/zig-extras commit-74f0ddb0a4dfa7921739b88cc381951a6b6e73ce
99git https://github.com/nektro/zig-inquirer commit-9e1d873db79e9ffa6ae6e06bd372428c9be85d97
1010git https://github.com/nektro/zig-leven commit-e548b0bcc7b6f34f636c0b6b905928d31254c54d
1111git https://github.com/nektro/zig-licenses commit-f46d9f774df929885eef66c733a1e2a46bf16aec
1212git https://github.com/nektro/zig-licenses-text commit-b01e5a2dffcc564bddd8f514fe64bab9b5c52572
1313git https://github.com/nektro/zig-range commit-4b2f12808aa09be4b27a163efc424dd4e0415992
14git https://github.com/nektro/zig-time commit-913d3ff01878326955bb3b265dcb3fdb3607d232
14git https://github.com/nektro/zig-time commit-ba546bbf2e8438c9b2325f36f392c9d95b432e8e
1515git https://github.com/nektro/zig-yaml commit-0d17fb99cba338aedc1abac12d78d5e5f04f0b6b
16git https://github.com/truemedian/hzzp commit-31563ce8173038aff326f83b18d49d84e2737255
17git https://github.com/ziglibs/known-folders commit-bf79988adcfce166f848e4b11e718c1966365329
16git https://github.com/truemedian/hzzp commit-a7f03a1e652abe8c89b376d090cec50acb0d2a1a
17git https://github.com/ziglibs/known-folders commit-0ad514dcfb7525e32ae349b9acc0a53976f3a9fa
1818git https://github.com/yaml/libyaml tag-0.2.5