- Zig 92%
- Nix 8%
zig-build-libgpg-error #
Zig 0.17 build package for libgpg-error 1.61. It builds libgpg-error directly from the official release tarball as a static library and exposes both the library artifact and raw translate-C bindings. Autotools, awk and a system C compiler are not required.
Use as a dependency #
Add this package to your project's build.zig.zon, then pass the target and
optimization mode when requesting the dependency:
const libgpg_error = b.dependency("libgpg_error", .{
.target = target,
.optimize = optimize,
});
Import the translated libgpg-error API as a Zig module:
exe.root_module.addImport("gpg_error", libgpg_error.module("gpg_error"));
The module links libgpg-error and libc transitively. Its declarations can be
used with const gpg_error = @import("gpg_error");.
Alternatively, link the C library artifact directly:
exe.root_module.linkLibrary(libgpg_error.artifact("gpg-error"));
The artifact propagates the installed gpg-error.h and gpgrt.h include
path.
Supported targets #
x86_64 and aarch64, each with linux-gnu, linux-musl or macos. The build
stops with an error for any other target. Windows is not supported.
The library is built with threading (POSIX threads) and without NLS. The
gpg-error command line tool, gpgrt-config, gpg-error.pc and the m4 files
are not built. The compiled-in configuration directory is upstream's default for
the /usr/local prefix, /usr/local/etc.
Build and test #
Zig 0.17.0 is required.
zig build
zig build test
The default build installs the static library and public headers under
zig-out/. The test step runs the generator's unit tests, checks the generator
against the headers shipped in the tarball, and runs these upstream tests:
t-b64, t-lock, t-name-value, t-printf, t-strerror, t-stringutils,
t-strlist, t-syserror and t-version, plus a Zig smoke test through the
gpg_error module.
The Nix flake provides the pinned Zig toolchain and a build check:
nix develop
nix flake check
Inside the Nix build sandbox Zig skips natively linked test executables, so on
Linux the check also runs the test step for the static <arch>-linux-musl
target.
How the build works #
Upstream's Makefile generates most of libgpg-error's headers at build time:
tools/generate.zigreplaces the awk scripts (mkstrtable.awk,mkerrnos.awk,mkerrcodes*.awk) andmkerrcodes.c. The errno values come from runningzig cc -Efor the target.- Upstream's
mkheader.cis built for the build machine and producesgpg-error.h(and its copygpgrt.h). It reads the lock object layout from the matchingsrc/syscfg/lock-obj-pub.*.h. aarch64 musl reuses the x86_64 musl file, because musl'spthread_mutex_tis the same on both. config.his written bybuild.zigand holds only the values the sources consult, set per target.
Upstream source #
- Version:
1.61 - Archive: https://gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-1.61.tar.gz
- SHA-256:
7980d7d43178b06a74bfba3d4606c13955bf2370344e12938d56ae4a9da6d36f
The archive is pinned by its Zig package hash in build.zig.zon.
License #
Like libgpg-error itself, this package is licensed under the GNU Lesser General
Public License, version 2.1 or later. See LICENSE.