From 0bf546d95cb27488eadc3a6d3e389da9eed272ef Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Wed, 7 Jul 2021 00:30:48 -0700 Subject: [PATCH] rework `deps.zig` format --- deps.zig | 169 +++++++++++++++------------- docs/deps.zig.md | 53 ++++----- src/cmd/fetch.zig | 261 +++++++++++++++++++------------------------- src/util/module.zig | 9 ++ 4 files changed, 232 insertions(+), 260 deletions(-) diff --git a/deps.zig b/deps.zig index 30cae6e5f809dfc463418562aa861bf64b190d17..1fcbd9bb38c20fada6de6eb803e2015e6a31e2ce 100644 --- a/deps.zig +++ b/deps.zig @@ -1,103 +1,116 @@ const std = @import("std"); const Pkg = std.build.Pkg; -const FileSource = std.build.FileSource; +const string = []const u8; pub const cache = ".zigmod/deps"; pub fn addAllTo(exe: *std.build.LibExeObjStep) void { @setEvalBranchQuota(1_000_000); for (packages) |pkg| { - exe.addPackage(pkg); + exe.addPackage(pkg.pkg.?); } - if (c_include_dirs.len > 0 or c_source_files.len > 0) { - exe.linkLibC(); + inline for (std.meta.declarations(package_data)) |decl| { + const pkg = @as(Package, @field(package_data, decl.name)); + var llc = false; + inline for (pkg.system_libs) |item| { + exe.linkSystemLibrary(item); + llc = true; + } + inline for (pkg.c_include_dirs) |item| { + exe.addIncludeDir(@field(dirs, decl.name) ++ "/" ++ item); + llc = true; + } + inline for (pkg.c_source_files) |item| { + exe.addCSourceFile(@field(dirs, decl.name) ++ "/" ++ item, pkg.c_source_flags); + llc = true; + } + if (llc) { + exe.linkLibC(); + } } - for (c_include_dirs) |dir| { - exe.addIncludeDir(dir); - } - inline for (c_source_files) |fpath| { - exe.addCSourceFile(fpath[1], @field(c_source_flags, fpath[0])); - } - for (system_libs) |lib| { - exe.linkSystemLibrary(lib); - } -} - -fn get_flags(comptime index: usize) []const u8 { - return @field(c_source_flags, _paths[index]); } -pub const _ids = .{ - "89ujp8gq842x", - "8mdbh0zuneb0", - "s84v9o48ucb0", - "2ta738wrqbaq", - "0npcrzfdlrvk", - "ejw82j2ipa0e", - "9k24gimke1an", - "csbnipaad8n7", - "yyhw90zkzgmu", - "u9w9dpp6p804", - "ocmr9rtohgcc", - "tnj3qf44tpeq", +pub const Package = struct { + pkg: ?Pkg = null, + c_include_dirs: []const string = &.{}, + c_source_files: []const string = &.{}, + c_source_flags: []const string = &.{}, + system_libs: []const string = &.{}, }; -pub const _paths = .{ - "/../../", - "/v/git/github.com/yaml/libyaml/tag-0.2.5/", - "/git/github.com/nektro/zig-ansi/", - "/git/github.com/ziglibs/known-folders/", - "/git/github.com/nektro/zig-licenses/", - "/git/github.com/truemedian/zfetch/", - "/git/github.com/truemedian/hzzp/", - "/git/github.com/alexnask/iguanaTLS/", - "/git/github.com/MasterQ32/zig-network/", - "/git/github.com/MasterQ32/zig-uri/", - "/git/github.com/nektro/zig-json/", - "/git/github.com/nektro/zig-range/", +pub const dirs = struct { + pub const _89ujp8gq842x = cache ++ "/../.."; + pub const _8mdbh0zuneb0 = cache ++ "/v/git/github.com/yaml/libyaml/tag-0.2.5"; + pub const _s84v9o48ucb0 = cache ++ "/git/github.com/nektro/zig-ansi"; + pub const _2ta738wrqbaq = cache ++ "/git/github.com/ziglibs/known-folders"; + pub const _0npcrzfdlrvk = cache ++ "/git/github.com/nektro/zig-licenses"; + pub const _ejw82j2ipa0e = cache ++ "/git/github.com/truemedian/zfetch"; + pub const _9k24gimke1an = cache ++ "/git/github.com/truemedian/hzzp"; + pub const _csbnipaad8n7 = cache ++ "/git/github.com/alexnask/iguanaTLS"; + pub const _yyhw90zkzgmu = cache ++ "/git/github.com/MasterQ32/zig-network"; + pub const _u9w9dpp6p804 = cache ++ "/git/github.com/MasterQ32/zig-uri"; + pub const _ocmr9rtohgcc = cache ++ "/git/github.com/nektro/zig-json"; + pub const _tnj3qf44tpeq = cache ++ "/git/github.com/nektro/zig-range"; }; pub const package_data = struct { - pub const _s84v9o48ucb0 = Pkg{ .name = "ansi", .path = FileSource{ .path = cache ++ "/git/github.com/nektro/zig-ansi/src/lib.zig" }, .dependencies = &[_]Pkg{ } }; - pub const _2ta738wrqbaq = Pkg{ .name = "known-folders", .path = FileSource{ .path = cache ++ "/git/github.com/ziglibs/known-folders/known-folders.zig" }, .dependencies = &[_]Pkg{ } }; - pub const _0npcrzfdlrvk = Pkg{ .name = "licenses", .path = FileSource{ .path = cache ++ "/git/github.com/nektro/zig-licenses/src/lib.zig" }, .dependencies = &[_]Pkg{ } }; - pub const _9k24gimke1an = Pkg{ .name = "hzzp", .path = FileSource{ .path = cache ++ "/git/github.com/truemedian/hzzp/src/main.zig" }, .dependencies = &[_]Pkg{ } }; - pub const _csbnipaad8n7 = Pkg{ .name = "iguanaTLS", .path = FileSource{ .path = cache ++ "/git/github.com/alexnask/iguanaTLS/src/main.zig" }, .dependencies = &[_]Pkg{ } }; - pub const _yyhw90zkzgmu = Pkg{ .name = "network", .path = FileSource{ .path = cache ++ "/git/github.com/MasterQ32/zig-network/network.zig" }, .dependencies = &[_]Pkg{ } }; - pub const _u9w9dpp6p804 = Pkg{ .name = "uri", .path = FileSource{ .path = cache ++ "/git/github.com/MasterQ32/zig-uri/uri.zig" }, .dependencies = &[_]Pkg{ } }; - pub const _ejw82j2ipa0e = Pkg{ .name = "zfetch", .path = FileSource{ .path = cache ++ "/git/github.com/truemedian/zfetch/src/main.zig" }, .dependencies = &[_]Pkg{ _9k24gimke1an, _csbnipaad8n7, _yyhw90zkzgmu, _u9w9dpp6p804, } }; - pub const _ocmr9rtohgcc = Pkg{ .name = "json", .path = FileSource{ .path = cache ++ "/git/github.com/nektro/zig-json/src/lib.zig" }, .dependencies = &[_]Pkg{ } }; - pub const _tnj3qf44tpeq = Pkg{ .name = "range", .path = FileSource{ .path = cache ++ "/git/github.com/nektro/zig-range/src/lib.zig" }, .dependencies = &[_]Pkg{ } }; - pub const _89ujp8gq842x = Pkg{ .name = "zigmod", .path = FileSource{ .path = cache ++ "/../../src/lib.zig" }, .dependencies = &[_]Pkg{ _s84v9o48ucb0, _2ta738wrqbaq, _0npcrzfdlrvk, _ejw82j2ipa0e, _ocmr9rtohgcc, _tnj3qf44tpeq, } }; + pub const _8mdbh0zuneb0 = Package{ + .c_include_dirs = &.{ "include" }, + .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" }, + .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" }, + }; + + pub const _s84v9o48ucb0 = Package{ + .pkg = Pkg{ .name = "ansi", .path = .{ .path = dirs._s84v9o48ucb0 ++ "/src/lib.zig" }, .dependencies = null }, + }; + + pub const _2ta738wrqbaq = Package{ + .pkg = Pkg{ .name = "known-folders", .path = .{ .path = dirs._2ta738wrqbaq ++ "/known-folders.zig" }, .dependencies = null }, + }; + + pub const _0npcrzfdlrvk = Package{ + .pkg = Pkg{ .name = "licenses", .path = .{ .path = dirs._0npcrzfdlrvk ++ "/src/lib.zig" }, .dependencies = null }, + }; + + pub const _9k24gimke1an = Package{ + .pkg = Pkg{ .name = "hzzp", .path = .{ .path = dirs._9k24gimke1an ++ "/src/main.zig" }, .dependencies = null }, + }; + + pub const _csbnipaad8n7 = Package{ + .pkg = Pkg{ .name = "iguanaTLS", .path = .{ .path = dirs._csbnipaad8n7 ++ "/src/main.zig" }, .dependencies = null }, + }; + + pub const _yyhw90zkzgmu = Package{ + .pkg = Pkg{ .name = "network", .path = .{ .path = dirs._yyhw90zkzgmu ++ "/network.zig" }, .dependencies = null }, + }; + + pub const _u9w9dpp6p804 = Package{ + .pkg = Pkg{ .name = "uri", .path = .{ .path = dirs._u9w9dpp6p804 ++ "/uri.zig" }, .dependencies = null }, + }; + + pub const _ejw82j2ipa0e = Package{ + .pkg = Pkg{ .name = "zfetch", .path = .{ .path = dirs._ejw82j2ipa0e ++ "/src/main.zig" }, .dependencies = &.{ _9k24gimke1an.pkg.?, _csbnipaad8n7.pkg.?, _yyhw90zkzgmu.pkg.?, _u9w9dpp6p804.pkg.? } }, + }; + + pub const _ocmr9rtohgcc = Package{ + .pkg = Pkg{ .name = "json", .path = .{ .path = dirs._ocmr9rtohgcc ++ "/src/lib.zig" }, .dependencies = null }, + }; + + pub const _tnj3qf44tpeq = Package{ + .pkg = Pkg{ .name = "range", .path = .{ .path = dirs._tnj3qf44tpeq ++ "/src/lib.zig" }, .dependencies = null }, + }; + + pub const _89ujp8gq842x = Package{ + .pkg = Pkg{ .name = "zigmod", .path = .{ .path = dirs._89ujp8gq842x ++ "/src/lib.zig" }, .dependencies = &.{ _s84v9o48ucb0.pkg.?, _2ta738wrqbaq.pkg.?, _0npcrzfdlrvk.pkg.?, _ejw82j2ipa0e.pkg.?, _ocmr9rtohgcc.pkg.?, _tnj3qf44tpeq.pkg.? } }, + }; + }; -pub const packages = &[_]Pkg{ +pub const packages = &[_]Package{ package_data._89ujp8gq842x, }; pub const pkgs = struct { - pub const zigmod = packages[0]; -}; - -pub const c_include_dirs = &[_][]const u8{ - cache ++ _paths[1] ++ "include", -}; - -pub const c_source_flags = struct { - 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",}; -}; - -pub const c_source_files = &[_][2][]const u8{ - [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/api.c"}, - [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/dumper.c"}, - [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/emitter.c"}, - [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/loader.c"}, - [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/parser.c"}, - [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/reader.c"}, - [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/scanner.c"}, - [_][]const u8{_ids[1], cache ++ _paths[1] ++ "src/writer.c"}, -}; - -pub const system_libs = &[_][]const u8{ + pub const zigmod = package_data._89ujp8gq842x; }; diff --git a/docs/deps.zig.md b/docs/deps.zig.md index 7b9dacac6fb5dd6bc021c7b6950ba3459625a3e5..7e342fe8fc2216dd30201c41fa1aa4e57820ee90 100644 --- a/docs/deps.zig.md +++ b/docs/deps.zig.md @@ -9,42 +9,29 @@ The relative path root to which all dependency sources are saved. Currently alwa - Type: `pub fn (exe: *std.build.LibExeObjStep) void` A 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. -### `_ids` -- Type: `[][]const u8` -A comptime-known string array of all of the [ID's](zig.mod.md#id) used in this project. - -### `_paths` -- Type: `[][]const u8` -A comptime-known string array of the source paths to each dependency relative to `cache`. - -### `package_data` -- Type: `struct` -This is a meta struct that associates ID's to their relavant `std.build.Pkg` initialization, complete with sub-packages and all. - -### `packages` -- Type: `[]std.build.Pkg` -This is a an array of all of the items in `package_data`, but able to be referenced by index, rather than package ID. - -### `pkgs` -- Type: `struct` -This 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: +### `Package` ```zig -const deps = @import("./deps.zig"); -const my_dev_dep = @import(deps.pkgs.my_dev_dep.path); +pub const Package = struct { + pkg: ?Pkg = null, + c_include_dirs: []const string = &.{}, + c_source_files: []const string = &.{}, + c_source_flags: []const string = &.{}, + system_libs: []const string = &.{}, +}; ``` -### `c_include_dirs` -- Type: `[][]const u8` -An ensembled list of all the `c_include_dirs` lists. - -### `c_source_flags` +### `dirs` - Type: `struct` -An ensembled list of all the `c_source_flags` lists. +A comptime-known string array of the package directories for each dependency relative to the project root. -### `c_source_files` -- Type: `[][2][]const u8` -An ensembled list of all the `c_source_files` lists. +### `package_data` +- Type: `struct` +This is a meta struct that associates ID's to their relavant `Package` definition. -### `system_libs` -- Type: `[][]const u8` -An ensembled list of all the `system_libs` lists. +### `packages` +- Type: `[]Package` +This is a an array of all of the items in `package_data`, but only contains the final versions of `dev_dependencies`. + +### `pkgs` +- Type: `struct` +This is a struct that associates the package name to the relavant `Package`. The only packages listed are the dependencies of the root project. diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index 1541bdf7e5eec33b1d22b51eb329efcf67f57e43..3773bdf15c5f9637a9b0d963e335c8e52e8abfe3 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -34,7 +34,7 @@ pub fn create_depszig(dir: []const u8, top_module: u.Module, list: *std.ArrayLis const w = f.writer(); try w.writeAll("const std = @import(\"std\");\n"); try w.writeAll("const Pkg = std.build.Pkg;\n"); - try w.writeAll("const FileSource = std.build.FileSource;\n"); + try w.writeAll("const string = []const u8;\n"); try w.writeAll("\n"); try w.print("pub const cache = \"{}\";\n", .{std.zig.fmtEscapes(dir)}); try w.writeAll("\n"); @@ -42,34 +42,45 @@ pub fn create_depszig(dir: []const u8, top_module: u.Module, list: *std.ArrayLis \\pub fn addAllTo(exe: *std.build.LibExeObjStep) void { \\ @setEvalBranchQuota(1_000_000); \\ for (packages) |pkg| { - \\ exe.addPackage(pkg); + \\ exe.addPackage(pkg.pkg.?); \\ } - \\ if (c_include_dirs.len > 0 or c_source_files.len > 0) { - \\ exe.linkLibC(); - \\ } - \\ for (c_include_dirs) |dir| { - \\ exe.addIncludeDir(dir); - \\ } - \\ inline for (c_source_files) |fpath| { - \\ exe.addCSourceFile(fpath[1], @field(c_source_flags, fpath[0])); - \\ } - \\ for (system_libs) |lib| { - \\ exe.linkSystemLibrary(lib); + \\ inline for (std.meta.declarations(package_data)) |decl| { + \\ const pkg = @as(Package, @field(package_data, decl.name)); + \\ var llc = false; + \\ inline for (pkg.system_libs) |item| { + \\ exe.linkSystemLibrary(item); + \\ llc = true; + \\ } + \\ inline for (pkg.c_include_dirs) |item| { + \\ exe.addIncludeDir(@field(dirs, decl.name) ++ "/" ++ item); + \\ llc = true; + \\ } + \\ inline for (pkg.c_source_files) |item| { + \\ exe.addCSourceFile(@field(dirs, decl.name) ++ "/" ++ item, pkg.c_source_flags); + \\ llc = true; + \\ } + \\ if (llc) { + \\ exe.linkLibC(); + \\ } \\ } \\} \\ - \\fn get_flags(comptime index: usize) []const u8 { - \\ return @field(c_source_flags, _paths[index]); - \\} + \\pub const Package = struct { + \\ pkg: ?Pkg = null, + \\ c_include_dirs: []const string = &.{}, + \\ c_source_files: []const string = &.{}, + \\ c_source_flags: []const string = &.{}, + \\ system_libs: []const string = &.{}, + \\}; \\ }); - try w.writeAll("pub const _ids = .{\n"); - try print_ids(w, list.items); - try w.writeAll("};\n\n"); + // try w.writeAll("pub const _ids = .{\n"); + // try print_ids(w, list.items); + // try w.writeAll("};\n\n"); - try w.print("pub const _paths = {s}\n", .{".{"}); - try print_paths(w, list.items); + try w.writeAll("pub const dirs = struct {\n"); + try print_dirs(w, list.items); try w.writeAll("};\n\n"); 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 if (std.mem.eql(u8, mod.id, "root")) { continue; } - if (mod.main.len == 0) { - continue; - } try duped.append(mod); } try print_pkg_data_to(w, duped, &std.ArrayList(u.Module).init(gpa)); try w.writeAll("};\n\n"); try w.writeAll("pub const packages = "); - try print_deps(w, dir, top_module, 0, true); + try print_deps(w, top_module); try w.writeAll(";\n\n"); try w.writeAll("pub const pkgs = "); - try print_deps(w, dir, top_module, 0, false); + try print_pkgs(w, top_module); try w.writeAll(";\n\n"); - - try w.writeAll("pub const c_include_dirs = &[_][]const u8{\n"); - try print_incl_dirs_to(w, list.items); - try w.writeAll("};\n\n"); - - try w.writeAll("pub const c_source_flags = struct {\n"); - try print_csrc_flags_to(w, list.items); - try w.writeAll("};\n\n"); - - try w.writeAll("pub const c_source_files = &[_][2][]const u8{\n"); - try print_csrc_dirs_to(w, list.items); - try w.writeAll("};\n\n"); - - try w.writeAll("pub const system_libs = &[_][]const u8{\n"); - try print_sys_libs_to(w, list.items, &std.ArrayList([]const u8).init(gpa)); - try w.writeAll("};\n\n"); } 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 { } } -fn print_ids(w: std.fs.File.Writer, list: []u.Module) !void { +fn print_dirs(w: std.fs.File.Writer, list: []const u.Module) !void { for (list) |mod| { if (std.mem.eql(u8, mod.id, "root")) { continue; } - if (mod.is_sys_lib) { - continue; - } - try w.print(" \"{s}\",\n", .{mod.id[0..12]}); + try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.id[0..12], std.zig.fmtEscapes(mod.clean_path) }); } } -fn print_paths(w: std.fs.File.Writer, list: []u.Module) !void { - for (list) |mod| { - if (std.mem.eql(u8, mod.id, "root")) { - continue; - } - if (mod.is_sys_lib) { - continue; - } - if (mod.clean_path.len == 0) { - try w.print(" \"\",\n", .{}); - } else { - const s = std.fs.path.sep_str; - try w.print(" \"{}{}{}\",\n", .{ std.zig.fmtEscapes(s), std.zig.fmtEscapes(mod.clean_path), std.zig.fmtEscapes(s) }); - } - } -} - -fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32, array: bool) !void { - _ = dir; - - if (m.has_no_zig_deps() and tabs > 0) { - try w.print("null", .{}); - return; - } - if (array) { - try u.print_all(w, .{"&[_]Pkg{"}, true); - } else { - try u.print_all(w, .{"struct {"}, true); - } - const t = " "; - const r = try u.repeat(t, tabs); - for (m.deps) |d, i| { +fn print_deps(w: std.fs.File.Writer, m: u.Module) !void { + try u.print_all(w, .{"&[_]Package{"}, true); + for (m.deps) |d| { if (d.main.len == 0) { continue; } - if (!array) { - const r1 = try std.mem.replaceOwned(u8, gpa, d.name, "-", "_"); - const r2 = try std.mem.replaceOwned(u8, gpa, r1, "/", "_"); - try w.print(" pub const {s} = packages[{}];\n", .{ r2, i }); - } else { - try w.print(" package_data._{s},\n", .{d.id[0..12]}); - } - } - try w.print("{s}", .{try u.concat(&.{ r, "}" })}); -} - -fn print_incl_dirs_to(w: std.fs.File.Writer, list: []u.Module) !void { - for (list) |mod, i| { - if (mod.is_sys_lib) { - continue; - } - for (mod.c_include_dirs) |it| { - if (i > 0) { - try w.print(" cache ++ _paths[{}] ++ \"{}\",\n", .{ i - 1, std.zig.fmtEscapes(it) }); - } else { - try w.print(" \"{}\",\n", .{std.zig.fmtEscapes(it)}); - } - } - } -} - -fn print_csrc_dirs_to(w: std.fs.File.Writer, list: []u.Module) !void { - for (list) |mod, i| { - if (mod.is_sys_lib) { - continue; - } - for (mod.c_source_files) |it| { - if (i > 0) { - try w.print(" {s}_ids[{}], cache ++ _paths[{}] ++ \"{s}\"{s},\n", .{ "[_][]const u8{", i - 1, i - 1, it, "}" }); - } else { - try w.print(" {s}_ids[{}], \".{}/{s}\"{s},\n", .{ "[_][]const u8{", i - 1, std.zig.fmtEscapes(mod.clean_path), it, "}" }); - } - } - } -} - -fn print_csrc_flags_to(w: std.fs.File.Writer, list: []u.Module) !void { - for (list) |mod| { - if (mod.is_sys_lib) { - continue; - } - if (mod.c_source_flags.len == 0 and mod.c_source_files.len == 0) { - continue; - } - try w.print(" pub const @\"{s}\" = {s}", .{ mod.id[0..12], "&.{" }); - for (mod.c_source_flags) |it| { - try w.print("\"{}\",", .{std.zig.fmtEscapes(it)}); - } - try w.print("{s};\n", .{"}"}); - } -} - -fn print_sys_libs_to(w: std.fs.File.Writer, list: []u.Module, list2: *std.ArrayList([]const u8)) !void { - _ = list2; - - for (list) |mod| { - if (!mod.is_sys_lib) { - continue; - } - try w.print(" \"{s}\",\n", .{mod.name}); + try w.print(" package_data._{s},\n", .{d.id[0..12]}); } + try w.writeAll("}"); } fn 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 while (notdone.items.len > 0) { for (notdone.items) |mod, i| { if (contains_all(mod.deps, done.items)) { - 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 }); - for (mod.deps) |d| { - if (d.main.len > 0) { - try w.print(" _{s},", .{d.id[0..12]}); + try w.print( + \\ pub const _{s} = Package{{ + \\ + , .{ + mod.id[0..12], + }); + if (mod.main.len > 0) { + try w.print( + \\ .pkg = Pkg{{ .name = "{s}", .path = .{{ .path = dirs._{s} ++ "/{s}" }}, .dependencies = + , .{ + mod.name, + mod.id[0..12], + mod.main, + }); + if (mod.has_no_zig_deps()) { + try w.writeAll(" null },\n"); + } else { + try w.writeAll(" &.{"); + for (mod.deps) |moddep, j| { + if (moddep.main.len == 0) continue; + try w.print(" _{s}.pkg.?", .{moddep.id[0..12]}); + if (j != mod.deps.len - 1) try w.writeAll(","); + } + try w.writeAll(" } },\n"); } } - try w.print(" }} }};\n", .{}); + if (mod.c_include_dirs.len > 0) { + try w.writeAll(" .c_include_dirs = &.{"); + for (mod.c_include_dirs) |item, j| { + try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)}); + if (j != mod.c_include_dirs.len - 1) try w.writeAll(","); + } + try w.writeAll(" },\n"); + } + if (mod.c_source_files.len > 0) { + try w.writeAll(" .c_source_files = &.{"); + for (mod.c_source_files) |item, j| { + try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)}); + if (j != mod.c_source_files.len - 1) try w.writeAll(","); + } + try w.writeAll(" },\n"); + } + if (mod.c_source_flags.len > 0) { + try w.writeAll(" .c_source_flags = &.{"); + for (mod.c_source_flags) |item, j| { + try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)}); + if (j != mod.c_source_flags.len - 1) try w.writeAll(","); + } + try w.writeAll(" },\n"); + } + if (mod.has_syslib_deps()) { + try w.writeAll(" .system_libs = &.{"); + for (mod.deps) |item, j| { + if (!mod.is_sys_lib) continue; + try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)}); + if (j != mod.deps.len - 1) try w.writeAll(","); + } + try w.writeAll(" },\n"); + } + try w.writeAll(" };\n\n"); try done.append(mod); _ = notdone.orderedRemove(i); @@ -278,3 +228,16 @@ fn contains_all(needles: []u.Module, haystack: []const u.Module) bool { } return true; } + +fn print_pkgs(w: std.fs.File.Writer, m: u.Module) !void { + try w.writeAll("struct {\n"); + for (m.deps) |d| { + if (d.main.len == 0) { + continue; + } + const r1 = try std.mem.replaceOwned(u8, gpa, d.name, "-", "_"); + const r2 = try std.mem.replaceOwned(u8, gpa, r1, "/", "_"); + try w.print(" pub const {s} = package_data._{s};\n", .{ r2, d.id[0..12] }); + } + try w.writeAll("}"); +} diff --git a/src/util/module.zig b/src/util/module.zig index 0e1e247a82f63b3be6bb89372d42d48b7eebac13..a36d562335bb9dd5f6033fbddb67e189838ace37 100644 --- a/src/util/module.zig +++ b/src/util/module.zig @@ -107,4 +107,13 @@ pub const Module = struct { } return true; } + + pub fn has_syslib_deps(self: Module) bool { + for (self.deps) |d| { + if (d.is_sys_lib) { + return true; + } + } + return false; + } }; -- 2.54.0