Dioxus

From NixOS Wiki
Revision as of 21:02, 24 December 2024 by CathalMullan (talk | contribs) (Showcase replacing lock file.)

Dioxus is a full-stack Rust app framework for web, desktop, mobile, and more.

Troubleshooting

wasm-bindgen mismatch

A common issue when using the dioxus-cli version from Nixpkgs is encountering the following error:

it looks like the Rust project used to create this Wasm file was linked against
version of wasm-bindgen that uses a different bindgen format than this binary:

  rust Wasm file schema version: 0.2.99
     this binary schema version: 0.2.97

There are two solutions to solving this:

  1. Downgrade wasm-bindgen to the version that dioxus-cli expects.
  2. Update dioxus-cli to use a newer lock file.
Downgrading wasm-bindgen

Within your Cargo.toml file, force wasm-bindgen to use the expected version.

[dependencies]
wasm-bindgen = "=0.2.97"

Run cargo update, and you should see the version being downgraded.

Downgrading wasm-bindgen v0.2.99 -> v0.2.97 (available: v0.2.99)
Updating lock file

If you can't downgrade, you can instead manually update the lock file.

Download the source from crates.io for the given version of the CLI.

e.g. https://crates.io/api/v1/crates/dioxus-cli/0.6.0/download

Extract the file, cd into the directory, and run cargo update. You should be able to see the wasm-bindgen version being updated.

Updating wasm-bindgen v0.2.97 -> v0.2.99

Copy the newly updated lock file into your project (here called Dioxus.lock), and override the Nixpkgs version.

dioxus-cli = pkgs.dioxus-cli.overrideAttrs (_: {
  postPatch = ''
    rm Cargo.lock
    cp ${./Dioxus.lock} Cargo.lock
  '';

  cargoDeps = pkgs.rustPlatform.importCargoLock {
    lockFile = ./Dioxus.lock;
  };
});

wasm-bindgen-cli version

You will also want to ensure the version of wasm-bindgen-cli matches whatever is in your lock file.

cargoLock = builtins.fromTOML (builtins.readFile ./Cargo.lock);

wasmBindgen = pkgs.lib.findFirst
  (pkg: pkg.name == "wasm-bindgen")
  (throw "Could not find wasm-bindgen package")
  cargoLock.package;

wasm-bindgen-cli = pkgs.wasm-bindgen-cli.override {
  version = wasmBindgen.version;
  hash = pkgs.lib.fakeHash;
  cargoHash = pkgs.lib.fakeHash;
};