Extract Zig package builder
All checks were successful
Build and test / test (push) Successful in 3m0s
All checks were successful
Build and test / test (push) Successful in 3m0s
Consider moving to NUR or upstream?
This commit is contained in:
parent
2279e958bf
commit
2cef1b682c
42
flake.nix
42
flake.nix
@ -12,6 +12,10 @@
|
||||
inherit (nixpkgs) lib;
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
zig = pkgs.zig_0_11;
|
||||
buildZigPackage = import ./nix/build-zig-package.nix {
|
||||
inherit (pkgs) stdenv;
|
||||
inherit zig;
|
||||
};
|
||||
in
|
||||
{
|
||||
devShells = {
|
||||
@ -23,39 +27,9 @@
|
||||
};
|
||||
};
|
||||
|
||||
packages.default =
|
||||
let
|
||||
optimize = "ReleaseSafe";
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
name = "aoc23";
|
||||
src = lib.cleanSource ./.;
|
||||
|
||||
buildInputs = [ zig ];
|
||||
|
||||
# https://github.com/ziglang/zig/issues/6810
|
||||
XDG_CACHE_HOME = "xdg_cache";
|
||||
|
||||
zigFlags = [ "-Doptimize=${optimize}" ];
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
zig build $zigFlags
|
||||
runHook postBuild
|
||||
'';
|
||||
|
||||
doCheck = true;
|
||||
checkPhase = ''
|
||||
runHook preCheck
|
||||
zig build test $zigFlags
|
||||
runHook postCheck
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
zig build install --prefix $out $zigFlags
|
||||
runHook postInstall
|
||||
'';
|
||||
};
|
||||
packages.default = buildZigPackage {
|
||||
name = "aoc23";
|
||||
src = lib.cleanSource ./.;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
57
nix/build-zig-package.nix
Normal file
57
nix/build-zig-package.nix
Normal file
@ -0,0 +1,57 @@
|
||||
{ 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;
|
||||
})
|
Loading…
Reference in New Issue
Block a user