Skip to content

Build Integration API

Build-time update checking integration for build.zig.

Types

BuildConfig

Configuration for build-time update checking.

zig
pub const BuildConfig = struct {
    /// Repository owner (required)
    owner: []const u8,

    /// Repository name (required)
    repo: []const u8,

    /// Current version (required)
    current_version: []const u8,

    /// Provider to use
    provider: Provider = .github,

    /// Show warnings
    show_warnings: bool = true,

    pub const Provider = enum {
        github,
        gitlab,
        codeberg,
    };
};

UpdateCheckStep

Build step for checking updates.

zig
pub const UpdateCheckStep = struct {
    step: std.Build.Step,
    config: BuildConfig,
    allocator: std.mem.Allocator,

    pub fn create(b: *std.Build, config: BuildConfig) *UpdateCheckStep;
};

Functions

addUpdateCheck

Add update checking to a build.

zig
pub fn addUpdateCheck(b: *std.Build, config: BuildConfig) void;

Parameters

  • b: The build instance
  • config: Update check configuration

Behavior

  • Adds a step to the default build that checks for updates
  • Logs a warning if an update is available
  • Never fails the build
  • Automatically skipped in CI environments

Example

zig
const std = @import("std");
const updater = @import("updater");

pub fn build(b: *std.Build) void {
    updater.build_integration.addUpdateCheck(b, .{
        .owner = "username",
        .repo = "myproject",
        .current_version = "1.0.0",
        .provider = .github,
    });

    // ... rest of build
}

Output

When an update is available:

┌────────────────────────────────────────────────────────────────┐
│  UPDATE AVAILABLE                                              │
│                                                                │
│  Current version: 1.0.0                                        │
│  Latest version:  2.0.0                                        │
│                                                                │
│  Download: https://github.com/username/repo/releases/v2.0.0    │
└────────────────────────────────────────────────────────────────┘

Automatic Disabling

Build-time checks are skipped when:

  1. ZIG_UPDATE_CHECK_DISABLE environment variable is set
  2. Any of these CI environment variables are detected:
    • CI
    • CONTINUOUS_INTEGRATION
    • GITHUB_ACTIONS
    • GITLAB_CI
    • CIRCLECI
    • TRAVIS

Error Handling

Network errors are logged as warnings but never fail the build:

warning: [updater.zig] Update check failed: ConnectionFailed

Released under the MIT License.