build: retry when nested lazy dependency causes missing artifact

Consider root build.zig having a mandatory dependency on package A which
in turns has a lazy dependency on package B.

When the root build.zig calls

    const artifact = dep_a.artifact("a_artifact");

This might cause an error, as package B needs to be fetched before the
artifact can be built. However, the hard panic in Dependency.artifact()
is seen as a fatal error which _prevents_ the parent `zig build` process
from fetching missing dependencies and trying once more.

Handle this more gracefully by checking if we already know there were
missing lazy dependencies, which might come from package A. In the case
we still reach a fixed point with a missing artifact, panic as before.
This commit is contained in:
bfredl 2024-05-23 21:07:40 +02:00
parent d3ba5f397d
commit d1bf035017

View File

@ -1889,6 +1889,10 @@ pub const Dependency = struct {
}
}
return found orelse {
if (d.builder.graph.needed_lazy_dependencies.entries.len != 0) {
// The artifact might become available after missing lazy dependencies have been resolved.
process.exit(3);
}
for (d.builder.install_tls.step.dependencies.items) |dep_step| {
const inst = dep_step.cast(Step.InstallArtifact) orelse continue;
log.info("available artifact: '{s}'", .{inst.artifact.name});