authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-07 00:30:48 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-07 00:30:48 -07:00
log0bf546d95cb27488eadc3a6d3e389da9eed272ef
tree2363d831ccf1a71f6f166570eb6d707b7d782bf4
parentf3827eb95bff4b93a243e8e6cffd18a486a5b26c

rework `deps.zig` format


4 files changed, 229 insertions(+), 257 deletions(-)

deps.zig+89-76
...@@ -1,103 +1,116 @@...@@ -1,103 +1,116 @@
1const std = @import("std");1const std = @import("std");
2const Pkg = std.build.Pkg;2const Pkg = std.build.Pkg;
3const FileSource = std.build.FileSource;3const string = []const u8;
44
5pub const cache = ".zigmod/deps";5pub const cache = ".zigmod/deps";
66
7pub fn addAllTo(exe: *std.build.LibExeObjStep) void {7pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
8 @setEvalBranchQuota(1_000_000);8 @setEvalBranchQuota(1_000_000);
9 for (packages) |pkg| {9 for (packages) |pkg| {
10 exe.addPackage(pkg);10 exe.addPackage(pkg.pkg.?);
11 }11 }
12 if (c_include_dirs.len > 0 or c_source_files.len > 0) {12 inline for (std.meta.declarations(package_data)) |decl| {
13 exe.linkLibC();13 const pkg = @as(Package, @field(package_data, decl.name));
14 }14 var llc = false;
15 for (c_include_dirs) |dir| {15 inline for (pkg.system_libs) |item| {
16 exe.addIncludeDir(dir);16 exe.linkSystemLibrary(item);
17 }17 llc = true;
18 inline for (c_source_files) |fpath| {18 }
19 exe.addCSourceFile(fpath[1], @field(c_source_flags, fpath[0]));19 inline for (pkg.c_include_dirs) |item| {
20 }20 exe.addIncludeDir(@field(dirs, decl.name) ++ "/" ++ item);
21 for (system_libs) |lib| {21 llc = true;
22 exe.linkSystemLibrary(lib);22 }
23 inline for (pkg.c_source_files) |item| {
24 exe.addCSourceFile(@field(dirs, decl.name) ++ "/" ++ item, pkg.c_source_flags);
25 llc = true;
26 }
27 if (llc) {
28 exe.linkLibC();
29 }
23 }30 }
24}31}
2532
26fn get_flags(comptime index: usize) []const u8 {33pub const Package = struct {
27 return @field(c_source_flags, _paths[index]);34 pkg: ?Pkg = null,
28}35 c_include_dirs: []const string = &.{},
2936 c_source_files: []const string = &.{},
30pub const _ids = .{37 c_source_flags: []const string = &.{},
31 "89ujp8gq842x",38 system_libs: []const string = &.{},
32 "8mdbh0zuneb0",
33 "s84v9o48ucb0",
34 "2ta738wrqbaq",
35 "0npcrzfdlrvk",
36 "ejw82j2ipa0e",
37 "9k24gimke1an",
38 "csbnipaad8n7",
39 "yyhw90zkzgmu",
40 "u9w9dpp6p804",
41 "ocmr9rtohgcc",
42 "tnj3qf44tpeq",
43};39};
4440
45pub const _paths = .{41pub const dirs = struct {
46 "/../../",42 pub const _89ujp8gq842x = cache ++ "/../..";
47 "/v/git/github.com/yaml/libyaml/tag-0.2.5/",43 pub const _8mdbh0zuneb0 = cache ++ "/v/git/github.com/yaml/libyaml/tag-0.2.5";
48 "/git/github.com/nektro/zig-ansi/",44 pub const _s84v9o48ucb0 = cache ++ "/git/github.com/nektro/zig-ansi";
49 "/git/github.com/ziglibs/known-folders/",45 pub const _2ta738wrqbaq = cache ++ "/git/github.com/ziglibs/known-folders";
50 "/git/github.com/nektro/zig-licenses/",46 pub const _0npcrzfdlrvk = cache ++ "/git/github.com/nektro/zig-licenses";
51 "/git/github.com/truemedian/zfetch/",47 pub const _ejw82j2ipa0e = cache ++ "/git/github.com/truemedian/zfetch";
52 "/git/github.com/truemedian/hzzp/",48 pub const _9k24gimke1an = cache ++ "/git/github.com/truemedian/hzzp";
53 "/git/github.com/alexnask/iguanaTLS/",49 pub const _csbnipaad8n7 = cache ++ "/git/github.com/alexnask/iguanaTLS";
54 "/git/github.com/MasterQ32/zig-network/",50 pub const _yyhw90zkzgmu = cache ++ "/git/github.com/MasterQ32/zig-network";
55 "/git/github.com/MasterQ32/zig-uri/",51 pub const _u9w9dpp6p804 = cache ++ "/git/github.com/MasterQ32/zig-uri";
56 "/git/github.com/nektro/zig-json/",52 pub const _ocmr9rtohgcc = cache ++ "/git/github.com/nektro/zig-json";
57 "/git/github.com/nektro/zig-range/",53 pub const _tnj3qf44tpeq = cache ++ "/git/github.com/nektro/zig-range";
58};54};
5955
60pub const package_data = struct {56pub const package_data = struct {
61 pub const _s84v9o48ucb0 = Pkg{ .name = "ansi", .path = FileSource{ .path = cache ++ "/git/github.com/nektro/zig-ansi/src/lib.zig" }, .dependencies = &[_]Pkg{ } };57 pub const _8mdbh0zuneb0 = Package{
62 pub const _2ta738wrqbaq = Pkg{ .name = "known-folders", .path = FileSource{ .path = cache ++ "/git/github.com/ziglibs/known-folders/known-folders.zig" }, .dependencies = &[_]Pkg{ } };58 .c_include_dirs = &.{ "include" },
63 pub const _0npcrzfdlrvk = Pkg{ .name = "licenses", .path = FileSource{ .path = cache ++ "/git/github.com/nektro/zig-licenses/src/lib.zig" }, .dependencies = &[_]Pkg{ } };59 .c_source_files = &.{ "src/api.c", "src/dumper.c", "src/emitter.c", "src/loader.c", "src/parser.c", "src/reader.c", "src/scanner.c", "src/writer.c" },
64 pub const _9k24gimke1an = Pkg{ .name = "hzzp", .path = FileSource{ .path = cache ++ "/git/github.com/truemedian/hzzp/src/main.zig" }, .dependencies = &[_]Pkg{ } };60 .c_source_flags = &.{ "-DYAML_VERSION_MAJOR=0", "-DYAML_VERSION_MINOR=2", "-DYAML_VERSION_PATCH=5", "-DYAML_VERSION_STRING=\"0.2.5\"", "-DYAML_DECLARE_STATIC=1" },
65 pub const _csbnipaad8n7 = Pkg{ .name = "iguanaTLS", .path = FileSource{ .path = cache ++ "/git/github.com/alexnask/iguanaTLS/src/main.zig" }, .dependencies = &[_]Pkg{ } };61 };
66 pub const _yyhw90zkzgmu = Pkg{ .name = "network", .path = FileSource{ .path = cache ++ "/git/github.com/MasterQ32/zig-network/network.zig" }, .dependencies = &[_]Pkg{ } };
67 pub const _u9w9dpp6p804 = Pkg{ .name = "uri", .path = FileSource{ .path = cache ++ "/git/github.com/MasterQ32/zig-uri/uri.zig" }, .dependencies = &[_]Pkg{ } };
68 pub const _ejw82j2ipa0e = Pkg{ .name = "zfetch", .path = FileSource{ .path = cache ++ "/git/github.com/truemedian/zfetch/src/main.zig" }, .dependencies = &[_]Pkg{ _9k24gimke1an, _csbnipaad8n7, _yyhw90zkzgmu, _u9w9dpp6p804, } };
69 pub const _ocmr9rtohgcc = Pkg{ .name = "json", .path = FileSource{ .path = cache ++ "/git/github.com/nektro/zig-json/src/lib.zig" }, .dependencies = &[_]Pkg{ } };
70 pub const _tnj3qf44tpeq = Pkg{ .name = "range", .path = FileSource{ .path = cache ++ "/git/github.com/nektro/zig-range/src/lib.zig" }, .dependencies = &[_]Pkg{ } };
71 pub const _89ujp8gq842x = Pkg{ .name = "zigmod", .path = FileSource{ .path = cache ++ "/../../src/lib.zig" }, .dependencies = &[_]Pkg{ _s84v9o48ucb0, _2ta738wrqbaq, _0npcrzfdlrvk, _ejw82j2ipa0e, _ocmr9rtohgcc, _tnj3qf44tpeq, } };
72};
7362
74pub const packages = &[_]Pkg{63 pub const _s84v9o48ucb0 = Package{
75 package_data._89ujp8gq842x,64 .pkg = Pkg{ .name = "ansi", .path = .{ .path = dirs._s84v9o48ucb0 ++ "/src/lib.zig" }, .dependencies = null },
76};65 };
7766
78pub const pkgs = struct {67 pub const _2ta738wrqbaq = Package{
79 pub const zigmod = packages[0];68 .pkg = Pkg{ .name = "known-folders", .path = .{ .path = dirs._2ta738wrqbaq ++ "/known-folders.zig" }, .dependencies = null },
80};69 };
8170
82pub const c_include_dirs = &[_][]const u8{71 pub const _0npcrzfdlrvk = Package{
83 cache ++ _paths[1] ++ "include",72 .pkg = Pkg{ .name = "licenses", .path = .{ .path = dirs._0npcrzfdlrvk ++ "/src/lib.zig" }, .dependencies = null },
84};73 };
74
75 pub const _9k24gimke1an = Package{
76 .pkg = Pkg{ .name = "hzzp", .path = .{ .path = dirs._9k24gimke1an ++ "/src/main.zig" }, .dependencies = null },
77 };
78
79 pub const _csbnipaad8n7 = Package{
80 .pkg = Pkg{ .name = "iguanaTLS", .path = .{ .path = dirs._csbnipaad8n7 ++ "/src/main.zig" }, .dependencies = null },
81 };
82
83 pub const _yyhw90zkzgmu = Package{
84 .pkg = Pkg{ .name = "network", .path = .{ .path = dirs._yyhw90zkzgmu ++ "/network.zig" }, .dependencies = null },
85 };
86
87 pub const _u9w9dpp6p804 = Package{
88 .pkg = Pkg{ .name = "uri", .path = .{ .path = dirs._u9w9dpp6p804 ++ "/uri.zig" }, .dependencies = null },
89 };
90
91 pub const _ejw82j2ipa0e = Package{
92 .pkg = Pkg{ .name = "zfetch", .path = .{ .path = dirs._ejw82j2ipa0e ++ "/src/main.zig" }, .dependencies = &.{ _9k24gimke1an.pkg.?, _csbnipaad8n7.pkg.?, _yyhw90zkzgmu.pkg.?, _u9w9dpp6p804.pkg.? } },
93 };
94
95 pub const _ocmr9rtohgcc = Package{
96 .pkg = Pkg{ .name = "json", .path = .{ .path = dirs._ocmr9rtohgcc ++ "/src/lib.zig" }, .dependencies = null },
97 };
98
99 pub const _tnj3qf44tpeq = Package{
100 .pkg = Pkg{ .name = "range", .path = .{ .path = dirs._tnj3qf44tpeq ++ "/src/lib.zig" }, .dependencies = null },
101 };
102
103 pub const _89ujp8gq842x = Package{
104 .pkg = Pkg{ .name = "zigmod", .path = .{ .path = dirs._89ujp8gq842x ++ "/src/lib.zig" }, .dependencies = &.{ _s84v9o48ucb0.pkg.?, _2ta738wrqbaq.pkg.?, _0npcrzfdlrvk.pkg.?, _ejw82j2ipa0e.pkg.?, _ocmr9rtohgcc.pkg.?, _tnj3qf44tpeq.pkg.? } },
105 };
85106
86pub const c_source_flags = struct {
87 pub const @"8mdbh0zuneb0" = &.{"-DYAML_VERSION_MAJOR=0","-DYAML_VERSION_MINOR=2","-DYAML_VERSION_PATCH=5","-DYAML_VERSION_STRING=\"0.2.5\"","-DYAML_DECLARE_STATIC=1",};
88};107};
89108
90pub const c_source_files = &[_][2][]const u8{109pub const packages = &[_]Package{
91 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/api.c"},110 package_data._89ujp8gq842x,
92 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/dumper.c"},
93 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/emitter.c"},
94 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/loader.c"},
95 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/parser.c"},
96 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/reader.c"},
97 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/scanner.c"},
98 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/writer.c"},
99};111};
100112
101pub const system_libs = &[_][]const u8{113pub const pkgs = struct {
114 pub const zigmod = package_data._89ujp8gq842x;
102};115};
103116
docs/deps.zig.md+19-32
...@@ -9,42 +9,29 @@ The relative path root to which all dependency sources are saved. Currently alwa...@@ -9,42 +9,29 @@ The relative path root to which all dependency sources are saved. Currently alwa
9- Type: `pub fn (exe: *std.build.LibExeObjStep) void`9- Type: `pub fn (exe: *std.build.LibExeObjStep) void`
10A helper function to add all of the packages, C files, and system libraries to the passed exectuable. It will also automatically link libC in the event that any C files are found in the dependency tree.10A helper function to add all of the packages, C files, and system libraries to the passed exectuable. It will also automatically link libC in the event that any C files are found in the dependency tree.
1111
12### `_ids`12### `Package`
13- Type: `[][]const u8`13```zig
14A comptime-known string array of all of the [ID's](zig.mod.md#id) used in this project.14pub const Package = struct {
15 pkg: ?Pkg = null,
16 c_include_dirs: []const string = &.{},
17 c_source_files: []const string = &.{},
18 c_source_flags: []const string = &.{},
19 system_libs: []const string = &.{},
20};
21```
1522
16### `_paths`23### `dirs`
17- Type: `[][]const u8`24- Type: `struct<ID, []const u8>`
18A comptime-known string array of the source paths to each dependency relative to `cache`.25A comptime-known string array of the package directories for each dependency relative to the project root.
1926
20### `package_data`27### `package_data`
21- Type: `struct<ID, std.build.Pkg>`28- Type: `struct<ID, Package>`
22This is a meta struct that associates ID's to their relavant `std.build.Pkg` initialization, complete with sub-packages and all.29This is a meta struct that associates ID's to their relavant `Package` definition.
2330
24### `packages`31### `packages`
25- Type: `[]std.build.Pkg`32- Type: `[]Package`
26This is a an array of all of the items in `package_data`, but able to be referenced by index, rather than package ID.33This is a an array of all of the items in `package_data`, but only contains the final versions of `dev_dependencies`.
2734
28### `pkgs`35### `pkgs`
29- Type: `struct<NAME, std.build.Pkg>`36- Type: `struct<NAME, Package>`
30This is a struct that associates the package name to the relavant `std.build.Pkg`. The only packages listed are the dependencies of the root project. Additionally, the data here can be referenced to use dependencies at build time in `build.zig` through importing the path of the project like so:37This is a struct that associates the package name to the relavant `Package`. The only packages listed are the dependencies of the root project.
31```zig
32const deps = @import("./deps.zig");
33const my_dev_dep = @import(deps.pkgs.my_dev_dep.path);
34```
35
36### `c_include_dirs`
37- Type: `[][]const u8`
38An ensembled list of all the `c_include_dirs` lists.
39
40### `c_source_flags`
41- Type: `struct<ID, []const u8>`
42An ensembled list of all the `c_source_flags` lists.
43
44### `c_source_files`
45- Type: `[][2][]const u8`
46An ensembled list of all the `c_source_files` lists.
47
48### `system_libs`
49- Type: `[][]const u8`
50An ensembled list of all the `system_libs` lists.
src/cmd/fetch.zig+112-149
...@@ -34,7 +34,7 @@ pub fn create_depszig(dir: []const u8, top_module: u.Module, list: *std.ArrayLis...@@ -34,7 +34,7 @@ pub fn create_depszig(dir: []const u8, top_module: u.Module, list: *std.ArrayLis
34 const w = f.writer();34 const w = f.writer();
35 try w.writeAll("const std = @import(\"std\");\n");35 try w.writeAll("const std = @import(\"std\");\n");
36 try w.writeAll("const Pkg = std.build.Pkg;\n");36 try w.writeAll("const Pkg = std.build.Pkg;\n");
37 try w.writeAll("const FileSource = std.build.FileSource;\n");37 try w.writeAll("const string = []const u8;\n");
38 try w.writeAll("\n");38 try w.writeAll("\n");
39 try w.print("pub const cache = \"{}\";\n", .{std.zig.fmtEscapes(dir)});39 try w.print("pub const cache = \"{}\";\n", .{std.zig.fmtEscapes(dir)});
40 try w.writeAll("\n");40 try w.writeAll("\n");
...@@ -42,34 +42,45 @@ pub fn create_depszig(dir: []const u8, top_module: u.Module, list: *std.ArrayLis...@@ -42,34 +42,45 @@ pub fn create_depszig(dir: []const u8, top_module: u.Module, list: *std.ArrayLis
42 \\pub fn addAllTo(exe: *std.build.LibExeObjStep) void {42 \\pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
43 \\ @setEvalBranchQuota(1_000_000);43 \\ @setEvalBranchQuota(1_000_000);
44 \\ for (packages) |pkg| {44 \\ for (packages) |pkg| {
45 \\ exe.addPackage(pkg);45 \\ exe.addPackage(pkg.pkg.?);
46 \\ }46 \\ }
47 \\ if (c_include_dirs.len > 0 or c_source_files.len > 0) {47 \\ inline for (std.meta.declarations(package_data)) |decl| {
48 \\ exe.linkLibC();48 \\ const pkg = @as(Package, @field(package_data, decl.name));
49 \\ }49 \\ var llc = false;
50 \\ for (c_include_dirs) |dir| {50 \\ inline for (pkg.system_libs) |item| {
51 \\ exe.addIncludeDir(dir);51 \\ exe.linkSystemLibrary(item);
52 \\ }52 \\ llc = true;
53 \\ inline for (c_source_files) |fpath| {53 \\ }
54 \\ exe.addCSourceFile(fpath[1], @field(c_source_flags, fpath[0]));54 \\ inline for (pkg.c_include_dirs) |item| {
55 \\ }55 \\ exe.addIncludeDir(@field(dirs, decl.name) ++ "/" ++ item);
56 \\ for (system_libs) |lib| {56 \\ llc = true;
57 \\ exe.linkSystemLibrary(lib);57 \\ }
58 \\ inline for (pkg.c_source_files) |item| {
59 \\ exe.addCSourceFile(@field(dirs, decl.name) ++ "/" ++ item, pkg.c_source_flags);
60 \\ llc = true;
61 \\ }
62 \\ if (llc) {
63 \\ exe.linkLibC();
64 \\ }
58 \\ }65 \\ }
59 \\}66 \\}
60 \\67 \\
61 \\fn get_flags(comptime index: usize) []const u8 {68 \\pub const Package = struct {
62 \\ return @field(c_source_flags, _paths[index]);69 \\ pkg: ?Pkg = null,
63 \\}70 \\ c_include_dirs: []const string = &.{},
71 \\ c_source_files: []const string = &.{},
72 \\ c_source_flags: []const string = &.{},
73 \\ system_libs: []const string = &.{},
74 \\};
64 \\75 \\
65 });76 });
6677
67 try w.writeAll("pub const _ids = .{\n");78 // try w.writeAll("pub const _ids = .{\n");
68 try print_ids(w, list.items);79 // try print_ids(w, list.items);
69 try w.writeAll("};\n\n");80 // try w.writeAll("};\n\n");
7081
71 try w.print("pub const _paths = {s}\n", .{".{"});82 try w.writeAll("pub const dirs = struct {\n");
72 try print_paths(w, list.items);83 try print_dirs(w, list.items);
73 try w.writeAll("};\n\n");84 try w.writeAll("};\n\n");
7485
75 try w.writeAll("pub const package_data = struct {\n");86 try w.writeAll("pub const package_data = struct {\n");
...@@ -78,37 +89,18 @@ pub fn create_depszig(dir: []const u8, top_module: u.Module, list: *std.ArrayLis...@@ -78,37 +89,18 @@ pub fn create_depszig(dir: []const u8, top_module: u.Module, list: *std.ArrayLis
78 if (std.mem.eql(u8, mod.id, "root")) {89 if (std.mem.eql(u8, mod.id, "root")) {
79 continue;90 continue;
80 }91 }
81 if (mod.main.len == 0) {
82 continue;
83 }
84 try duped.append(mod);92 try duped.append(mod);
85 }93 }
86 try print_pkg_data_to(w, duped, &std.ArrayList(u.Module).init(gpa));94 try print_pkg_data_to(w, duped, &std.ArrayList(u.Module).init(gpa));
87 try w.writeAll("};\n\n");95 try w.writeAll("};\n\n");
8896
89 try w.writeAll("pub const packages = ");97 try w.writeAll("pub const packages = ");
90 try print_deps(w, dir, top_module, 0, true);98 try print_deps(w, top_module);
91 try w.writeAll(";\n\n");99 try w.writeAll(";\n\n");
92100
93 try w.writeAll("pub const pkgs = ");101 try w.writeAll("pub const pkgs = ");
94 try print_deps(w, dir, top_module, 0, false);102 try print_pkgs(w, top_module);
95 try w.writeAll(";\n\n");103 try w.writeAll(";\n\n");
96
97 try w.writeAll("pub const c_include_dirs = &[_][]const u8{\n");
98 try print_incl_dirs_to(w, list.items);
99 try w.writeAll("};\n\n");
100
101 try w.writeAll("pub const c_source_flags = struct {\n");
102 try print_csrc_flags_to(w, list.items);
103 try w.writeAll("};\n\n");
104
105 try w.writeAll("pub const c_source_files = &[_][2][]const u8{\n");
106 try print_csrc_dirs_to(w, list.items);
107 try w.writeAll("};\n\n");
108
109 try w.writeAll("pub const system_libs = &[_][]const u8{\n");
110 try print_sys_libs_to(w, list.items, &std.ArrayList([]const u8).init(gpa));
111 try w.writeAll("};\n\n");
112}104}
113105
114fn create_lockfile(list: *std.ArrayList(u.Module), dir: []const u8) !void {106fn create_lockfile(list: *std.ArrayList(u.Module), dir: []const u8) !void {
...@@ -129,119 +121,24 @@ fn create_lockfile(list: *std.ArrayList(u.Module), dir: []const u8) !void {...@@ -129,119 +121,24 @@ fn create_lockfile(list: *std.ArrayList(u.Module), dir: []const u8) !void {
129 }121 }
130}122}
131123
132fn print_ids(w: std.fs.File.Writer, list: []u.Module) !void {124fn print_dirs(w: std.fs.File.Writer, list: []const u.Module) !void {
133 for (list) |mod| {
134 if (std.mem.eql(u8, mod.id, "root")) {
135 continue;
136 }
137 if (mod.is_sys_lib) {
138 continue;
139 }
140 try w.print(" \"{s}\",\n", .{mod.id[0..12]});
141 }
142}
143
144fn print_paths(w: std.fs.File.Writer, list: []u.Module) !void {
145 for (list) |mod| {125 for (list) |mod| {
146 if (std.mem.eql(u8, mod.id, "root")) {126 if (std.mem.eql(u8, mod.id, "root")) {
147 continue;127 continue;
148 }128 }
149 if (mod.is_sys_lib) {129 try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.id[0..12], std.zig.fmtEscapes(mod.clean_path) });
150 continue;
151 }
152 if (mod.clean_path.len == 0) {
153 try w.print(" \"\",\n", .{});
154 } else {
155 const s = std.fs.path.sep_str;
156 try w.print(" \"{}{}{}\",\n", .{ std.zig.fmtEscapes(s), std.zig.fmtEscapes(mod.clean_path), std.zig.fmtEscapes(s) });
157 }
158 }130 }
159}131}
160132
161fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32, array: bool) !void {133fn print_deps(w: std.fs.File.Writer, m: u.Module) !void {
162 _ = dir;134 try u.print_all(w, .{"&[_]Package{"}, true);
163135 for (m.deps) |d| {
164 if (m.has_no_zig_deps() and tabs > 0) {
165 try w.print("null", .{});
166 return;
167 }
168 if (array) {
169 try u.print_all(w, .{"&[_]Pkg{"}, true);
170 } else {
171 try u.print_all(w, .{"struct {"}, true);
172 }
173 const t = " ";
174 const r = try u.repeat(t, tabs);
175 for (m.deps) |d, i| {
176 if (d.main.len == 0) {136 if (d.main.len == 0) {
177 continue;137 continue;
178 }138 }
179 if (!array) {139 try w.print(" package_data._{s},\n", .{d.id[0..12]});
180 const r1 = try std.mem.replaceOwned(u8, gpa, d.name, "-", "_");
181 const r2 = try std.mem.replaceOwned(u8, gpa, r1, "/", "_");
182 try w.print(" pub const {s} = packages[{}];\n", .{ r2, i });
183 } else {
184 try w.print(" package_data._{s},\n", .{d.id[0..12]});
185 }
186 }
187 try w.print("{s}", .{try u.concat(&.{ r, "}" })});
188}
189
190fn print_incl_dirs_to(w: std.fs.File.Writer, list: []u.Module) !void {
191 for (list) |mod, i| {
192 if (mod.is_sys_lib) {
193 continue;
194 }
195 for (mod.c_include_dirs) |it| {
196 if (i > 0) {
197 try w.print(" cache ++ _paths[{}] ++ \"{}\",\n", .{ i - 1, std.zig.fmtEscapes(it) });
198 } else {
199 try w.print(" \"{}\",\n", .{std.zig.fmtEscapes(it)});
200 }
201 }
202 }
203}
204
205fn print_csrc_dirs_to(w: std.fs.File.Writer, list: []u.Module) !void {
206 for (list) |mod, i| {
207 if (mod.is_sys_lib) {
208 continue;
209 }
210 for (mod.c_source_files) |it| {
211 if (i > 0) {
212 try w.print(" {s}_ids[{}], cache ++ _paths[{}] ++ \"{s}\"{s},\n", .{ "[_][]const u8{", i - 1, i - 1, it, "}" });
213 } else {
214 try w.print(" {s}_ids[{}], \".{}/{s}\"{s},\n", .{ "[_][]const u8{", i - 1, std.zig.fmtEscapes(mod.clean_path), it, "}" });
215 }
216 }
217 }
218}
219
220fn print_csrc_flags_to(w: std.fs.File.Writer, list: []u.Module) !void {
221 for (list) |mod| {
222 if (mod.is_sys_lib) {
223 continue;
224 }
225 if (mod.c_source_flags.len == 0 and mod.c_source_files.len == 0) {
226 continue;
227 }
228 try w.print(" pub const @\"{s}\" = {s}", .{ mod.id[0..12], "&.{" });
229 for (mod.c_source_flags) |it| {
230 try w.print("\"{}\",", .{std.zig.fmtEscapes(it)});
231 }
232 try w.print("{s};\n", .{"}"});
233 }
234}
235
236fn print_sys_libs_to(w: std.fs.File.Writer, list: []u.Module, list2: *std.ArrayList([]const u8)) !void {
237 _ = list2;
238
239 for (list) |mod| {
240 if (!mod.is_sys_lib) {
241 continue;
242 }
243 try w.print(" \"{s}\",\n", .{mod.name});
244 }140 }
141 try w.writeAll("}");
245}142}
246143
247fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(u.Module), done: *std.ArrayList(u.Module)) !void {144fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(u.Module), done: *std.ArrayList(u.Module)) !void {
...@@ -249,13 +146,66 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(u.Module), d...@@ -249,13 +146,66 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(u.Module), d
249 while (notdone.items.len > 0) {146 while (notdone.items.len > 0) {
250 for (notdone.items) |mod, i| {147 for (notdone.items) |mod, i| {
251 if (contains_all(mod.deps, done.items)) {148 if (contains_all(mod.deps, done.items)) {
252 try w.print(" pub const _{s} = Pkg{{ .name = \"{s}\", .path = FileSource{{ .path = cache ++ \"/{}/{s}\" }}, .dependencies = &[_]Pkg{{", .{ mod.id[0..12], mod.name, std.zig.fmtEscapes(mod.clean_path), mod.main });149 try w.print(
253 for (mod.deps) |d| {150 \\ pub const _{s} = Package{{
254 if (d.main.len > 0) {151 \\
255 try w.print(" _{s},", .{d.id[0..12]});152 , .{
153 mod.id[0..12],
154 });
155 if (mod.main.len > 0) {
156 try w.print(
157 \\ .pkg = Pkg{{ .name = "{s}", .path = .{{ .path = dirs._{s} ++ "/{s}" }}, .dependencies =
158 , .{
159 mod.name,
160 mod.id[0..12],
161 mod.main,
162 });
163 if (mod.has_no_zig_deps()) {
164 try w.writeAll(" null },\n");
165 } else {
166 try w.writeAll(" &.{");
167 for (mod.deps) |moddep, j| {
168 if (moddep.main.len == 0) continue;
169 try w.print(" _{s}.pkg.?", .{moddep.id[0..12]});
170 if (j != mod.deps.len - 1) try w.writeAll(",");
171 }
172 try w.writeAll(" } },\n");
173 }
174 }
175 if (mod.c_include_dirs.len > 0) {
176 try w.writeAll(" .c_include_dirs = &.{");
177 for (mod.c_include_dirs) |item, j| {
178 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});
179 if (j != mod.c_include_dirs.len - 1) try w.writeAll(",");
180 }
181 try w.writeAll(" },\n");
182 }
183 if (mod.c_source_files.len > 0) {
184 try w.writeAll(" .c_source_files = &.{");
185 for (mod.c_source_files) |item, j| {
186 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});
187 if (j != mod.c_source_files.len - 1) try w.writeAll(",");
188 }
189 try w.writeAll(" },\n");
190 }
191 if (mod.c_source_flags.len > 0) {
192 try w.writeAll(" .c_source_flags = &.{");
193 for (mod.c_source_flags) |item, j| {
194 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});
195 if (j != mod.c_source_flags.len - 1) try w.writeAll(",");
196 }
197 try w.writeAll(" },\n");
198 }
199 if (mod.has_syslib_deps()) {
200 try w.writeAll(" .system_libs = &.{");
201 for (mod.deps) |item, j| {
202 if (!mod.is_sys_lib) continue;
203 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)});
204 if (j != mod.deps.len - 1) try w.writeAll(",");
256 }205 }
206 try w.writeAll(" },\n");
257 }207 }
258 try w.print(" }} }};\n", .{});208 try w.writeAll(" };\n\n");
259209
260 try done.append(mod);210 try done.append(mod);
261 _ = notdone.orderedRemove(i);211 _ = notdone.orderedRemove(i);
...@@ -278,3 +228,16 @@ fn contains_all(needles: []u.Module, haystack: []const u.Module) bool {...@@ -278,3 +228,16 @@ fn contains_all(needles: []u.Module, haystack: []const u.Module) bool {
278 }228 }
279 return true;229 return true;
280}230}
231
232fn print_pkgs(w: std.fs.File.Writer, m: u.Module) !void {
233 try w.writeAll("struct {\n");
234 for (m.deps) |d| {
235 if (d.main.len == 0) {
236 continue;
237 }
238 const r1 = try std.mem.replaceOwned(u8, gpa, d.name, "-", "_");
239 const r2 = try std.mem.replaceOwned(u8, gpa, r1, "/", "_");
240 try w.print(" pub const {s} = package_data._{s};\n", .{ r2, d.id[0..12] });
241 }
242 try w.writeAll("}");
243}
src/util/module.zig+9
...@@ -107,4 +107,13 @@ pub const Module = struct {...@@ -107,4 +107,13 @@ pub const Module = struct {
107 }107 }
108 return true;108 return true;
109 }109 }
110
111 pub fn has_syslib_deps(self: Module) bool {
112 for (self.deps) |d| {
113 if (d.is_sys_lib) {
114 return true;
115 }
116 }
117 return false;
118 }
110};119};