From 7310f785f61e9d279bf51e200c474af222c19ad6 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Thu, 2 May 2024 12:29:05 -0300 Subject: [PATCH 1/3] Add simple package output --- flake.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 8fc6110..8ecf056 100644 --- a/flake.nix +++ b/flake.nix @@ -64,6 +64,10 @@ packages = forAllSystems ({ pkgs, system }: rec { default = hello-wasm-pkg; + hello-wasm = pkgs.buildRustWasiWasm { + name = "hello-wasm"; + src = self; + }; hello-wasm-pkg = pkgs.buildRustWasmPackage { }; hello-wasmtime-exec = pkgs.buildRustWasmtimeExec { }; hello-wasmedge-exec = pkgs.buildRustWasmEdgeExec { }; @@ -171,7 +175,6 @@ --details $out/lib/${finalArgs.pkgName}.wasm > $out/share/${finalArgs.pkgName}-dump.txt ''; checkPhase = '' - wasm-validate $out/lib/${finalArgs.pkgName}.wasm wasm-validate $out/lib/${finalArgs.pkgName}-stripped.wasm ''; doCheck = true; From 2883d1f99e638f7fb1715a6d7b618e08d28e5026 Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Thu, 2 May 2024 12:41:27 -0300 Subject: [PATCH 2/3] Move wasm-strip into initial derivation --- flake.nix | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/flake.nix b/flake.nix index 8ecf056..4e0b239 100644 --- a/flake.nix +++ b/flake.nix @@ -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; @@ -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 { }; }); @@ -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 ''; }; @@ -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" \ @@ -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 { @@ -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; }; }; From c5832b33e3399511b4bbb055bd2dae38ee7a1b5c Mon Sep 17 00:00:00 2001 From: Luc Perkins Date: Fri, 3 May 2024 11:38:43 -0300 Subject: [PATCH 3/3] Remove unnecessary flags --- flake.nix | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 4e0b239..a3b12c5 100644 --- a/flake.nix +++ b/flake.nix @@ -124,14 +124,12 @@ name = finalArgs.name; src = finalArgs.src; nativeBuildInputs = with pkgs; [ makeWrapper ]; - # TODO: bring in accordance with the new Wasmtime interface (WASMTIME_NEW_CLI=1) installPhase = '' mkdir -p $out/lib 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" \ - --add-flags "--" + --set WASMTIME_NEW_CLI 1 \ + --add-flags "$out/lib/${finalArgs.pkgName}.wasm" ''; };