zig-build-system
БесплатноБез исполняемых скриптовНе проверенZig build system skill for multi-file Zig projects. Use when writing or debugging build.zig files, adding executables or libraries, integrating C source…
от mohitmishra786★ 307 звёзд на GitHubОб этом скилле
Zig Build System
Purpose
Guide agents through writing build.zig files for Zig 0.16: executables, libraries, C source integration, build options, test configuration, and build.zig.zon package manifests.
Triggers
- "How do I set up a build.zig file?"
- "How do I add a C library to a Zig project?"
- "How do I define build-time options in Zig?"
- "How do I run Zig tests with zig build test?"
- "What is build.zig.zon and how do I use it?"
- "How do I add a Zig package dependency?"
Workflow
1. Project initialization
# Initialize a new project
mkdir myproject && cd myproject
zig init # creates build.zig, build.zig.zon, src/main.zig, src/root.zig
# Build
zig build
# Run
zig build run
# Test
zig build test
2. build.zig structure
Since Zig 0.15, every artifact is built from a root module created with b.createModule.
Source file, target, optimize mode, libc linking and imports are module settings.
const std = @import("std");
pub fn build(b: *std.Build) void {
// Standard options (-Doptimize=..., -Dtarget=...)
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const exe = b.addExecutable(.{
.name = "myapp",
.root_module = exe_mod,
});
// Install step (zig build → copies to zig-out/bin/)
b.installArtifact(exe);
// Run step (zig build run)
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 the app");
run_step.dependOn(&run_cmd.step);
// Test step (zig build test) — tests the same module
const unit_tests = b.addTest(.{
.root_module = exe_mod,
});
const run_unit_tests = b.addRunArtifact(unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_unit_tests.step);
}
3. Libraries
const lib_mod = b.createModule(.{
.root_source_file = b.path("src/mylib.zig"),
.target = target,
.optimize = optimize,
});
// Static library (addStaticLibrary was removed; use addLibrary)
const lib = b.addLibrary(.{
.name = "mylib",
.linkage = .static,
.root_module = lib_mod,
});
b.installArtifact(lib);
// Shared library
const shared_lib = b.addLibrary(.{
.name = "mylib",
.linkage = .dynamic,
.root_module = lib_mod,
.version = .{ .major = 1, .minor = 0, .patch = 0 },
});
b.installArtifact(shared_lib);
// Link library into executable
exe.root_module.linkLibrary(lib);
4. Adding C source files
C sources, include paths and system libraries are added to a module, not to the artifact.
exe.addCSourceFile(...), exe.linkLibC() and similar Compile methods no longer exist.
// Single C file
exe.root_module.addCSourceFile(.{
.file = b.path("src/legacy.c"),
.flags = &.{ "-std=c11", "-Wall", "-Wextra" },
});
// Multiple C files
exe.root_module.addCSourceFiles(.{
.files = &.{
"src/a.c",
"src/b.c",
"src/c.c",
},
.flags = &.{ "-std=c11", "-O2" },
});
// Include directories
exe.root_module.addIncludePath(b.path("include/"));
exe.root_module.addIncludePath(.{ .cwd_relative = "/usr/local/include" });
// System libraries (second argument: needed/weak/use_pkg_config/...)
exe.root_module.linkSystemLibrary("curl", .{});
exe.root_module.linkSystemLibrary("ssl", .{});
exe.root_module.link_libc = true; // or .link_libc = true in createModule
5. Build-time options
pub fn build(b: *std.Build) void {
// Boolean option
const enable_logging = b.option(
bool,
"logging",
"Enable debug logging",
) orelse false;
// Enum option
const Backend = enum { opengl, vulkan, software };
const backend = b.option(
Backend,
"backend",
"Rendering backend",
) orelse .opengl;
// Integer option
const max_connections = b.option(
u32,
"max-connections",
"Maximum concurrent connections",
) orelse 64;
// Pass to Zig code as compile-time constant
const options = b.addOptions();
options.addOption(bool, "enable_logging", enable_logging);
options.addOption(Backend, "backend", backend);
options.addOption(u32, "max_connections", max_connections);
exe.root_module.addOptions("build_options", options);
}
In Zig source:
const build_options = @import("build_options");
pub fn main() void {
if (build_options.enable_logging) {
std.debug.print("Logging enabled\n", .{});
}
}
# Pass options on command line
zig build -Dlogging=true -Dbackend=vulkan -Dmax-connections=256
6. Module system
// Public module: other packages can import it via b.dependency(...).module("mymodul
Установить zig-build-system в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл zig-build-system?
Zig build system skill for multi-file Zig projects. Use when writing or debugging build.zig files, adding executables or libraries, integrating C source files, configuring build-time options, running tests with zig build test, or managing build.zig.zon package manifests. Activates on queries about build.zig, b.addExecutable, addCSourceFiles, b.option, zig build, build.zig.zon, or Zig package management.
Как установить скилл zig-build-system?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл zig-build-system запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic