Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Move wasm-strip into initial derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
lucperkins committed May 2, 2024
1 parent 7310f78 commit 2883d1f
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
];

buildRustWasiWasm = self.lib.buildRustWasiWasm final;
buildRustWasmPackage = self.lib.buildRustWasmPackage final;
buildWasmPackage = self.lib.buildWasmPackage final;
buildRustWasmScript = self.lib.buildRustWasmScript final;
buildRustWasmEdgeExec = self.lib.buildRustWasmEdgeExec final;
buildRustWasmtimeExec = self.lib.buildRustWasmtimeExec final;
Expand All @@ -63,12 +63,12 @@
});

packages = forAllSystems ({ pkgs, system }: rec {
default = hello-wasm-pkg;
default = hello-wasm;
hello-wasm = pkgs.buildRustWasiWasm {
name = "hello-wasm";
src = self;
};
hello-wasm-pkg = pkgs.buildRustWasmPackage { };
hello-wasm-pkg = pkgs.buildWasmPackage { };
hello-wasmtime-exec = pkgs.buildRustWasmtimeExec { };
hello-wasmedge-exec = pkgs.buildRustWasmEdgeExec { };
});
Expand Down Expand Up @@ -106,7 +106,10 @@
CARGO_BUILD_TARGET = rustWasmTarget;
buildInputs = with pkgs; [ wabt ];
postInstall = ''
wasm-validate $out/bin/${name}.wasm
mkdir -p $out/lib
wasm-strip $out/bin/${name}.wasm -o $out/lib/${name}.wasm
rm -rf $out/bin
wasm-validate $out/lib/${name}.wasm
'';
};

Expand All @@ -124,7 +127,7 @@
# TODO: bring in accordance with the new Wasmtime interface (WASMTIME_NEW_CLI=1)
installPhase = ''
mkdir -p $out/lib
cp ${wasmPkg}/bin/${finalArgs.name}.wasm $out/lib/${finalArgs.pkgName}.wasm
cp ${wasmPkg}/lib/${finalArgs.name}.wasm $out/lib/${finalArgs.pkgName}.wasm
makeWrapper ${pkgs.wasmtime}/bin/wasmtime $out/bin/${finalArgs.pkgName} \
--set WASMTIME_NEW_CLI 0 \
--add-flags "$out/lib/${finalArgs.pkgName}.wasm" \
Expand All @@ -145,13 +148,14 @@
nativeBuildInputs = with pkgs; [ makeWrapper ];
installPhase = ''
mkdir -p $out/lib
cp ${wasmPkg}/bin/${finalArgs.name}.wasm $out/lib/${finalArgs.pkgName}.wasm
cp ${wasmPkg}/lib/${finalArgs.name}.wasm $out/lib/${finalArgs.pkgName}.wasm
makeWrapper ${pkgs.wasmedge}/bin/wasmedge $out/bin/${finalArgs.pkgName} \
--add-flags "$out/lib/${finalArgs.pkgName}.wasm"
'';
};

buildRustWasmPackage = pkgs: args:
# Take a Wasm binary and strip it, provide stats, etc.
buildWasmPackage = pkgs: args:
let
finalArgs = self.lib.handleArgs args;
wasmPkg = self.lib.buildRustWasiWasm pkgs {
Expand All @@ -167,16 +171,12 @@
];
buildPhase = ''
mkdir -p $out/{lib,share}
cp ${wasmPkg}/bin/${finalArgs.name}.wasm $out/lib/${finalArgs.pkgName}.wasm
wasm-strip $out/lib/${finalArgs.pkgName}.wasm -o $out/lib/${finalArgs.pkgName}-stripped.wasm
cp ${wasmPkg}/lib/${finalArgs.name}.wasm $out/lib/${finalArgs.pkgName}.wasm
wasm2wat $out/lib/${finalArgs.pkgName}.wasm > $out/share/${finalArgs.pkgName}.wat
wasm-stats $out/lib/${finalArgs.pkgName}.wasm -o $out/share/${finalArgs.pkgName}.dist
wasm-objdump \
--details $out/lib/${finalArgs.pkgName}.wasm > $out/share/${finalArgs.pkgName}-dump.txt
'';
checkPhase = ''
wasm-validate $out/lib/${finalArgs.pkgName}-stripped.wasm
'';
doCheck = true;
};
};
Expand Down

0 comments on commit 2883d1f

Please sign in to comment.