kitchen/nix/kitchenWasm/default.nix

48 lines
1.7 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,
features ? "",
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/* ./
'';
2022-02-28 14:28:21 -05:00
# TODO(jwall): Build this from the root rather than the src.
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
2024-06-30 20:53:35 -05:00
sh ../scripts/wasm-build.sh release
#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
#sh ../scripts/wasm-opt.sh release
wasm-opt $out/kitchen_wasm_bg.wasm -o $out/kitchen_wasm_bg-opt.wasm -O
rm -f $out/kitchen_wasm_bg.wasm
mv $out/kitchen_wasm_bg-opt.wasm $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
}