refactor: make the wasm builder a little more configurable.

This commit is contained in:
Jeremy Wall 2024-06-30 20:31:47 -05:00
parent e1735e4243
commit e3c4a01648
2 changed files with 13 additions and 13 deletions

View File

@ -45,6 +45,14 @@
wasm-bindgen = pkgs.callPackage wasm-bindgenGen { inherit pkgs; };
kitchenWasm = kitchenWasmGen {
inherit pkgs rust-wasm wasm-bindgen version;
lockFile = ./Cargo.lock;
outputHashes = {
# I'm maintaining some patches for these so the lockfile hashes are a little
# incorrect. We override those here.
"wasm-web-component-0.2.0" = "sha256-quuPgzGb2F96blHmD3BAUjsWQYbSyJGZl27PVrwL92k=";
"sycamore-0.8.2" = "sha256-D968+8C5EelGGmot9/LkAlULZOf/Cr+1WYXRCMwb1nQ=";
"sqlx-0.6.2" = "sha256-X/LFvtzRfiOIEZJiVzmFvvULPpjhqvI99pSwH7a//GM=";
};
};
kitchen = (kitchenGen {
inherit pkgs version naersk-lib kitchenWasm rust-wasm;

View File

@ -3,23 +3,18 @@
features ? "",
rust-wasm,
wasm-bindgen,
lockFile,
outputHashes,
}:
with pkgs;
let
pname = "kitchen-wasm";
src = ./../..;
lockFile = ./../../Cargo.lock;
# NOTE(jwall): Because we use wasm-pack directly below we need
# the cargo dependencies to already be installed.
cargoDeps = (pkgs.rustPlatform.importCargoLock { inherit lockFile; outputHashes = {
# I'm maintaining some patches for these so the lockfile hashes are a little
# incorrect. We override those here.
"wasm-web-component-0.2.0" = "sha256-quuPgzGb2F96blHmD3BAUjsWQYbSyJGZl27PVrwL92k=";
"sycamore-0.8.2" = "sha256-D968+8C5EelGGmot9/LkAlULZOf/Cr+1WYXRCMwb1nQ=";
"sqlx-0.6.2" = "sha256-X/LFvtzRfiOIEZJiVzmFvvULPpjhqvI99pSwH7a//GM=";
};
});
cargoDeps = (pkgs.rustPlatform.importCargoLock { inherit lockFile outputHashes; });
in
# TODO(zaphar): I should actually be leveraging naersklib.buildPackage with a postInstall for the optimization and bindgen
stdenv.mkDerivation {
inherit src pname;
version = version;
@ -34,13 +29,10 @@ stdenv.mkDerivation {
'';
# TODO(jwall): Build this from the root rather than the src.
buildPhase = ''
set -x
echo building with wasm-pack
wasm-pack --version
mkdir -p $out
cd web
cp -r static $out
cargo build --lib --release --target wasm32-unknown-unknown --target-dir $out --offline
cargo build --lib --release --target wasm32-unknown-unknown --target-dir $out ${features} --offline
wasm-bindgen $out/wasm32-unknown-unknown/release/kitchen_wasm.wasm --out-dir $out --typescript --target web
wasm-opt $out/kitchen_wasm_bg.wasm -o $out/kitchen_wasm_bg-opt.wasm -O
rm -f $out/kitchen_wasm_bg.wasm