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 @@
11const std = @import("std");
22const Pkg = std.build.Pkg;
3const FileSource = std.build.FileSource;
3const string = []const u8;
44
55pub const cache = ".zigmod/deps";
66
77pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
88 @setEvalBranchQuota(1_000_000);
99 for (packages) |pkg| {
10 exe.addPackage(pkg);
10 exe.addPackage(pkg.pkg.?);
1111 }
12 if (c_include_dirs.len > 0 or c_source_files.len > 0) {
13 exe.linkLibC();
14 }
15 for (c_include_dirs) |dir| {
16 exe.addIncludeDir(dir);
17 }
18 inline for (c_source_files) |fpath| {
19 exe.addCSourceFile(fpath[1], @field(c_source_flags, fpath[0]));
20 }
21 for (system_libs) |lib| {
22 exe.linkSystemLibrary(lib);
12 inline for (std.meta.declarations(package_data)) |decl| {
13 const pkg = @as(Package, @field(package_data, decl.name));
14 var llc = false;
15 inline for (pkg.system_libs) |item| {
16 exe.linkSystemLibrary(item);
17 llc = true;
18 }
19 inline for (pkg.c_include_dirs) |item| {
20 exe.addIncludeDir(@field(dirs, decl.name) ++ "/" ++ item);
21 llc = true;
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 }
2330 }
2431}
2532
26fn get_flags(comptime index: usize) []const u8 {
27 return @field(c_source_flags, _paths[index]);
28}
29
30pub const _ids = .{
31 "89ujp8gq842x",
32 "8mdbh0zuneb0",
33 "s84v9o48ucb0",
34 "2ta738wrqbaq",
35 "0npcrzfdlrvk",
36 "ejw82j2ipa0e",
37 "9k24gimke1an",
38 "csbnipaad8n7",
39 "yyhw90zkzgmu",
40 "u9w9dpp6p804",
41 "ocmr9rtohgcc",
42 "tnj3qf44tpeq",
33pub const Package = struct {
34 pkg: ?Pkg = null,
35 c_include_dirs: []const string = &.{},
36 c_source_files: []const string = &.{},
37 c_source_flags: []const string = &.{},
38 system_libs: []const string = &.{},
4339};
4440
45pub const _paths = .{
46 "/../../",
47 "/v/git/github.com/yaml/libyaml/tag-0.2.5/",
48 "/git/github.com/nektro/zig-ansi/",
49 "/git/github.com/ziglibs/known-folders/",
50 "/git/github.com/nektro/zig-licenses/",
51 "/git/github.com/truemedian/zfetch/",
52 "/git/github.com/truemedian/hzzp/",
53 "/git/github.com/alexnask/iguanaTLS/",
54 "/git/github.com/MasterQ32/zig-network/",
55 "/git/github.com/MasterQ32/zig-uri/",
56 "/git/github.com/nektro/zig-json/",
57 "/git/github.com/nektro/zig-range/",
41pub const dirs = struct {
42 pub const _89ujp8gq842x = cache ++ "/../..";
43 pub const _8mdbh0zuneb0 = cache ++ "/v/git/github.com/yaml/libyaml/tag-0.2.5";
44 pub const _s84v9o48ucb0 = cache ++ "/git/github.com/nektro/zig-ansi";
45 pub const _2ta738wrqbaq = cache ++ "/git/github.com/ziglibs/known-folders";
46 pub const _0npcrzfdlrvk = cache ++ "/git/github.com/nektro/zig-licenses";
47 pub const _ejw82j2ipa0e = cache ++ "/git/github.com/truemedian/zfetch";
48 pub const _9k24gimke1an = cache ++ "/git/github.com/truemedian/hzzp";
49 pub const _csbnipaad8n7 = cache ++ "/git/github.com/alexnask/iguanaTLS";
50 pub const _yyhw90zkzgmu = cache ++ "/git/github.com/MasterQ32/zig-network";
51 pub const _u9w9dpp6p804 = cache ++ "/git/github.com/MasterQ32/zig-uri";
52 pub const _ocmr9rtohgcc = cache ++ "/git/github.com/nektro/zig-json";
53 pub const _tnj3qf44tpeq = cache ++ "/git/github.com/nektro/zig-range";
5854};
5955
6056pub 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{ } };
62 pub const _2ta738wrqbaq = Pkg{ .name = "known-folders", .path = FileSource{ .path = cache ++ "/git/github.com/ziglibs/known-folders/known-folders.zig" }, .dependencies = &[_]Pkg{ } };
63 pub const _0npcrzfdlrvk = Pkg{ .name = "licenses", .path = FileSource{ .path = cache ++ "/git/github.com/nektro/zig-licenses/src/lib.zig" }, .dependencies = &[_]Pkg{ } };
64 pub const _9k24gimke1an = Pkg{ .name = "hzzp", .path = FileSource{ .path = cache ++ "/git/github.com/truemedian/hzzp/src/main.zig" }, .dependencies = &[_]Pkg{ } };
65 pub const _csbnipaad8n7 = Pkg{ .name = "iguanaTLS", .path = FileSource{ .path = cache ++ "/git/github.com/alexnask/iguanaTLS/src/main.zig" }, .dependencies = &[_]Pkg{ } };
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};
57 pub const _8mdbh0zuneb0 = Package{
58 .c_include_dirs = &.{ "include" },
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" },
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" },
61 };
7362
74pub const packages = &[_]Pkg{
75 package_data._89ujp8gq842x,
76};
63 pub const _s84v9o48ucb0 = Package{
64 .pkg = Pkg{ .name = "ansi", .path = .{ .path = dirs._s84v9o48ucb0 ++ "/src/lib.zig" }, .dependencies = null },
65 };
7766
78pub const pkgs = struct {
79 pub const zigmod = packages[0];
80};
67 pub const _2ta738wrqbaq = Package{
68 .pkg = Pkg{ .name = "known-folders", .path = .{ .path = dirs._2ta738wrqbaq ++ "/known-folders.zig" }, .dependencies = null },
69 };
8170
82pub const c_include_dirs = &[_][]const u8{
83 cache ++ _paths[1] ++ "include",
84};
71 pub const _0npcrzfdlrvk = Package{
72 .pkg = Pkg{ .name = "licenses", .path = .{ .path = dirs._0npcrzfdlrvk ++ "/src/lib.zig" }, .dependencies = null },
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",};
88107};
89108
90pub const c_source_files = &[_][2][]const u8{
91 [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/api.c"},
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"},
109pub const packages = &[_]Package{
110 package_data._89ujp8gq842x,
99111};
100112
101pub const system_libs = &[_][]const u8{
113pub const pkgs = struct {
114 pub const zigmod = package_data._89ujp8gq842x;
102115};
103116
docs/deps.zig.md+19-32
......@@ -9,42 +9,29 @@ The relative path root to which all dependency sources are saved. Currently alwa
99- Type: `pub fn (exe: *std.build.LibExeObjStep) void`
1010A 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`
13- Type: `[][]const u8`
14A comptime-known string array of all of the [ID's](zig.mod.md#id) used in this project.
12### `Package`
13```zig
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`
17- Type: `[][]const u8`
18A comptime-known string array of the source paths to each dependency relative to `cache`.
23### `dirs`
24- Type: `struct<ID, []const u8>`
25A comptime-known string array of the package directories for each dependency relative to the project root.
1926
2027### `package_data`
21- Type: `struct<ID, std.build.Pkg>`
22This is a meta struct that associates ID's to their relavant `std.build.Pkg` initialization, complete with sub-packages and all.
28- Type: `struct<ID, Package>`
29This is a meta struct that associates ID's to their relavant `Package` definition.
2330
2431### `packages`
25- Type: `[]std.build.Pkg`
26This is a an array of all of the items in `package_data`, but able to be referenced by index, rather than package ID.
32- Type: `[]Package`
33This is a an array of all of the items in `package_data`, but only contains the final versions of `dev_dependencies`.
2734
2835### `pkgs`
29- Type: `struct<NAME, std.build.Pkg>`
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:
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.
36- Type: `struct<NAME, Package>`
37This is a struct that associates the package name to the relavant `Package`. The only packages listed are the dependencies of the root project.
src/cmd/fetch.zig+112-149
......@@ -34,7 +34,7 @@ pub fn create_depszig(dir: []const u8, top_module: u.Module, list: *std.ArrayLis
3434 const w = f.writer();
3535 try w.writeAll("const std = @import(\"std\");\n");
3636 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");
3838 try w.writeAll("\n");
3939 try w.print("pub const cache = \"{}\";\n", .{std.zig.fmtEscapes(dir)});
4040 try w.writeAll("\n");
......@@ -42,34 +42,45 @@ pub fn create_depszig(dir: []const u8, top_module: u.Module, list: *std.ArrayLis
4242 \\pub fn addAllTo(exe: *std.build.LibExeObjStep) void {
4343 \\ @setEvalBranchQuota(1_000_000);
4444 \\ for (packages) |pkg| {
45 \\ exe.addPackage(pkg);
45 \\ exe.addPackage(pkg.pkg.?);
4646 \\ }
47 \\ if (c_include_dirs.len > 0 or c_source_files.len > 0) {
48 \\ exe.linkLibC();
49 \\ }
50 \\ for (c_include_dirs) |dir| {
51 \\ exe.addIncludeDir(dir);
52 \\ }
53 \\ inline for (c_source_files) |fpath| {
54 \\ exe.addCSourceFile(fpath[1], @field(c_source_flags, fpath[0]));
55 \\ }
56 \\ for (system_libs) |lib| {
57 \\ exe.linkSystemLibrary(lib);
47 \\ inline for (std.meta.declarations(package_data)) |decl| {
48 \\ const pkg = @as(Package, @field(package_data, decl.name));
49 \\ var llc = false;
50 \\ inline for (pkg.system_libs) |item| {
51 \\ exe.linkSystemLibrary(item);
52 \\ llc = true;
53 \\ }
54 \\ inline for (pkg.c_include_dirs) |item| {
55 \\ exe.addIncludeDir(@field(dirs, decl.name) ++ "/" ++ item);
56 \\ llc = true;
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 \\ }
5865 \\ }
5966 \\}
6067 \\
61 \\fn get_flags(comptime index: usize) []const u8 {
62 \\ return @field(c_source_flags, _paths[index]);
63 \\}
68 \\pub const Package = struct {
69 \\ pkg: ?Pkg = null,
70 \\ c_include_dirs: []const string = &.{},
71 \\ c_source_files: []const string = &.{},
72 \\ c_source_flags: []const string = &.{},
73 \\ system_libs: []const string = &.{},
74 \\};
6475 \\
6576 });
6677
67 try w.writeAll("pub const _ids = .{\n");
68 try print_ids(w, list.items);
69 try w.writeAll("};\n\n");
78 // try w.writeAll("pub const _ids = .{\n");
79 // try print_ids(w, list.items);
80 // try w.writeAll("};\n\n");
7081
71 try w.print("pub const _paths = {s}\n", .{".{"});
72 try print_paths(w, list.items);
82 try w.writeAll("pub const dirs = struct {\n");
83 try print_dirs(w, list.items);
7384 try w.writeAll("};\n\n");
7485
7586 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
7889 if (std.mem.eql(u8, mod.id, "root")) {
7990 continue;
8091 }
81 if (mod.main.len == 0) {
82 continue;
83 }
8492 try duped.append(mod);
8593 }
8694 try print_pkg_data_to(w, duped, &std.ArrayList(u.Module).init(gpa));
8795 try w.writeAll("};\n\n");
8896
8997 try w.writeAll("pub const packages = ");
90 try print_deps(w, dir, top_module, 0, true);
98 try print_deps(w, top_module);
9199 try w.writeAll(";\n\n");
92100
93101 try w.writeAll("pub const pkgs = ");
94 try print_deps(w, dir, top_module, 0, false);
102 try print_pkgs(w, top_module);
95103 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");
112104}
113105
114106fn 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 {
129121 }
130122}
131123
132fn print_ids(w: std.fs.File.Writer, list: []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 {
124fn print_dirs(w: std.fs.File.Writer, list: []const u.Module) !void {
145125 for (list) |mod| {
146126 if (std.mem.eql(u8, mod.id, "root")) {
147127 continue;
148128 }
149 if (mod.is_sys_lib) {
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 }
129 try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.id[0..12], std.zig.fmtEscapes(mod.clean_path) });
158130 }
159131}
160132
161fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32, array: bool) !void {
162 _ = dir;
163
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| {
133fn print_deps(w: std.fs.File.Writer, m: u.Module) !void {
134 try u.print_all(w, .{"&[_]Package{"}, true);
135 for (m.deps) |d| {
176136 if (d.main.len == 0) {
177137 continue;
178138 }
179 if (!array) {
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});
139 try w.print(" package_data._{s},\n", .{d.id[0..12]});
244140 }
141 try w.writeAll("}");
245142}
246143
247144fn 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
249146 while (notdone.items.len > 0) {
250147 for (notdone.items) |mod, i| {
251148 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 });
253 for (mod.deps) |d| {
254 if (d.main.len > 0) {
255 try w.print(" _{s},", .{d.id[0..12]});
149 try w.print(
150 \\ pub const _{s} = Package{{
151 \\
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(",");
256205 }
206 try w.writeAll(" },\n");
257207 }
258 try w.print(" }} }};\n", .{});
208 try w.writeAll(" };\n\n");
259209
260210 try done.append(mod);
261211 _ = notdone.orderedRemove(i);
......@@ -278,3 +228,16 @@ fn contains_all(needles: []u.Module, haystack: []const u.Module) bool {
278228 }
279229 return true;
280230}
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 {
107107 }
108108 return true;
109109 }
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 }
110119};