Something went wrong. Try again.
Zig bindings for the Singlewire InformaCast API, generated at build time from its OpenAPI specification.
Something went wrong. Try again.
zig-informacast build.zig
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
const std = @import("std");
pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{});
// openapi2zig is only ever linked into the generator, so it is built for // the host too. const openapi2zig_dep = b.dependency("openapi2zig", .{ .target = b.graph.host, .optimize = optimize, });
const generate_exe = b.addExecutable(.{ .name = "generate", .root_module = b.createModule(.{ .root_source_file = b.path("src/generate.zig"), // The generator runs on the machine doing the build, whatever // -Dtarget the bindings are being built for. .target = b.graph.host, .optimize = optimize, .imports = &.{ .{ .name = "openapi2zig", .module = openapi2zig_dep.module("openapi2zig"), }, }, }), });
const generate_cmd = b.addRunArtifact(generate_exe); generate_cmd.setStdIn(.{ .lazy_path = b.path("api/api.json") }); const api_zig = generate_cmd.captureStdOut(.{ .basename = "api.zig" });
const informacast_mod = b.addModule("informacast", .{ .root_source_file = api_zig, .target = target, .optimize = optimize, });
const tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("src/test.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "informacast", .module = informacast_mod, }, }, }), });
// A plain `zig build` generates the bindings and compiles all of them. // Nothing is installed: the module is for dependents to import. b.getInstallStep().dependOn(&tests.step);
const check_step = b.step("check", "Generate the bindings and compile all of them"); check_step.dependOn(&tests.step);
const test_step = b.step("test", "Run the tests"); test_step.dependOn(&b.addRunArtifact(tests).step);}