DioxusLabs / dioxus

Fullstack GUI library for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
19.45k stars 747 forks source link

Allow running dioxus-cli without rustup installed #2052

Closed holly-hacker closed 4 months ago

holly-hacker commented 4 months ago

Feature Request

I want to try out dioxus and tried to install the 0.5 alpha through a nix flake. I managed to get it to build, but it fails with the following error:

❯ dx build
[INFO] You appear to be creating a Dioxus project from scratch; we will use the default config
[INFO] 🚅 Running build command...
Error: 🚫 Building project failed:

Caused by:
    0: I/O Error: No such file or directory (os error 2)
    1: No such file or directory (os error 2)

This error also appears when using the dx command to create a project, and when using serve rather than build.

As I understand, this is because the dioxus cli invokes rustup show to check if the wasm32-unknown-unknown target is installed: https://github.com/DioxusLabs/dioxus/blob/9241730d275ff849bb77751e6fc9241566b1dfcb/packages/cli/src/builder.rs#L102-L104

I tried to add a .context call to this check to verify that this is the error but couldn't get it to build, but adding rustup to my buildInputs does get past the error.

For reproduction, here is my current flake:

flake.nix ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; rust-overlay = { url = "github:oxalica/rust-overlay"; inputs.nixpkgs.follows = "nixpkgs"; inputs.flake-utils.follows = "flake-utils"; }; }; outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }: flake-utils.lib.eachDefaultSystem (system: let overlays = [ (import rust-overlay) ]; pkgs = import nixpkgs { inherit system overlays; }; dx = with pkgs; (rustPlatform.buildRustPackage rec { pname = "dioxus-cli"; version = "0.5.0-alpha.0"; cargoHash = "sha256-l/FOB1sUWQmHOZPfSJ0nJ3WZFInnwoh0n9Z00qfaa1k="; src = fetchCrate { inherit pname version; hash = "sha256-POEO5G0uw1y+FkV3HWi4ifhkEsFcGaY6VNABTm9C9+M="; }; doCheck = false; nativeBuildInputs = [ pkg-config cacert nasm ]; buildInputs = [ openssl ] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.CoreServices ]; OPENSSL_NO_VENDOR = 1; }); in with pkgs; rec { devShell = mkShell rec { nativeBuildInputs = [ (rust-bin.stable.latest.default.override { extensions = [ "rust-analyzer" "rust-src" ]; targets = [ "wasm32-unknown-unknown" ]; }) ]; buildInputs = []; # buildInputs = [ rustup ]; shellHook = '' PATH="${dx}/bin:$PATH" ''; }; }); } ```

Implement Suggestion

Implement a different check to check for the wasm32-unknown-unknown target, or add an environment variable that allows bypassing this check.

ealmloff commented 4 months ago

We can log a warning if rustup is not installed and skip the check without stopping the CLI. It looks like there are specific directories that we can check for each platform for targets, but I don't if those locations are stable