Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trunk build --offline fails to find wasm-bindgen even when available in PATH #650

Closed
jonboh opened this issue Dec 19, 2023 · 2 comments · Fixed by #655
Closed

trunk build --offline fails to find wasm-bindgen even when available in PATH #650

jonboh opened this issue Dec 19, 2023 · 2 comments · Fixed by #655
Labels
help wanted Extra attention is needed investigate More investigation is needed

Comments

@jonboh
Copy link

jonboh commented Dec 19, 2023

I'm packaging an application on a Nix flake. To do that I'm using the --offline flag. And providing the needed packages as buildInputs.

{ pkgs }:
pkgs.rustPlatform.buildRustPackage rec {
  pname = "my_application";
  version = "0.1";

  src = ./.;

  cargoLock = {
    lockFile = ./Cargo.lock;
  };

  nativeBuildInputs = with pkgs; [ pkg-config openssl rustToolchain trunk binaryen sass wasm-bindgen-cli ];
  PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";

  buildPhase = ''
    source ${./.env}
    trunk build --offline --release
  '';

  installPhase = ''
    cp -r dist $out/
  '';

However the build fails with couldn't find application wasm-bindgen. If I enter the flake environment the wasm-bindgen binary is available and I can manually run it.

I've been able to reproduce this behavior as well in my development environment (not the one of the flake).

cargo install trunk
cargo install wasm-bindgen-cli
trunk build --offline

Output:

...
2023-12-19T19:57:42.207939Z  INFO fetching cargo artifacts
2023-12-19T19:57:42.416413Z ERROR ❌ error
error from build pipeline

Caused by:
    0: error from asset pipeline
    1: couldn't find application wasm-bindgen
Error: error from build pipeline

Caused by:
    0: error from asset pipeline
    1: couldn't find application wasm-bindgen

However I can run the wasm-bindgen binary after that:

$ wasm-bindgen --version
wasm-bindgen 0.2.89

If I drop the ``--offline``` flag the application builds correctly, however in the flake build that is not possible.

I've tested both with the nixpkgs trunk which has version 0.18.0 as well as with the 0.18.2 version from the last release.

@ctron ctron added help wanted Extra attention is needed investigate More investigation is needed labels Dec 20, 2023
@ctron
Copy link
Collaborator

ctron commented Dec 20, 2023

Ok, that may be a case of bad error reporting. I think it should work more "expected" with other tools. But wasm-bindgen seems a bit special.

For other tools, there's a default version. There's a "required" version. And maybe a system installed version. If a version is required, then the system version must match for trunk to consider the system installed binary.

For wasm_bindgen, it will however look into Cargo.lock and Cargo.toml too for the wasm_bindgen crate dependency. Which makes sense, as the wasm_bindgen CLI should be the same version as the crate dependency.

So what seems to happen in this case is that trunk detect a different version in the project's Cargo file than in the system. That will lead to a simple "not found" error.

I think it should lead to a "tool version mismatch" error instead.

As for your case, I think you need to:

  • either align the project's wasm_bingen version with the installed tool
  • or override the required version using Trunk.toml

ctron added a commit to ctron/trunk that referenced this issue Dec 20, 2023
In case of using --offline, and requiring a specific version
of a tool, the error just says "not found". However, it would
be more helpful to indicate that the tool was found, but was
of the wrong version ("version mismatch").

Closes: trunk-rs#650
ctron added a commit to ctron/trunk that referenced this issue Dec 20, 2023
In case of using --offline, and requiring a specific version
of a tool, the error just says "not found". However, it would
be more helpful to indicate that the tool was found, but was
of the wrong version ("version mismatch").

Closes: trunk-rs#650
ctron added a commit that referenced this issue Dec 20, 2023
In case of using --offline, and requiring a specific version
of a tool, the error just says "not found". However, it would
be more helpful to indicate that the tool was found, but was
of the wrong version ("version mismatch").

Closes: #650
@jonboh
Copy link
Author

jonboh commented Dec 20, 2023

yap, that was exactly it, I've updated the Cargo.lock and now the application builds correctly, both in my dev-environment and in the flake. Thanks!
I agree that it would be clearer if it explicitly said that the wasm-bindgen version was not found. (just saw you made the change, thanks!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed investigate More investigation is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants