mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 01:37:26 +00:00
Make a variant builder helper
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
|
|
||||||
packageVariants = {
|
variantOptions = {
|
||||||
base = {
|
base = {
|
||||||
simd = false;
|
simd = false;
|
||||||
};
|
};
|
||||||
@@ -30,19 +30,19 @@
|
|||||||
system:
|
system:
|
||||||
let
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
inherit (pkgs) lib stdenv runCommand emscripten writeShellScriptBin cmake callPackage;
|
inherit (pkgs) lib stdenv callPackage;
|
||||||
buildSquooshCppCodec = callPackage (import ../../nix/squoosh-cxx-builder) {};
|
buildSquooshCppCodec = callPackage (import ../../nix/squoosh-cxx-builder) {};
|
||||||
mkInstallable = callPackage (import ../../nix/mk-installable) {};
|
mkInstallable = callPackage (import ../../nix/mk-installable) {};
|
||||||
|
|
||||||
packageVariantBuilder =
|
builder =
|
||||||
name:
|
name:
|
||||||
{ simd }@variantOptions:
|
{ simd }:
|
||||||
{
|
{
|
||||||
"webp-squoosh-${name}" = buildSquooshCppCodec {
|
"webp-squoosh" = buildSquooshCppCodec {
|
||||||
name = "webp-squoosh-${name}";
|
name = "webp-squoosh-${name}";
|
||||||
src = lib.sources.sourceByRegex ./. ["Makefile" "enc(/.+)?" "dec(/.+)?"];
|
src = lib.sources.sourceByRegex ./. ["Makefile" "enc(/.+)?" "dec(/.+)?"];
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
emscripten
|
pkgs.emscripten
|
||||||
self.packages.${system}."webp-${name}"
|
self.packages.${system}."webp-${name}"
|
||||||
];
|
];
|
||||||
WEBP = self.packages.${system}."webp-${name}";
|
WEBP = self.packages.${system}."webp-${name}";
|
||||||
@@ -56,12 +56,12 @@
|
|||||||
cp -r enc dec $out
|
cp -r enc dec $out
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
"webp-${name}" = stdenv.mkDerivation {
|
"webp" = stdenv.mkDerivation {
|
||||||
name = "webp-${name}";
|
name = "webp-${name}";
|
||||||
src = webp-src;
|
src = webp-src;
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
emscripten
|
pkgs.emscripten
|
||||||
cmake
|
pkgs.cmake
|
||||||
];
|
];
|
||||||
configurePhase = ''
|
configurePhase = ''
|
||||||
# $HOME is required for Emscripten to work.
|
# $HOME is required for Emscripten to work.
|
||||||
@@ -97,10 +97,31 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
packages = lib.foldl (acc: v: acc//v) {} (lib.mapAttrsToList packageVariantBuilder packageVariants);
|
suffixAttrNames = suffix: attrs:
|
||||||
|
lib.mapAttrs'
|
||||||
|
(name: val:
|
||||||
|
lib.nameValuePair
|
||||||
|
"${name}${suffix}"
|
||||||
|
val)
|
||||||
|
attrs;
|
||||||
|
forAllVariants =
|
||||||
|
{builder, variants}:
|
||||||
|
lib.lists.foldl
|
||||||
|
(acc: v: acc//v)
|
||||||
|
{}
|
||||||
|
(lib.mapAttrsToList
|
||||||
|
(variantName: value:
|
||||||
|
suffixAttrNames "-${variantName}" (builder variantName value))
|
||||||
|
variants
|
||||||
|
);
|
||||||
|
|
||||||
|
packageVariants = forAllVariants {
|
||||||
|
inherit builder;
|
||||||
|
variants = variantOptions;
|
||||||
|
};
|
||||||
|
|
||||||
defaultPackage = let
|
defaultPackage = let
|
||||||
variants = lib.mapAttrs (name: opts: packages."webp-squoosh-${name}") packageVariants;
|
variants = lib.mapAttrs (name: opts: packageVariants."webp-squoosh-${name}") variantOptions;
|
||||||
copyCommands = lib.concatLines (lib.mapAttrsToList (name: path: "cp -r ${path} $out/${name}") variants);
|
copyCommands = lib.concatLines (lib.mapAttrsToList (name: path: "cp -r ${path} $out/${name}") variants);
|
||||||
in
|
in
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
@@ -114,7 +135,7 @@
|
|||||||
in
|
in
|
||||||
|
|
||||||
mkInstallable {
|
mkInstallable {
|
||||||
packages = packages // {default = defaultPackage;};
|
packages = packageVariants // {default = defaultPackage;};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user