kitchen/nix/kitchenWasm/default.nix

41 lines
1.4 KiB
Nix
Raw Normal View History

2022-02-25 19:10:55 -05:00
{pkgs? (import <nixpkgs>) {},
version ? "0.2.1",
2022-03-06 15:16:30 -05:00
rust-wasm,
2022-02-25 19:10:55 -05:00
}:
with pkgs;
let
pname = "kitchen-wasm";
2022-02-28 14:28:21 -05:00
src = ./../..;
lockFile = ./../../Cargo.lock;
# NOTE(jwall): Because we use wasm-pack directly below we need
# the cargo dependencies to already be installed.
2022-10-11 16:49:12 -04:00
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.
"sycamore-0.8.2" = "sha256-I+NTfT83l8kST//IxJOZmeuhi1xWX070LToWPRU9j2A=";
"sqlx-0.6.2" = "sha256-X/LFvtzRfiOIEZJiVzmFvvULPpjhqvI99pSwH7a//GM=";
};
});
2022-02-25 19:10:55 -05:00
in
stdenv.mkDerivation {
inherit src pname;
version = version;
# we need wasmb-bindgen v0.2.81 exactly
buildInputs = [ rust-wasm wasm-bindgen-cli wasm-pack binaryen];
propagatedBuildInputs = [ rust-wasm wasm-bindgen-cli 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 = ''
echo building with wasm-pack
2022-02-25 19:10:55 -05:00
mkdir -p $out
2022-03-06 15:16:30 -05:00
cd web
cp -r static $out
RUST_LOG=info wasm-pack build --mode no-install --release --target web --out-dir $out;
cp -r index.html $out
2022-02-25 19:10:55 -05:00
'';
}