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

Commit

Permalink
Merge pull request #4 from DeterminateSystems/simple-wasm-output
Browse files Browse the repository at this point in the history
  • Loading branch information
lucperkins authored May 3, 2024
2 parents af9947e + c5832b3 commit c69bd6e
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 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,8 +63,12 @@
});

packages = forAllSystems ({ pkgs, system }: rec {
default = hello-wasm-pkg;
hello-wasm-pkg = pkgs.buildRustWasmPackage { };
default = hello-wasm;
hello-wasm = pkgs.buildRustWasiWasm {
name = "hello-wasm";
src = self;
};
hello-wasm-pkg = pkgs.buildWasmPackage { };
hello-wasmtime-exec = pkgs.buildRustWasmtimeExec { };
hello-wasmedge-exec = pkgs.buildRustWasmEdgeExec { };
});
Expand Down Expand Up @@ -102,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 @@ -117,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}/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" \
--add-flags "--"
--set WASMTIME_NEW_CLI 1 \
--add-flags "$out/lib/${finalArgs.pkgName}.wasm"
'';
};

Expand All @@ -141,13 +146,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 @@ -163,17 +169,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}.wasm
wasm-validate $out/lib/${finalArgs.pkgName}-stripped.wasm
'';
doCheck = true;
};
};
Expand Down

0 comments on commit c69bd6e

Please sign in to comment.