-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
ability to fetch only needed dependencies #14597
Comments
Question, how can we fetch dependency only if we run some command? const exe = b.addExecutable(.{
.name = "ffmpeg",
.target = target,
.optimize = optimize,
});
exe.linkLibrary(libz_dep.artifact("z"));
const benchmark_cmd = exe.run();
const benchmark_step = b.step("benchmark", "Benchmark");
benchmark_step.dependOn(&benchmark_cmd.step); How can we build exe (and fetch its dependencies) only if: zig build benchmark has been invoken. |
I imagine that could be done by only calling |
If I understand correctly, the proposal here is to not add functionality to cover optional dependencies or those only needed for a package's development as the conditional use of For example if I think either declaring dependencies as explicitly optional/dev-only as in #14591 or just fetching lazily (as suggested in comments there) would helpful for reducing this complication in The |
Lazy fetching should be the default, and we should have a If we provide an explicit |
How might this proposal handle a hypothetical “build dependencies” feature? Cargo offers a
// build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
...
useLua(b.allocator);
...
}
// Not possible to use ziglua library during build:
//fn useLua(allocator: std.mem.Allocator) void {
// const ziglua = @import("ziglua");
// const Lua = ziglua.Lua;
// var lua = Lua.init(allocator) catch unreachable;
// defer lua.deinit();
// lua.openLibs();
// lua.doString("return 100") catch unreachable;
// std.debug.print("{d}\n", .{lua.checkNumber(-1)});
//}
// Possible to reference publicly accessible declarations in ziglua’s `build.zig`.
fn useLua(_: std.mem.Allocator) void {
const ziglua = @import("ziglua");
for (std.enums.values(ziglua.LuaVersion)) |v| std.debug.print("{}\n", .{v});
} zig build
|
This would solve two challenges we have with using the package manager for platform-specific binaries (#17914) as well as fetching source vs. binaries depending on a build flag (hexops/mach#901) - so would be a great win for us. |
One slight challenge here: normally dependencies in |
`--fetch` flag now has additional optional parameter, which specifies how lazy dependencies should be fetched: * `lazy` — lazy dependencies are fetched only if they are required for current build configuration to work. Default and works same as old `--fetch` flag. * `all` — lazy dependencies are always fetched. If `--system` flag is used after that, it's guaranteed that **any** build configuration will not require additional download of dependencies during build. Helpful for distro packagers and CI systems: ziglang#14597 (comment) If none is passed, behaviour is same as if `lazy` was passed. Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
`--fetch` flag now has additional optional parameter, which specifies how lazy dependencies should be fetched: * `lazy` — lazy dependencies are fetched only if they are required for current build configuration to work. Default and works same as old `--fetch` flag. * `all` — lazy dependencies are always fetched. If `--system` flag is used after that, it's guaranteed that **any** build configuration will not require additional download of dependencies during build. Helpful for distro packagers and CI systems: ziglang#14597 (comment) If none is passed, behaviour is same as if `lazy` was passed. Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
`--fetch` flag now has additional optional parameter, which specifies how lazy dependencies should be fetched: * `lazy` — lazy dependencies are fetched only if they are required for current build configuration to work. Default and works same as old `--fetch` flag. * `all` — lazy dependencies are always fetched. If `--system` flag is used after that, it's guaranteed that **any** build configuration will not require additional download of dependencies during build. Helpful for distro packagers and CI systems: ziglang#14597 (comment) If none is passed, behaviour is same as if `lazy` was passed. Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
This is a competing proposal to #14591.
Inside of a build.zig file, there may be conditional logic that decides whether a dependency is needed. For example:
Key point here being that
b.dependency("mp3lame")
is only called if theenable_libmp3lame
option is set to true. This means that when that option is not set, libmp3lame is in fact not a dependency.This proposal is to embrace arbitrary logic deciding what is or isn't a dependency. Instead of marking categories of dependencies in the
build.zig.zon
file, Zig would have the heuristic choice to pre-fetch some, all, or none of the dependencies. When running build.zig, if any packages referenced with dependency() were not fetched already, the build runner would exit in a special manner and communicate the set of dependency packages that were missing. Zig would fetch them and then re-execute the build runner.Along with this proposal would come a new flag to
zig build
:--fetch
. Note that this is still part of thezig build
subcommand - indeed it would support all of the same flags and build options as a standardzig build
operation. However, in this case, after running the build.zig script, it would not actually perform the make(). Instead it would only fetch missing packages for the given set of flags. In most typical cases, no additional flags would be used, but one could imagine passing something like this:zig build --fetch --Denable-libmp3lame=false
to avoid fetching libmp3lame in the above example.Related: #14283
The text was updated successfully, but these errors were encountered: