Skip to content

add resolveTargets function for improved lazy import support#83

Merged
silbinarywolf merged 3 commits intomainfrom
feature/add-resolve-targets-for-improved-lazy-import-support
Apr 11, 2026
Merged

add resolveTargets function for improved lazy import support#83
silbinarywolf merged 3 commits intomainfrom
feature/add-resolve-targets-for-improved-lazy-import-support

Conversation

@silbinarywolf
Copy link
Copy Markdown
Owner

@silbinarywolf silbinarywolf commented Apr 11, 2026

Based on request here: #82

Example usage:

// Example usage in Zig 0.16.0-dev.3061+9b1eaad13
pub fn build(b: *std.Build) void {
    const exe_name: []const u8 = "minimal";
    const root_target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const all_android_targets = b.option(bool, "android", "Build for all Android targets (x86, x86_64, aarch64, arm, etc)") orelse false;
    const android_targets: []std.Build.ResolvedTarget = blk: {
        if (all_android_targets or root_target.result.abi.isAndroid()) {
            if (b.lazyImport(@This(), "android")) |android| {
                break :blk android.resolveTargets(b, .{
                    .default_target = root_target,
                    .all_targets = all_android_targets,
                });
            }
        }
        break :blk &[0]std.Build.ResolvedTarget{};
    };

I opted to look at how Zig separates build option creation for targets and took a similar route, for example Zig has resolveTarget for handling the logic without invoking b.option

/// Exposes standard `zig build` options for choosing a target and additionally
/// resolves the target query.
pub fn standardTargetOptions(b: *Build, args: StandardTargetOptionsArgs) ResolvedTarget {
    const query = b.standardTargetOptionsQueryOnly(args);
    return b.resolveTargetQuery(query);
}

@silbinarywolf silbinarywolf merged commit a32c14d into main Apr 11, 2026
10 of 11 checks passed
@silbinarywolf silbinarywolf deleted the feature/add-resolve-targets-for-improved-lazy-import-support branch April 11, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant