DioxusLabs/dioxus · error

Failed to execute rustc command

Error message

Failed to execute rustc command

What it means

dx installs a rustc wrapper (rustcwrapper.rs) as RUSTC to intercept crate arguments for WASM splitting and hot-reload metadata; after capturing args it re-spawns the real `rustc` with inherited stdio. This expect fires when that rustc process cannot be spawned.

Source

Thrown at packages/cli/src/rustcwrapper.rs:94

        return crate::link::LinkAction::from_env()
            .expect("Linker action not found")
            .run_link();
    }

    // Run the actual rustc command.
    // We want all stdout/stderr to be inherited, so the user sees the compiler output.
    let mut cmd = std::process::Command::new("rustc");

    // The first argument in `captured_args` is the rustc path, which we need to skip
    // when passing arguments to the `rustc` command we are spawning.
    cmd.args(captured_args.iter().skip(1));
    cmd.envs(rustc_args.envs);
    cmd.current_dir(rustc_args.cwd);
    cmd.stdout(std::process::Stdio::inherit());
    cmd.stderr(std::process::Stdio::inherit());

    // Spawn the process and propagate its exit code.
    let status = cmd.status().expect("Failed to execute rustc command");
    std::process::exit(status.code().unwrap_or(1)); // Exit with 1 if process was killed by signal
}

fn write_rustc_args(args_dir: &PathBuf, rustc_args: &RustcArgs) {
    // Extract the crate name from the args to use as the filename.
    // Skip non-sensical args when a build is completely fresh (rustc is invoked with --crate-name ___)
    let crate_name = rustc_args
        .args
        .iter()
        .skip_while(|arg| *arg != "--crate-name")
        .nth(1);

    if let Some(crate_name) = crate_name {
        if crate_name != "___" {
            std::fs::create_dir_all(args_dir)
                .expect("Failed to create args directory for rustc wrapper");

            let crate_type = rustc_args

View on GitHub (pinned to 393d190a80)

Solutions

  1. Confirm `rustc --version` works in the environment dx runs in
  2. Restart the dx build after toolchain changes settle
  3. Pin one toolchain for the session (rust-toolchain.toml or rustup default) and avoid switching during builds
  4. Check the project directory was not deleted/moved mid-build (the wrapper re-runs with a recorded cwd)
Defensive patterns

Strategy: validation

Validate before calling

fn rustc_available() -> bool {
    std::process::Command::new("rustc").arg("--version").output().is_ok()
}

Prevention

When it happens

Trigger: rustc disappearing or becoming non-executable while dx runs: toolchain uninstalled/switched mid-build, PATH changed by the build itself, or the recorded cwd no longer existing.

Common situations: Running rustup update or toolchain cleanup concurrently with dx serve; ephemeral CI containers pruning toolchains; Nix-style environments where the rustc path is transient.

Related errors


AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16). Data as JSON: /api/errors/e57f2a97d04e43be. Report an issue: GitHub.