mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-13 09:17:20 +00:00
Minor refactor
This commit is contained in:
@@ -17,15 +17,14 @@
|
|||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
inherit (pkgs) callPackage writeShellScriptBin;
|
inherit (pkgs) callPackage writeShellScriptBin;
|
||||||
|
|
||||||
squooshCodecBuilders = callPackage (import ../../nix/squoosh-codec-builders) {fenix = fenix.packages.${system};};
|
buildSquooshRustCodec= callPackage (import ../../nix/squoosh-rust-builder) {fenix = fenix.packages.${system};};
|
||||||
inherit (squooshCodecBuilders) buildSquooshCodecRust;
|
|
||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages = rec {
|
packages = rec {
|
||||||
default = resize-squoosh;
|
default = resize-squoosh;
|
||||||
resize-squoosh = buildSquooshCodecRust {
|
resize-squoosh = buildSquooshRustCodec {
|
||||||
name = "resize-squoosh";
|
name = "resize-squoosh";
|
||||||
inherit src;
|
inherit src;
|
||||||
cargoLock = {
|
cargoLock = {
|
||||||
|
|||||||
@@ -18,15 +18,14 @@
|
|||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
inherit (pkgs) callPackage writeShellScriptBin;
|
inherit (pkgs) callPackage writeShellScriptBin;
|
||||||
|
|
||||||
squooshCodecBuilders = callPackage (import ../../nix/squoosh-codec-builders) {fenix = fenix.packages.${system};};
|
buildSquooshRustCodec= callPackage (import ../../nix/squoosh-rust-builder) {fenix = fenix.packages.${system};};
|
||||||
inherit (squooshCodecBuilders) buildSquooshCodecRust;
|
|
||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages = rec {
|
packages = rec {
|
||||||
default = rotate-squoosh;
|
default = rotate-squoosh;
|
||||||
rotate-squoosh = buildSquooshCodecRust {
|
rotate-squoosh = buildSquooshRustCodec {
|
||||||
name = "rotate-squoosh";
|
name = "rotate-squoosh";
|
||||||
inherit src;
|
inherit src;
|
||||||
cargoLock = {
|
cargoLock = {
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
{
|
|
||||||
pkgs,
|
|
||||||
fenix,
|
|
||||||
wasm-bindgen ? pkgs.callPackage (import ../wasm-bindgen) { },
|
|
||||||
rust-helpers ? pkgs.callPackage (import ../rust-helpers) { inherit fenix; },
|
|
||||||
binaryen,
|
|
||||||
stdenv,
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
inherit (rust-helpers) buildRustPackage;
|
|
||||||
in
|
|
||||||
|
|
||||||
{
|
|
||||||
buildSquooshCodecRust =
|
|
||||||
{
|
|
||||||
name,
|
|
||||||
src,
|
|
||||||
cargoLock ? {
|
|
||||||
lockFile = "${src}/Cargo.lock";
|
|
||||||
},
|
|
||||||
wasmBindgen ? {
|
|
||||||
sha256 = "";
|
|
||||||
},
|
|
||||||
...
|
|
||||||
}@args:
|
|
||||||
let
|
|
||||||
codecBuild = buildRustPackage {
|
|
||||||
inherit src cargoLock;
|
|
||||||
name = "${name}-codec";
|
|
||||||
target = "wasm32-unknown-unknown";
|
|
||||||
};
|
|
||||||
|
|
||||||
wasm-bindgen-bin = wasm-bindgen.buildFromCargoLock {
|
|
||||||
inherit cargoLock;
|
|
||||||
sha256 = wasmBindgen.sha256;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
if wasmBindgen != null then
|
|
||||||
stdenv.mkDerivation (
|
|
||||||
(removeAttrs args [
|
|
||||||
"cargoLock"
|
|
||||||
"wasmBindgen"
|
|
||||||
])
|
|
||||||
// {
|
|
||||||
inherit codecBuild;
|
|
||||||
dontConfigure = true;
|
|
||||||
nativeBuildInputs = [ wasm-bindgen-bin ];
|
|
||||||
buildPhase = ''
|
|
||||||
runHook preBuild
|
|
||||||
|
|
||||||
wasm-bindgen --target web --out-dir $out $codecBuild/*.wasm
|
|
||||||
|
|
||||||
runHook postBuild
|
|
||||||
'';
|
|
||||||
dontInstall = true;
|
|
||||||
}
|
|
||||||
)
|
|
||||||
else
|
|
||||||
stdenv.mkDerivation (
|
|
||||||
(removeAttrs args [
|
|
||||||
"cargoLock"
|
|
||||||
"wasmBindgen"
|
|
||||||
])
|
|
||||||
// {
|
|
||||||
inherit codecBuild;
|
|
||||||
dontConfigure = true;
|
|
||||||
nativeBuildInputs = [ binaryen ];
|
|
||||||
buildPhase = ''
|
|
||||||
runHook preBuild
|
|
||||||
|
|
||||||
wasm-opt -O3 --strip -o optimized.wasm $codecBuild/*.wasm
|
|
||||||
|
|
||||||
runHook postBuild
|
|
||||||
'';
|
|
||||||
installPhase = ''
|
|
||||||
mkdir -p $out
|
|
||||||
cp optimized.wasm $out
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
78
nix/squoosh-rust-builder/default.nix
Normal file
78
nix/squoosh-rust-builder/default.nix
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
fenix,
|
||||||
|
wasm-bindgen ? pkgs.callPackage (import ../wasm-bindgen) { },
|
||||||
|
rust-helpers ? pkgs.callPackage (import ../rust-helpers) { inherit fenix; },
|
||||||
|
binaryen,
|
||||||
|
stdenv,
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (rust-helpers) buildRustPackage;
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
name,
|
||||||
|
src,
|
||||||
|
cargoLock ? {
|
||||||
|
lockFile = "${src}/Cargo.lock";
|
||||||
|
},
|
||||||
|
wasmBindgen ? {
|
||||||
|
sha256 = "";
|
||||||
|
},
|
||||||
|
...
|
||||||
|
}@args:
|
||||||
|
let
|
||||||
|
codecBuild = buildRustPackage {
|
||||||
|
inherit src cargoLock;
|
||||||
|
name = "${name}-codec";
|
||||||
|
target = "wasm32-unknown-unknown";
|
||||||
|
};
|
||||||
|
|
||||||
|
wasm-bindgen-bin = wasm-bindgen.buildFromCargoLock {
|
||||||
|
inherit cargoLock;
|
||||||
|
sha256 = wasmBindgen.sha256;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
if wasmBindgen != null then
|
||||||
|
stdenv.mkDerivation (
|
||||||
|
(removeAttrs args [
|
||||||
|
"cargoLock"
|
||||||
|
"wasmBindgen"
|
||||||
|
])
|
||||||
|
// {
|
||||||
|
inherit codecBuild;
|
||||||
|
dontConfigure = true;
|
||||||
|
nativeBuildInputs = [ wasm-bindgen-bin ];
|
||||||
|
buildPhase = ''
|
||||||
|
runHook preBuild
|
||||||
|
|
||||||
|
wasm-bindgen --target web --out-dir $out $codecBuild/*.wasm
|
||||||
|
|
||||||
|
runHook postBuild
|
||||||
|
'';
|
||||||
|
dontInstall = true;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
else
|
||||||
|
stdenv.mkDerivation (
|
||||||
|
(removeAttrs args [
|
||||||
|
"cargoLock"
|
||||||
|
"wasmBindgen"
|
||||||
|
])
|
||||||
|
// {
|
||||||
|
inherit codecBuild;
|
||||||
|
dontConfigure = true;
|
||||||
|
nativeBuildInputs = [ binaryen ];
|
||||||
|
buildPhase = ''
|
||||||
|
runHook preBuild
|
||||||
|
|
||||||
|
wasm-opt -O3 --strip -o optimized.wasm $codecBuild/*.wasm
|
||||||
|
|
||||||
|
runHook postBuild
|
||||||
|
'';
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out
|
||||||
|
cp optimized.wasm $out
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user