dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

wasm-bindgen version confusion

Open brianmay opened this issue 1 year ago • 9 comments

Problem

After creating new full stack project with dioxus cli 6.1, and attempting to build it, I get the following error:

08:25:39 [dev] Build failed: Other(Failed to write main executable

Caused by:
    0: Failed to generate wasm-bindgen bindings
    1:

       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

       Currently the bindgen format is unstable enough that these two schema versions
       must exactly match. You can accomplish this by either updating this binary or
       the wasm-bindgen dependency in the Rust project.

       You should be able to update the wasm-bindgen dependency with:

           cargo update -p wasm-bindgen --precise 0.2.97

       don't forget to recompile your Wasm file! Alternatively, you can update the
       binary with:

           cargo install -f wasm-bindgen-cli --version 0.2.99

       if this warning fails to go away though and you're not sure what to do feel free
       to open an issue at https://github.com/rustwasm/wasm-bindgen/issues!
       )

So according to this I have two options:

  1. I should upgrade wasm-bindgen-cli binaries to version 0.2.99.

    This doesn't work. I already have 0.2.99 installed:

    # wasm-bindgen -V
    wasm-bindgen 0.2.99
    

    The problem is that dioxus cli is directly linked into 0.2.97, and I can't change this at run time.

    https://github.com/DioxusLabs/dioxus/blob/v0.6/Cargo.lock#L14886-L14895

  2. Downgrade the project to use version 0.2.97 not 0.2.99.

    This also doesn't work,

    # cargo update -p wasm-bindgen --precise 0.2.97
        Updating crates.io index
    error: failed to select a version for the requirement `wasm-bindgen = "^0.2.99"`
    candidate versions found which didn't match: 0.2.97
    location searched: crates.io index
    required by package `dioxus-cli-config v0.6.1`
        ... which satisfies dependency `dioxus-cli-config = "^0.6.0"` (locked to 0.6.1) of package `dioxus v0.6.0`
        ... which satisfies dependency `dioxus = "=0.6.0"` (locked to 0.6.0) of package `dioxus-fs v0.1.0 (/home/brian/tree/3rdparty/dioxus-fs)`
    

Originally I thought this was a nixos specific issue, so I reported it there, but on closer inspection it looks like a dioxus bug.

Steps To Reproduce

Steps to reproduce the behavior:

  • Create new dx fulls stack project with "dx new".
  • Try to build it with dx serve --platform web

Expected behavior

This operation should work.

Environment:

  • Dioxus version: 0.6
  • Rust version: 1.83.0
  • OS info: Linux
  • App platform: web

Questionnaire

brianmay avatar Dec 19 '24 21:12 brianmay

Forgot to mention, I changed the dioxus dependency to:

dioxus = { version = "=0.6.0", features = ["router", "fullstack"] }

In order to work around https://github.com/DioxusLabs/dioxus/issues/3391

But the output above indicates it is pulling in dioxus-cli-config v0.6.1, which looks wrong. Lets try to fix that:

# cargo update -p dioxus-cli-config --precise 0.6.0
    Updating crates.io index
error: failed to select a version for the requirement `dioxus-cli-config = "^0.6.1"`
candidate versions found which didn't match: 0.6.0
location searched: crates.io index
required by package `dioxus-desktop v0.6.1`
    ... which satisfies dependency `dioxus-desktop = "^0.6.0"` (locked to 0.6.1) of package `dioxus v0.6.0`
    ... which satisfies dependency `dioxus = "=0.6.0"` (locked to 0.6.0) of package `dioxus-fs v0.1.0 (/home/brian/tree/3rdparty/dioxus-fs)`

Dependency hell!

Dependencies need to be upgraded in exactly the right order.

I think something like:

# cargo update -p dioxus-fullstack  --precise 0.6.0
    Updating crates.io index
 Downgrading dioxus-fullstack v0.6.1 -> v0.6.0
note: pass `--verbose` to see 12 unchanged dependencies behind latest

# cargo update -p dioxus-mobile  --precise 0.6.0
    Updating crates.io index
 Downgrading dioxus-mobile v0.6.1 -> v0.6.0
note: pass `--verbose` to see 13 unchanged dependencies behind latest

# cargo update -p dioxus-desktop  --precise 0.6.0
    Updating crates.io index
 Downgrading dioxus-desktop v0.6.1 -> v0.6.0
note: pass `--verbose` to see 14 unchanged dependencies behind latest

# cargo update -p dioxus-logger --precise 0.6.0
    Updating crates.io index
 Downgrading dioxus-logger v0.6.1 -> v0.6.0
note: pass `--verbose` to see 15 unchanged dependencies behind latest

# cargo update -p dioxus-router --precise 0.6.0
    Updating crates.io index
 Downgrading dioxus-router v0.6.1 -> v0.6.0
note: pass `--verbose` to see 16 unchanged dependencies behind latest

# cargo update -p dioxus-web --precise 0.6.0
    Updating crates.io index
 Downgrading dioxus-web v0.6.1 -> v0.6.0
note: pass `--verbose` to see 17 unchanged dependencies behind latest

# cargo update -p manganis --precise 0.6.0
    Updating crates.io index
 Downgrading manganis v0.6.1 -> v0.6.0
note: pass `--verbose` to see 18 unchanged dependencies behind latest

# cargo update -p manganis-macro --precise 0.6.0
    Updating crates.io index
 Downgrading manganis-macro v0.6.1 -> v0.6.0
note: pass `--verbose` to see 19 unchanged dependencies behind latest

# cargo update -p manganis-core --precise 0.6.0
    Updating crates.io index
 Downgrading manganis-core v0.6.1 -> v0.6.0
note: pass `--verbose` to see 20 unchanged dependencies behind latest

# cargo update -p dioxus-cli-config --precise 0.6.0
    Updating crates.io index
 Downgrading dioxus-cli-config v0.6.1 -> v0.6.0
note: pass `--verbose` to see 21 unchanged dependencies behind latest

Out of time, not tested yet, but I expect this might work now

brianmay avatar Dec 19 '24 21:12 brianmay

Sorry, missed one, how to deal with this not so obvious.

# cargo update -p wasm-bindgen --precise 0.2.97
    Updating crates.io index
error: failed to select a version for the requirement `wasm-bindgen = "=0.2.99"`
candidate versions found which didn't match: 0.2.97
location searched: crates.io index
required by package `web-sys v0.3.76`
    ... which satisfies dependency `web-sys = "^0.3.61"` (locked to 0.3.76) of package `dioxus-fullstack v0.6.0`
    ... which satisfies dependency `dioxus-fullstack = "^0.6.0"` (locked to 0.6.0) of package `dioxus v0.6.0`
    ... which satisfies dependency `dioxus = "=0.6.0"` (locked to 0.6.0) of package `dioxus-fs v0.1.0 (/home/brian/tree/3rdparty/dioxus-fs)`

brianmay avatar Dec 19 '24 21:12 brianmay

Is this happening on a Mac? I had a similar issue which I was able to resolve. My issue was Rustup was installed from brew instead of the official way as described with Installing Rust. After uninstalling with the following commands, I reinstalled everything and it all works for me now. That being said my issue was similar but not exactly the same as yours, hope this helps. see #3418

Steps (on MacOS)

  • cargo install --list | grep : | cut -d' ' -f1 -f3 list all your installed cargo plugins, you will have reinstall them
  • rustup show list your targets and toolchains, you will have to reinstall them too
  • rustup self uninstall
  • brew uninstall rust
  • curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Nejat avatar Dec 22 '24 13:12 Nejat

No, this is Linux. The problem was mentioned here:

https://github.com/DioxusLabs/dioxus/discussions/3402#discussioncomment-11632372

The wasm-bindgen folks recently started pinning the version of wasm-bindgen indirectly, meaning our CLI uses a wasm-bindgen version that's "frozen in time" and can never work with a rust project that runs "cargo update".

https://github.com/rustwasm/wasm-bindgen/issues/4304#issuecomment-2525003682

This forced us to add a feature that downloads wasm-bindgen from the binary source to match the schema version in the wasm output.

brianmay avatar Dec 22 '24 20:12 brianmay

I can reproduce this on NixOS 24.11. It would be helpful for reproducible build systems (such as Nix) if Dixous CLI didn't force you to use its internal wasm-bindgen. I pinned it correctly in my Nix project after getting an error about a version mismatch, only for the dx utility to silently overrule me. It would be helpful to be able to override dx's behavior so that it just trusts the PATH to be correct, instead of trying to manage which version it's using itself.

crabdancing avatar Dec 27 '24 02:12 crabdancing

I am facing this issue as well.

Caused by:
    0: Failed to generate wasm-bindgen bindings
    1:

       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

       Currently the bindgen format is unstable enough that these two schema versions
       must exactly match. You can accomplish this by either updating this binary or
       the wasm-bindgen dependency in the Rust project.

       You should be able to update the wasm-bindgen dependency with:

           cargo update -p wasm-bindgen --precise 0.2.97

       don't forget to recompile your Wasm file! Alternatively, you can update the
       binary with:

           cargo install -f wasm-bindgen-cli --version 0.2.99

wrothmir avatar Dec 27 '24 10:12 wrothmir

@fenrir-san Check that you have Dioxus 6.1 CLI, it should automatically try to download the correct version at build time.

The solution in Dioxus 6.1 is good for everywhere (I think!) except nix builds, because nix builders do not have network access. Or a home directory (by default anyway). I have found a work around. Requires Dioxus 6.1

export XDG_DATA_HOME="$PWD/.data"
mkdir -p .data/dioxus/wasm-bindgen
ln -s ${wasm-bindgen-cli}/bin/wasm-bindgen .data/dioxus/wasm-bindgen/wasm-bindgen-0.2.99
dx build --release --platform web

But would be better if it just searched the $PATH for the correct wasm-bindgen.

brianmay avatar Dec 27 '24 21:12 brianmay

@brianmay I fixed the issue by not installing dioxus-cli through the Nix Store and instead just using cargo to do that. It works correctly now. I've just started with Rust on NixOS so I'm not entirely sure what the issue is with installing it directly from the Nix Store.

wrothmir avatar Dec 27 '24 21:12 wrothmir

Nixpkgs still have version 0.6.0 of dioxus-cli, it hasn't been updated yet.

https://github.com/NixOS/nixpkgs/pull/366178

brianmay avatar Dec 28 '24 08:12 brianmay

NixOS user here.

I've found that if you have differing versions of dx vs what your library is using, you'll have a bad time.

I've solved this by doing two things.

  1. I hard pin dioxus, wasm-bindgen, and web-sys to specific versions in my crate dependencies.
  2. I have a project specific flake.nix (tied to direnv) which installs a specific version of dx:
let
  dioxus-cli = pkgs.rustPlatform.buildRustPackage rec {
    pname = "dioxus-cli";
    version = "0.6.0";

    src = pkgs.fetchCrate {
      inherit pname version;
      sha256 = "sha256-0Kg2/+S8EuMYZQaK4Ao+mbS7K48VhVWjPL+LnoVJMSw="; # 0.6.0
    };

    cargoHash = "sha256-RMo6q/GSAV1bCMWtR+wu9xGKCgz/Ie6t/8oirBly/LQ="; # 0.6.0

    OPENSSL_NO_VENDOR = 1;

    nativeBuildInputs = [ pkgs.pkg-config pkgs.cacert myrust ];
    buildInputs = [ pkgs.openssl ];
  };
in
  devShell.${system} = pkgs.mkShell {
    packages = [dioxus-cli]
  }

This way my system doesn't break if nixos updates dioxus-cli when I'm not ready to update my dependencies.

Houndie avatar Jan 15 '25 13:01 Houndie

In 0.6.2 we shipped the PR that allows the CLI to use system CLI.

https://github.com/DioxusLabs/dioxus/pull/3465

Hopefully this closes this issue!

jkelleyrtp avatar Jan 22 '25 03:01 jkelleyrtp

I tried it out and I believe it's working great. Thank you @jkelleyrtp :)

crabdancing avatar Jan 23 '25 23:01 crabdancing