-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build.zig: implement lazy dependencies #139
Conversation
ba33a14
to
39fefd7
Compare
The usage of lazy dependencies in build.zig.zon suggests dvui intends to avoid fetching dependencies for backends that it is not currently building. However, this requires that the `b.lazyDependency` function only be called when that backend is actually enabled. This means having to add build options that avoid calling `b.lazyDependency` when applicable. In addition, it's also nice to still see all the build steps even if the build options for backends have not been given. To accomplish this, I've added `BackendDisabledStep` which can be substituted in for any step when it's associated backend has not been enabled. This step will print a nice error message informing the user how to enable the backend: ```sh $ zig build sdl-standalone +- Assert sdl backend is disabled failure error: the sdl backend requires either -Dsdl to fetch/build its lazy dependencies or --system sdl2 to use the system package Build Summary: 0/2 steps succeeded; 1 failed (disable with --summary none) sdl-standalone transitive failure +- Assert sdl backend is disabled failure error: the following build command failed with exit code 1: C:\git\dvui\.zig-cache\o\af161e5d03a51c0d4c1d598e4941a320\build.exe D:\bin\zig\0.13.0\files\zig.exe C:\git\dvui C:\git\dvui\.zig-cache C:\Users\Jonathan\AppData\Local\zig --seed 0x304864c -Zdd4b5c3ef8c742eb sdl-standalone ``` I've also updated the compile/run step descriptions to show the builld options they require, i.e. ``` C:\git\dvui>zig build --help Usage: D:\bin\zig\0.13.0\files\zig.exe build [steps] [options] Steps: install (default) Copy build artifacts to prefix path uninstall Remove build artifacts from prefix path compile-sdl-standalone Compile sdl-standalone (requires -Dsdl or --system sdl2) sdl-standalone Run sdl-standalone (requires -Dsdl or --system sdl2) compile-sdl-ontop Compile sdl-ontop (requires -Dsdl or --system sdl2) sdl-ontop Run sdl-ontop (requires -Dsdl or --system sdl2) compile-raylib-standalone Compile raylib-standalone (requires -Draylib) raylib-standalone Run raylib-standalone (requires -Draylib) compile-raylib-ontop Compile raylib-ontop (requires -Draylib) raylib-ontop Run raylib-ontop (requires -Draylib) ... ```
I think I understand the problem now. To prevent confusion, I'm going to assign names to the two phases of build.zig (do these already have names?):
We have to call Is that correct? If so, I agree with your zig proposal - that pushes the question of whether to resolve a lazy dependency to make phase. For dvui for now, I think this workaround is more complexity than we need considering our few dependencies, so I'm inclined to go with your other option and make the dependencies non-lazy. That sound good? |
Sure that's a reasonable position. To summarize, the unfortunate part of this situation is projects that don't already use build options to select variations have to add build options for the sole purpose of selecting lazy dependencies (i.e. By the way there's a small correction to your description of the situation. The build runner actually already makes the decision of what lazy dependencies are needed after the |
The usage of lazy dependencies in build.zig.zon suggests dvui intends to avoid fetching dependencies for backends that it is not currently building. However, this requires that the
b.lazyDependency
function only be called when that backend is actually enabled (see https://github.com/ziglang/zig/blob/085cc54aadb327b9910be2c72b31ea046e7e8f52/lib/std/Build.zig#L1961). This means having to add build options that avoid callingb.lazyDependency
when applicable.In addition, it's also nice to still see all the build steps even if the build options for backends have not been given. To accomplish this, I've added
BackendDisabledStep
which can be substituted in for any step when it's associated backend has not been enabled. This step will print a nice error message informing the user how to enable the backend:I've also updated the compile/run step descriptions to show the builld options they require, i.e.
P.S. I wrote up a proposal in zig for us to be able to have lazy dependencies without also having to add build options for them here: ziglang/zig#21525