From e3c4a016487977ce479528328524e3a3f6500ae8 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Sun, 30 Jun 2024 20:31:47 -0500 Subject: [PATCH] refactor: make the wasm builder a little more configurable. --- flake.nix | 8 ++++++++ nix/kitchenWasm/default.nix | 18 +++++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/flake.nix b/flake.nix index dc36109..8884f75 100644 --- a/flake.nix +++ b/flake.nix @@ -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; diff --git a/nix/kitchenWasm/default.nix b/nix/kitchenWasm/default.nix index 29c2c09..6d0055f 100644 --- a/nix/kitchenWasm/default.nix +++ b/nix/kitchenWasm/default.nix @@ -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