Improve cpp nix builder

This commit is contained in:
Surma
2024-09-07 14:15:49 +01:00
parent 00082becab
commit 24e63eafc6
3 changed files with 43 additions and 34 deletions

View File

@@ -18,35 +18,24 @@
system: system:
let let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) stdenv runCommand writeShellScriptBin; inherit (pkgs) callPackage stdenv;
buildSquooshCppCodec = callPackage (import ../../nix/squoosh-cxx-builder) {};
mkInstallable = callPackage (import ../../nix/mk-installable) {};
in in
rec { mkInstallable {
packages = rec { packages = rec {
default = mozjpeg-squoosh; default = mozjpeg-squoosh;
mozjpeg-squoosh = stdenv.mkDerivation { mozjpeg-squoosh = buildSquooshCppCodec {
name = "mozjpeg-squoosh"; name = "mozjpeg-squoosh";
# Only copy files that are actually relevant to avoid unnecessary src = ./.;
# cache invalidations.
src = runCommand "src" { } ''
mkdir $out
cp -r ${./.}/enc $out/
cp ${./.}/Makefile $out/
'';
nativeBuildInputs = [
pkgs.emscripten
pkgs.mozjpeg
];
MOZJPEG = mozjpeg; MOZJPEG = mozjpeg;
dontConfigure = true; dontConfigure = true;
buildPhase = '' decoder = null;
export HOME=$TMPDIR
emmake make -j$(nproc)
'';
installPhase = ''
mkdir -p $out
cp -r enc $out
'';
}; };
mozjpeg = stdenv.mkDerivation { mozjpeg = stdenv.mkDerivation {
name = "mozjpeg"; name = "mozjpeg";
src = mozjpeg-src; src = mozjpeg-src;
@@ -82,17 +71,6 @@
''; '';
dontFixup = true; dontFixup = true;
}; };
installScript = writeShellScriptBin "install.sh" ''
${pkgs.coreutils}/bin/rm -rf wasm_build
${pkgs.coreutils}/bin/mkdir -p wasm_build
${pkgs.rsync}/bin/rsync --chmod=u+w -r ${mozjpeg-squoosh}/* wasm_build/
'';
};
apps = {
install = {
type = "app";
program = "${packages.installScript}/bin/install.sh";
};
}; };
} }
); );

View File

@@ -16,7 +16,7 @@
system: system:
let let
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) callPackage writeShellScriptBin; inherit (pkgs) callPackage;
buildSquooshRustCodec= callPackage (import ../../nix/squoosh-rust-builder) {fenix = fenix.packages.${system};}; buildSquooshRustCodec= callPackage (import ../../nix/squoosh-rust-builder) {fenix = fenix.packages.${system};};
mkInstallable = callPackage (import ../../nix/mk-installable) {}; mkInstallable = callPackage (import ../../nix/mk-installable) {};

View File

@@ -0,0 +1,31 @@
{
pkgs,
stdenv,
runCommand,
}:
{
name,
src,
nativeBuildInputs ? [ ],
encoder ? "enc",
decoder ? "dec",
...
}@args:
stdenv.mkDerivation (
final:
args
// {
inherit name src;
nativeBuildInputs = [ pkgs.emscripten ] ++ nativeBuildInputs;
buildPhase = ''
export HOME=$TMPDIR
emmake make -j$(nproc)
'';
installPhase = ''
mkdir -p $out
${if (encoder != null) then "cp -r ${encoder} $out" else ""}
${if (decoder != null) then "cp -r ${decoder} $out" else ""}
'';
}
)