ZigBuildDispatcher 0.1.1

dotnet add package ZigBuildDispatcher --version 0.1.1
                    
NuGet\Install-Package ZigBuildDispatcher -Version 0.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZigBuildDispatcher" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZigBuildDispatcher" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="ZigBuildDispatcher" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ZigBuildDispatcher --version 0.1.1
                    
#r "nuget: ZigBuildDispatcher, 0.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ZigBuildDispatcher@0.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ZigBuildDispatcher&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=ZigBuildDispatcher&version=0.1.1
                    
Install as a Cake Tool

WARNING

This package provides no security guarantees for inputs passed to the build dispatcher; untrusted inputs can lead to code execution. This project is AI-generated/experimental and should be used at your own risk.

ZigBuildDispatcher

High-performance build dispatcher for Zig projects with concurrent builds, isolated workspaces, and streamed output.

Highlights

  • Concurrent build execution with a bounded semaphore.
  • Per-build workspace isolation (zig-cache/zig-out/zig-tmp).
  • Optional shared global cache for faster repeated builds.
  • Output streaming without exceptions (railway-style Result<T>).
  • Artifact selection by name, extension, pattern, or explicit path.
  • Zig discovery via explicit ZigHome, zvm, zvm home, or PATH.

Requirements

  • .NET 10.0 (projects target net10.0).
  • Zig installed (or managed via zvm).

Install

dotnet add package ZigBuildDispatcher

Quick Start

using ZigBuildDispatcher;

var options = new BuildDispatcherOptions
{
    MaxConcurrency = Math.Max(1, Environment.ProcessorCount),
    WorkspaceRoot = Path.Combine(Path.GetTempPath(), "zig-build-dispatcher"),
    SharedGlobalCacheDir = Path.Combine(Path.GetTempPath(), "zig-build-dispatcher", "zig-global-cache"),
    CleanupWorkspaceOnSuccess = true,
    CleanupWorkspaceOnFailure = false
};

var dispatcher = new BuildDispatcher(options);

var request = BuildRequest.Create(
        buildZigPath: @"C:\path\to\build.zig",
        "-Doptimize=Debug",
        "--summary", "all")
    with
    {
        // Optional: set to a file path or Zig install directory.
        ZigHome = string.Empty,
        // Optional: select output if auto-detect is ambiguous.
        ArtifactSelector = BuildArtifactSelector.Auto,
        // Optional: reuse cache/workspace per user/session.
        CacheKey = "user-123",
        WorkspaceKey = "tab-456"
    };

var result = await dispatcher.DispatchAsync(request);
if (!result.IsSuccess)
{
    Console.WriteLine($"Build failed: {result.Error.Code} - {result.Error.Message}");
    return;
}

var build = result.Value;
Console.WriteLine($"Exit code: {build.ExitCode}");
Console.WriteLine($"Artifact path: {build.Artifact.Path}");
Console.WriteLine($"Artifact bytes: {build.Artifact.Bytes.Length}");

Output Streaming

Use BuildOutputChannel for realtime output:

var output = new BuildOutputChannel(new BuildOutputChannelOptions
{
    Capacity = 2048,
    SingleReader = true
});

var request = BuildRequest.Create(buildZigPath, "--summary", "all") with
{
    OutputSubscriber = output
};

var readTask = Task.Run(async () =>
{
    await foreach (var line in output.ReadAllAsync())
    {
        Console.WriteLine(line.Text);
    }
});

var result = await dispatcher.DispatchAsync(request);
output.Complete();
await readTask;

Note: Zig only emits full progress output on a real TTY. If you want output when redirected, include --summary all as shown above.

Artifact Selection

Auto-detect tries to find a single artifact in zig-out/bin (then zig-out) and ignores common debug sidecars.

Explicit selectors:

BuildArtifactSelector.RelativePath("bin/mytool.exe")
BuildArtifactSelector.FileName("mytool.exe")
BuildArtifactSelector.Extension(".dll")
BuildArtifactSelector.Pattern("plugin-*.xll")

You can also select by build arguments if you configure a selector strategy:

var rules = new[]
{
    BuildArgumentSelectorRule.FileNamePrefix("-Dartifact="),
    BuildArgumentSelectorRule.ExtensionPrefix("-DartifactExt="),
    BuildArgumentSelectorRule.PatternPrefix("-DartifactPattern=")
};

var dispatcher = new BuildDispatcher(options, new BuildArgumentSelectorStrategy(rules));

Example arguments:

-Dartifact=foo.exe
-DartifactExt=.dll
-DartifactPattern=plugin-*.xll

Workspace and Caching

Every build uses a workspace with these folders:

  • zig-cache (per build)
  • zig-out (per build)
  • zig-tmp (per build)
  • zig-global-cache (per build unless SharedGlobalCacheDir is set)

Keys:

  • CacheKey namespaces the workspace root and shared global cache per user.
  • WorkspaceKey reuses the workspace root (per tab/session) to avoid re-copying.

Cleanup:

// Default is All (cache/out/tmp).
var request = BuildRequest.Create(buildZigPath) with
{
    ArtifactCleanupMode = BuildArtifactCleanupMode.OutputOnly, // keep caches
    WorkspaceCleanupMode = WorkspaceCleanupMode.Never          // keep workspace root
};

Zig Discovery

The dispatcher resolves the Zig binary in this order:

  1. BuildRequest.ZigHome (file path or install directory).
  2. zvm (via zvm which zig or zvm which).
  3. zvm home (ZVM_HOME or %USERPROFILE%\.zvm, selects latest version).
  4. PATH.

Errors and Results (Railway Style)

All APIs return Result<T> instead of throwing:

  • Result.IsSuccess == true → use Result.Value.
  • Result.IsSuccess == false → inspect Result.Error and Result.Error.Output.

Sample App

Run the Blazor sample:

dotnet run --project ZigBuildDispatcher.Sample

The Build page uses XtermBlazor for live output streaming and exposes cache/workspace knobs.

Tests

dotnet test ZigBuildDispatcher.Tests

Performance tests are opt-in:

set RUN_PERF_TESTS=1
dotnet test ZigBuildDispatcher.Tests
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.1 425 1/22/2026
0.1.0 132 1/22/2026