authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-01-18 04:19:46 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-01-18 04:19:46 -08:00
log814eba696608f569764a53b00dc4541c8bd9d1b6
tree99c3f5bc87ef7fe8d1bfc9190db0b22e1f8bb29d
parent1546e70d470facfd40b5e5ecd2ceb24a453487ea

add ModFile.min_zig_version prop, fixes #51


7 files changed, 41 insertions(+), 0 deletions(-)

deps.zig+6
......@@ -6,6 +6,7 @@ const string = []const u8;
66pub const cache = ".zigmod/deps";
77
88pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
9 checkMinZig(builtin.zig_version, exe);
910 @setEvalBranchQuota(1_000_000);
1011 for (packages) |pkg| {
1112 exe.addPackage(pkg.pkg.?);
......@@ -42,6 +43,11 @@ pub const Package = struct {
4243 vcpkg: bool = false,
4344};
4445
46fn checkMinZig(current: std.SemanticVersion, exe: *std.build.LibExeObjStep) void {
47 const min = std.SemanticVersion.parse("0.9.0") catch return;
48 if (current.order(min).compare(.lt)) @panic(exe.builder.fmt("Your Zig version v{} does not meet the minimum build requirement of v{}", .{current, min}));
49}
50
4551pub const dirs = struct {
4652 pub const _root = "";
4753 pub const _89ujp8gq842x = cache ++ "/../..";
docs/zig.mod.md+4
......@@ -50,6 +50,10 @@ Similar to `dependencies` but will only get added to the project if the current
5050- Type: `[]Dep`
5151Similar to `dependencies` but will only get added to the project if the current `zig.mod` is the root module. Exposed in `deps.zig` through the `deps.imports` decl.
5252
53### `min_zig_version`
54- Type: `string`
55Parsed 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.
56
5357----
5458
5559### Dep Object
src/cmd/fetch.zig+10
......@@ -53,6 +53,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
5353 try w.writeAll("\n");
5454 try w.writeAll(
5555 \\pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
56 \\ checkMinZig(builtin.zig_version, exe);
5657 \\ @setEvalBranchQuota(1_000_000);
5758 \\ for (packages) |pkg| {
5859 \\ exe.addPackage(pkg.pkg.?);
......@@ -92,6 +93,15 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
9293 \\
9394 );
9495
96 try w.print(
97 \\fn checkMinZig(current: std.SemanticVersion, exe: *std.build.LibExeObjStep) void {{
98 \\ const min = std.SemanticVersion.parse("{}") catch return;
99 \\ if (current.order(min).compare(.lt)) @panic(exe.builder.fmt("Your Zig version v{{}} does not meet the minimum build requirement of v{{}}", .{{current, min}}));
100 \\}}
101 \\
102 \\
103 , .{top_module.minZigVersion()});
104
95105 try w.writeAll("pub const dirs = struct {\n");
96106 try print_dirs(w, list.items);
97107 try w.writeAll("};\n\n");
src/common.zig+3
......@@ -59,6 +59,7 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO
5959 .clean_path = "",
6060 .yaml = m.yaml,
6161 .dep = null,
62 .min_zig_version = m.min_zig_version,
6263 };
6364}
6465
......@@ -89,6 +90,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption
8990 .clean_path = "../..",
9091 .yaml = m.yaml,
9192 .dep = null,
93 .min_zig_version = m.min_zig_version,
9294 };
9395}
9496
......@@ -239,6 +241,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
239241 .yaml = null,
240242 .dep = d.*,
241243 .for_build = d.for_build,
244 .min_zig_version = null,
242245 };
243246 },
244247 else => {
src/util/modfile.zig+2
......@@ -27,6 +27,7 @@ pub const ModFile = struct {
2727 files: []const string,
2828 rootdeps: []zigmod.Dep,
2929 builddeps: []zigmod.Dep,
30 min_zig_version: ?std.SemanticVersion,
3031
3132 pub fn init(alloc: std.mem.Allocator, mpath: string) !Self {
3233 const file = try std.fs.cwd().openFile(mpath, .{});
......@@ -66,6 +67,7 @@ pub const ModFile = struct {
6667 .files = try mapping.get_string_array(alloc, "files"),
6768 .rootdeps = try dep_list_by_name(alloc, mapping, &.{ "dev_dependencies", "root_dependencies" }, false),
6869 .builddeps = try dep_list_by_name(alloc, mapping, &.{ "dev_dependencies", "build_dependencies" }, true),
70 .min_zig_version = std.SemanticVersion.parse(mapping.get_string("min_zig_version")) catch null,
6971 };
7072 }
7173
src/util/module.zig+15
......@@ -26,6 +26,7 @@ pub const Module = struct {
2626 clean_path: string,
2727 dep: ?zigmod.Dep,
2828 for_build: bool = false,
29 min_zig_version: ?std.SemanticVersion,
2930
3031 pub fn from(alloc: std.mem.Allocator, dep: zigmod.Dep, modpath: string, options: *common.CollectOptions) !Module {
3132 var moddeps = std.ArrayList(Module).init(alloc);
......@@ -52,6 +53,7 @@ pub const Module = struct {
5253 .yaml = dep.yaml,
5354 .dep = dep,
5455 .for_build = dep.for_build,
56 .min_zig_version = null,
5557 };
5658 }
5759
......@@ -134,4 +136,17 @@ pub const Module = struct {
134136 pub fn short_id(self: Module) string {
135137 return u.slice(u8, self.id, 0, 12);
136138 }
139
140 pub fn minZigVersion(self: Module) ?std.SemanticVersion {
141 var res = self.min_zig_version;
142
143 for (self.deps) |dm| {
144 if (dm.minZigVersion()) |sv| {
145 if (res == null or sv.order(res.?).compare(.gt)) {
146 res = sv;
147 }
148 }
149 }
150 return res;
151 }
137152};
zig.mod+1
......@@ -3,6 +3,7 @@ name: zigmod
33main: src/lib.zig
44license: MIT
55description: A package manager for the Zig programming language.
6min_zig_version: 0.9.0
67dependencies:
78 - src: git https://github.com/yaml/libyaml tag-0.2.5
89 id: 8mdbh0zuneb0i3hs5jby5je0heem1i6yxusl7c8y8qx68hqc