| author | |
| committer | |
| log | 814eba696608f569764a53b00dc4541c8bd9d1b6 |
| tree | 99c3f5bc87ef7fe8d1bfc9190db0b22e1f8bb29d |
| parent | 1546e70d470facfd40b5e5ecd2ceb24a453487ea |
7 files changed, 41 insertions(+), 0 deletions(-)
deps.zig+6| ... | @@ -6,6 +6,7 @@ const string = []const u8; | ... | @@ -6,6 +6,7 @@ const string = []const u8; |
| 6 | pub const cache = ".zigmod/deps"; | 6 | pub const cache = ".zigmod/deps"; |
| 7 | 7 | ||
| 8 | pub fn addAllTo(exe: *std.build.LibExeObjStep) void { | 8 | pub fn addAllTo(exe: *std.build.LibExeObjStep) void { |
| 9 | checkMinZig(builtin.zig_version, exe); | ||
| 9 | @setEvalBranchQuota(1_000_000); | 10 | @setEvalBranchQuota(1_000_000); |
| 10 | for (packages) |pkg| { | 11 | for (packages) |pkg| { |
| 11 | exe.addPackage(pkg.pkg.?); | 12 | exe.addPackage(pkg.pkg.?); |
| ... | @@ -42,6 +43,11 @@ pub const Package = struct { | ... | @@ -42,6 +43,11 @@ pub const Package = struct { |
| 42 | vcpkg: bool = false, | 43 | vcpkg: bool = false, |
| 43 | }; | 44 | }; |
| 44 | 45 | ||
| 46 | fn 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 | |||
| 45 | pub const dirs = struct { | 51 | pub const dirs = struct { |
| 46 | pub const _root = ""; | 52 | pub const _root = ""; |
| 47 | pub const _89ujp8gq842x = cache ++ "/../.."; | 53 | 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 | ... | @@ -50,6 +50,10 @@ Similar to `dependencies` but will only get added to the project if the current |
| 50 | - Type: `[]Dep` | 50 | - Type: `[]Dep` |
| 51 | Similar 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. | 51 | Similar 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. |
| 52 | 52 | ||
| 53 | ### `min_zig_version` | ||
| 54 | - Type: `string` | ||
| 55 | Parsed 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 | |||
| 53 | ---- | 57 | ---- |
| 54 | 58 | ||
| 55 | ### Dep Object | 59 | ### 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 | ... | @@ -53,6 +53,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D |
| 53 | try w.writeAll("\n"); | 53 | try w.writeAll("\n"); |
| 54 | try w.writeAll( | 54 | try w.writeAll( |
| 55 | \\pub fn addAllTo(exe: *std.build.LibExeObjStep) void { | 55 | \\pub fn addAllTo(exe: *std.build.LibExeObjStep) void { |
| 56 | \\ checkMinZig(builtin.zig_version, exe); | ||
| 56 | \\ @setEvalBranchQuota(1_000_000); | 57 | \\ @setEvalBranchQuota(1_000_000); |
| 57 | \\ for (packages) |pkg| { | 58 | \\ for (packages) |pkg| { |
| 58 | \\ exe.addPackage(pkg.pkg.?); | 59 | \\ exe.addPackage(pkg.pkg.?); |
| ... | @@ -92,6 +93,15 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D | ... | @@ -92,6 +93,15 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D |
| 92 | \\ | 93 | \\ |
| 93 | ); | 94 | ); |
| 94 | 95 | ||
| 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 | |||
| 95 | try w.writeAll("pub const dirs = struct {\n"); | 105 | try w.writeAll("pub const dirs = struct {\n"); |
| 96 | try print_dirs(w, list.items); | 106 | try print_dirs(w, list.items); |
| 97 | try w.writeAll("};\n\n"); | 107 | 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 | ... | @@ -59,6 +59,7 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO |
| 59 | .clean_path = "", | 59 | .clean_path = "", |
| 60 | .yaml = m.yaml, | 60 | .yaml = m.yaml, |
| 61 | .dep = null, | 61 | .dep = null, |
| 62 | .min_zig_version = m.min_zig_version, | ||
| 62 | }; | 63 | }; |
| 63 | } | 64 | } |
| 64 | 65 | ||
| ... | @@ -89,6 +90,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption | ... | @@ -89,6 +90,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption |
| 89 | .clean_path = "../..", | 90 | .clean_path = "../..", |
| 90 | .yaml = m.yaml, | 91 | .yaml = m.yaml, |
| 91 | .dep = null, | 92 | .dep = null, |
| 93 | .min_zig_version = m.min_zig_version, | ||
| 92 | }; | 94 | }; |
| 93 | } | 95 | } |
| 94 | 96 | ||
| ... | @@ -239,6 +241,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO | ... | @@ -239,6 +241,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 239 | .yaml = null, | 241 | .yaml = null, |
| 240 | .dep = d.*, | 242 | .dep = d.*, |
| 241 | .for_build = d.for_build, | 243 | .for_build = d.for_build, |
| 244 | .min_zig_version = null, | ||
| 242 | }; | 245 | }; |
| 243 | }, | 246 | }, |
| 244 | else => { | 247 | else => { |
src/util/modfile.zig+2| ... | @@ -27,6 +27,7 @@ pub const ModFile = struct { | ... | @@ -27,6 +27,7 @@ pub const ModFile = struct { |
| 27 | files: []const string, | 27 | files: []const string, |
| 28 | rootdeps: []zigmod.Dep, | 28 | rootdeps: []zigmod.Dep, |
| 29 | builddeps: []zigmod.Dep, | 29 | builddeps: []zigmod.Dep, |
| 30 | min_zig_version: ?std.SemanticVersion, | ||
| 30 | 31 | ||
| 31 | pub fn init(alloc: std.mem.Allocator, mpath: string) !Self { | 32 | pub fn init(alloc: std.mem.Allocator, mpath: string) !Self { |
| 32 | const file = try std.fs.cwd().openFile(mpath, .{}); | 33 | const file = try std.fs.cwd().openFile(mpath, .{}); |
| ... | @@ -66,6 +67,7 @@ pub const ModFile = struct { | ... | @@ -66,6 +67,7 @@ pub const ModFile = struct { |
| 66 | .files = try mapping.get_string_array(alloc, "files"), | 67 | .files = try mapping.get_string_array(alloc, "files"), |
| 67 | .rootdeps = try dep_list_by_name(alloc, mapping, &.{ "dev_dependencies", "root_dependencies" }, false), | 68 | .rootdeps = try dep_list_by_name(alloc, mapping, &.{ "dev_dependencies", "root_dependencies" }, false), |
| 68 | .builddeps = try dep_list_by_name(alloc, mapping, &.{ "dev_dependencies", "build_dependencies" }, true), | 69 | .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, | ||
| 69 | }; | 71 | }; |
| 70 | } | 72 | } |
| 71 | 73 |
src/util/module.zig+15| ... | @@ -26,6 +26,7 @@ pub const Module = struct { | ... | @@ -26,6 +26,7 @@ pub const Module = struct { |
| 26 | clean_path: string, | 26 | clean_path: string, |
| 27 | dep: ?zigmod.Dep, | 27 | dep: ?zigmod.Dep, |
| 28 | for_build: bool = false, | 28 | for_build: bool = false, |
| 29 | min_zig_version: ?std.SemanticVersion, | ||
| 29 | 30 | ||
| 30 | pub fn from(alloc: std.mem.Allocator, dep: zigmod.Dep, modpath: string, options: *common.CollectOptions) !Module { | 31 | pub fn from(alloc: std.mem.Allocator, dep: zigmod.Dep, modpath: string, options: *common.CollectOptions) !Module { |
| 31 | var moddeps = std.ArrayList(Module).init(alloc); | 32 | var moddeps = std.ArrayList(Module).init(alloc); |
| ... | @@ -52,6 +53,7 @@ pub const Module = struct { | ... | @@ -52,6 +53,7 @@ pub const Module = struct { |
| 52 | .yaml = dep.yaml, | 53 | .yaml = dep.yaml, |
| 53 | .dep = dep, | 54 | .dep = dep, |
| 54 | .for_build = dep.for_build, | 55 | .for_build = dep.for_build, |
| 56 | .min_zig_version = null, | ||
| 55 | }; | 57 | }; |
| 56 | } | 58 | } |
| 57 | 59 | ||
| ... | @@ -134,4 +136,17 @@ pub const Module = struct { | ... | @@ -134,4 +136,17 @@ pub const Module = struct { |
| 134 | pub fn short_id(self: Module) string { | 136 | pub fn short_id(self: Module) string { |
| 135 | return u.slice(u8, self.id, 0, 12); | 137 | return u.slice(u8, self.id, 0, 12); |
| 136 | } | 138 | } |
| 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 | } | ||
| 137 | }; | 152 | }; |
zig.mod+1| ... | @@ -3,6 +3,7 @@ name: zigmod | ... | @@ -3,6 +3,7 @@ name: zigmod |
| 3 | main: src/lib.zig | 3 | main: src/lib.zig |
| 4 | license: MIT | 4 | license: MIT |
| 5 | description: A package manager for the Zig programming language. | 5 | description: A package manager for the Zig programming language. |
| 6 | min_zig_version: 0.9.0 | ||
| 6 | dependencies: | 7 | dependencies: |
| 7 | - src: git https://github.com/yaml/libyaml tag-0.2.5 | 8 | - src: git https://github.com/yaml/libyaml tag-0.2.5 |
| 8 | id: 8mdbh0zuneb0i3hs5jby5je0heem1i6yxusl7c8y8qx68hqc | 9 | id: 8mdbh0zuneb0i3hs5jby5je0heem1i6yxusl7c8y8qx68hqc |