kitchen/nix/kitchenWasm/default.nix

44 lines
1.3 KiB
Nix
Raw Normal View History

2022-02-25 19:10:55 -05:00
{pkgs? (import <nixpkgs>) {},
2023-01-07 19:01:11 -05:00
version,
2022-03-06 15:16:30 -05:00
rust-wasm,
wasm-bindgen,
lockFile,
outputHashes,
2022-02-25 19:10:55 -05:00
}:
with pkgs;
let
pname = "kitchen-wasm";
2022-02-28 14:28:21 -05:00
src = ./../..;
# 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; });
2022-02-25 19:10:55 -05:00
in
# TODO(zaphar): I should actually be leveraging naersklib.buildPackage with a postInstall for the optimization and bindgen
2022-02-25 19:10:55 -05:00
stdenv.mkDerivation {
inherit src pname;
version = version;
# we need wasmb-bindgen v0.2.83 exactly
buildInputs = [ rust-wasm wasm-bindgen wasm-pack binaryen];
propagatedBuildInputs = [ rust-wasm wasm-bindgen wasm-pack binaryen];
2022-03-06 15:16:30 -05:00
phases = [ "postUnpackPhase" "buildPhase"];
2022-02-25 19:10:55 -05:00
postUnpackPhase = ''
ln -s ${cargoDeps} ./cargo-vendor-dir
2022-02-25 19:10:55 -05:00
cp -r ./cargo-vendor-dir/.cargo ./
cp -r $src/* ./
'';
# TODO(jwall): Use the makefile for as much of this as possible.
2022-02-25 19:10:55 -05:00
buildPhase = ''
mkdir -p $out
2022-03-06 15:16:30 -05:00
cd web
cp -r static $out
export project=kitchen
2024-06-30 20:53:35 -05:00
sh ../scripts/wasm-build.sh release
sh ../scripts/wasm-opt.sh release
rm -f $out/kitchen_wasm_bg.wasm
cp -r index.html $out
cp -r favicon.ico $out
rm -rf $out/release
rm -rf $out/wasm32-unknown-unknown
2022-02-25 19:10:55 -05:00
'';
2023-11-25 09:37:29 -05:00
}