| author | |
| committer | |
| log | 7a2ee7e11cbe1b982d5a9f916d3da50619ae68bb |
| tree | 9bfdea4fe6bd07189318335db16143df13391960 |
| parent | c46ba2b2421043f61b7eccce131aa4b1fc75d264 |
6 files changed, 81 insertions(+), 1 deletions(-)
README.md+2-1| ... | @@ -53,6 +53,7 @@ zigmod add <type> <path> | ... | @@ -53,6 +53,7 @@ zigmod add <type> <path> |
| 53 | --> | 53 | --> |
| 54 | 54 | ||
| 55 | #### Available types | 55 | #### Available types |
| 56 | - `system_lib` | ||
| 56 | - `git` | 57 | - `git` |
| 57 | - `hg` | 58 | - `hg` |
| 58 | 59 | ||
| ... | @@ -102,7 +103,7 @@ pub fn build(b: *Builder) void { | ... | @@ -102,7 +103,7 @@ pub fn build(b: *Builder) void { |
| 102 | #### Dep object | 103 | #### Dep object |
| 103 | | Name | Type | Note | Description | | 104 | | Name | Type | Note | Description | |
| 104 | |------|------|------|-------------| | 105 | |------|------|------|-------------| |
| 105 | | `type` | `string` | required, enum | One of `git`, `hg` | | 106 | | `type` | `string` | required, enum | One of `system_lib`, `git`, `hg` | |
| 106 | | `path` | `string` | required | URL/path to this dependency. depends on the type | | 107 | | `path` | `string` | required | URL/path to this dependency. depends on the type | |
| 107 | | `version` | `string` | only on some types | pin this dependency at a specific version | | 108 | | `version` | `string` | only on some types | pin this dependency at a specific version | |
| 108 | | `only_os` | `string` | | comma separated list of OS names to add this Dep to | | 109 | | `only_os` | `string` | | comma separated list of OS names to add this Dep to | |
src/cmd_fetch.zig+47| ... | @@ -40,6 +40,9 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -40,6 +40,9 @@ pub fn execute(args: [][]u8) !void { |
| 40 | \\ inline for (c_source_files) |fpath| { | 40 | \\ inline for (c_source_files) |fpath| { |
| 41 | \\ exe.addCSourceFile(fpath[1], @field(c_source_flags, fpath[0])); | 41 | \\ exe.addCSourceFile(fpath[1], @field(c_source_flags, fpath[0])); |
| 42 | \\ } | 42 | \\ } |
| 43 | \\ for (system_libs) |lib| { | ||
| 44 | \\ exe.linkSystemLibrary(lib); | ||
| 45 | \\ } | ||
| 43 | \\} | 46 | \\} |
| 44 | \\ | 47 | \\ |
| 45 | \\fn get_flags(comptime index: usize) []const u8 { | 48 | \\fn get_flags(comptime index: usize) []const u8 { |
| ... | @@ -62,6 +65,11 @@ pub fn execute(args: [][]u8) !void { | ... | @@ -62,6 +65,11 @@ pub fn execute(args: [][]u8) !void { |
| 62 | try w.print("{}\n", .{"pub const c_source_files = &[_][2][]const u8{"}); | 65 | try w.print("{}\n", .{"pub const c_source_files = &[_][2][]const u8{"}); |
| 63 | try print_csrc_dirs_to(w, top_module, &std.ArrayList([]const u8).init(gpa), true); | 66 | try print_csrc_dirs_to(w, top_module, &std.ArrayList([]const u8).init(gpa), true); |
| 64 | try w.print("{};\n", .{"}"}); | 67 | try w.print("{};\n", .{"}"}); |
| 68 | try w.print("\n", .{}); | ||
| 69 | try w.print("{}\n", .{"pub const system_libs = &[_][]const u8{"}); | ||
| 70 | try print_sys_libs_to(w, top_module, &std.ArrayList([]const u8).init(gpa), &std.ArrayList([]const u8).init(gpa)); | ||
| 71 | try w.print("{};\n", .{"}"}); | ||
| 72 | |||
| 65 | } | 73 | } |
| 66 | 74 | ||
| 67 | fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | 75 | fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| ... | @@ -74,6 +82,9 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -74,6 +82,9 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 74 | u.print("fetch: {}: {}: {}", .{m.name, @tagName(d.type), d.path}); | 82 | u.print("fetch: {}: {}: {}", .{m.name, @tagName(d.type), d.path}); |
| 75 | moddir = p; | 83 | moddir = p; |
| 76 | switch (d.type) { | 84 | switch (d.type) { |
| 85 | .system_lib => { | ||
| 86 | // no op | ||
| 87 | }, | ||
| 77 | .git => blk: { | 88 | .git => blk: { |
| 78 | if (!try u.does_file_exist(p)) { | 89 | if (!try u.does_file_exist(p)) { |
| 79 | _ = try d.type.pull(d.path, p); | 90 | _ = try d.type.pull(d.path, p); |
| ... | @@ -121,6 +132,20 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -121,6 +132,20 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 121 | }, | 132 | }, |
| 122 | } | 133 | } |
| 123 | switch (d.type) { | 134 | switch (d.type) { |
| 135 | .system_lib => { | ||
| 136 | if (d.is_for_this()) try moduledeps.append(u.Module{ | ||
| 137 | .is_sys_lib = true, | ||
| 138 | .name = d.path, | ||
| 139 | .only_os = d.only_os, | ||
| 140 | .except_os = d.except_os, | ||
| 141 | .main = "", | ||
| 142 | .c_include_dirs = &[_][]const u8{}, | ||
| 143 | .c_source_flags = &[_][]const u8{}, | ||
| 144 | .c_source_files = &[_][]const u8{}, | ||
| 145 | .deps = &[_]u.Module{}, | ||
| 146 | .clean_path = "", | ||
| 147 | }); | ||
| 148 | }, | ||
| 124 | else => blk: { | 149 | else => blk: { |
| 125 | var dd = try fetch_deps(dir, try u.concat(&[_][]const u8{moddir, "/zig.mod"})) catch |e| switch (e) { | 150 | var dd = try fetch_deps(dir, try u.concat(&[_][]const u8{moddir, "/zig.mod"})) catch |e| switch (e) { |
| 126 | error.FileNotFound => { | 151 | error.FileNotFound => { |
| ... | @@ -148,6 +173,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -148,6 +173,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 148 | } | 173 | } |
| 149 | } | 174 | } |
| 150 | return u.Module{ | 175 | return u.Module{ |
| 176 | .is_sys_lib = false, | ||
| 151 | .name = m.name, | 177 | .name = m.name, |
| 152 | .main = m.main, | 178 | .main = m.main, |
| 153 | .c_include_dirs = m.c_include_dirs, | 179 | .c_include_dirs = m.c_include_dirs, |
| ... | @@ -196,6 +222,7 @@ fn print_incl_dirs_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]c | ... | @@ -196,6 +222,7 @@ fn print_incl_dirs_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]c |
| 196 | } | 222 | } |
| 197 | } | 223 | } |
| 198 | for (mod.deps) |d| { | 224 | for (mod.deps) |d| { |
| 225 | if (d.is_sys_lib) continue; | ||
| 199 | try print_incl_dirs_to(w, d, list, false); | 226 | try print_incl_dirs_to(w, d, list, false); |
| 200 | } | 227 | } |
| 201 | } | 228 | } |
| ... | @@ -213,6 +240,7 @@ fn print_csrc_dirs_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]c | ... | @@ -213,6 +240,7 @@ fn print_csrc_dirs_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]c |
| 213 | } | 240 | } |
| 214 | } | 241 | } |
| 215 | for (mod.deps) |d| { | 242 | for (mod.deps) |d| { |
| 243 | if (d.is_sys_lib) continue; | ||
| 216 | try print_csrc_dirs_to(w, d, list, false); | 244 | try print_csrc_dirs_to(w, d, list, false); |
| 217 | } | 245 | } |
| 218 | } | 246 | } |
| ... | @@ -233,6 +261,25 @@ fn print_csrc_flags_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([] | ... | @@ -233,6 +261,25 @@ fn print_csrc_flags_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([] |
| 233 | try w.print("{};\n", .{"}"}); | 261 | try w.print("{};\n", .{"}"}); |
| 234 | } | 262 | } |
| 235 | for (mod.deps) |d| { | 263 | for (mod.deps) |d| { |
| 264 | if (d.is_sys_lib) continue; | ||
| 236 | try print_csrc_flags_to(w, d, list, false); | 265 | try print_csrc_flags_to(w, d, list, false); |
| 237 | } | 266 | } |
| 238 | } | 267 | } |
| 268 | |||
| 269 | fn print_sys_libs_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]const u8), list2: *std.ArrayList([]const u8)) anyerror!void { | ||
| 270 | if (u.list_contains(list.items, mod.clean_path)) { | ||
| 271 | return; | ||
| 272 | } | ||
| 273 | try list.append(mod.clean_path); | ||
| 274 | // | ||
| 275 | for (mod.deps) |d| { | ||
| 276 | if (!d.is_sys_lib) continue; | ||
| 277 | // | ||
| 278 | if (!u.list_contains(list2.items, d.name)) { | ||
| 279 | try w.print(" \"{}\",\n", .{d.name}); | ||
| 280 | try list2.append(d.name); | ||
| 281 | } | ||
| 282 | // | ||
| 283 | try print_sys_libs_to(w, d, list, list2); | ||
| 284 | } | ||
| 285 | } |
src/common.zig+15| ... | @@ -21,6 +21,20 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -21,6 +21,20 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 21 | moddir = p; | 21 | moddir = p; |
| 22 | } | 22 | } |
| 23 | switch (d.type) { | 23 | switch (d.type) { |
| 24 | .system_lib => { | ||
| 25 | if (d.is_for_this()) try moduledeps.append(u.Module{ | ||
| 26 | .is_sys_lib = true, | ||
| 27 | .name = d.path, | ||
| 28 | .only_os = d.only_os, | ||
| 29 | .except_os = d.except_os, | ||
| 30 | .main = "", | ||
| 31 | .c_include_dirs = &[_][]const u8{}, | ||
| 32 | .c_source_flags = &[_][]const u8{}, | ||
| 33 | .c_source_files = &[_][]const u8{}, | ||
| 34 | .deps = &[_]u.Module{}, | ||
| 35 | .clean_path = "", | ||
| 36 | }); | ||
| 37 | }, | ||
| 24 | else => blk: { | 38 | else => blk: { |
| 25 | var dd = try collect_deps(dir, try u.concat(&[_][]const u8{moddir, "/zig.mod"})) catch |e| switch (e) { | 39 | var dd = try collect_deps(dir, try u.concat(&[_][]const u8{moddir, "/zig.mod"})) catch |e| switch (e) { |
| 26 | error.FileNotFound => { | 40 | error.FileNotFound => { |
| ... | @@ -48,6 +62,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { | ... | @@ -48,6 +62,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 48 | } | 62 | } |
| 49 | } | 63 | } |
| 50 | return u.Module{ | 64 | return u.Module{ |
| 65 | .is_sys_lib = false, | ||
| 51 | .name = m.name, | 66 | .name = m.name, |
| 52 | .main = m.main, | 67 | .main = m.main, |
| 53 | .c_include_dirs = m.c_include_dirs, | 68 | .c_include_dirs = m.c_include_dirs, |
src/util/dep.zig+12| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const gpa = std.heap.c_allocator; | 2 | const gpa = std.heap.c_allocator; |
| 3 | const builtin = @import("builtin"); | ||
| 3 | 4 | ||
| 4 | const u = @import("index.zig"); | 5 | const u = @import("index.zig"); |
| 5 | 6 | ||
| ... | @@ -29,4 +30,15 @@ pub const Dep = struct { | ... | @@ -29,4 +30,15 @@ pub const Dep = struct { |
| 29 | p = try std.fmt.allocPrint(gpa, "{}{}{}", .{@tagName(self.type), "/", p}); | 30 | p = try std.fmt.allocPrint(gpa, "{}{}{}", .{@tagName(self.type), "/", p}); |
| 30 | return p; | 31 | return p; |
| 31 | } | 32 | } |
| 33 | |||
| 34 | pub fn is_for_this(self: Dep) bool { | ||
| 35 | const os = @tagName(builtin.os.tag); | ||
| 36 | if (self.only_os.len > 0) { | ||
| 37 | return u.list_contains(self.only_os, os); | ||
| 38 | } | ||
| 39 | if (self.except_os.len > 0) { | ||
| 40 | return !u.list_contains(self.except_os, os); | ||
| 41 | } | ||
| 42 | return true; | ||
| 43 | } | ||
| 32 | }; | 44 | }; |
src/util/dep_type.zig+3| ... | @@ -4,11 +4,13 @@ const u = @import("./index.zig"); | ... | @@ -4,11 +4,13 @@ const u = @import("./index.zig"); |
| 4 | // | 4 | // |
| 5 | 5 | ||
| 6 | pub const DepType = enum { | 6 | pub const DepType = enum { |
| 7 | system_lib, // std.build.LibExeObjStep.linkSystemLibrary | ||
| 7 | git, // https://git-scm.com/ | 8 | git, // https://git-scm.com/ |
| 8 | hg, // https://www.mercurial-scm.org/ | 9 | hg, // https://www.mercurial-scm.org/ |
| 9 | 10 | ||
| 10 | pub fn pull(self: DepType, rpath: []const u8, dpath: []const u8) !void { | 11 | pub fn pull(self: DepType, rpath: []const u8, dpath: []const u8) !void { |
| 11 | switch (self) { | 12 | switch (self) { |
| 13 | .system_lib => {}, | ||
| 12 | .git => { | 14 | .git => { |
| 13 | _ = try u.run_cmd(null, &[_][]const u8{"git", "clone", rpath, dpath}); | 15 | _ = try u.run_cmd(null, &[_][]const u8{"git", "clone", rpath, dpath}); |
| 14 | }, | 16 | }, |
| ... | @@ -21,6 +23,7 @@ pub const DepType = enum { | ... | @@ -21,6 +23,7 @@ pub const DepType = enum { |
| 21 | 23 | ||
| 22 | pub fn update(self: DepType, dpath: []const u8, rpath: []const u8) !void { | 24 | pub fn update(self: DepType, dpath: []const u8, rpath: []const u8) !void { |
| 23 | switch (self) { | 25 | switch (self) { |
| 26 | .system_lib => {}, | ||
| 24 | .git => { | 27 | .git => { |
| 25 | _ = try u.run_cmd(dpath, &[_][]const u8{"git", "fetch"}); | 28 | _ = try u.run_cmd(dpath, &[_][]const u8{"git", "fetch"}); |
| 26 | _ = try u.run_cmd(dpath, &[_][]const u8{"git", "pull"}); | 29 | _ = try u.run_cmd(dpath, &[_][]const u8{"git", "pull"}); |
src/util/module.zig+2| ... | @@ -12,6 +12,7 @@ const kb = b * 1024; | ... | @@ -12,6 +12,7 @@ const kb = b * 1024; |
| 12 | const mb = kb * 1024; | 12 | const mb = kb * 1024; |
| 13 | 13 | ||
| 14 | pub const Module = struct { | 14 | pub const Module = struct { |
| 15 | is_sys_lib: bool, | ||
| 15 | name: []const u8, | 16 | name: []const u8, |
| 16 | main: []const u8, | 17 | main: []const u8, |
| 17 | c_include_dirs: [][]const u8, | 18 | c_include_dirs: [][]const u8, |
| ... | @@ -25,6 +26,7 @@ pub const Module = struct { | ... | @@ -25,6 +26,7 @@ pub const Module = struct { |
| 25 | 26 | ||
| 26 | pub fn from(dep: u.Dep) !Module { | 27 | pub fn from(dep: u.Dep) !Module { |
| 27 | return Module{ | 28 | return Module{ |
| 29 | .is_sys_lib = false, | ||
| 28 | .name = dep.name, | 30 | .name = dep.name, |
| 29 | .main = dep.main, | 31 | .main = dep.main, |
| 30 | .c_include_dirs = dep.c_include_dirs, | 32 | .c_include_dirs = dep.c_include_dirs, |