Description
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:
const std = @import("std");
pub fn build(b: *std.build.Builder) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const enable_libmp3lame = b.option(bool, "enable-libmp3lame",
"support MP3 decoding via libmp3lame") orelse true;
const lib = b.addStaticLibrary(.{
.name = "ffmpeg",
.target = target,
.optimize = optimize,
});
lib.linkLibrary(libz_dep.artifact("z"));
if (enable_libmp3lame) {
const libmp3lame_dep = b.dependency("libmp3lame", .{
.target = target,
.optimize = optimize,
});
lib.linkLibrary(libmp3lame_dep.artifact("mp3lame"));
}
lib.linkLibC();
lib.addIncludePath(".");
}
Key point here being that b.dependency("mp3lame")
is only called if the enable_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 the zig build
subcommand - indeed it would support all of the same flags and build options as a standard zig 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
Metadata
Metadata
Assignees
Labels
Type
Projects
Status