Zig build, non-zig dependency target inheritance

With 16667 merged, we can make any c package with zig build without vendoring it, but it looks like that the target option will not be inherited by dependencies that do not use module but only artifacts. here is My temporary hack, is there any other way that I am not aware of?

    const wepoll_dep = b.dependency("wepoll", .{});
    if (t.os.tag == .windows) {
        var wepoll_lib = wepoll_dep.artifact("wepoll");
        wepoll_lib.target = target;
        wepoll_lib.optimize = optimize;
        lib.linkLibrary(wepoll_lib);
    }

link to the repo: libev/build.zig at main - libev - Codeberg.org

looks like that I need to pass the target and optimize option during dependency initialization:

    const wepoll_dep = b.dependency("wepoll", .{
        .target = target,
        .optimize = optimize,
    });
1 Like