I have a web application that involves a Typeshare GUI with a Rust logic engine. I discovered that it’s not all that hard, through a bunch of manual steps, to connect that gui to a WASM32 build of Rust.
But I don’t want to stick to manual steps. I want to have a single command to build the app and its dependencies. Since nix build .kifu-gtk
(a GTK GUI for the same core library) already works, nix build .#kifu-pwa
seems like a good command to run.
In order to constrain my build times, I’m using buildRustCrate
so that I get the crate-level caching. That actually helps me quite a lot since one of my crates is rust-gtk, which has a huge number of dependencies and leads to 10+ minute builds on my machine.
So my question becomes, how can I direct buildRustCrate
to pass --target wasm32-unknown-unknown
to rustc
? The only prior art I’ve found on something like this was an article Tom Houle wrote, but that article is still using Cargo. I haven’t figured out how to adapt it to a Cargoless world.
Here’s what I have right now, and this would work if I were targeting my host platform:
kifu/kifu-wasm/default.nix
:
{ pkgs, typeshare, wasm-pack }:
let
customBuildInfo = pkgs: pkgs.buildRustCrate.override {
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
kifu-wasm = attrs: {
buildInputs = [
typeshare
];
};
};
};
in (import ./Cargo.nix {
inherit pkgs;
buildRustCrateForPkgs = customBuildInfo;
release = true;
}).rootCrate.build
flake.nix
:
packages."x86_64-linux" = {
kifu-gtk = import ./kifu/kifu-gtk {
inherit pkgs;
typeshare = typeshare.packages."x86_64-linux".default;
};
kifu-wasm = import ./kifu/kifu-wasm {
inherit pkgs;
typeshare = typeshare.packages."x86_64-linux".default;
wasm-pack = pkgs.wasm-pack;
};
You can find these, including the full context, on my branch as long as it lives….
I would appreciate any help in getting this working, even if it means that I have to rearchitect my nix expressions. The actual goal is to build kifu-pwa
, bundling kifu-wasm
in. The only requirement is that I very much want to keep the crate-level dependency caching.