authoravatarMeghan Denny<hello@nektro.net>2026-10-18 00:44:31-07:00
committeravatarMeghan Denny<hello@nektro.net>2026-10-18 00:47:08-07:00
logcf28bfe96f0e7c72e242bbbf4bab8231f35bd7e4
treeacd4c22f3ba7d590d5eb337c52057ceab94c6d91
parent9e7b050b9648533cfb04baf316beccf2b02f91f8
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

update to zig 0.17.0


22 files changed, 654 insertions(+), 81 deletions(-)

.github/workflows/push.yml+1-1
......@@ -20,7 +20,7 @@ jobs:
2020 uses: mlugg/setup-zig@v2
2121 with:
2222 mirror: "http://mirrors.nektro.net/s3cgi"
23 version: "0.16.0"
23 version: "0.17.0"
2424
2525 - run: zig version
2626 - run: zig env
.gitignore+1
......@@ -1,5 +1,6 @@
11zig-cache
22.zig-cache
33zig-out
4zig-pkg
45.zigmod
56bin
README.md+1-1
......@@ -22,7 +22,7 @@ A package manager for the Zig programming language.
2222
2323## Built With
2424
25- Zig `0.16.0`
25- Zig `0.17.0`
2626- See [`zig.mod`](./zig.mod) and [`zigmod.lock`](./zigmod.lock)
2727
2828### Build from Source
build.zig+4-6
......@@ -4,10 +4,10 @@ const builtin = @import("builtin");
44const deps = @import("./deps.zig");
55
66pub fn build(b: *std.Build) void {
7 b.reference_trace = 256;
7 // b.reference_trace = 255; // https://codeberg.org/ziglang/zig/issues/37136
88
99 const target = b.standardTargetOptions(.{});
10 const mode = b.option(std.builtin.OptimizeMode, "mode", "") orelse .Debug;
10 const optimize = b.standardOptimizeOption(.{});
1111 const use_full_name = b.option(bool, "use-full-name", "") orelse false;
1212 const with_arch_os = b.fmt("-{s}-{s}", .{ @tagName(target.result.cpu.arch), @tagName(target.result.os.tag) });
1313 const exe_name = b.fmt("{s}{s}", .{ "zigmod", if (use_full_name) with_arch_os else "" });
......@@ -16,7 +16,7 @@ pub fn build(b: *std.Build) void {
1616 .root_module = b.createModule(.{
1717 .root_source_file = b.path("src/main.zig"),
1818 .target = target,
19 .optimize = mode,
19 .optimize = optimize,
2020 }),
2121 });
2222 const tag = b.option(string, "tag", "");
......@@ -37,9 +37,7 @@ pub fn build(b: *std.Build) void {
3737
3838 const run_cmd = b.addRunArtifact(exe);
3939 run_cmd.step.dependOn(b.getInstallStep());
40 if (b.args) |args| {
41 run_cmd.addArgs(args);
42 }
40 run_cmd.addPassthruArgs();
4341
4442 const run_step = b.step("run", "Run the app");
4543 run_step.dependOn(&run_cmd.step);
build.zig.zon created+19
......@@ -0,0 +1,19 @@
1.{
2 .fingerprint = 0xc11ddfd84b6c7d6b,
3 .name = .zigmod,
4 .version = "0.0.0",
5 .minimum_zig_version = "0.17.0",
6
7 .paths = .{
8 "build.zig",
9 "build.zig.zon",
10 "src",
11 },
12
13 .dependencies = .{
14 .translate_c = .{
15 .url = "git+https://codeberg.org/ziglang/translate-c?ref=2.0.2#c11030012dc325d446474d17b78c242fd1d622ec",
16 .hash = "translate_c-2.0.2-Q_BUWvBNBwBgPKQJPblip6M7AHNK_IPNPmyv4rSIQMQc",
17 },
18 },
19}
deps.zig+51-24
......@@ -2,6 +2,10 @@
22const std = @import("std");
33const builtin = @import("builtin");
44const string = []const u8;
5const any_translate_c = true;
6const Translator = @import("translate_c").Translator; // need to depend on ziglang/translate-c#2.0.2
7
8pub var translate_c: ?*std.Build.Dependency = null;
59
610pub const GitExactStep = struct {
711 step: *std.Build.Step,
......@@ -28,30 +32,30 @@ pub fn fetch(exe: *std.Build.Step.Compile) *std.Build.Step {
2832 const b = exe.step.owner;
2933 const step = b.step("fetch", "");
3034 dependOnGit(GitExactStep.create(b, "https://github.com/marlersoft/zigwin32", "fb2645891520f3e99931db17a7eba04057e87e89"), step, &@field(package_data, "_o6ogpor87xc2"));
31 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/arqv-ini", "d2465c64833590a04bd9b7f50c87363fd03e65bf"), step, &@field(package_data, "_u7sysdckdymi"));
32 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-ansi", "bebb39ae30d9848a1c212cee582d0b1c102d8b87"), step, &@field(package_data, "_s84v9o48ucb0"));
33 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-detect-license", "6de79b4ff8f7462e26f224f4bed3c81710c8893b"), step, &@field(package_data, "_2ovav391ivak"));
34 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-extras", "0c90ee9a82d8863e0e142211a587940ee2a09790"), step, &@field(package_data, "_f7dubzb7cyqe"));
35 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-git", "88b94a1960be841bb93a0bca65d556cb6385d1fd"), step, &@field(package_data, "_0k64oe2nuzvj"));
36 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "e745b018f87ddc4c8958370332e6cf61625403cc"), step, &@field(package_data, "_c1xirp1ota5p"));
37 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-intrusive-parser", "2409be829d989bd03b6d123159880660c6089820"), step, &@field(package_data, "_7l3oxw6nqqws"));
38 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-json", "d32454ad6d1a6e6e58a8c12a4f3ee1223be2e316"), step, &@field(package_data, "_ocmr9rtohgcc"));
39 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-leven", "014971d4b1e327a5c61322c3a6b9369fd1863864"), step, &@field(package_data, "_96h80ezrvj7i"));
40 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "bc1cd51625c13d6c7df819fd0d85968e617f5c57"), step, &@field(package_data, "_0npcrzfdlrvk"));
41 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-licenses-text", "a9d067c3c4d6c226a1de5531b66785bc15d869ee"), step, &@field(package_data, "_pt88y5d80m25"));
42 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-nfs", "1a27fe574706f0b91c9f66b22fe7d3fa8f5129d5"), step, &@field(package_data, "_vph9l0hxpeze"));
43 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-nio", "17c4f044b15917efc1d3f018765881d53fa27e48"), step, &@field(package_data, "_kscsl0145t7x"));
44 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-darwin", "b349aa32b55aae4cf2ae56740003f8aff0394920"), step, &@field(package_data, "_73bukkeci2u6"));
45 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-freebsd", "f97e6c2de30af76818572490735c84ce1015958b"), step, &@field(package_data, "_qfev2g50alvp"));
46 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-linux", "6dabe7cce239d882c8fd132ab5cda1d1f9ff3634"), step, &@field(package_data, "_h7tv7ayhffak"));
47 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-netbsd", "5ad432ca421c59099be3630b9d0dda49e8bef0a7"), step, &@field(package_data, "_uvkgl6xf1azv"));
48 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-openbsd", "164646a5e7c4129eb92ac524a60f1759605c99df"), step, &@field(package_data, "_4rmxgmcykiba"));
49 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-time", "1349fb2c8aaaa1503e8730facea6f87c5fe75dc0"), step, &@field(package_data, "_iecwp4b3bsfm"));
50 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-tracer", "4ad0602d52a3f40ef74f59f648602c61409f7ba7"), step, &@field(package_data, "_ede2wygpe1iy"));
51 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-yaml", "dff9fd43ebf1046c70090bdccfeb2e4f1c0d584b"), step, &@field(package_data, "_g982zq6e8wsv"));
35 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/arqv-ini", "2951069265792192bd714980d44ccb4abee4a6e8"), step, &@field(package_data, "_u7sysdckdymi"));
36 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-ansi", "952d0751c359612fc1a7c493453cc6223bbaff5d"), step, &@field(package_data, "_s84v9o48ucb0"));
37 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-detect-license", "2ec231c2ae5274d926851f355f0896e0fcbbb5d0"), step, &@field(package_data, "_2ovav391ivak"));
38 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-extras", "fb3aa273de9116bbb7befd448835b854d906f2ee"), step, &@field(package_data, "_f7dubzb7cyqe"));
39 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-git", "f4bd29ad59967102db4532bda2d95d1512fbf3fb"), step, &@field(package_data, "_0k64oe2nuzvj"));
40 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "6feae6d21ac54cba8e5d4da91868c4db9f82343b"), step, &@field(package_data, "_c1xirp1ota5p"));
41 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-intrusive-parser", "6d074187f8c5aa2bdab11ee57c7180df768fca72"), step, &@field(package_data, "_7l3oxw6nqqws"));
42 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-json", "4f6aa411f1dc93cc86a052d8a69804c8ff762e59"), step, &@field(package_data, "_ocmr9rtohgcc"));
43 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-leven", "d990af4f7706edcb0d928d953d1a56c2830fa036"), step, &@field(package_data, "_96h80ezrvj7i"));
44 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "1fd04fc1b7619ca2ddfd07354a93e6d72334f76f"), step, &@field(package_data, "_0npcrzfdlrvk"));
45 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-licenses-text", "a20d31da306967253b8a46c60d8368c7ac4b7229"), step, &@field(package_data, "_pt88y5d80m25"));
46 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-nfs", "b32bb30bbdc7e5ad9bb3adb5c477a98897c9cb10"), step, &@field(package_data, "_vph9l0hxpeze"));
47 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-nio", "b28c8efc86f3baec3737de86ffde5c4b3a5260f6"), step, &@field(package_data, "_kscsl0145t7x"));
48 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-darwin", "312638dcf043c3163e260ec5b42610856fc9eeab"), step, &@field(package_data, "_73bukkeci2u6"));
49 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-freebsd", "967ac568e385534825e6849bc82a9b51d45c600c"), step, &@field(package_data, "_qfev2g50alvp"));
50 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-linux", "750d2aa874a9ddb473e7cd0af99f1e722aaab79d"), step, &@field(package_data, "_h7tv7ayhffak"));
51 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-netbsd", "e16386268223744ac3f6036a028cc4359056731b"), step, &@field(package_data, "_uvkgl6xf1azv"));
52 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-openbsd", "081e11079887e8f02d8480b6219a13a41afd8d69"), step, &@field(package_data, "_4rmxgmcykiba"));
53 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-time", "29f3f902cc8948faa36b853380c38ff587236661"), step, &@field(package_data, "_iecwp4b3bsfm"));
54 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-tracer", "ccf9a6b85a38cc343aba772f2d2aac4df49000e1"), step, &@field(package_data, "_ede2wygpe1iy"));
55 dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-yaml", "e4e8dfe78a3a0e39d134382a18e8eb771418e850"), step, &@field(package_data, "_g982zq6e8wsv"));
5256 dependOnGit(GitExactStep.create(b, "https://github.com/madler/zlib", "da607da739fa6047df13e66a2af6b8bec7c2a498"), step, &@field(package_data, "_0e2d06bb494b"));
5357 dependOnGit(GitExactStep.create(b, "https://github.com/yaml/libyaml", "2c891fc7a770e8ba2fec34fc6b545c672beb37e6"), step, &@field(package_data, "_8mdbh0zuneb0"));
54 dependOnGit(GitExactStep.create(b, "https://github.com/ziglibs/known-folders", "207c34a16e4365edc20d92c7892f962b3bed46e8"), step, &@field(package_data, "_2ta738wrqbaq"));
58 dependOnGit(GitExactStep.create(b, "https://github.com/ziglibs/known-folders", "6da0d0c41b78b9ed2d34fa364fcb81b5ebece6c4"), step, &@field(package_data, "_2ta738wrqbaq"));
5559 return step;
5660}
5761
......@@ -76,7 +80,7 @@ pub fn addAllTo(exe: *std.Build.Step.Compile) void {
7680 exe.root_module.addImport(pkg.name, module);
7781 }
7882 // clear module memo cache so addAllTo can be called more than once in the same build.zig
79 inline for (comptime std.meta.declarations(package_data)) |decl| @field(package_data, decl.name).module_memo = null;
83 inline for (comptime std.meta.declarations(package_data)) |decl| @field(package_data, decl).module_memo = null;
8084}
8185
8286pub fn dependOnGit(ge: GitExactStep, s: *std.Build.Step, p: *Package) void {
......@@ -96,6 +100,7 @@ pub const Package = struct {
96100 system_libs: []const string = &.{},
97101 frameworks: []const string = &.{},
98102 module_memo: ?*std.Build.Module = null,
103 translate_c_h: ?string = null,
99104
100105 pub fn module(self: *Package, exe: *std.Build.Step.Compile, fetch_step: *std.Build.Step) *std.Build.Module {
101106 if (self.module_memo) |cached| {
......@@ -140,6 +145,7 @@ pub const Package = struct {
140145 for (self.c_include_dirs) |item| {
141146 result.addIncludePath(self.path.?.path(b, item));
142147 dummy_library.root_module.addIncludePath(self.path.?.path(b, item));
148 exe.root_module.addIncludePath(self.path.?.path(b, item));
143149 link_lib_c = true;
144150 links += 1;
145151 }
......@@ -147,6 +153,20 @@ pub const Package = struct {
147153 dummy_library.root_module.addCSourceFile(.{ .file = self.path.?.path(b, item), .flags = self.c_source_flags });
148154 links += 1;
149155 }
156 if (any_translate_c) if (self.translate_c_h) |h| {
157 if (translate_c == null) translate_c = b.dependency("translate_c", .{});
158 const t: Translator = .init(translate_c.?, .{
159 .c_source_file = b.addWriteFile("c.h", b.fmt("// {s}\n#include <{s}>\n", .{ self.name, h })).getDirectory().path(b, "c.h"),
160 .target = exe.root_module.resolved_target.?,
161 .optimize = exe.root_module.optimize.?,
162 });
163 for (exe.root_module.include_dirs.items) |d| {
164 if (d != .path) continue;
165 t.addIncludePath(d.path);
166 }
167 result.addImport("c", t.mod);
168 link_lib_c = true;
169 };
150170 for (self.system_libs) |item| {
151171 if (std.zig.target.isLibCLibName(&target, item)) continue;
152172 dummy_library.root_module.linkSystemLibrary(item, .{});
......@@ -170,7 +190,7 @@ pub const Package = struct {
170190};
171191
172192fn checkMinZig(current: std.SemanticVersion, exe: *std.Build.Step.Compile) void {
173 const min = std.SemanticVersion.parse("0.16.0") catch return;
193 const min = std.SemanticVersion.parse("0.17.0") catch return;
174194 if (current.order(min).compare(.lt)) @panic(exe.step.owner.fmt("Your Zig version v{f} does not meet the minimum build requirement of v{f}", .{current, min}));
175195}
176196
......@@ -195,6 +215,7 @@ pub const package_data = struct {
195215 .name = "inquirer",
196216 .main = "src/lib.zig",
197217 .deps = &[_]*Package{ &_s84v9o48ucb0 },
218 .translate_c_h = "termios.h",
198219 };
199220 pub var _96h80ezrvj7i = Package{
200221 .name = "leven",
......@@ -215,18 +236,22 @@ pub const package_data = struct {
215236 pub var _qfev2g50alvp = Package{
216237 .name = "sys-freebsd",
217238 .main = "freebsd.zig",
239 .translate_c_h = "pthread.h",
218240 };
219241 pub var _h7tv7ayhffak = Package{
220242 .name = "sys-linux",
221243 .main = "mod.zig",
244 .translate_c_h = "pthread.h",
222245 };
223246 pub var _uvkgl6xf1azv = Package{
224247 .name = "sys-netbsd",
225248 .main = "netbsd.zig",
249 .translate_c_h = "pthread.h",
226250 };
227251 pub var _4rmxgmcykiba = Package{
228252 .name = "sys-openbsd",
229253 .main = "openbsd.zig",
254 .translate_c_h = "pthread.h",
230255 };
231256 pub var _kscsl0145t7x = Package{
232257 .name = "nio",
......@@ -262,6 +287,7 @@ pub const package_data = struct {
262287 .name = "git",
263288 .main = "git.zig",
264289 .deps = &[_]*Package{ &_iecwp4b3bsfm, &_f7dubzb7cyqe, &_ede2wygpe1iy, &_vph9l0hxpeze, &_kscsl0145t7x, &_0e2d06bb494b },
290 .translate_c_h = "zlib.h",
265291 };
266292 pub var _ocmr9rtohgcc = Package{
267293 .name = "json",
......@@ -272,6 +298,7 @@ pub const package_data = struct {
272298 .name = "yaml",
273299 .main = "yaml.zig",
274300 .deps = &[_]*Package{ &_8mdbh0zuneb0 },
301 .translate_c_h = "yaml.h",
275302 };
276303 pub var _0e2d06bb494b = Package{
277304 .c_include_dirs = &.{ "" },
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.16.0`.
13The earliest Zig release this Zigmod was verified to work with is `0.17.0`.
1414
1515## Download
1616You may download a precompiled binary from https://github.com/nektro/zigmod/releases or build the project from source.
docs/zig.mod.md+4
......@@ -42,6 +42,10 @@ This accepts a list of local directories to embed static assets. These files wil
4242- Type: `[]string`
4343This accepts a list of local directories to embed static assets. These files will be provided through a `files.zig` files in the package root. It generates a list of `@embedFile` calls.
4444
45### `translate_c_h`
46- Type: `string`
47A name a header file eg `foo.h` that will be passed as `#include <foo.h>` to [`translate_c`](https://codeberg.org/ziglang/translate-c) and provided in an `@import("c")` module.
48
4549### `dependencies`
4650- Type: `[]Dep`
4751This is a list of `Dep` objects. `Dep` objects are how you include the other people's code in your project. See the `Dep` documentation below to learn more about the attributes available here.
src/cmd/fetch.0.16.zig created+463
......@@ -0,0 +1,463 @@
1const std = @import("std");
2const string = []const u8;
3const ansi = @import("ansi");
4const extras = @import("extras");
5const nfs = @import("nfs");
6const nio = @import("nio");
7
8const zigmod = @import("../lib.zig");
9const u = @import("./../util/funcs.zig");
10const common = @import("./../common.zig");
11const license = @import("./license.zig");
12
13//
14//
15
16pub fn execute(self_name: []const u8, args: []const [:0]const u8) !void {
17 _ = self_name;
18
19 const gpa = std.heap.c_allocator;
20 const cachepath = try u.find_cachepath();
21 const dir = nfs.cwd();
22 const should_update = !(args.len >= 1 and std.mem.eql(u8, args[0], "--no-update"));
23
24 var options = common.CollectOptions{
25 .log = should_update,
26 .update = should_update,
27 .alloc = gpa,
28 };
29 const top_module = try common.collect_deps_deep(cachepath, dir, &options);
30
31 var list = std.array_list.Managed(zigmod.Module).init(gpa);
32 try common.collect_pkgs(top_module, &list);
33
34 try create_depszig(gpa, cachepath, dir, top_module, &list);
35
36 try create_lockfile(gpa, &list, cachepath, dir);
37
38 try diff_lockfile(gpa);
39
40 options.update = false;
41
42 var outfile = try dir.createFile("licenses.txt", .{});
43 defer outfile.close();
44
45 try license.do(cachepath, dir, &options, outfile);
46}
47
48pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: nfs.Dir, top_module: zigmod.Module, list: *std.array_list.Managed(zigmod.Module)) !void {
49 const f = try dir.createFile("deps.zig", .{});
50 defer f.close();
51
52 const w = f;
53 try w.writeAll("// zig fmt: off\n");
54 try w.writeAll("const std = @import(\"std\");\n");
55 try w.writeAll("const builtin = @import(\"builtin\");\n");
56 try w.writeAll("const string = []const u8;\n");
57 try w.writeAll("\n");
58 try w.print("pub const cache = \"{}\";\n", .{u.altStringEscape(cachepath)});
59 try w.writeAll("pub var skip_libc = false;\n");
60 try w.writeAll("\n");
61 try w.writeAll(
62 \\pub fn addAllTo(exe: *std.Build.Step.Compile) void {
63 \\ checkMinZig(builtin.zig_version, exe);
64 \\ @setEvalBranchQuota(1_000_000);
65 \\ for (packages) |pkg| {
66 \\ const module = pkg.module(exe);
67 \\ exe.root_module.addImport(pkg.import.?[0], module);
68 \\ }
69 \\ for (package_data._root.system_libs) |libname| {
70 \\ exe.root_module.linkSystemLibrary(libname, .{});
71 \\ exe.root_module.link_libc = true;
72 \\ }
73 \\ // clear module memo cache so addAllTo can be called more than once in the same build.zig
74 \\ module_memo.clearAndFree(exe.step.owner.allocator);
75 \\}
76 \\
77 \\var link_lib_c = false;
78 \\var module_memo: std.StringArrayHashMapUnmanaged(*std.Build.Module) = .empty;
79 \\pub const Package = struct {
80 \\ id: string,
81 \\ directory: string,
82 \\ import: ?struct { string, std.Build.LazyPath } = null,
83 \\ dependencies: []const *const Package,
84 \\ c_include_dirs: []const string = &.{},
85 \\ c_source_files: []const string = &.{},
86 \\ c_source_flags: []const string = &.{},
87 \\ system_libs: []const string = &.{},
88 \\ frameworks: []const string = &.{},
89 \\
90 \\ pub fn module(self: *const Package, exe: *std.Build.Step.Compile) *std.Build.Module {
91 \\ if (module_memo.get(self.id)) |cached| {
92 \\ return cached;
93 \\ }
94 \\ const b = exe.step.owner;
95 \\ const result = b.createModule(.{
96 \\ .target = exe.root_module.resolved_target,
97 \\ });
98 \\ const target = result.resolved_target.?.result;
99 \\ if (self.import) |capture| {
100 \\ result.root_source_file = capture[1];
101 \\ }
102 \\ for (self.dependencies) |item| {
103 \\ const module_dep = item.module(exe);
104 \\ if (module_dep.root_source_file != null) {
105 \\ result.addImport(item.import.?[0], module_dep);
106 \\ }
107 \\ for (module_dep.include_dirs.items) |jtem| {
108 \\ switch (jtem) {
109 \\ .path => result.addIncludePath(jtem.path),
110 \\ .path_system, .path_after, .framework_path, .framework_path_system, .other_step, .config_header_step => {},
111 \\ .embed_path => {},
112 \\ }
113 \\ }
114 \\ }
115 \\ for (self.c_include_dirs) |item| {
116 \\ result.addIncludePath(.{ .cwd_relative = (b.fmt("{s}/{s}", .{ self.directory, item })) });
117 \\ exe.root_module.addIncludePath(.{ .cwd_relative = (b.fmt("{s}/{s}", .{ self.directory, item })) });
118 \\ link_lib_c = true;
119 \\ }
120 \\ for (self.c_source_files) |item| {
121 \\ exe.root_module.addCSourceFile(.{ .file = .{ .cwd_relative = (b.fmt("{s}/{s}", .{ self.directory, item })) }, .flags = self.c_source_flags });
122 \\ link_lib_c = true;
123 \\ }
124 \\ for (self.system_libs) |item| {
125 \\ if (skip_libc and std.zig.target.isLibCLibName(&target, item)) continue;
126 \\ result.linkSystemLibrary(item, .{});
127 \\ exe.root_module.linkSystemLibrary(item, .{});
128 \\ link_lib_c = true;
129 \\ }
130 \\ for (self.frameworks) |item| {
131 \\ result.linkFramework(item, .{});
132 \\ exe.root_module.linkFramework(item, .{});
133 \\ link_lib_c = true;
134 \\ }
135 \\ if (link_lib_c and !skip_libc) {
136 \\ result.link_libc = true;
137 \\ exe.root_module.link_libc = true;
138 \\ }
139 \\ module_memo.putNoClobber(b.allocator, self.id, result) catch @panic("OOM");
140 \\ return result;
141 \\ }
142 \\};
143 \\
144 \\
145 );
146
147 try w.print(
148 \\fn checkMinZig(current: std.SemanticVersion, exe: *std.Build.Step.Compile) void {{
149 \\ const min = std.SemanticVersion.parse("{?}") catch return;
150 \\ if (current.order(min).compare(.lt)) @panic(exe.step.owner.fmt("Your Zig version v{{f}} does not meet the minimum build requirement of v{{f}}", .{{current, min}}));
151 \\}}
152 \\
153 \\
154 , .{if (top_module.minZigVersion()) |sv| u.altSemanticVersion(sv) else null});
155
156 try w.writeAll("pub const dirs = struct {\n");
157 try print_dirs(w, list.items, alloc);
158 try w.writeAll("};\n\n");
159
160 try w.writeAll("pub const package_data = struct {\n");
161 var duped = std.array_list.Managed(zigmod.Module).init(alloc);
162 var done = std.array_list.Managed(zigmod.Module).init(alloc);
163 for (list.items) |mod| {
164 if (mod.type == .system_lib or mod.type == .framework) {
165 continue;
166 }
167 try duped.append(mod);
168 }
169 try print_pkg_data_to(w, &duped, &done);
170 try w.writeAll("};\n\n");
171
172 try w.writeAll("pub const packages = ");
173 try print_deps(w, top_module);
174 try w.writeAll(";\n\n");
175
176 try w.writeAll("pub const pkgs = ");
177 try print_pkgs(alloc, w, top_module);
178 try w.writeAll(";\n\n");
179
180 try w.writeAll("pub const imports = struct {\n");
181 try print_imports(alloc, w, top_module, cachepath);
182 try w.writeAll("};\n");
183}
184
185fn create_lockfile(alloc: std.mem.Allocator, list: *std.array_list.Managed(zigmod.Module), path: string, dir: nfs.Dir) !void {
186 const fl = try dir.createFile("zigmod.lock", .{});
187 defer fl.close();
188
189 std.mem.sort(zigmod.Module, list.items, {}, zigmod.Module.lessThan);
190
191 const wl = fl;
192 try wl.writeAll("2\n");
193 for (list.items) |m| {
194 if (m.dep) |md| {
195 if (md.type.isLocal()) continue;
196 const mpath = try std.fs.path.joinZ(alloc, &.{ path, m.clean_path });
197 const version = try md.exact_version(alloc, mpath);
198 try wl.print("{s} {s} {s}\n", .{ @tagName(md.type), md.path, version });
199 }
200 }
201}
202
203const DiffChange = struct {
204 from: string,
205 to: string,
206};
207
208fn diff_lockfile(alloc: std.mem.Allocator) !void {
209 const max = std.math.maxInt(usize);
210
211 if (try nfs.cwd().existsDir(".git")) {
212 const result = try u.run_cmd_raw(alloc, null, &.{ "git", "diff", "zigmod.lock" });
213 var stdout = nio.FixedBufferStream([]const u8).init(result.stdout);
214 const r = &stdout;
215 while (try r.readUntilDelimiterOrEofAlloc(alloc, '\n', max)) |line| {
216 if (std.mem.startsWith(u8, line, "@@")) break;
217 }
218
219 var rems = std.array_list.Managed(string).init(alloc);
220 var adds = std.array_list.Managed(string).init(alloc);
221 while (try r.readUntilDelimiterOrEofAlloc(alloc, '\n', max)) |line_full| {
222 const line = line_full[0 .. line_full.len - 1];
223 if (line[0] == ' ') continue;
224 if (line[0] == '-') try rems.append(line[1..]);
225 if (line[0] == '+') if (line[1] == '2') break else try adds.append(line[1..]);
226 }
227
228 var changes = std.StringHashMap(DiffChange).init(alloc);
229
230 var didbreak = false;
231 var i: usize = 0;
232 while (i < rems.items.len) {
233 const it = rems.items[i];
234 const sni = u.indexOfN(it, ' ', 2).?;
235
236 var j: usize = 0;
237 while (j < adds.items.len) {
238 const jt = adds.items[j];
239 const snj = u.indexOfN(jt, ' ', 2).?;
240
241 if (std.mem.eql(u8, it[0..sni], jt[0..snj])) {
242 try changes.put(it[0..sni], .{
243 .from = it[u.indexOfAfter(it, '-', sni).? + 1 .. it.len],
244 .to = jt[u.indexOfAfter(jt, '-', snj).? + 1 .. jt.len],
245 });
246 _ = rems.orderedRemove(i);
247 _ = adds.orderedRemove(j);
248 didbreak = true;
249 break;
250 }
251 if (!didbreak) j += 1;
252 }
253 if (!didbreak) i += 1;
254 if (didbreak) didbreak = false;
255 }
256
257 if (adds.items.len > 0) {
258 std.debug.print(comptime ansi.color.Faint("Newly added packages:\n"), .{});
259 defer std.debug.print("\n", .{});
260
261 for (adds.items) |it| {
262 std.debug.print("- {s}\n", .{it});
263 }
264 }
265
266 if (rems.items.len > 0) {
267 std.debug.print(comptime ansi.color.Faint("Removed packages:\n"), .{});
268 defer std.debug.print("\n", .{});
269
270 for (rems.items) |it| {
271 std.debug.print("- {s}\n", .{it});
272 }
273 }
274
275 if (changes.unmanaged.size > 0) std.debug.print(comptime ansi.color.Faint("Updated packages:\n"), .{});
276 var iter = changes.iterator();
277 while (iter.next()) |it| {
278 if (diff_printchange("git https://github.com", "- {s}/compare/{s}...{s}\n", it)) continue;
279 if (diff_printchange("git https://gitlab.com", "- {s}/-/compare/{s}...{s}\n", it)) continue;
280 if (diff_printchange("git https://gitea.com", "- {s}/compare/{s}...{s}\n", it)) continue;
281
282 std.debug.print("- {s}\n", .{it.key_ptr.*});
283 std.debug.print(" - {s} ... {s}\n", .{ it.value_ptr.from, it.value_ptr.to });
284 }
285 }
286}
287
288fn diff_printchange(comptime testt: string, comptime replacement: string, item: std.StringHashMap(DiffChange).Entry) bool {
289 if (std.mem.startsWith(u8, item.key_ptr.*, testt)) {
290 if (std.mem.eql(u8, item.value_ptr.from, item.value_ptr.to)) return true;
291 std.debug.print(replacement, .{ item.key_ptr.*[4..], item.value_ptr.from, item.value_ptr.to });
292 return true;
293 }
294 return false;
295}
296
297fn print_dirs(w: nfs.File, list: []const zigmod.Module, alloc: std.mem.Allocator) !void {
298 for (list) |mod| {
299 if (mod.type == .system_lib or mod.type == .framework) continue;
300 if (std.mem.eql(u8, &mod.id, &zigmod.Module.ROOT)) {
301 try w.writeAll(" pub const _root = \"\";\n");
302 continue;
303 }
304 if (std.mem.eql(u8, mod.clean_path, "../..")) {
305 const cwd_realpath = try nfs.cwd().realpathAlloc(alloc, ".");
306 try w.print(" pub const _{s} = \"{}\";\n", .{ mod.short_id(), u.altStringEscape(cwd_realpath) });
307 continue;
308 }
309 try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), u.altStringEscape(mod.clean_path) });
310 }
311}
312
313fn print_deps(w: nfs.File, m: zigmod.Module) !void {
314 try w.writeAll("&[_]*const Package{\n");
315 for (m.deps) |d| {
316 if (d.main.len == 0) {
317 continue;
318 }
319 if (d.for_build) {
320 continue;
321 }
322 try w.print(" &package_data._{s},\n", .{d.id[0..12]});
323 }
324 try w.writeAll("}");
325}
326
327fn print_pkg_data_to(w: nfs.File, notdone: *std.array_list.Managed(zigmod.Module), done: *std.array_list.Managed(zigmod.Module)) !void {
328 var len: usize = notdone.items.len;
329 while (notdone.items.len > 0) {
330 for (notdone.items, 0..) |mod, i| {
331 if (contains_all(mod.deps, done.items)) {
332 try w.print(
333 \\ pub const _{s} = Package{{
334 \\ .id = "{s}",
335 \\ .directory = dirs._{s},
336 \\
337 , .{
338 mod.short_id(),
339 mod.short_id(),
340 mod.short_id(),
341 });
342 if (mod.main.len > 0 and !std.mem.eql(u8, &mod.id, &zigmod.Module.ROOT)) {
343 try w.print(
344 \\ .import = .{{ "{s}", .{{ .cwd_relative = dirs._{s} ++ "/{s}" }} }},
345 \\
346 , .{
347 mod.name,
348 mod.short_id(),
349 mod.main,
350 });
351 }
352 {
353 try w.writeAll(" .dependencies =");
354 try w.writeAll(" &.{");
355 for (mod.deps, 0..) |moddep, j| {
356 if (moddep.type == .system_lib) continue;
357 if (moddep.type == .framework) continue;
358 try w.print(" &_{s}", .{moddep.id[0..12]});
359 if (j != mod.deps.len - 1) try w.writeAll(",");
360 }
361 try w.writeAll(" },\n");
362 }
363 if (mod.c_include_dirs.len > 0) {
364 try w.writeAll(" .c_include_dirs = &.{");
365 for (mod.c_include_dirs, 0..) |item, j| {
366 try w.print(" \"{}\"", .{u.altStringEscape(item)});
367 if (j != mod.c_include_dirs.len - 1) try w.writeAll(",");
368 }
369 try w.writeAll(" },\n");
370 }
371 if (mod.c_source_files.len > 0) {
372 try w.writeAll(" .c_source_files = &.{");
373 for (mod.c_source_files, 0..) |item, j| {
374 try w.print(" \"{}\"", .{u.altStringEscape(item)});
375 if (j != mod.c_source_files.len - 1) try w.writeAll(",");
376 }
377 try w.writeAll(" },\n");
378 }
379 if (mod.c_source_flags.len > 0) {
380 try w.writeAll(" .c_source_flags = &.{");
381 for (mod.c_source_flags, 0..) |item, j| {
382 try w.print(" \"{}\"", .{u.altStringEscape(item)});
383 if (j != mod.c_source_flags.len - 1) try w.writeAll(",");
384 }
385 try w.writeAll(" },\n");
386 }
387 if (mod.has_syslib_deps()) {
388 try w.writeAll(" .system_libs = &.{");
389 for (mod.deps, 0..) |item, j| {
390 if (!(item.type == .system_lib)) continue;
391 try w.print(" \"{}\"", .{u.altStringEscape(item.name)});
392 if (j != mod.deps.len - 1) try w.writeAll(",");
393 }
394 try w.writeAll(" },\n");
395 }
396 if (mod.has_framework_deps()) {
397 try w.writeAll(" .frameworks = &.{");
398 for (mod.deps, 0..) |item, j| {
399 if (!(item.type == .system_lib)) continue;
400 try w.print(" \"{}\"", .{u.altStringEscape(item.name)});
401 if (j != mod.deps.len - 1) try w.writeAll(",");
402 }
403 try w.writeAll(" },\n");
404 }
405 try w.writeAll(" };\n");
406
407 try done.append(mod);
408 _ = notdone.orderedRemove(i);
409 break;
410 }
411 }
412 if (notdone.items.len == len) {
413 u.fail("notdone still has {d} items", .{len});
414 }
415 len = notdone.items.len;
416 }
417}
418
419/// returns if all of the zig modules in needles are in haystack
420fn contains_all(needles: []zigmod.Module, haystack: []const zigmod.Module) bool {
421 for (needles) |item| {
422 if (item.main.len > 0 and !extras.containsAggregate(zigmod.Module, haystack, item)) {
423 return false;
424 }
425 }
426 return true;
427}
428
429fn print_pkgs(alloc: std.mem.Allocator, w: nfs.File, m: zigmod.Module) !void {
430 try w.writeAll("struct {\n");
431 for (m.deps) |d| {
432 if (d.main.len == 0) {
433 continue;
434 }
435 if (d.for_build) {
436 continue;
437 }
438 const ident = try zig_name_from_pkg_name(alloc, d.name);
439 try w.print(" pub const {s} = &package_data._{s};\n", .{ ident, d.id[0..12] });
440 }
441 try w.writeAll("}");
442}
443
444fn print_imports(alloc: std.mem.Allocator, w: nfs.File, m: zigmod.Module, path: string) !void {
445 for (m.deps) |d| {
446 if (d.main.len == 0) {
447 continue;
448 }
449 if (!d.for_build) {
450 continue;
451 }
452 const ident = try zig_name_from_pkg_name(alloc, d.name);
453 try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ ident, u.altStringEscape(path), u.altStringEscape(d.clean_path), d.main });
454 }
455}
456
457fn zig_name_from_pkg_name(alloc: std.mem.Allocator, name: string) !string {
458 var legal = name;
459 legal = try std.mem.replaceOwned(u8, alloc, legal, "-", "_");
460 legal = try std.mem.replaceOwned(u8, alloc, legal, "/", "_");
461 legal = try std.mem.replaceOwned(u8, alloc, legal, ".", "_");
462 return legal;
463}
src/cmd/fetch.zig+21
......@@ -54,9 +54,12 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: nfs.Dir,
5454 try w.writeAll("const std = @import(\"std\");\n");
5555 try w.writeAll("const builtin = @import(\"builtin\");\n");
5656 try w.writeAll("const string = []const u8;\n");
57 try w.print("const any_translate_c = {};\n", .{top_module.any_translate_c()});
58 try w.writeAll("const Translator = @import(\"translate_c\").Translator; // need to depend on ziglang/translate-c#2.0.2\n");
5759 try w.writeAll("\n");
5860 try w.print("pub const cache = \"{}\";\n", .{u.altStringEscape(cachepath)});
5961 try w.writeAll("pub var skip_libc = false;\n");
62 try w.writeAll("pub var translate_c: ?*std.Build.Dependency = null;\n");
6063 try w.writeAll("\n");
6164 try w.writeAll(
6265 \\pub fn addAllTo(exe: *std.Build.Step.Compile) void {
......@@ -86,6 +89,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: nfs.Dir,
8689 \\ c_source_flags: []const string = &.{},
8790 \\ system_libs: []const string = &.{},
8891 \\ frameworks: []const string = &.{},
92 \\ translate_c_h: ?string = null,
8993 \\
9094 \\ pub fn module(self: *const Package, exe: *std.Build.Step.Compile) *std.Build.Module {
9195 \\ if (module_memo.get(self.id)) |cached| {
......@@ -121,6 +125,20 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: nfs.Dir,
121125 \\ exe.root_module.addCSourceFile(.{ .file = .{ .cwd_relative = (b.fmt("{s}/{s}", .{ self.directory, item })) }, .flags = self.c_source_flags });
122126 \\ link_lib_c = true;
123127 \\ }
128 \\ if (any_translate_c) if (self.translate_c_h) |h| {
129 \\ if (translate_c == null) translate_c = b.dependency("translate_c", .{});
130 \\ const t: Translator = .init(translate_c.?, .{
131 \\ .c_source_file = b.addWriteFile("c.h", b.fmt("// {s}\n#include <{s}>\n", .{ self.id, h })).getDirectory().path(b, "c.h"),
132 \\ .target = exe.root_module.resolved_target.?,
133 \\ .optimize = exe.root_module.optimize.?,
134 \\ });
135 \\ for (exe.root_module.include_dirs.items) |d| {
136 \\ if (d != .path) continue;
137 \\ t.addIncludePath(d.path);
138 \\ }
139 \\ result.addImport("c", t.mod);
140 \\ link_lib_c = true;
141 \\ };
124142 \\ for (self.system_libs) |item| {
125143 \\ if (skip_libc and std.zig.target.isLibCLibName(&target, item)) continue;
126144 \\ result.linkSystemLibrary(item, .{});
......@@ -402,6 +420,9 @@ fn print_pkg_data_to(w: nfs.File, notdone: *std.array_list.Managed(zigmod.Module
402420 }
403421 try w.writeAll(" },\n");
404422 }
423 if (mod.translate_c_h) |h| {
424 try w.print(" .translate_c_h = \"{s}\",\n", .{h});
425 }
405426 try w.writeAll(" };\n");
406427
407428 try done.append(mod);
src/cmd/generate.zig+24-1
......@@ -44,6 +44,10 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: [:0]const u8, dir: nf
4444 try w.writeAll("const std = @import(\"std\");\n");
4545 try w.writeAll("const builtin = @import(\"builtin\");\n");
4646 try w.writeAll("const string = []const u8;\n");
47 try w.print("const any_translate_c = {};\n", .{top_module.any_translate_c()});
48 try w.writeAll("const Translator = @import(\"translate_c\").Translator; // need to depend on ziglang/translate-c#2.0.2\n");
49 try w.writeAll("\n");
50 try w.writeAll("pub var translate_c: ?*std.Build.Dependency = null;\n");
4751 try w.writeAll("\n");
4852 try w.writeAll(
4953 \\pub const GitExactStep = struct {
......@@ -107,7 +111,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: [:0]const u8, dir: nf
107111 \\ exe.root_module.addImport(pkg.name, module);
108112 \\ }
109113 \\ // clear module memo cache so addAllTo can be called more than once in the same build.zig
110 \\ inline for (comptime std.meta.declarations(package_data)) |decl| @field(package_data, decl.name).module_memo = null;
114 \\ inline for (comptime std.meta.declarations(package_data)) |decl| @field(package_data, decl).module_memo = null;
111115 \\}
112116 \\
113117 \\pub fn dependOnGit(ge: GitExactStep, s: *std.Build.Step, p: *Package) void {
......@@ -127,6 +131,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: [:0]const u8, dir: nf
127131 \\ system_libs: []const string = &.{},
128132 \\ frameworks: []const string = &.{},
129133 \\ module_memo: ?*std.Build.Module = null,
134 \\ translate_c_h: ?string = null,
130135 \\
131136 \\ pub fn module(self: *Package, exe: *std.Build.Step.Compile, fetch_step: *std.Build.Step) *std.Build.Module {
132137 \\ if (self.module_memo) |cached| {
......@@ -171,6 +176,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: [:0]const u8, dir: nf
171176 \\ for (self.c_include_dirs) |item| {
172177 \\ result.addIncludePath(self.path.?.path(b, item));
173178 \\ dummy_library.root_module.addIncludePath(self.path.?.path(b, item));
179 \\ exe.root_module.addIncludePath(self.path.?.path(b, item));
174180 \\ link_lib_c = true;
175181 \\ links += 1;
176182 \\ }
......@@ -178,6 +184,20 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: [:0]const u8, dir: nf
178184 \\ dummy_library.root_module.addCSourceFile(.{ .file = self.path.?.path(b, item), .flags = self.c_source_flags });
179185 \\ links += 1;
180186 \\ }
187 \\ if (any_translate_c) if (self.translate_c_h) |h| {
188 \\ if (translate_c == null) translate_c = b.dependency("translate_c", .{});
189 \\ const t: Translator = .init(translate_c.?, .{
190 \\ .c_source_file = b.addWriteFile("c.h", b.fmt("// {s}\n#include <{s}>\n", .{ self.name, h })).getDirectory().path(b, "c.h"),
191 \\ .target = exe.root_module.resolved_target.?,
192 \\ .optimize = exe.root_module.optimize.?,
193 \\ });
194 \\ for (exe.root_module.include_dirs.items) |d| {
195 \\ if (d != .path) continue;
196 \\ t.addIncludePath(d.path);
197 \\ }
198 \\ result.addImport("c", t.mod);
199 \\ link_lib_c = true;
200 \\ };
181201 \\ for (self.system_libs) |item| {
182202 \\ if (std.zig.target.isLibCLibName(&target, item)) continue;
183203 \\ dummy_library.root_module.linkSystemLibrary(item, .{});
......@@ -329,6 +349,9 @@ fn print_pkg_data_to(w: nfs.File, notdone: *std.array_list.Managed(zigmod.Module
329349 }
330350 try w.writeAll(" },\n");
331351 }
352 if (mod.translate_c_h) |h| {
353 try w.print(" .translate_c_h = \"{s}\",\n", .{h});
354 }
332355 try w.writeAll(" };\n");
333356
334357 try done.append(mod);
src/cmd/init.zig+6-5
......@@ -44,7 +44,7 @@ pub fn execute(self_name: []const u8, args: []const [:0]const u8) !void {
4444 error.CantFindMain => try std.mem.concat(gpa, u8, &.{ flatname, ".zig" }),
4545 else => |ee| return ee,
4646 }) else null;
47 const entry = if (entry_bare) |ent| try gpa.dupeZ(u8, ent) else null;
47 const entry = if (entry_bare) |ent| try gpa.dupeSentinel(u8, ent, 0) else null;
4848
4949 const maybe_license_text = try detectlicense.detectInDir(gpa, cwd);
5050 const license = try inquirer.forString(stdout, stdin, "license:", gpa, maybe_license_text);
......@@ -153,6 +153,7 @@ pub fn execute(self_name: []const u8, args: []const [:0]const u8) !void {
153153 }
154154 if (!exists) try w.writeAll(".zig-cache\n");
155155 if (!exists) try w.writeAll("zig-out\n");
156 if (!exists) try w.writeAll("zig-pkg\n");
156157 try w.writeAll(".zigmod\n");
157158 try w.writeAll("deps.zig\n");
158159 try w.writeAll("files.zig\n");
......@@ -194,7 +195,7 @@ pub fn execute(self_name: []const u8, args: []const [:0]const u8) !void {
194195 \\
195196 \\pub fn build(b: *std.Build) void {
196197 \\ const target = b.standardTargetOptions(.{});
197 \\ const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug;
198 \\ const optimize = b.standardOptimizeOption(.{});
198199 \\
199200 \\ const exe = b.addExecutable(.{
200201 \\
......@@ -203,7 +204,7 @@ pub fn execute(self_name: []const u8, args: []const [:0]const u8) !void {
203204 try w.writeAll(
204205 \\ .root_source_file = b.path("main.zig"),
205206 \\ .target = target,
206 \\ .optimize = mode,
207 \\ .optimize = optimize,
207208 \\ });
208209 \\ deps.addAllTo(exe);
209210 \\ b.installArtifact(exe);
......@@ -224,12 +225,12 @@ pub fn execute(self_name: []const u8, args: []const [:0]const u8) !void {
224225 \\
225226 \\pub fn build(b: *std.Build) void {
226227 \\ const target = b.standardTargetOptions(.{});
227 \\ const mode = b.option(std.builtin.Mode, "mode", "") orelse .Debug;
228 \\ const optimize = b.standardOptimizeOption(.{});
228229 \\
229230 \\ const tests = b.addTest(.{
230231 \\ .root_source_file = b.path("test.zig"),
231232 \\ .target = target,
232 \\ .optimize = mode,
233 \\ .optimize = optimize,
233234 \\ });
234235 \\ deps.addAllTo(tests);
235236 \\
src/cmd/install.zig+3-2
......@@ -67,7 +67,7 @@ pub fn execute(self_name: []const u8, args: []const [:0]const u8) !void {
6767
6868 const modfile = try zigmod.ModFile.from_dir(gpa, moddir, modpath);
6969 const zigversion_sv = modfile.min_zig_version orelse u.fail("zigmod manifest requires min_zig_version field", .{});
70 const zigversion = try nio.fmt.allocPrint(gpa, "{s}", .{u.altSemanticVersion(zigversion_sv)});
70 const zigversion = try nio.fmt.allocPrint(gpa, "{}", .{u.altSemanticVersion(zigversion_sv)});
7171 const zigpath = try std.fs.path.joinZ(gpa, &.{ datapath, "zig", zigversion, "zig" });
7272
7373 // regen deps.zig with the repo's zig version
......@@ -89,7 +89,8 @@ pub fn execute(self_name: []const u8, args: []const [:0]const u8) !void {
8989 0x0000_000d => try @import("./fetch.0.13.zig").create_depszig(gpa, cachepath, moddir, fetch_top_module, &fetch_list),
9090 0x0000_000e => try @import("./fetch.0.14.zig").create_depszig(gpa, cachepath, moddir, fetch_top_module, &fetch_list),
9191 0x0000_000f => try @import("./fetch.0.15.zig").create_depszig(gpa, cachepath, moddir, fetch_top_module, &fetch_list),
92 0x0000_0010 => {}, // that's us, zigmod is already 0.16.0
92 0x0000_0010 => try @import("./fetch.0.16.zig").create_depszig(gpa, cachepath, moddir, fetch_top_module, &fetch_list),
93 0x0000_0011 => {}, // that's us, zigmod is already 0.17.0
9394 else => u.fail("zig {d}.{d} unimplemented", .{ version_sct.major, version_sct.minor }),
9495 }
9596
src/cmd/zpm.zig+2-2
......@@ -48,8 +48,8 @@ pub fn execute(self_name: []const u8, args: []const [:0]const u8) !void {
4848 }
4949
5050 inline for (comptime std.meta.declarations(commands)) |decl| {
51 if (std.mem.eql(u8, args[0], decl.name)) {
52 const cmd = @field(commands, decl.name);
51 if (std.mem.eql(u8, args[0], decl)) {
52 const cmd = @field(commands, decl);
5353 try cmd.execute(self_name, args[1..]);
5454 return;
5555 }
src/common.zig+7-4
......@@ -58,6 +58,7 @@ pub fn collect_deps_deep(cachepath: [:0]const u8, mdir: nfs.Dir, options: *Colle
5858 .yaml = m.yaml,
5959 .dep = null,
6060 .min_zig_version = m.min_zig_version,
61 .translate_c_h = m.translate_c_h,
6162 };
6263}
6364
......@@ -88,6 +89,7 @@ pub fn collect_deps(cachepath: [:0]const u8, mdir: nfs.Dir, mdir_path: string, d
8889 .yaml = m.yaml,
8990 .dep = null,
9091 .min_zig_version = m.min_zig_version,
92 .translate_c_h = m.translate_c_h,
9193 };
9294}
9395
......@@ -121,7 +123,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
121123 switch (d.type) {
122124 .local => {
123125 if (!std.mem.endsWith(u8, d.main, ".zig")) {
124 return gpa.dupeZ(u8, d.main);
126 return gpa.dupeSentinel(u8, d.main, 0);
125127 }
126128 return d.path;
127129 },
......@@ -206,7 +208,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
206208 }
207209 const file_path_s = try std.fs.path.resolve(options.alloc, &.{ p, file_name });
208210 defer gpa.free(file_path_s);
209 const file_path = try gpa.dupeZ(u8, file_path_s);
211 const file_path = try gpa.dupeSentinel(u8, file_path_s, 0);
210212 try d.type.pull(options.alloc, d.path, p);
211213 try nfs.cwd().deleteFile(file_path);
212214 return p;
......@@ -219,7 +221,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *Co
219221 for (lock) |item| {
220222 if (std.mem.eql(u8, item[0], try d.clean_path(options.alloc))) {
221223 d.type = std.meta.stringToEnum(zigmod.Dep.Type, item[1]).?;
222 d.path = try gpa.dupeZ(u8, item[2]);
224 d.path = try gpa.dupeSentinel(u8, item[2], 0);
223225 d.version = item[3];
224226 break;
225227 }
......@@ -247,6 +249,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *Co
247249 .dep = d.*,
248250 .for_build = d.for_build,
249251 .min_zig_version = null,
252 .translate_c_h = null,
250253 };
251254 },
252255 else => {
......@@ -384,7 +387,7 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const [4]string
384387 var iter = std.mem.splitScalar(u8, line, ' ');
385388 const asdep = zigmod.Dep{
386389 .type = std.meta.stringToEnum(zigmod.Dep.Type, iter.next().?).?,
387 .path = try gpa.dupeZ(u8, iter.next().?),
390 .path = try gpa.dupeSentinel(u8, iter.next().?, 0),
388391 .version = iter.next().?,
389392 .id = zigmod.Dep.EMPTY,
390393 .name = "",
src/main.zig+3-3
......@@ -39,7 +39,7 @@ pub fn main(init: std.process.Init.Minimal) !void {
3939 std.debug.print("\n", .{});
4040 std.debug.print("The commands available are:\n", .{});
4141 inline for (comptime std.meta.declarations(zigmod.commands)) |decl| {
42 std.debug.print(" - {s}\n", .{decl.name});
42 std.debug.print(" - {s}\n", .{decl});
4343 }
4444 return;
4545 }
......@@ -58,8 +58,8 @@ pub fn main(init: std.process.Init.Minimal) !void {
5858 defer zigmod.deinit();
5959
6060 inline for (comptime std.meta.declarations(zigmod.commands)) |decl| {
61 if (std.mem.eql(u8, args[0], decl.name)) {
62 const cmd = @field(zigmod.commands, decl.name);
61 if (std.mem.eql(u8, args[0], decl)) {
62 const cmd = @field(zigmod.commands, decl);
6363 try cmd.execute(self_path, args[1..]);
6464 return;
6565 }
src/util/dep.zig+2-1
......@@ -28,8 +28,9 @@ pub const Dep = struct {
2828 deps: []zigmod.Dep,
2929 keep: bool = false,
3030 for_build: bool = false,
31 translate_c_h: ?string = null,
3132
32 pub const EMPTY = (" " ** 48).*;
33 pub const EMPTY: [48]u8 = @splat(' ');
3334
3435 pub const Type = @import("./dep_type.zig").DepType;
3536
src/util/funcs.zig+2-2
......@@ -56,7 +56,7 @@ pub fn file_list(alloc: std.mem.Allocator, dpath: [:0]const u8) ![]const [:0]con
5656 defer walker.deinit();
5757 while (try walker.next()) |entry| {
5858 if (entry.type != .REG) continue;
59 try list.append(try alloc.dupeZ(u8, entry.path));
59 try list.append(try alloc.dupeSentinel(u8, entry.path, 0));
6060 }
6161 return list.toOwnedSlice();
6262}
......@@ -230,7 +230,7 @@ pub fn find_cachepath() ![:0]const u8 {
230230 const needle = "/.zigmod/deps";
231231
232232 if (std.mem.indexOf(u8, haystack, needle)) |index| {
233 return gpa.dupeZ(u8, haystack[0 .. index + needle.len]);
233 return gpa.dupeSentinel(u8, haystack[0 .. index + needle.len], 0);
234234 }
235235 return try std.fs.path.joinZ(gpa, &.{ haystack, ".zigmod", "deps" });
236236}
src/util/modfile.zig+5-2
......@@ -33,6 +33,7 @@ pub const ModFile = struct {
3333 rootdeps: []zigmod.Dep,
3434 builddeps: []zigmod.Dep,
3535 min_zig_version: ?std.SemanticVersion,
36 translate_c_h: ?string = null,
3637
3738 pub fn openFile(dir: nfs.Dir, ops: nfs.Dir.OpenFileFlags) !struct { string, nfs.File } {
3839 return .{ "zig.mod", dir.openFile("zig.mod", ops) catch |err| switch (err) {
......@@ -91,6 +92,7 @@ pub const ModFile = struct {
9192 .rootdeps = try dep_list_by_name(alloc, mapping, &.{ "dev_dependencies", "root_dependencies" }, false),
9293 .builddeps = try dep_list_by_name(alloc, mapping, &.{ "dev_dependencies", "build_dependencies" }, true),
9394 .min_zig_version = std.SemanticVersion.parse(mapping.get_string("min_zig_version") orelse "") catch null,
95 .translate_c_h = mapping.get_string("translate_c_h"),
9496 };
9597 }
9698
......@@ -110,9 +112,9 @@ pub const ModFile = struct {
110112 if (item.mapping.get("src")) |val| {
111113 var src_iter = std.mem.tokenizeScalar(u8, val.string, ' ');
112114 dtype = src_iter.next().?;
113 path = try gpa.dupeZ(u8, src_iter.next().?);
115 path = try gpa.dupeSentinel(u8, src_iter.next().?, 0);
114116 if (src_iter.next()) |dver| {
115 version = try gpa.dupeZ(u8, dver);
117 version = try gpa.dupeSentinel(u8, dver, 0);
116118 }
117119 } else {
118120 dtype = item.mapping.get("type").?.string;
......@@ -151,6 +153,7 @@ pub const ModFile = struct {
151153 .deps = try dep_list_by_name(alloc, item.mapping, &.{"dependencies"}, for_build),
152154 .keep = std.mem.eql(u8, "true", item.mapping.get_string("keep") orelse ""),
153155 .for_build = for_build,
156 .translate_c_h = item.mapping.get_string("translate_c_h"),
154157 });
155158 // const d = &dep_list.getLast();
156159 }
src/util/module.zig+10-2
......@@ -29,8 +29,9 @@ pub const Module = struct {
2929 dep: ?zigmod.Dep,
3030 for_build: bool = false,
3131 min_zig_version: ?std.SemanticVersion,
32 translate_c_h: ?string,
3233
33 pub const ROOT: [48]u8 = ("root" ++ (" " ** 44)).*;
34 pub const ROOT: [48]u8 = ("root" ++ @as([44]u8, @splat(' '))).*;
3435
3536 pub fn from(alloc: std.mem.Allocator, dep: zigmod.Dep, cachepath: [:0]const u8, options: *common.CollectOptions) !Module {
3637 var moddeps = std.array_list.Managed(Module).init(alloc);
......@@ -61,6 +62,7 @@ pub const Module = struct {
6162 .dep = dep,
6263 .for_build = dep.for_build,
6364 .min_zig_version = null,
65 .translate_c_h = dep.translate_c_h,
6466 };
6567 }
6668
......@@ -80,7 +82,7 @@ pub const Module = struct {
8082 try file_list_2.append(_b);
8183 }
8284
83 std.mem.sort(string, file_list_2.items, void{}, struct {
85 std.mem.sort(string, file_list_2.items, {}, struct {
8486 pub fn lt(context: void, lhs: string, rhs: string) bool {
8587 _ = context;
8688 return std.mem.lessThan(u8, lhs, rhs);
......@@ -204,4 +206,10 @@ pub const Module = struct {
204206 },
205207 };
206208 }
209
210 pub fn any_translate_c(self: *const Module) bool {
211 if (self.translate_c_h) |_| return true;
212 for (self.deps) |d| if (d.any_translate_c()) return true;
213 return false;
214 }
207215};
zig.mod+2-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.16.0
6min_zig_version: 0.17.0
77min_zigmod_version: r96
88dependencies:
99 - src: git https://github.com/nektro/zig-yaml
......@@ -13,7 +13,7 @@ dependencies:
1313 name: known-folders
1414 main: known-folders.zig
1515 license: MIT
16 version: commit-207c34a16e4365edc20d92c7892f962b3bed46e8
16 version: commit-6da0d0c41b78b9ed2d34fa364fcb81b5ebece6c4
1717 - src: git https://github.com/nektro/zig-licenses
1818 - src: git https://github.com/nektro/zig-detect-license
1919 - src: git https://github.com/nektro/zig-inquirer
zigmod.lock+22-22
......@@ -1,26 +1,26 @@
112
22git https://github.com/marlersoft/zigwin32 commit-fb2645891520f3e99931db17a7eba04057e87e89
3git https://github.com/nektro/arqv-ini commit-d2465c64833590a04bd9b7f50c87363fd03e65bf
4git https://github.com/nektro/zig-ansi commit-bebb39ae30d9848a1c212cee582d0b1c102d8b87
5git https://github.com/nektro/zig-detect-license commit-6de79b4ff8f7462e26f224f4bed3c81710c8893b
6git https://github.com/nektro/zig-extras commit-0c90ee9a82d8863e0e142211a587940ee2a09790
7git https://github.com/nektro/zig-git commit-88b94a1960be841bb93a0bca65d556cb6385d1fd
8git https://github.com/nektro/zig-inquirer commit-e745b018f87ddc4c8958370332e6cf61625403cc
9git https://github.com/nektro/zig-intrusive-parser commit-2409be829d989bd03b6d123159880660c6089820
10git https://github.com/nektro/zig-json commit-d32454ad6d1a6e6e58a8c12a4f3ee1223be2e316
11git https://github.com/nektro/zig-leven commit-014971d4b1e327a5c61322c3a6b9369fd1863864
12git https://github.com/nektro/zig-licenses commit-bc1cd51625c13d6c7df819fd0d85968e617f5c57
13git https://github.com/nektro/zig-licenses-text commit-a9d067c3c4d6c226a1de5531b66785bc15d869ee
14git https://github.com/nektro/zig-nfs commit-1a27fe574706f0b91c9f66b22fe7d3fa8f5129d5
15git https://github.com/nektro/zig-nio commit-17c4f044b15917efc1d3f018765881d53fa27e48
16git https://github.com/nektro/zig-sys-darwin commit-b349aa32b55aae4cf2ae56740003f8aff0394920
17git https://github.com/nektro/zig-sys-freebsd commit-f97e6c2de30af76818572490735c84ce1015958b
18git https://github.com/nektro/zig-sys-linux commit-6dabe7cce239d882c8fd132ab5cda1d1f9ff3634
19git https://github.com/nektro/zig-sys-netbsd commit-5ad432ca421c59099be3630b9d0dda49e8bef0a7
20git https://github.com/nektro/zig-sys-openbsd commit-164646a5e7c4129eb92ac524a60f1759605c99df
21git https://github.com/nektro/zig-time commit-1349fb2c8aaaa1503e8730facea6f87c5fe75dc0
22git https://github.com/nektro/zig-tracer commit-4ad0602d52a3f40ef74f59f648602c61409f7ba7
23git https://github.com/nektro/zig-yaml commit-dff9fd43ebf1046c70090bdccfeb2e4f1c0d584b
3git https://github.com/nektro/arqv-ini commit-2951069265792192bd714980d44ccb4abee4a6e8
4git https://github.com/nektro/zig-ansi commit-952d0751c359612fc1a7c493453cc6223bbaff5d
5git https://github.com/nektro/zig-detect-license commit-2ec231c2ae5274d926851f355f0896e0fcbbb5d0
6git https://github.com/nektro/zig-extras commit-fb3aa273de9116bbb7befd448835b854d906f2ee
7git https://github.com/nektro/zig-git commit-f4bd29ad59967102db4532bda2d95d1512fbf3fb
8git https://github.com/nektro/zig-inquirer commit-6feae6d21ac54cba8e5d4da91868c4db9f82343b
9git https://github.com/nektro/zig-intrusive-parser commit-6d074187f8c5aa2bdab11ee57c7180df768fca72
10git https://github.com/nektro/zig-json commit-4f6aa411f1dc93cc86a052d8a69804c8ff762e59
11git https://github.com/nektro/zig-leven commit-d990af4f7706edcb0d928d953d1a56c2830fa036
12git https://github.com/nektro/zig-licenses commit-1fd04fc1b7619ca2ddfd07354a93e6d72334f76f
13git https://github.com/nektro/zig-licenses-text commit-a20d31da306967253b8a46c60d8368c7ac4b7229
14git https://github.com/nektro/zig-nfs commit-b32bb30bbdc7e5ad9bb3adb5c477a98897c9cb10
15git https://github.com/nektro/zig-nio commit-b28c8efc86f3baec3737de86ffde5c4b3a5260f6
16git https://github.com/nektro/zig-sys-darwin commit-312638dcf043c3163e260ec5b42610856fc9eeab
17git https://github.com/nektro/zig-sys-freebsd commit-967ac568e385534825e6849bc82a9b51d45c600c
18git https://github.com/nektro/zig-sys-linux commit-750d2aa874a9ddb473e7cd0af99f1e722aaab79d
19git https://github.com/nektro/zig-sys-netbsd commit-e16386268223744ac3f6036a028cc4359056731b
20git https://github.com/nektro/zig-sys-openbsd commit-081e11079887e8f02d8480b6219a13a41afd8d69
21git https://github.com/nektro/zig-time commit-29f3f902cc8948faa36b853380c38ff587236661
22git https://github.com/nektro/zig-tracer commit-ccf9a6b85a38cc343aba772f2d2aac4df49000e1
23git https://github.com/nektro/zig-yaml commit-e4e8dfe78a3a0e39d134382a18e8eb771418e850
2424git https://github.com/madler/zlib tag-v1.3.2
2525git https://github.com/yaml/libyaml tag-0.2.5
26git https://github.com/ziglibs/known-folders commit-207c34a16e4365edc20d92c7892f962b3bed46e8
26git https://github.com/ziglibs/known-folders commit-6da0d0c41b78b9ed2d34fa364fcb81b5ebece6c4