diff --git a/codecs/resize/flake.nix b/codecs/resize/flake.nix index 6d98ca97f..6ebd3f48f 100644 --- a/codecs/resize/flake.nix +++ b/codecs/resize/flake.nix @@ -18,15 +18,16 @@ inherit (pkgs) callPackage writeShellScriptBin; squooshCodecBuilders = callPackage (import ../../nix/squoosh-codec-builders) {fenix = fenix.packages.${system};}; + inherit (squooshCodecBuilders) buildSquooshCodecRust; src = ./.; in { packages = rec { default = resize-squoosh; - resize-squoosh = squooshCodecBuilders.buildSquooshCodecRust { + resize-squoosh = buildSquooshCodecRust { name = "resize-squoosh"; - inherit system src; + inherit src; cargoLock = { lockFile = "${src}/Cargo.lock"; }; diff --git a/codecs/rotate/flake.lock b/codecs/rotate/flake.lock new file mode 100644 index 000000000..fb8d127f2 --- /dev/null +++ b/codecs/rotate/flake.lock @@ -0,0 +1,115 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1723616992, + "narHash": "sha256-jDHYfEECzFwZm4huz7AbPjlH3jJ4/2ns9PddtFA5XMY=", + "owner": "nix-community", + "repo": "fenix", + "rev": "7bad6c7ff73b784a9c7de9147626c8d5d5072809", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "rev": "7bad6c7ff73b784a9c7de9147626c8d5d5072809", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1723362943, + "narHash": "sha256-dFZRVSgmJkyM0bkPpaYRtG/kRMRTorUIDj8BxoOt1T4=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a58bc8ad779655e790115244571758e8de055e3d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1717179513, + "narHash": "sha256-vboIEwIQojofItm2xGCdZCzW96U85l9nDW3ifMuAIdM=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "63dacb46bf939521bdc93981b4cbb7ecb58427a0", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1723561310, + "narHash": "sha256-a3KMMsIDvdo+ClLabh5wfJoa17YTSvy2wDLb8yZCXvc=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "78c2bdce860dbd996a8083224d01a96660dd6a15", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/codecs/rotate/flake.nix b/codecs/rotate/flake.nix new file mode 100644 index 000000000..dd9fde4d7 --- /dev/null +++ b/codecs/rotate/flake.nix @@ -0,0 +1,51 @@ + +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/24.05"; + flake-utils.url = "github:numtide/flake-utils"; + fenix.url = "github:nix-community/fenix/7bad6c7ff73b784a9c7de9147626c8d5d5072809"; + }; + outputs = + { + self, + nixpkgs, + flake-utils, + fenix + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + inherit (pkgs) callPackage writeShellScriptBin; + + squooshCodecBuilders = callPackage (import ../../nix/squoosh-codec-builders) {fenix = fenix.packages.${system};}; + inherit (squooshCodecBuilders) buildSquooshCodecRust; + + src = ./.; + in + { + packages = rec { + default = rotate-squoosh; + rotate-squoosh = buildSquooshCodecRust { + name = "rotate-squoosh"; + inherit src; + cargoLock = { + lockFile = "${src}/Cargo.lock"; + }; + wasmBindgen = null; + }; + + installScript = writeShellScriptBin "install.sh" '' + ${pkgs.coreutils}/bin/mkdir -p wasm_build + ${pkgs.rsync}/bin/rsync --chmod=u+w -r ${self.packages.${system}.rotate-squoosh}/* wasm_build/ + ''; + }; + apps = { + install = { + type = "app"; + program = "${self.packages.${system}.installScript}/bin/install.sh"; + }; + }; + } + ); +} diff --git a/codecs/rotate/rotate.wasm b/codecs/rotate/rotate.wasm deleted file mode 100755 index 8c7122c9f..000000000 Binary files a/codecs/rotate/rotate.wasm and /dev/null differ diff --git a/codecs/rotate/wasm_build/optimized.wasm b/codecs/rotate/wasm_build/optimized.wasm new file mode 100644 index 000000000..7ee65ab4b Binary files /dev/null and b/codecs/rotate/wasm_build/optimized.wasm differ diff --git a/nix/squoosh-codec-builders/default.nix b/nix/squoosh-codec-builders/default.nix index 77a95fb48..285856500 100644 --- a/nix/squoosh-codec-builders/default.nix +++ b/nix/squoosh-codec-builders/default.nix @@ -3,6 +3,7 @@ fenix, wasm-bindgen ? pkgs.callPackage (import ../wasm-bindgen) { }, rust-helpers ? pkgs.callPackage (import ../rust-helpers) { inherit fenix; }, + binaryen, stdenv, }: let @@ -43,7 +44,7 @@ in // { inherit codecBuild; dontConfigure = true; - nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ wasm-bindgen-bin ]; + nativeBuildInputs = [ wasm-bindgen-bin ]; buildPhase = '' runHook preBuild @@ -55,5 +56,27 @@ in } ) else - codecBuild; + 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 + ''; + } + ); + } diff --git a/src/features/preprocessors/rotate/worker/rotate.ts b/src/features/preprocessors/rotate/worker/rotate.ts index 905f6bf24..346ceea31 100644 --- a/src/features/preprocessors/rotate/worker/rotate.ts +++ b/src/features/preprocessors/rotate/worker/rotate.ts @@ -10,7 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import wasmUrl from 'url:codecs/rotate/rotate.wasm'; +import wasmUrl from 'url:codecs/rotate/wasm_build/optimized.wasm'; import { Options } from '../shared/meta'; export interface RotateModuleInstance {