about summary refs log blame commit diff
path: root/corp/rih/default.nix
blob: 24bbde09b9750e5a6b54fda0988fbf145c99cb9a (plain) (tree)


















































                                                                                
{ lib, pkgs, ... }:

let
  wasmRust = pkgs.rust-bin.stable.latest.default.override {
    targets = [ "wasm32-unknown-unknown" ];
  };

  cargoToml = with builtins; fromTOML (readFile ./Cargo.toml);

  wasmBindgenMatch =
    cargoToml.dependencies.wasm-bindgen == "= ${pkgs.wasm-bindgen-cli.version}";

  assertWasmBindgen = assert (lib.assertMsg wasmBindgenMatch ''
    Due to instability in the Rust WASM ecosystem, the trunk build
    tool enforces that the Cargo-dependency version of `wasm-bindgen`
    MUST match the version of the CLI supplied in the environment.

    This can get out of sync when nixpkgs is updated. To resolve it,
    wasm-bindgen must be bumped in the Cargo.toml file and cargo needs
    to be run to resolve the dependencies.

    Versions of `wasm-bindgen` in Cargo.toml:

      Expected: '= ${pkgs.wasm-bindgen-cli.version}'
      Actual:   '${cargoToml.dependencies.wasm-bindgen}'
  ''); pkgs.wasm-bindgen-cli;

  deps = with pkgs; [
    binaryen
    sass
    wasmRust
    trunk
    assertWasmBindgen
  ];

in
pkgs.rustPlatform.buildRustPackage rec {
  pname = "rih-frontend";
  version = "canon";
  src = lib.cleanSource ./.;
  cargoLock.lockFile = ./Cargo.lock;

  buildPhase = ''
    export PATH=${lib.makeBinPath deps}:$PATH
    mkdir home
    export HOME=$PWD/.home
    env
    trunk build --release -d $out
  '';

  dontInstall = true;
}