authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-03-07 21:22:58 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-03-07 21:22:58 -08:00
log9e628ca44b6817ebda927de8d7974ff98d8f95b8
tree7c899c9c3cdcec321b665f79f27a0efa6fadf23a
parent1a078abb8e9727e98054e1f45bc49aac5a2ce5f8

add framework dep type, fixes #10


9 files changed, 53 insertions(+), 8 deletions(-)

deps.zig+6
...@@ -19,6 +19,11 @@ pub fn addAllTo(exe: *std.build.LibExeObjStep) void {...@@ -19,6 +19,11 @@ pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
19 exe.linkSystemLibrary(item);19 exe.linkSystemLibrary(item);
20 llc = true;20 llc = true;
21 }21 }
22 for (pkg.frameworks) |item| {
23 if (!std.Target.current.isDarwin()) @panic(exe.builder.fmt("a dependency is attempting to link to the framework {s}, which is only possible under Darwin", .{item}));
24 exe.linkFramework(item);
25 llc = true;
26 }
22 inline for (pkg.c_include_dirs) |item| {27 inline for (pkg.c_include_dirs) |item| {
23 exe.addIncludeDir(@field(dirs, decl.name) ++ "/" ++ item);28 exe.addIncludeDir(@field(dirs, decl.name) ++ "/" ++ item);
24 llc = true;29 llc = true;
...@@ -40,6 +45,7 @@ pub const Package = struct {...@@ -40,6 +45,7 @@ pub const Package = struct {
40 c_source_files: []const string = &.{},45 c_source_files: []const string = &.{},
41 c_source_flags: []const string = &.{},46 c_source_flags: []const string = &.{},
42 system_libs: []const string = &.{},47 system_libs: []const string = &.{},
48 frameworks: []const string = &.{},
43 vcpkg: bool = false,49 vcpkg: bool = false,
44};50};
4551
docs/deps.zig.md+1
...@@ -18,6 +18,7 @@ pub const Package = struct {...@@ -18,6 +18,7 @@ pub const Package = struct {
18 c_source_files: []const string = &.{},18 c_source_files: []const string = &.{},
19 c_source_flags: []const string = &.{},19 c_source_flags: []const string = &.{},
20 system_libs: []const string = &.{},20 system_libs: []const string = &.{},
21 frameworks: []const string = &.{},
21 vcpkg: bool = false,22 vcpkg: bool = false,
22};23};
23```24```
docs/tutorial.md+3
...@@ -63,6 +63,9 @@ The core of expandability, it is possible to add dependencies to your project. H...@@ -63,6 +63,9 @@ The core of expandability, it is possible to add dependencies to your project. H
63- Other/System Library63- Other/System Library
64 - System libraries are similar to Git dependencies, but instead of `git <url>` it is `system_lib <name>`.64 - System libraries are similar to Git dependencies, but instead of `git <url>` it is `system_lib <name>`.
6565
66- Other/Framework
67 - Frameworks are similar to system libraries but are specific to Darwin (macOS, iOS, etc) and are defined with `framework <name>`.
68
66- Other/HTTP69- Other/HTTP
67 - Http tarballs are also allowed and follow a similar pattern as Git dependencies but use the `http` type. One thing to note is that it is recomended to add a hash verification after your tarball URL so that zigmod may assert whether or not it has been downloaded already to prevent unnecessary trips to the network. Hash verification versions are placed after the URL and in the form `type-string` such as `sha256-8ff0b79fd9118af7a760f1f6a98cac3e69daed325c8f9f0a581ecb62f797fd64`. They may also be placed in their own `version` key instead of `src`. The available hash algorithms are `blake3`, `sha256`, `sha512`.70 - Http tarballs are also allowed and follow a similar pattern as Git dependencies but use the `http` type. One thing to note is that it is recomended to add a hash verification after your tarball URL so that zigmod may assert whether or not it has been downloaded already to prevent unnecessary trips to the network. Hash verification versions are placed after the URL and in the form `type-string` such as `sha256-8ff0b79fd9118af7a760f1f6a98cac3e69daed325c8f9f0a581ecb62f797fd64`. They may also be placed in their own `version` key instead of `src`. The available hash algorithms are `blake3`, `sha256`, `sha512`.
6871
docs/zig.mod.md+3
...@@ -77,6 +77,7 @@ This is the base attribute used to reference external code for use in your proje...@@ -77,6 +77,7 @@ This is the base attribute used to reference external code for use in your proje
77The available `type`s are:77The available `type`s are:
78- `local`78- `local`
79- `system_lib`79- `system_lib`
80- `framework`
80- `git`81- `git`
81- `hg`82- `hg`
82- `http`83- `http`
...@@ -94,6 +95,8 @@ This attribute is used to reference the `type`/`path` combo by a specific revisi...@@ -94,6 +95,8 @@ This attribute is used to reference the `type`/`path` combo by a specific revisi
94Version types available to each Dep type:95Version types available to each Dep type:
95- `system_lib`96- `system_lib`
96 - Not affected by `version`.97 - Not affected by `version`.
98- `framework`
99 - Not affected by `version`.
97- `git`100- `git`
98 - `commit`101 - `commit`
99 - `tag`102 - `tag`
src/cmd/fetch.zig+17-2
...@@ -66,6 +66,11 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D...@@ -66,6 +66,11 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
66 \\ exe.linkSystemLibrary(item);66 \\ exe.linkSystemLibrary(item);
67 \\ llc = true;67 \\ llc = true;
68 \\ }68 \\ }
69 \\ for (pkg.frameworks) |item| {
70 \\ if (!std.Target.current.isDarwin()) @panic(exe.builder.fmt("a dependency is attempting to link to the framework {s}, which is only possible under Darwin", .{item}));
71 \\ exe.linkFramework(item);
72 \\ llc = true;
73 \\ }
69 \\ inline for (pkg.c_include_dirs) |item| {74 \\ inline for (pkg.c_include_dirs) |item| {
70 \\ exe.addIncludeDir(@field(dirs, decl.name) ++ "/" ++ item);75 \\ exe.addIncludeDir(@field(dirs, decl.name) ++ "/" ++ item);
71 \\ llc = true;76 \\ llc = true;
...@@ -87,6 +92,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D...@@ -87,6 +92,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
87 \\ c_source_files: []const string = &.{},92 \\ c_source_files: []const string = &.{},
88 \\ c_source_flags: []const string = &.{},93 \\ c_source_flags: []const string = &.{},
89 \\ system_libs: []const string = &.{},94 \\ system_libs: []const string = &.{},
95 \\ frameworks: []const string = &.{},
90 \\ vcpkg: bool = false,96 \\ vcpkg: bool = false,
91 \\};97 \\};
92 \\98 \\
...@@ -109,7 +115,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D...@@ -109,7 +115,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
109 try w.writeAll("pub const package_data = struct {\n");115 try w.writeAll("pub const package_data = struct {\n");
110 var duped = std.ArrayList(zigmod.Module).init(alloc);116 var duped = std.ArrayList(zigmod.Module).init(alloc);
111 for (list.items) |mod| {117 for (list.items) |mod| {
112 if (mod.is_sys_lib) {118 if (mod.is_sys_lib or mod.is_framework) {
113 continue;119 continue;
114 }120 }
115 try duped.append(mod);121 try duped.append(mod);
...@@ -240,7 +246,7 @@ fn diff_printchange(comptime testt: string, comptime replacement: string, item:...@@ -240,7 +246,7 @@ fn diff_printchange(comptime testt: string, comptime replacement: string, item:
240246
241fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module) !void {247fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module) !void {
242 for (list) |mod| {248 for (list) |mod| {
243 if (mod.is_sys_lib) continue;249 if (mod.is_sys_lib or mod.is_framework) continue;
244 if (std.mem.eql(u8, mod.id, "root")) {250 if (std.mem.eql(u8, mod.id, "root")) {
245 try w.print(" pub const _root = \"\";\n", .{});251 try w.print(" pub const _root = \"\";\n", .{});
246 continue;252 continue;
...@@ -329,6 +335,15 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul...@@ -329,6 +335,15 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
329 }335 }
330 try w.writeAll(" },\n");336 try w.writeAll(" },\n");
331 }337 }
338 if (mod.has_framework_deps()) {
339 try w.writeAll(" .frameworks = &.{");
340 for (mod.deps) |item, j| {
341 if (!item.is_sys_lib) continue;
342 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)});
343 if (j != mod.deps.len - 1) try w.writeAll(",");
344 }
345 try w.writeAll(" },\n");
346 }
332 if (mod.vcpkg) {347 if (mod.vcpkg) {
333 try w.writeAll(" .vcpkg = true,\n");348 try w.writeAll(" .vcpkg = true,\n");
334 }349 }
src/cmd/sum.zig+1-1
...@@ -36,7 +36,7 @@ pub fn execute(args: [][]u8) !void {...@@ -36,7 +36,7 @@ pub fn execute(args: [][]u8) !void {
36 if (std.mem.eql(u8, m.clean_path, "../..")) {36 if (std.mem.eql(u8, m.clean_path, "../..")) {
37 continue;37 continue;
38 }38 }
39 if (m.is_sys_lib) continue;39 if (m.is_sys_lib or m.is_framework) continue;
40 const hash = try m.get_hash(cachepath);40 const hash = try m.get_hash(cachepath);
41 try w.print("{s} {s}\n", .{ hash, m.clean_path });41 try w.print("{s} {s}\n", .{ hash, m.clean_path });
42 }42 }
src/common.zig+6-3
...@@ -50,6 +50,7 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO...@@ -50,6 +50,7 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO
50 return zigmod.Module{50 return zigmod.Module{
51 .alloc = options.alloc,51 .alloc = options.alloc,
52 .is_sys_lib = false,52 .is_sys_lib = false,
53 .is_framework = false,
53 .id = "root",54 .id = "root",
54 .name = "root",55 .name = "root",
55 .main = m.main,56 .main = m.main,
...@@ -79,6 +80,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption...@@ -79,6 +80,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption
79 return zigmod.Module{80 return zigmod.Module{
80 .alloc = options.alloc,81 .alloc = options.alloc,
81 .is_sys_lib = false,82 .is_sys_lib = false,
83 .is_framework = false,
82 .id = m.id,84 .id = m.id,
83 .name = m.name,85 .name = m.name,
84 .main = m.main,86 .main = m.main,
...@@ -128,7 +130,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !...@@ -128,7 +130,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
128 }130 }
129 return d.path;131 return d.path;
130 },132 },
131 .system_lib => {133 .system_lib, .framework => {
132 // no op134 // no op
133 return "";135 return "";
134 },136 },
...@@ -227,10 +229,11 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO...@@ -227,10 +229,11 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
227 if (!nocache) try options.already_fetched.append(modpath);229 if (!nocache) try options.already_fetched.append(modpath);
228230
229 switch (d.type) {231 switch (d.type) {
230 .system_lib => {232 .system_lib, .framework => {
231 return zigmod.Module{233 return zigmod.Module{
232 .alloc = options.alloc,234 .alloc = options.alloc,
233 .is_sys_lib = true,235 .is_sys_lib = d.type == .system_lib,
236 .is_framework = d.type == .framework,
234 .id = try u.do_hash(options.alloc, std.crypto.hash.sha3.Sha3_384, d.path),237 .id = try u.do_hash(options.alloc, std.crypto.hash.sha3.Sha3_384, d.path),
235 .name = d.path,238 .name = d.path,
236 .only_os = d.only_os,239 .only_os = d.only_os,
src/util/dep_type.zig+5-2
...@@ -10,6 +10,7 @@ const u = @import("./index.zig");...@@ -10,6 +10,7 @@ const u = @import("./index.zig");
10pub const DepType = enum {10pub const DepType = enum {
11 local, // A 'package' derived from files in the same repository.11 local, // A 'package' derived from files in the same repository.
12 system_lib, // std.build.LibExeObjStep.linkSystemLibrary12 system_lib, // std.build.LibExeObjStep.linkSystemLibrary
13 framework, // std.build.LibExeObjStep.linkFramework
13 git, // https://git-scm.com/14 git, // https://git-scm.com/
14 hg, // https://www.mercurial-scm.org/15 hg, // https://www.mercurial-scm.org/
15 http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol16 http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
...@@ -36,6 +37,7 @@ pub const DepType = enum {...@@ -36,6 +37,7 @@ pub const DepType = enum {
36 switch (self) {37 switch (self) {
37 .local => {},38 .local => {},
38 .system_lib => {},39 .system_lib => {},
40 .framework => {},
39 .git => {41 .git => {
40 u.assert((try u.run_cmd(alloc, null, &.{ "git", "clone", "--recurse-submodules", rpath, dpath })) == 0, "git clone {s} failed", .{rpath});42 u.assert((try u.run_cmd(alloc, null, &.{ "git", "clone", "--recurse-submodules", rpath, dpath })) == 0, "git clone {s} failed", .{rpath});
41 },43 },
...@@ -56,13 +58,13 @@ pub const DepType = enum {...@@ -56,13 +58,13 @@ pub const DepType = enum {
56 }58 }
57 }59 }
5860
59 // zig fmt: on
60 pub fn update(self: DepType, alloc: std.mem.Allocator, dpath: string, rpath: string) !void {61 pub fn update(self: DepType, alloc: std.mem.Allocator, dpath: string, rpath: string) !void {
61 _ = rpath;62 _ = rpath;
6263
63 switch (self) {64 switch (self) {
64 .local => {},65 .local => {},
65 .system_lib => {},66 .system_lib => {},
67 .framework => {},
66 .git => {68 .git => {
67 u.assert((try u.run_cmd(alloc, dpath, &.{ "git", "fetch" })) == 0, "git fetch failed", .{});69 u.assert((try u.run_cmd(alloc, dpath, &.{ "git", "fetch" })) == 0, "git fetch failed", .{});
68 u.assert((try u.run_cmd(alloc, dpath, &.{ "git", "pull" })) == 0, "git pull failed", .{});70 u.assert((try u.run_cmd(alloc, dpath, &.{ "git", "pull" })) == 0, "git pull failed", .{});
...@@ -76,13 +78,13 @@ pub const DepType = enum {...@@ -76,13 +78,13 @@ pub const DepType = enum {
76 }78 }
77 }79 }
7880
79 // zig fmt: on
80 pub fn exact_version(self: DepType, alloc: std.mem.Allocator, mpath: string) !string {81 pub fn exact_version(self: DepType, alloc: std.mem.Allocator, mpath: string) !string {
81 var mdir = try std.fs.cwd().openDir(mpath, .{});82 var mdir = try std.fs.cwd().openDir(mpath, .{});
82 defer mdir.close();83 defer mdir.close();
83 return switch (self) {84 return switch (self) {
84 .local => "",85 .local => "",
85 .system_lib => "",86 .system_lib => "",
87 .framework => "",
86 .git => try std.fmt.allocPrint(alloc, "commit-{s}", .{(try u.git_rev_HEAD(alloc, mdir))}),88 .git => try std.fmt.allocPrint(alloc, "commit-{s}", .{(try u.git_rev_HEAD(alloc, mdir))}),
87 .hg => "",89 .hg => "",
88 .http => "",90 .http => "",
...@@ -93,6 +95,7 @@ pub const DepType = enum {...@@ -93,6 +95,7 @@ pub const DepType = enum {
93 return switch (self) {95 return switch (self) {
94 .local => true,96 .local => true,
95 .system_lib => true,97 .system_lib => true,
98 .framework => true,
96 .git => false,99 .git => false,
97 .hg => false,100 .hg => false,
98 .http => false,101 .http => false,
src/util/module.zig+11
...@@ -13,6 +13,7 @@ const common = @import("./../common.zig");...@@ -13,6 +13,7 @@ const common = @import("./../common.zig");
13pub const Module = struct {13pub const Module = struct {
14 alloc: std.mem.Allocator,14 alloc: std.mem.Allocator,
15 is_sys_lib: bool,15 is_sys_lib: bool,
16 is_framework: bool,
16 id: string,17 id: string,
17 name: string,18 name: string,
18 main: string,19 main: string,
...@@ -41,6 +42,7 @@ pub const Module = struct {...@@ -41,6 +42,7 @@ pub const Module = struct {
41 return Module{42 return Module{
42 .alloc = alloc,43 .alloc = alloc,
43 .is_sys_lib = false,44 .is_sys_lib = false,
45 .is_framework = false,
44 .id = if (dep.id.len > 0) dep.id else try u.random_string(alloc, 48),46 .id = if (dep.id.len > 0) dep.id else try u.random_string(alloc, 48),
45 .name = dep.name,47 .name = dep.name,
46 .main = dep.main,48 .main = dep.main,
...@@ -125,6 +127,15 @@ pub const Module = struct {...@@ -125,6 +127,15 @@ pub const Module = struct {
125 return false;127 return false;
126 }128 }
127129
130 pub fn has_framework_deps(self: Module) bool {
131 for (self.deps) |d| {
132 if (d.is_framework) {
133 return true;
134 }
135 }
136 return false;
137 }
138
128 pub fn short_id(self: Module) string {139 pub fn short_id(self: Module) string {
129 return u.slice(u8, self.id, 0, 12);140 return u.slice(u8, self.id, 0, 12);
130 }141 }