authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-02 16:21:52 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-06-02 16:21:52 -07:00
logdf8e9fbb79dfeb0634ade259486d01da9e6cef71
treec75294963aa6680a3eafc17a3926c2d1f5407e78
parent21683f9329aa22ed8a2d0e3cdff48a398521b65c

generate: fix build graph dependency ordering bug

the addition of dummy_library needed to be added in the build dep tree

2 files changed, 34 insertions(+), 30 deletions(-)

deps.zig+25-23
...@@ -31,7 +31,6 @@ pub const GitExactStep = struct {...@@ -31,7 +31,6 @@ pub const GitExactStep = struct {
3131
32 var clonestep = std.Build.Step.Run.create(b, "clone");32 var clonestep = std.Build.Step.Run.create(b, "clone");
33 clonestep.addArgs(&.{ "git", "clone", "-q", "--progress", url, repopath });33 clonestep.addArgs(&.{ "git", "clone", "-q", "--progress", url, repopath });
34 result.step.dependOn(&clonestep.step);
3534
36 var checkoutstep = std.Build.Step.Run.create(b, "checkout");35 var checkoutstep = std.Build.Step.Run.create(b, "checkout");
37 checkoutstep.addArgs(&.{ "git", "-C", repopath, "checkout", "-q", commit });36 checkoutstep.addArgs(&.{ "git", "-C", repopath, "checkout", "-q", commit });
...@@ -47,30 +46,32 @@ pub const GitExactStep = struct {...@@ -47,30 +46,32 @@ pub const GitExactStep = struct {
47 }46 }
48};47};
4948
50pub fn fetch(exe: *std.Build.Step.Compile) void {49pub fn fetch(exe: *std.Build.Step.Compile) *std.Build.Step {
51 const b = exe.step.owner;50 const b = exe.step.owner;
51 const step = b.step("fetch", "");
52 inline for (comptime std.meta.declarations(package_data)) |decl| {52 inline for (comptime std.meta.declarations(package_data)) |decl| {
53 const path = &@field(package_data, decl.name).entry;53 const path = &@field(package_data, decl.name).entry;
54 const root = if (@field(package_data, decl.name).store) |_| b.cache_root.path.? else ".";54 const root = if (@field(package_data, decl.name).store) |_| b.cache_root.path.? else ".";
55 if (path.* != null) path.* = b.fmt("{s}/zigmod/deps{s}", .{ root, path.*.? });55 if (path.* != null) path.* = b.fmt("{s}/zigmod/deps{s}", .{ root, path.*.? });
56 }56 }
57 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/marlersoft/zigwin32", "c778640d3dc153e900fbe37e2816b5176af3c802").step);57 step.dependOn(&GitExactStep.create(b, "https://github.com/marlersoft/zigwin32", "c778640d3dc153e900fbe37e2816b5176af3c802").step);
58 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/arqv-ini", "38a018ad3a19d5b4663a5364d2d31271f250846b").step);58 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/arqv-ini", "38a018ad3a19d5b4663a5364d2d31271f250846b").step);
59 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/iguanaTLS", "4dc8850883b49e4a452871298788b06b1af9fe24").step);59 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/iguanaTLS", "4dc8850883b49e4a452871298788b06b1af9fe24").step);
60 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zfetch", "863be236188e5f24d16554f9dcd7df96dd254a13").step);60 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zfetch", "863be236188e5f24d16554f9dcd7df96dd254a13").step);
61 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-ansi", "c3e439f86b0484e4428f38c4d8b07b7b5ae1634b").step);61 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-ansi", "c3e439f86b0484e4428f38c4d8b07b7b5ae1634b").step);
62 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-detect-license", "3ff57d0681b7bd7f8ca9bd092afa0b4bfe2f1afd").step);62 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-detect-license", "3ff57d0681b7bd7f8ca9bd092afa0b4bfe2f1afd").step);
63 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-extras", "74f0ddb0a4dfa7921739b88cc381951a6b6e73ce").step);63 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-extras", "74f0ddb0a4dfa7921739b88cc381951a6b6e73ce").step);
64 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "9e1d873db79e9ffa6ae6e06bd372428c9be85d97").step);64 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "9e1d873db79e9ffa6ae6e06bd372428c9be85d97").step);
65 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-leven", "e548b0bcc7b6f34f636c0b6b905928d31254c54d").step);65 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-leven", "e548b0bcc7b6f34f636c0b6b905928d31254c54d").step);
66 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "f46d9f774df929885eef66c733a1e2a46bf16aec").step);66 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "f46d9f774df929885eef66c733a1e2a46bf16aec").step);
67 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses-text", "b01e5a2dffcc564bddd8f514fe64bab9b5c52572").step);67 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses-text", "b01e5a2dffcc564bddd8f514fe64bab9b5c52572").step);
68 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-range", "4b2f12808aa09be4b27a163efc424dd4e0415992").step);68 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-range", "4b2f12808aa09be4b27a163efc424dd4e0415992").step);
69 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-time", "ba546bbf2e8438c9b2325f36f392c9d95b432e8e").step);69 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-time", "ba546bbf2e8438c9b2325f36f392c9d95b432e8e").step);
70 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-yaml", "0d17fb99cba338aedc1abac12d78d5e5f04f0b6b").step);70 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-yaml", "0d17fb99cba338aedc1abac12d78d5e5f04f0b6b").step);
71 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/truemedian/hzzp", "a7f03a1e652abe8c89b376d090cec50acb0d2a1a").step);71 step.dependOn(&GitExactStep.create(b, "https://github.com/truemedian/hzzp", "a7f03a1e652abe8c89b376d090cec50acb0d2a1a").step);
72 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/ziglibs/known-folders", "0ad514dcfb7525e32ae349b9acc0a53976f3a9fa").step);72 step.dependOn(&GitExactStep.create(b, "https://github.com/ziglibs/known-folders", "0ad514dcfb7525e32ae349b9acc0a53976f3a9fa").step);
73 exe.step.dependOn(&GitExactStep.create(b, "https://github.com/yaml/libyaml", "2c891fc7a770e8ba2fec34fc6b545c672beb37e6").step);73 step.dependOn(&GitExactStep.create(b, "https://github.com/yaml/libyaml", "2c891fc7a770e8ba2fec34fc6b545c672beb37e6").step);
74 return step;
74}75}
7576
76fn trimPrefix(comptime T: type, haystack: []const T, needle: []const T) []const T {77fn trimPrefix(comptime T: type, haystack: []const T, needle: []const T) []const T {
...@@ -87,10 +88,10 @@ fn flip(foo: anytype) !void {...@@ -87,10 +88,10 @@ fn flip(foo: anytype) !void {
8788
88pub fn addAllTo(exe: *std.Build.Step.Compile) void {89pub fn addAllTo(exe: *std.Build.Step.Compile) void {
89 checkMinZig(builtin.zig_version, exe);90 checkMinZig(builtin.zig_version, exe);
90 fetch(exe);91 const fetch_step = fetch(exe);
91 @setEvalBranchQuota(1_000_000);92 @setEvalBranchQuota(1_000_000);
92 for (packages) |pkg| {93 for (packages) |pkg| {
93 const module = pkg.module(exe);94 const module = pkg.module(exe, fetch_step);
94 exe.root_module.addImport(pkg.name, module);95 exe.root_module.addImport(pkg.name, module);
95 }96 }
96}97}
...@@ -108,7 +109,7 @@ pub const Package = struct {...@@ -108,7 +109,7 @@ pub const Package = struct {
108 frameworks: []const string = &.{},109 frameworks: []const string = &.{},
109 module_memo: ?*std.Build.Module = null,110 module_memo: ?*std.Build.Module = null,
110111
111 pub fn module(self: *Package, exe: *std.Build.Step.Compile) *std.Build.Module {112 pub fn module(self: *Package, exe: *std.Build.Step.Compile, fetch_step: *std.Build.Step) *std.Build.Module {
112 if (self.module_memo) |cached| {113 if (self.module_memo) |cached| {
113 return cached;114 return cached;
114 }115 }
...@@ -120,11 +121,12 @@ pub const Package = struct {...@@ -120,11 +121,12 @@ pub const Package = struct {
120 .target = exe.root_module.resolved_target orelse b.host,121 .target = exe.root_module.resolved_target orelse b.host,
121 .optimize = exe.root_module.optimize.?,122 .optimize = exe.root_module.optimize.?,
122 });123 });
124 dummy_library.step.dependOn(fetch_step);
123 if (self.entry) |capture| {125 if (self.entry) |capture| {
124 result.root_source_file = .{ .path = capture };126 result.root_source_file = .{ .path = capture };
125 }127 }
126 for (self.deps) |item| {128 for (self.deps) |item| {
127 const module_dep = item.module(exe);129 const module_dep = item.module(exe, fetch_step);
128 if (module_dep.root_source_file != null) {130 if (module_dep.root_source_file != null) {
129 result.addImport(item.name, module_dep);131 result.addImport(item.name, module_dep);
130 }132 }
src/cmd/generate.zig+9-7
...@@ -72,7 +72,6 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D...@@ -72,7 +72,6 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
72 \\72 \\
73 \\ var clonestep = std.Build.Step.Run.create(b, "clone");73 \\ var clonestep = std.Build.Step.Run.create(b, "clone");
74 \\ clonestep.addArgs(&.{ "git", "clone", "-q", "--progress", url, repopath });74 \\ clonestep.addArgs(&.{ "git", "clone", "-q", "--progress", url, repopath });
75 \\ result.step.dependOn(&clonestep.step);
76 \\75 \\
77 \\ var checkoutstep = std.Build.Step.Run.create(b, "checkout");76 \\ var checkoutstep = std.Build.Step.Run.create(b, "checkout");
78 \\ checkoutstep.addArgs(&.{ "git", "-C", repopath, "checkout", "-q", commit });77 \\ checkoutstep.addArgs(&.{ "git", "-C", repopath, "checkout", "-q", commit });
...@@ -90,8 +89,9 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D...@@ -90,8 +89,9 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
90 \\ }89 \\ }
91 \\};90 \\};
92 \\91 \\
93 \\pub fn fetch(exe: *std.Build.Step.Compile) void {92 \\pub fn fetch(exe: *std.Build.Step.Compile) *std.Build.Step {
94 \\ const b = exe.step.owner;93 \\ const b = exe.step.owner;
94 \\ const step = b.step("fetch", "");
95 \\ inline for (comptime std.meta.declarations(package_data)) |decl| {95 \\ inline for (comptime std.meta.declarations(package_data)) |decl| {
96 \\ const path = &@field(package_data, decl.name).entry;96 \\ const path = &@field(package_data, decl.name).entry;
97 \\ const root = if (@field(package_data, decl.name).store) |_| b.cache_root.path.? else ".";97 \\ const root = if (@field(package_data, decl.name).store) |_| b.cache_root.path.? else ".";
...@@ -104,12 +104,13 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D...@@ -104,12 +104,13 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
104 .local => {},104 .local => {},
105 .system_lib => {},105 .system_lib => {},
106 .framework => {},106 .framework => {},
107 .git => try w.print(" exe.step.dependOn(&GitExactStep.create(b, \"{s}\", \"{s}\").step);\n", .{ module.dep.?.path, try module.pin(alloc, cachepath) }),107 .git => try w.print(" step.dependOn(&GitExactStep.create(b, \"{s}\", \"{s}\").step);\n", .{ module.dep.?.path, try module.pin(alloc, cachepath) }),
108 .hg => @panic("TODO"),108 .hg => @panic("TODO"),
109 .http => @panic("TODO"),109 .http => @panic("TODO"),
110 }110 }
111 }111 }
112 try w.writeAll(112 try w.writeAll(
113 \\ return step;
113 \\}114 \\}
114 \\115 \\
115 \\fn trimPrefix(comptime T: type, haystack: []const T, needle: []const T) []const T {116 \\fn trimPrefix(comptime T: type, haystack: []const T, needle: []const T) []const T {
...@@ -126,10 +127,10 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D...@@ -126,10 +127,10 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
126 \\127 \\
127 \\pub fn addAllTo(exe: *std.Build.Step.Compile) void {128 \\pub fn addAllTo(exe: *std.Build.Step.Compile) void {
128 \\ checkMinZig(builtin.zig_version, exe);129 \\ checkMinZig(builtin.zig_version, exe);
129 \\ fetch(exe);130 \\ const fetch_step = fetch(exe);
130 \\ @setEvalBranchQuota(1_000_000);131 \\ @setEvalBranchQuota(1_000_000);
131 \\ for (packages) |pkg| {132 \\ for (packages) |pkg| {
132 \\ const module = pkg.module(exe);133 \\ const module = pkg.module(exe, fetch_step);
133 \\ exe.root_module.addImport(pkg.name, module);134 \\ exe.root_module.addImport(pkg.name, module);
134 \\ }135 \\ }
135 \\}136 \\}
...@@ -147,7 +148,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D...@@ -147,7 +148,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
147 \\ frameworks: []const string = &.{},148 \\ frameworks: []const string = &.{},
148 \\ module_memo: ?*std.Build.Module = null,149 \\ module_memo: ?*std.Build.Module = null,
149 \\150 \\
150 \\ pub fn module(self: *Package, exe: *std.Build.Step.Compile) *std.Build.Module {151 \\ pub fn module(self: *Package, exe: *std.Build.Step.Compile, fetch_step: *std.Build.Step) *std.Build.Module {
151 \\ if (self.module_memo) |cached| {152 \\ if (self.module_memo) |cached| {
152 \\ return cached;153 \\ return cached;
153 \\ }154 \\ }
...@@ -159,11 +160,12 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D...@@ -159,11 +160,12 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
159 \\ .target = exe.root_module.resolved_target orelse b.host,160 \\ .target = exe.root_module.resolved_target orelse b.host,
160 \\ .optimize = exe.root_module.optimize.?,161 \\ .optimize = exe.root_module.optimize.?,
161 \\ });162 \\ });
163 \\ dummy_library.step.dependOn(fetch_step);
162 \\ if (self.entry) |capture| {164 \\ if (self.entry) |capture| {
163 \\ result.root_source_file = .{ .path = capture };165 \\ result.root_source_file = .{ .path = capture };
164 \\ }166 \\ }
165 \\ for (self.deps) |item| {167 \\ for (self.deps) |item| {
166 \\ const module_dep = item.module(exe);168 \\ const module_dep = item.module(exe, fetch_step);
167 \\ if (module_dep.root_source_file != null) {169 \\ if (module_dep.root_source_file != null) {
168 \\ result.addImport(item.name, module_dep);170 \\ result.addImport(item.name, module_dep);
169 \\ }171 \\ }