Skip to content

Instantly share code, notes, and snippets.

@marler8997
Created September 26, 2024 13:58
Show Gist options
  • Save marler8997/7fedca010547a36d05dba1127d118eab to your computer and use it in GitHub Desktop.
Save marler8997/7fedca010547a36d05dba1127d118eab to your computer and use it in GitHub Desktop.

Lazy Dependencies Today

  • Configure build (build.zig's build fn is invoked)
  • If lazyDependency is ever called during configuration, exit the build runner and resolve the missing dependencies and rebuild/rexecute

Example Usage:

const foo_enabled = b.option(bool, "foo", "Enable foo stuff") orelse false;
if (foo_enabled) {
    if (b.lazyDependency("foo", .{})) |foo_dep| {
        exe.linkLibrary(foo_dep.artifact("foo"));
    }
}

Lazy Dependencies Idea

  • Configure build (build.zig's build fn is invoked)
    • during configuration, lazyDependency returns a dependency object that yeilds paths/artifacts that are "poisoned" with the original lazy dependency
  • After configuration, take the set of steps being built and traverse the build graph to find all steps that we are intending to build and that have been poisoned by a lazy dependency that is missing
  • If any missing dependencies are found, do what we do today, exit the build runner and resolve the missing dependencies and rebuild/rexecute

Example usage:

const foo_dep = b.lazyDependency("foo", .{});
// foo_dep.artifact("foo") is "poisoned" with a lazy dependency
exe.linkLibrary(foo_dep.artifact("foo"));

This idea requires updating build.zig to track and associate artifacts/paths with dependencies...it's not clear to me how feasible this is.

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