Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
surma committed Sep 6, 2024
1 parent 53fc922 commit fae5959
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 89 deletions.
7 changes: 3 additions & 4 deletions codecs/resize/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) callPackage writeShellScriptBin;

squooshCodecBuilders = callPackage (import ../../nix/squoosh-codec-builders) {fenix = fenix.packages.${system};};
inherit (squooshCodecBuilders) buildSquooshCodecRust;

buildSquooshRustCodec= callPackage (import ../../nix/squoosh-rust-builder) {fenix = fenix.packages.${system};};

src = ./.;
in
{
packages = rec {
default = resize-squoosh;
resize-squoosh = buildSquooshCodecRust {
resize-squoosh = buildSquooshRustCodec {
name = "resize-squoosh";
inherit src;
cargoLock = {
Expand Down
5 changes: 2 additions & 3 deletions codecs/rotate/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) callPackage writeShellScriptBin;

squooshCodecBuilders = callPackage (import ../../nix/squoosh-codec-builders) {fenix = fenix.packages.${system};};
inherit (squooshCodecBuilders) buildSquooshCodecRust;
buildSquooshRustCodec= callPackage (import ../../nix/squoosh-rust-builder) {fenix = fenix.packages.${system};};

src = ./.;
in
{
packages = rec {
default = rotate-squoosh;
rotate-squoosh = buildSquooshCodecRust {
rotate-squoosh = buildSquooshRustCodec {
name = "rotate-squoosh";
inherit src;
cargoLock = {
Expand Down
82 changes: 0 additions & 82 deletions nix/squoosh-codec-builders/default.nix

This file was deleted.

78 changes: 78 additions & 0 deletions nix/squoosh-rust-builder/default.nix
Original file line number Diff line number Diff line change
@@ -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
'';
}
)

0 comments on commit fae5959

Please sign in to comment.