1
0
aoc23/nix/build-zig-package.nix
xeals 2cef1b682c
All checks were successful
Build and test / test (push) Successful in 3m0s
Extract Zig package builder
Consider moving to NUR or upstream?
2023-11-30 12:35:17 +11:00

58 lines
1.2 KiB
Nix

{ stdenv
, zig
}:
{ buildInputs ? [ ]
, nativeBuildInputs ? [ ]
, optimize ? "ReleaseSafe"
, meta ? { }
, ...
}@args:
stdenv.mkDerivation (args // {
nativeBuildInputs = nativeBuildInputs ++ [
zig
];
buildInputs = buildInputs;
strictDeps = true;
configurePhase = args.configurePhase or ''
runHook preConfigure
runHook postConfigure
'';
ZIGFLAGS = args.ZIGFLAGS or [
"-Doptimize=${optimize}"
];
# https://github.com/ziglang/zig/issues/6810 requires setting XDG_CACHE_HOME
# in all zig build phases. --cache-dir and --global-cache-dir do not prevent
# the builder from attempting to create the XDG cache.
buildPhase = args.buildPhase or ''
runHook preBuild
XDG_CACHE_HOME=_cache zig build $ZIGFLAGS
runHook postBuild
'';
doCheck = args.doCheck or true;
checkPhase = args.checkPhase or ''
runHook preCheck
XDG_CACHE_HOME=_cache zig build test $ZIGFLAGS
runHook postCheck
'';
installPhase = args.installPhase or ''
runHook preInstall
XDG_CACHE_HOME=_cache zig build install --prefix $out $ZIGFLAGS
runHook postInstall
'';
meta = {
# default to Zig's platforms
platforms = zig.meta.platforms;
} // meta;
})