about summary refs log tree commit diff
path: root/users/tazjin/predlozhnik/default.nix
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-07-27T11·04+0300
committertazjin <tazjin@tvl.su>2022-07-27T21·54+0000
commitd795a05c0719dd75b67327cb7cfdaaf6aded16dd (patch)
tree1fdb4464690e39c254034a1b7498c48322067ae3 /users/tazjin/predlozhnik/default.nix
parent38d01f7f3b3f5679e704456fe3ec51c768a7a052 (diff)
feat(tazjin/predlozhnik): bootstrap yew/wasm-based web UI r/4325
this commit is mostly to figure out hwo to build a yew application in
depot using the wasm toolchain. it's a bit finnicky, but could be a
lot worse.

Change-Id: I7804a774f1686a1f308ae1a3f549cd0ae7b5dbeb
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5980
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'users/tazjin/predlozhnik/default.nix')
-rw-r--r--users/tazjin/predlozhnik/default.nix52
1 files changed, 52 insertions, 0 deletions
diff --git a/users/tazjin/predlozhnik/default.nix b/users/tazjin/predlozhnik/default.nix
new file mode 100644
index 000000000000..2137be111278
--- /dev/null
+++ b/users/tazjin/predlozhnik/default.nix
@@ -0,0 +1,52 @@
+{ 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 = "predlozhnik";
+  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;
+}