Build and packaging
build.zig exposes the consumer build API. Its public surface includes Platform, Import, Dts, NpmConfig, LibOptions, and addLib.
Build behavior
addLibbuilds a host.nodeaddon.-Dnpm=trueenables release package generation and cross-compilation.-Dnpm-host=truerestricts native compilation to the host platform.-Dnpm-only=name-a,name-bfilters addons in multi-addon projects.Dts.none,Dts.file, andDts.autocontrol declaration output.Dts.noneomits bothtypesandindex.d.tsfrom the generated main manifest. When a release package switches to.none, reconciliation removes the build-ownedindex.d.tsand its managedfilesentry while preserving unrelated user files and manifest fields.
Boundaries
- Keep generated package names, binary suffixes, binding paths, optional dependencies, and npm manifest fields compatible.
- Keep npmjs as the public registry and preserve public access.
- Treat linker flags, Windows import libraries, target lists, and generated manifests as release-critical.
- Test build graph changes with the fixture projects and CLI release tests, not only the repository's own build.
Relevant tests live in tests/cli/build-dev.test.ts, tests/cli/build-release.test.ts, tests/fixture-cli/, and tests/fixture-lib/.
Internal structure
- Keep
build.zigas the public facade foraddLib,Platform,Import,Dts,NpmConfig, andLibOptions. - Keep target definitions and npm suffix mapping in
build/targets.zig. - Keep OS-specific link configuration in
build/linker.zig. - Keep escaped npm manifest and loader rendering in
build/npm_manifest.zig. - Keep declaration and local entry generation in the existing
build/*_emit.zigmodules.
These modules are implementation details. Moving work between them must not change the public build.zig API, generated package names, or output layout.
Use the detailed build API, TypeScript declaration, cross-compiling, and publishing pages when changing their user-visible behavior.