Something went wrong. Try again.
A client for the HashiCorp Vault and OpenBao HTTP API, for Zig 0.16.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394// 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(.{});
// The library. Consumers import this as `@import("vault")`. const mod = b.addModule("vault", .{ .root_source_file = b.path("src/root.zig"), .target = target, });
// `vaultctl`, a command line front end for the library and a worked // example of using it. const exe = b.addExecutable(.{ .name = "vaultctl", .root_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "vault", .module = mod }}, }), }); // Embedded so that a test can check it still matches the command line // this executable actually parses. exe.root_module.addAnonymousImport("fish_completion", .{ .root_source_file = b.path("completions/vaultctl.fish"), }); exe.root_module.addAnonymousImport("bash_completion", .{ .root_source_file = b.path("completions/vaultctl.bash"), }); b.installArtifact(exe);
// fish autoloads anything in this directory, so an installed vaultctl // completes without the user wiring anything up. b.installFile("completions/vaultctl.fish", "share/fish/vendor_completions.d/vaultctl.fish");
// bash-completion autoloads by exact command name, so no extension here. b.installFile("completions/vaultctl.bash", "share/bash-completion/completions/vaultctl");
const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| run_cmd.addArgs(args);
const run_step = b.step("run", "Run vaultctl"); run_step.dependOn(&run_cmd.step);
// Two test executables, because a test binary covers exactly one module. // The library tests include the end-to-end ones in `src/http_test.zig`, // which stand up a fake Vault on a loopback socket. const mod_tests = b.addTest(.{ .root_module = mod }); const exe_tests = b.addTest(.{ .root_module = exe.root_module });
const test_step = b.step("test", "Run tests"); test_step.dependOn(&b.addRunArtifact(mod_tests).step); test_step.dependOn(&b.addRunArtifact(exe_tests).step);
// Tests that need a live Vault or OpenBao server, so they are not part of // `zig build test`. `zig build integration` runs them against whatever // $VAULT_ADDR points at. const integration = b.addExecutable(.{ .name = "vault-integration-tests", .root_module = b.createModule(.{ .root_source_file = b.path("test/integration.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "vault", .module = mod }}, }), });
const run_integration = b.addRunArtifact(integration); if (b.args) |args| run_integration.addArgs(args); const integration_step = b.step("integration", "Run tests against a live Vault or OpenBao server"); integration_step.dependOn(&run_integration.step);
// Installing the binary lets it be shipped to a machine that has a server // but no Zig toolchain, which is how the NixOS VM test runs it. if (b.option(bool, "integration-binary", "Also install the live-server test binary") orelse false) { b.installArtifact(integration); }
// `zig build docs` renders the library's doc comments to zig-out/docs. const docs = b.addInstallDirectory(.{ .source_dir = b.addObject(.{ .name = "vault", .root_module = mod }).getEmittedDocs(), .install_dir = .prefix, .install_subdir = "docs", }); const docs_step = b.step("docs", "Build the API documentation"); docs_step.dependOn(&docs.step);}