diff --git a/deps.zig b/deps.zig index 22929503c75468e86640d573d26f9523fc5b7495..ca3b228fa14368872a3db2fb4f0d761047c9d3d4 100644 --- a/deps.zig +++ b/deps.zig @@ -4,78 +4,54 @@ const builtin = @import("builtin"); const string = []const u8; pub const GitExactStep = struct { - step: std.Build.Step, - builder: *std.Build, - url: string, - commit: string, - - pub fn create(b: *std.Build, url: string, commit: string) *GitExactStep { - var result = b.allocator.create(GitExactStep) catch @panic("memory"); - result.* = GitExactStep{ - .step = std.Build.Step.init(.{ - .id = .custom, - .name = b.fmt("git clone {s} @ {s}", .{ url, commit }), - .owner = b, - .makeFn = make, - }), - .builder = b, - .url = url, - .commit = commit, - }; - - - - var urlpath = url; - urlpath = trimPrefix(u8, urlpath, "https://"); - urlpath = trimPrefix(u8, urlpath, "git://"); - const repopath = b.fmt("{s}/zigmod/deps/git/{s}/{s}", .{ b.cache_root.path.?, urlpath, commit }); - flip(std.Io.Dir.cwd().access(std.Options.debug_io, repopath, .{})) catch return result; - - var clonestep = std.Build.Step.Run.create(b, "clone"); - clonestep.addArgs(&.{ "git", "clone", "-q", "--progress", url, repopath }); - - var checkoutstep = std.Build.Step.Run.create(b, "checkout"); - checkoutstep.addArgs(&.{ "git", "-C", repopath, "checkout", "-q", commit }); - result.step.dependOn(&checkoutstep.step); - checkoutstep.step.dependOn(&clonestep.step); - - return result; - } - - fn make(step: *std.Build.Step, options: std.Build.Step.MakeOptions) !void { - _ = step; - _ = options; - } + step: *std.Build.Step, + path: std.Build.LazyPath, + + pub fn create(b: *std.Build, url: string, commit: string) GitExactStep { + const sc_clone = b.addSystemCommand(&.{ "git", "clone" }); + sc_clone.addArg("--quiet"); + sc_clone.addArg("--progress"); + sc_clone.addArg("--depth"); + sc_clone.addArg("1"); + sc_clone.addArg("--revision"); + sc_clone.addArg(commit); + sc_clone.addArg(url); + const path = sc_clone.addOutputDirectoryArg(std.fs.path.basenamePosix(url)); + return .{ + .step = &sc_clone.step, + .path = path, + }; + } }; pub fn fetch(exe: *std.Build.Step.Compile) *std.Build.Step { const b = exe.step.owner; const step = b.step("fetch", ""); - step.dependOn(&GitExactStep.create(b, "https://github.com/marlersoft/zigwin32", "9f15c276b4e9d05afd34a10d8662a7dfc34647ea").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/arqv-ini", "d2465c64833590a04bd9b7f50c87363fd03e65bf").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-ansi", "bebb39ae30d9848a1c212cee582d0b1c102d8b87").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-detect-license", "6de79b4ff8f7462e26f224f4bed3c81710c8893b").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-extras", "8f6c4761e5c22c6a5c83a032e764154b840275bc").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-git", "88b94a1960be841bb93a0bca65d556cb6385d1fd").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "e745b018f87ddc4c8958370332e6cf61625403cc").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-intrusive-parser", "800cbe5b241fc52370cb8f892f0d9c6f97133725").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-json", "a731b57ee685ff1ddeea9456a924f45ce4da3031").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-leven", "014971d4b1e327a5c61322c3a6b9369fd1863864").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "bc1cd51625c13d6c7df819fd0d85968e617f5c57").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses-text", "a9d067c3c4d6c226a1de5531b66785bc15d869ee").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-nfs", "1a27fe574706f0b91c9f66b22fe7d3fa8f5129d5").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-nio", "17c4f044b15917efc1d3f018765881d53fa27e48").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-sys-darwin", "b349aa32b55aae4cf2ae56740003f8aff0394920").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-sys-freebsd", "f97e6c2de30af76818572490735c84ce1015958b").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-sys-linux", "6dabe7cce239d882c8fd132ab5cda1d1f9ff3634").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-sys-netbsd", "5ad432ca421c59099be3630b9d0dda49e8bef0a7").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-sys-openbsd", "164646a5e7c4129eb92ac524a60f1759605c99df").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-time", "1349fb2c8aaaa1503e8730facea6f87c5fe75dc0").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-tracer", "4ad0602d52a3f40ef74f59f648602c61409f7ba7").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-yaml", "dff9fd43ebf1046c70090bdccfeb2e4f1c0d584b").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/madler/zlib", "da607da739fa6047df13e66a2af6b8bec7c2a498").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/yaml/libyaml", "2c891fc7a770e8ba2fec34fc6b545c672beb37e6").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/ziglibs/known-folders", "207c34a16e4365edc20d92c7892f962b3bed46e8").step); + dependOnGit(GitExactStep.create(b, "https://github.com/marlersoft/zigwin32", "9f15c276b4e9d05afd34a10d8662a7dfc34647ea"), step, &@field(package_data, "_o6ogpor87xc2")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/arqv-ini", "d2465c64833590a04bd9b7f50c87363fd03e65bf"), step, &@field(package_data, "_u7sysdckdymi")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-ansi", "bebb39ae30d9848a1c212cee582d0b1c102d8b87"), step, &@field(package_data, "_s84v9o48ucb0")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-detect-license", "6de79b4ff8f7462e26f224f4bed3c81710c8893b"), step, &@field(package_data, "_2ovav391ivak")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-extras", "8f6c4761e5c22c6a5c83a032e764154b840275bc"), step, &@field(package_data, "_f7dubzb7cyqe")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-git", "88b94a1960be841bb93a0bca65d556cb6385d1fd"), step, &@field(package_data, "_0k64oe2nuzvj")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "e745b018f87ddc4c8958370332e6cf61625403cc"), step, &@field(package_data, "_c1xirp1ota5p")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-intrusive-parser", "800cbe5b241fc52370cb8f892f0d9c6f97133725"), step, &@field(package_data, "_7l3oxw6nqqws")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-json", "a731b57ee685ff1ddeea9456a924f45ce4da3031"), step, &@field(package_data, "_ocmr9rtohgcc")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-leven", "014971d4b1e327a5c61322c3a6b9369fd1863864"), step, &@field(package_data, "_96h80ezrvj7i")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "bc1cd51625c13d6c7df819fd0d85968e617f5c57"), step, &@field(package_data, "_0npcrzfdlrvk")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-licenses-text", "a9d067c3c4d6c226a1de5531b66785bc15d869ee"), step, &@field(package_data, "_pt88y5d80m25")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-nfs", "1a27fe574706f0b91c9f66b22fe7d3fa8f5129d5"), step, &@field(package_data, "_vph9l0hxpeze")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-nio", "17c4f044b15917efc1d3f018765881d53fa27e48"), step, &@field(package_data, "_kscsl0145t7x")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-darwin", "b349aa32b55aae4cf2ae56740003f8aff0394920"), step, &@field(package_data, "_73bukkeci2u6")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-freebsd", "f97e6c2de30af76818572490735c84ce1015958b"), step, &@field(package_data, "_qfev2g50alvp")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-linux", "6dabe7cce239d882c8fd132ab5cda1d1f9ff3634"), step, &@field(package_data, "_h7tv7ayhffak")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-netbsd", "5ad432ca421c59099be3630b9d0dda49e8bef0a7"), step, &@field(package_data, "_uvkgl6xf1azv")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-sys-openbsd", "164646a5e7c4129eb92ac524a60f1759605c99df"), step, &@field(package_data, "_4rmxgmcykiba")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-time", "1349fb2c8aaaa1503e8730facea6f87c5fe75dc0"), step, &@field(package_data, "_iecwp4b3bsfm")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-tracer", "4ad0602d52a3f40ef74f59f648602c61409f7ba7"), step, &@field(package_data, "_ede2wygpe1iy")); + dependOnGit(GitExactStep.create(b, "https://github.com/nektro/zig-yaml", "dff9fd43ebf1046c70090bdccfeb2e4f1c0d584b"), step, &@field(package_data, "_g982zq6e8wsv")); + dependOnGit(GitExactStep.create(b, "https://github.com/madler/zlib", "da607da739fa6047df13e66a2af6b8bec7c2a498"), step, &@field(package_data, "_0e2d06bb494b")); + dependOnGit(GitExactStep.create(b, "https://github.com/yaml/libyaml", "2c891fc7a770e8ba2fec34fc6b545c672beb37e6"), step, &@field(package_data, "_8mdbh0zuneb0")); + dependOnGit(GitExactStep.create(b, "https://github.com/ziglibs/known-folders", "207c34a16e4365edc20d92c7892f962b3bed46e8"), step, &@field(package_data, "_2ta738wrqbaq")); return step; } @@ -103,11 +79,16 @@ pub fn addAllTo(exe: *std.Build.Step.Compile) void { inline for (comptime std.meta.declarations(package_data)) |decl| @field(package_data, decl.name).module_memo = null; } +pub fn dependOnGit(ge: GitExactStep, s: *std.Build.Step, p: *Package) void { + s.dependOn(ge.step); + p.path = ge.path; +} + var link_lib_c = false; pub const Package = struct { name: string = "", - store: ?string = null, main: ?string = null, + path: ?std.Build.LazyPath = null, deps: []const *Package = &.{}, c_include_dirs: []const string = &.{}, c_source_files: []const string = &.{}, @@ -137,8 +118,8 @@ pub const Package = struct { dummy_library.step.dependOn(fetch_step); var links: u32 = 0; if (self.main) |m| { - if (self.store) |s| { - result.root_source_file = (std.Build.LazyPath{ .cwd_relative = b.cache_root.path.? }).path(b, "zigmod/deps").path(b, s[1..]).path(b, m); + if (self.path) |p| { + result.root_source_file = p.path(b, m); } else { result.root_source_file = b.path(m); } @@ -157,13 +138,13 @@ pub const Package = struct { } } for (self.c_include_dirs) |item| { - result.addIncludePath(.{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) }); - dummy_library.root_module.addIncludePath(.{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) }); + result.addIncludePath(self.path.?.path(b, item)); + dummy_library.root_module.addIncludePath(self.path.?.path(b, item)); link_lib_c = true; links += 1; } for (self.c_source_files) |item| { - dummy_library.root_module.addCSourceFile(.{ .file = .{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) }, .flags = self.c_source_flags }); + dummy_library.root_module.addCSourceFile(.{ .file = self.path.?.path(b, item), .flags = self.c_source_flags }); links += 1; } for (self.system_libs) |item| { @@ -195,139 +176,114 @@ fn checkMinZig(current: std.SemanticVersion, exe: *std.Build.Step.Compile) void pub const package_data = struct { pub var _o6ogpor87xc2 = Package{ - .store = "/git/github.com/marlersoft/zigwin32/9f15c276b4e9d05afd34a10d8662a7dfc34647ea", .name = "win32", .main = "win32.zig", }; pub var _u7sysdckdymi = Package{ - .store = "/git/github.com/nektro/arqv-ini/d2465c64833590a04bd9b7f50c87363fd03e65bf", .name = "ini", .main = "src/ini.zig", }; pub var _s84v9o48ucb0 = Package{ - .store = "/git/github.com/nektro/zig-ansi/bebb39ae30d9848a1c212cee582d0b1c102d8b87", .name = "ansi", .main = "src/lib.zig", }; pub var _f7dubzb7cyqe = Package{ - .store = "/git/github.com/nektro/zig-extras/8f6c4761e5c22c6a5c83a032e764154b840275bc", .name = "extras", .main = "src/lib.zig", }; pub var _c1xirp1ota5p = Package{ - .store = "/git/github.com/nektro/zig-inquirer/e745b018f87ddc4c8958370332e6cf61625403cc", .name = "inquirer", .main = "src/lib.zig", .deps = &[_]*Package{ &_s84v9o48ucb0 }, }; pub var _96h80ezrvj7i = Package{ - .store = "/git/github.com/nektro/zig-leven/014971d4b1e327a5c61322c3a6b9369fd1863864", .name = "leven", .main = "src/lib.zig", }; pub var _0npcrzfdlrvk = Package{ - .store = "/git/github.com/nektro/zig-licenses/bc1cd51625c13d6c7df819fd0d85968e617f5c57", .name = "licenses", .main = "src/lib.zig", }; pub var _pt88y5d80m25 = Package{ - .store = "/git/github.com/nektro/zig-licenses-text/a9d067c3c4d6c226a1de5531b66785bc15d869ee", .name = "licenses-text", .main = "src/lib.zig", }; pub var _73bukkeci2u6 = Package{ - .store = "/git/github.com/nektro/zig-sys-darwin/b349aa32b55aae4cf2ae56740003f8aff0394920", .name = "sys-darwin", .main = "sys_darwin.zig", }; pub var _qfev2g50alvp = Package{ - .store = "/git/github.com/nektro/zig-sys-freebsd/f97e6c2de30af76818572490735c84ce1015958b", .name = "sys-freebsd", .main = "freebsd.zig", }; pub var _h7tv7ayhffak = Package{ - .store = "/git/github.com/nektro/zig-sys-linux/6dabe7cce239d882c8fd132ab5cda1d1f9ff3634", .name = "sys-linux", .main = "mod.zig", }; pub var _uvkgl6xf1azv = Package{ - .store = "/git/github.com/nektro/zig-sys-netbsd/5ad432ca421c59099be3630b9d0dda49e8bef0a7", .name = "sys-netbsd", .main = "netbsd.zig", }; pub var _4rmxgmcykiba = Package{ - .store = "/git/github.com/nektro/zig-sys-openbsd/164646a5e7c4129eb92ac524a60f1759605c99df", .name = "sys-openbsd", .main = "openbsd.zig", }; pub var _kscsl0145t7x = Package{ - .store = "/git/github.com/nektro/zig-nio/17c4f044b15917efc1d3f018765881d53fa27e48", .name = "nio", .main = "nio.zig", .deps = &[_]*Package{ &_h7tv7ayhffak, &_f7dubzb7cyqe, &_73bukkeci2u6, &_qfev2g50alvp, &_uvkgl6xf1azv, &_4rmxgmcykiba }, }; pub var _7l3oxw6nqqws = Package{ - .store = "/git/github.com/nektro/zig-intrusive-parser/800cbe5b241fc52370cb8f892f0d9c6f97133725", .name = "intrusive-parser", .main = "intrusive_parser.zig", .deps = &[_]*Package{ &_f7dubzb7cyqe, &_kscsl0145t7x }, }; pub var _iecwp4b3bsfm = Package{ - .store = "/git/github.com/nektro/zig-time/1349fb2c8aaaa1503e8730facea6f87c5fe75dc0", .name = "time", .main = "time.zig", .deps = &[_]*Package{ &_f7dubzb7cyqe, &_h7tv7ayhffak, &_73bukkeci2u6, &_kscsl0145t7x, &_qfev2g50alvp, &_uvkgl6xf1azv, &_4rmxgmcykiba }, }; pub var _vph9l0hxpeze = Package{ - .store = "/git/github.com/nektro/zig-nfs/1a27fe574706f0b91c9f66b22fe7d3fa8f5129d5", .name = "nfs", .main = "nfs.zig", .deps = &[_]*Package{ &_h7tv7ayhffak, &_kscsl0145t7x, &_iecwp4b3bsfm, &_73bukkeci2u6, &_qfev2g50alvp, &_uvkgl6xf1azv, &_4rmxgmcykiba }, }; pub var _2ovav391ivak = Package{ - .store = "/git/github.com/nektro/zig-detect-license/6de79b4ff8f7462e26f224f4bed3c81710c8893b", .name = "detect-license", .main = "src/lib.zig", .deps = &[_]*Package{ &_pt88y5d80m25, &_96h80ezrvj7i, &_vph9l0hxpeze }, }; pub var _ede2wygpe1iy = Package{ - .store = "/git/github.com/nektro/zig-tracer/4ad0602d52a3f40ef74f59f648602c61409f7ba7", .name = "tracer", .main = "src/mod.zig", .deps = &[_]*Package{ &_f7dubzb7cyqe, &_h7tv7ayhffak, &_vph9l0hxpeze, &_kscsl0145t7x, &_iecwp4b3bsfm }, }; pub var _0k64oe2nuzvj = Package{ - .store = "/git/github.com/nektro/zig-git/88b94a1960be841bb93a0bca65d556cb6385d1fd", .name = "git", .main = "git.zig", .deps = &[_]*Package{ &_iecwp4b3bsfm, &_f7dubzb7cyqe, &_ede2wygpe1iy, &_vph9l0hxpeze, &_kscsl0145t7x, &_0e2d06bb494b }, }; pub var _ocmr9rtohgcc = Package{ - .store = "/git/github.com/nektro/zig-json/a731b57ee685ff1ddeea9456a924f45ce4da3031", .name = "json", .main = "json.zig", .deps = &[_]*Package{ &_f7dubzb7cyqe, &_ede2wygpe1iy, &_7l3oxw6nqqws, &_kscsl0145t7x }, }; pub var _g982zq6e8wsv = Package{ - .store = "/git/github.com/nektro/zig-yaml/dff9fd43ebf1046c70090bdccfeb2e4f1c0d584b", .name = "yaml", .main = "yaml.zig", .deps = &[_]*Package{ &_8mdbh0zuneb0 }, }; pub var _0e2d06bb494b = Package{ - .store = "/git/github.com/madler/zlib/da607da739fa6047df13e66a2af6b8bec7c2a498", .c_include_dirs = &.{ "" }, .c_source_files = &.{ "inftrees.c", "inflate.c", "adler32.c", "zutil.c", "trees.c", "gzclose.c", "gzwrite.c", "gzread.c", "deflate.c", "compress.c", "crc32.c", "infback.c", "gzlib.c", "uncompr.c", "inffast.c" }, .c_source_flags = &.{ "-DZ_HAVE_UNISTD_H=1" }, }; pub var _8mdbh0zuneb0 = Package{ - .store = "/git/github.com/yaml/libyaml/2c891fc7a770e8ba2fec34fc6b545c672beb37e6", .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 var _2ta738wrqbaq = Package{ - .store = "/git/github.com/ziglibs/known-folders/207c34a16e4365edc20d92c7892f962b3bed46e8", .name = "known-folders", .main = "known-folders.zig", }; diff --git a/src/cmd/generate.zig b/src/cmd/generate.zig index 8337114fa31096846de61d48d0317b82fc1e5c45..78c7bd1ebe3acb0005d83f7b9cddb5cb02f8eb3c 100644 --- a/src/cmd/generate.zig +++ b/src/cmd/generate.zig @@ -47,48 +47,24 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: [:0]const u8, dir: nf try w.writeAll("\n"); try w.writeAll( \\pub const GitExactStep = struct { - \\ step: std.Build.Step, - \\ builder: *std.Build, - \\ url: string, - \\ commit: string, + \\ step: *std.Build.Step, + \\ path: std.Build.LazyPath, \\ - \\ pub fn create(b: *std.Build, url: string, commit: string) *GitExactStep { - \\ var result = b.allocator.create(GitExactStep) catch @panic("memory"); - \\ result.* = GitExactStep{ - \\ .step = std.Build.Step.init(.{ - \\ .id = .custom, - \\ .name = b.fmt("git clone {s} @ {s}", .{ url, commit }), - \\ .owner = b, - \\ .makeFn = make, - \\ }), - \\ .builder = b, - \\ .url = url, - \\ .commit = commit, - \\ }; - \\ - \\ var urlpath = url; - \\ urlpath = trimPrefix(u8, urlpath, "https://"); - \\ urlpath = trimPrefix(u8, urlpath, "git://"); - \\ const repopath = b.fmt("{s}/zigmod/deps/git/{s}/{s}", .{ b.cache_root.path.?, urlpath, commit }); - \\ flip(std.Io.Dir.cwd().access(std.Options.debug_io, repopath, .{})) catch return result; - \\ - \\ var clonestep = std.Build.Step.Run.create(b, "clone"); - \\ clonestep.addArgs(&.{ "git", "clone", "-q", "--progress", url, repopath }); - \\ - \\ var checkoutstep = std.Build.Step.Run.create(b, "checkout"); - \\ checkoutstep.addArgs(&.{ "git", "-C", repopath, "checkout", "-q", commit }); - \\ result.step.dependOn(&checkoutstep.step); - \\ checkoutstep.step.dependOn(&clonestep.step); - // TODO rm the .git folder - // TODO mark folder as read-only - \\ - \\ return result; - \\ } - \\ - \\ fn make(step: *std.Build.Step, options: std.Build.Step.MakeOptions) !void { - \\ _ = step; - \\ _ = options; - \\ } + \\ pub fn create(b: *std.Build, url: string, commit: string) GitExactStep { + \\ const sc_clone = b.addSystemCommand(&.{ "git", "clone" }); + \\ sc_clone.addArg("--quiet"); + \\ sc_clone.addArg("--progress"); + \\ sc_clone.addArg("--depth"); + \\ sc_clone.addArg("1"); + \\ sc_clone.addArg("--revision"); + \\ sc_clone.addArg(commit); + \\ sc_clone.addArg(url); + \\ const path = sc_clone.addOutputDirectoryArg(std.fs.path.basenamePosix(url)); + \\ return .{ + \\ .step = &sc_clone.step, + \\ .path = path, + \\ }; + \\ } \\}; \\ \\pub fn fetch(exe: *std.Build.Step.Compile) *std.Build.Step { @@ -101,7 +77,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: [:0]const u8, dir: nf .local => {}, .system_lib => {}, .framework => {}, - .git => try w.print(" step.dependOn(&GitExactStep.create(b, \"{s}\", \"{s}\").step);\n", .{ module.dep.?.path, try module.pin(alloc, cachepath, options) }), + .git => try w.print(" dependOnGit(GitExactStep.create(b, \"{s}\", \"{s}\"), step, &@field(package_data, \"_{s}\"));\n", .{ module.dep.?.path, try module.pin(alloc, cachepath, options), module.short_id() }), .hg => @panic("TODO"), .http => @panic("TODO"), } @@ -134,11 +110,16 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: [:0]const u8, dir: nf \\ inline for (comptime std.meta.declarations(package_data)) |decl| @field(package_data, decl.name).module_memo = null; \\} \\ + \\pub fn dependOnGit(ge: GitExactStep, s: *std.Build.Step, p: *Package) void { + \\ s.dependOn(ge.step); + \\ p.path = ge.path; + \\} + \\ \\var link_lib_c = false; \\pub const Package = struct { \\ name: string = "", - \\ store: ?string = null, \\ main: ?string = null, + \\ path: ?std.Build.LazyPath = null, \\ deps: []const *Package = &.{}, \\ c_include_dirs: []const string = &.{}, \\ c_source_files: []const string = &.{}, @@ -168,8 +149,8 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: [:0]const u8, dir: nf \\ dummy_library.step.dependOn(fetch_step); \\ var links: u32 = 0; \\ if (self.main) |m| { - \\ if (self.store) |s| { - \\ result.root_source_file = (std.Build.LazyPath{ .cwd_relative = b.cache_root.path.? }).path(b, "zigmod/deps").path(b, s[1..]).path(b, m); + \\ if (self.path) |p| { + \\ result.root_source_file = p.path(b, m); \\ } else { \\ result.root_source_file = b.path(m); \\ } @@ -188,13 +169,13 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: [:0]const u8, dir: nf \\ } \\ } \\ for (self.c_include_dirs) |item| { - \\ result.addIncludePath(.{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) }); - \\ dummy_library.root_module.addIncludePath(.{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) }); + \\ result.addIncludePath(self.path.?.path(b, item)); + \\ dummy_library.root_module.addIncludePath(self.path.?.path(b, item)); \\ link_lib_c = true; \\ links += 1; \\ } \\ for (self.c_source_files) |item| { - \\ dummy_library.root_module.addCSourceFile(.{ .file = .{ .cwd_relative = b.fmt("{s}/zigmod/deps{s}/{s}", .{ b.cache_root.path.?, self.store.?, item }) }, .flags = self.c_source_flags }); + \\ dummy_library.root_module.addCSourceFile(.{ .file = self.path.?.path(b, item), .flags = self.c_source_flags }); \\ links += 1; \\ } \\ for (self.system_libs) |item| { @@ -240,7 +221,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: [:0]const u8, dir: nf } try duped.append(mod); } - try print_pkg_data_to(w, alloc, cachepath, &duped, &done, options); + try print_pkg_data_to(w, &duped, &done); try w.writeAll("};\n\n"); try w.writeAll("pub const packages = "); @@ -281,7 +262,7 @@ fn print_deps(w: nfs.File, m: zigmod.Module) !void { try w.writeAll("}"); } -fn print_pkg_data_to(w: nfs.File, alloc: std.mem.Allocator, cachepath: [:0]const u8, notdone: *std.array_list.Managed(zigmod.Module), done: *std.array_list.Managed(zigmod.Module), options: *common.CollectOptions) !void { +fn print_pkg_data_to(w: nfs.File, notdone: *std.array_list.Managed(zigmod.Module), done: *std.array_list.Managed(zigmod.Module)) !void { var len: usize = notdone.items.len; while (notdone.items.len > 0) { for (notdone.items, 0..) |mod, i| { @@ -292,14 +273,6 @@ fn print_pkg_data_to(w: nfs.File, alloc: std.mem.Allocator, cachepath: [:0]const , .{ mod.short_id(), }); - const fixed_path = if (std.mem.startsWith(u8, mod.clean_path, "v/")) mod.clean_path[2..std.mem.lastIndexOfScalar(u8, mod.clean_path, '/').?] else mod.clean_path; - switch (mod.type) { - .system_lib, .framework => {}, - .local => {}, - .git => try w.print(" .store = \"/{}/{s}\",\n", .{ u.altStringEscape(fixed_path), try mod.pin(alloc, cachepath, options) }), - .hg => @panic("TODO"), - .http => @panic("TODO"), - } if (mod.main.len > 0 and !std.mem.eql(u8, &mod.id, &zigmod.Module.ROOT)) { try w.print(" .name = \"{s}\",\n", .{mod.name}); try w.print(" .main = \"{s}\",\n", .{mod.main});