Skip to content

Commit

Permalink
Port rotate codec to nix
Browse files Browse the repository at this point in the history
  • Loading branch information
surma committed Sep 6, 2024
1 parent 4f93abb commit 53fc922
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 5 deletions.
5 changes: 3 additions & 2 deletions codecs/resize/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};
Expand Down
115 changes: 115 additions & 0 deletions codecs/rotate/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions codecs/rotate/flake.nix
Original file line number Diff line number Diff line change
@@ -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";
};
};
}
);
}
Binary file removed codecs/rotate/rotate.wasm
Binary file not shown.
Binary file added codecs/rotate/wasm_build/optimized.wasm
Binary file not shown.
27 changes: 25 additions & 2 deletions nix/squoosh-codec-builders/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
fenix,
wasm-bindgen ? pkgs.callPackage (import ../wasm-bindgen) { },
rust-helpers ? pkgs.callPackage (import ../rust-helpers) { inherit fenix; },
binaryen,
stdenv,
}:
let
Expand Down Expand Up @@ -43,7 +44,7 @@ in
// {
inherit codecBuild;
dontConfigure = true;
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ wasm-bindgen-bin ];
nativeBuildInputs = [ wasm-bindgen-bin ];
buildPhase = ''
runHook preBuild
Expand All @@ -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
'';
}
);

}
2 changes: 1 addition & 1 deletion src/features/preprocessors/rotate/worker/rotate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 53fc922

Please sign in to comment.