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

dioxus-cli: 0.6.0 -> 0.6.1 #366178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CathalMullan
Copy link
Member

@CathalMullan CathalMullan commented Dec 18, 2024

v0.6.1 added auto-downloading of wasm-bindgen to the CLI, hence the new skipped tests.

dx now installs wasm-bindgen to {data_local_dir}/dioxus/wasm-bindgen/wasm-bindgen-{version}. Assuming you symlink the correct version of wasm-bindgen to this location, everything still works fine.

I'll look into wrapping/patching dx to make this more seamless.

Since it uses dirs::data_local_dir, we can't easily wrap on MacOS without overriding $HOME, which isn't ideal. Dioxus also supports reading global config from {data_local_dir}, so overriding it would break some functionality.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@CathalMullan
Copy link
Member Author

CathalMullan commented Dec 19, 2024

We could patch the lookup directory easily:

--- a/src/wasm_bindgen.rs
+++ b/src/wasm_bindgen.rs
@@ -233,10 +233,15 @@ impl WasmBindgen {
 
     /// Get the installation directory for the wasm-bindgen executable.
     async fn install_dir() -> anyhow::Result<PathBuf> {
-        let bindgen_dir = dirs::data_local_dir()
-            .expect("user should be running on a compatible operating system")
-            .join("dioxus/wasm-bindgen/");
+        let tool_dir = if let Ok(dir) = std::env::var("DIOXUS_TOOL_DIR") {
+            PathBuf::from(dir)
+        } else {
+            dirs::data_local_dir()
+                .expect("user should be running on a compatible operating system")
+                .join("dioxus/")
+        };
 
+        let bindgen_dir = tool_dir.join("wasm-bindgen/");
         fs::create_dir_all(&bindgen_dir).await?;
 
         Ok(bindgen_dir)
postFixup = ''
  mkdir -p $out/libexec/wasm-bindgen
  ln -s ${wasm-bindgen-cli}/bin/wasm-bindgen $out/libexec/wasm-bindgen/wasm-bindgen-${wasm-bindgen-cli.version}

  wrapProgram $out/bin/dx \
    --set DIOXUS_TOOL_DIR "$out/libexec"
'';

Only issue is that the error messages aren't very helpful in the event you have a version mismatch:

> dx serve --example hello_world --platform web
12:59:23 [dev] Failed to verify tooling: I/O Error: No such file or directory (os error 2)
dx will proceed, but you might run into errors later.
12:59:23 [dev] Build failed: Other(Failed to write main executable)

Caused by:
    0: Failed to generate wasm-bindgen bindings
    1: No such file or directory (os error 2)

Though I suppose we could also patch the error message too?

@ToyVo
Copy link
Contributor

ToyVo commented Dec 23, 2024

could we have the version, hash, and cargoHash be parameters that we can override, could just be me but I'm having issues using overrideAttrs

@ToyVo
Copy link
Contributor

ToyVo commented Dec 24, 2024

for what its worth I've got the wrapping of wasm-bindgen-cli working like this on my end

wasm-bindgen-cli = pkgs.wasm-bindgen-cli.override {
  version = "0.2.99";
  hash = "sha256-1AN2E9t/lZhbXdVznhTcniy+7ZzlaEp/gwLEAucs6EA=";
  cargoHash = "sha256-DbwAh8RJtW38LJp+J9Ht8fAROK9OabaJ85D9C/Vkve4=";
};
dioxus-cli = pkgs.dioxus-cli.overrideAttrs (drv: rec {
  version = "0.6.1";
  src = pkgs.fetchCrate {
    inherit version;
    pname = drv.pname;
    hash = "sha256-mQnSduf8SHYyUs6gHfI+JAvpRxYQA1DiMlvNofImElU=";
  };
  cargoDeps = drv.cargoDeps.overrideAttrs (lib.const {
    name = "${drv.cargoDeps.name}-vendor";
    inherit src;
    outputHash = "sha256-QiGnBoZV4GZb5MQ3K/PJxCfw0p/7qDmoE607hlGKOns=";
  });
  postFixup = if pkgs.stdenv.isDarwin then ''
    mkdir -p "$out/home/Library/Application Support/dioxus/wasm-bindgen"
    ln -s ${lib.getExe wasm-bindgen-cli} "$out/home/Library/Application Support/dioxus/wasm-bindgen/wasm-bindgen-${wasm-bindgen-cli.version}"
    wrapProgram $out/bin/dx \
      --set HOME $out/home
  '' else ''
    mkdir -p $out/share/dioxus/wasm-bindgen
    ln -s ${lib.getExe wasm-bindgen-cli} $out/share/dioxus/wasm-bindgen/wasm-bindgen-${wasm-bindgen-cli.version}
    wrapProgram $out/bin/dx \
      --set XDG_DATA_HOME $out/share
  '';
  checkFlags = drv.checkFlags ++ ["--skip=wasm_bindgen::test"];
  nativeBuildInputs = drv.nativeBuildInputs ++ [pkgs.makeBinaryWrapper];
});

where I'm using dx within another rustPlatform.buildRustPackage derivation to build a fullstack dioxus app

edit:
Its since been brought to my attention that in my case exporting the variables just before using dx within the derivation is better than wrapping

@brianmay
Copy link
Contributor

I have some pull requests open with Dioxus to try to make building - in particular building manually without the cli tool on nix - easier.

DioxusLabs/dioxus#3419
DioxusLabs/dioxus#3429

There is an issue opened saying it should be possible to have it lookup wasm-bindgen in the path instead of automatically downloading it. Nothing has come of it yet though.

DioxusLabs/dioxus#3411

@brianmay
Copy link
Contributor

brianmay commented Dec 28, 2024

Anyone want to make this change into a PR and submit it to Dioxus?

#366178 (comment)

(although I think the environment variable should point directly to the executable, not the directory)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants