Skip to content

build: retry when nested lazy dependency causes missing artifact#20051

Open
bfredl wants to merge 1 commit intoziglang:masterfrom
bfredl:lazyartifact
Open

build: retry when nested lazy dependency causes missing artifact#20051
bfredl wants to merge 1 commit intoziglang:masterfrom
bfredl:lazyartifact

Conversation

@bfredl
Copy link
Copy Markdown
Contributor

@bfredl bfredl commented May 23, 2024

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 in A 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.

For reference, this happened when depending upon https://github.com/natecraddock/ziglua/blob/486f51d3acc61d805783f5f07aee34c75ab59a25/build.zig and using the ziglua.artifact("lua") artifact before its lazy dependencies were fetched.

@andrewrk
Copy link
Copy Markdown
Member

Are you sure this is right? In build_runner.zig I see that it prints the lazy dependencies to stdout before exiting with code 3.

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.
bfredl added a commit to bfredl/lazy_test that referenced this pull request Jan 18, 2025
bfredl added a commit to bfredl/lazy_test that referenced this pull request Jan 18, 2025
@bfredl
Copy link
Copy Markdown
Contributor Author

bfredl commented Jan 18, 2025

The original reproduce doesn't work anymore as ziglua currently doesn't use lazyDependencies (although it wants to again eventually). So I created a minimal one here https://github.com/bfredl/lazy_test

And yes, you are right this doesn't work (anymore or maybe it never did).

Spontaneously, this seems to me like something that should be modeled by an error which can be propagated upwards, cleanly. Something like:

pub fn artifact(d: *Dependency, name: []const u8) error.MissingLazyDependency!*Step.Compile {
    ...
}

The price would be that any use of dep.artifact() would need a try in front. I could prototype this if you think this is a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants