Dioxus: Difference between revisions

Neutral (talk | contribs)
wasm-bindgen-cli package uses buildWasmBindgenCli function now.
mNo edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 4: Line 4:


==== ''wasm-bindgen'' mismatch ====
==== ''wasm-bindgen'' mismatch ====
'''Note:''' As of Nixpkgs 25.11, the ''wasm-bindgen-cli'' is automatically bundled with the correct version when using ''dioxus-cli'', so the workarounds described below are no longer necessary.
A common issue when using the ''dioxus-cli'' version from Nixpkgs is encountering the following error:<syntaxhighlight lang="text">
A common issue when using the ''dioxus-cli'' version from Nixpkgs is encountering the following error:<syntaxhighlight lang="text">
it looks like the Rust project used to create this Wasm file was linked against
it looks like the Rust project used to create this Wasm file was linked against
Line 75: Line 77:
     hash = pkgs.lib.fakeHash;
     hash = pkgs.lib.fakeHash;
   };
   };
};</syntaxhighlight>
};</syntaxhighlight>'''Example flake.nix'''<syntaxhighlight lang="nix">
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
 
    # For installing non-standard rustc versions
    rust-overlay.url = "github:oxalica/rust-overlay";
    rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
  };
 
  outputs = {
    self,
    rust-overlay,
    nixpkgs,
  }:
  {
    devShells.x86_64-linux.default = let
      pkgs = import nixpkgs {
        system = "x86_64-linux";
        overlays = [
          rust-overlay.overlays.default
        ];
      };
 
      rustShellToolchain = (pkgs.rust-bin.selectLatestNightlyWith (t: t.default)).override {
        extensions = ["rust-src" "rust-analyzer"];
        targets = [ "wasm32-unknown-unknown" ];
      };
 
      dioxus-cli = pkgs.dioxus-cli.overrideAttrs (_: {
        postPatch = ''
          rm Cargo.lock
          cp ${./Dioxus.lock} Cargo.lock
        '';
 
        cargoDeps = pkgs.rustPlatform.importCargoLock {
          lockFile = ./Dioxus.lock;
        };
      });
 
      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.buildWasmBindgenCli rec {
        src = pkgs.fetchCrate {
          pname = "wasm-bindgen-cli";
          version = wasmBindgen.version;
          hash = "sha256-txpbTzlrPSEktyT9kSpw4RXQoiSZHm9t3VxeRn//9JI=";
        };


        cargoDeps = pkgs.rustPlatform.fetchCargoVendor {
          inherit src;
          inherit (src) pname version;
          hash = "sha256-J+F9SqTpH3T0MbvlNKVyKnMachgn8UXeoTF0Pk3Xtnc=";
        };
      };
    in
      pkgs.mkShell {
        name = "dioxus";
        packages = [ rustShellToolchain dioxus-cli wasm-bindgen-cli ];
    };
  };
}
</syntaxhighlight>
[[Category:Rust]]
[[Category:Rust]]