{"record":{"id":"e57f2a97d04e43be","repo":"DioxusLabs/dioxus","slug":"failed-to-execute-rustc-command","errorCode":null,"errorMessage":"Failed to execute rustc command","messagePattern":"Failed to execute rustc command","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/rustcwrapper.rs","lineNumber":94,"sourceCode":"        return crate::link::LinkAction::from_env()\n            .expect(\"Linker action not found\")\n            .run_link();\n    }\n\n    // Run the actual rustc command.\n    // We want all stdout/stderr to be inherited, so the user sees the compiler output.\n    let mut cmd = std::process::Command::new(\"rustc\");\n\n    // The first argument in `captured_args` is the rustc path, which we need to skip\n    // when passing arguments to the `rustc` command we are spawning.\n    cmd.args(captured_args.iter().skip(1));\n    cmd.envs(rustc_args.envs);\n    cmd.current_dir(rustc_args.cwd);\n    cmd.stdout(std::process::Stdio::inherit());\n    cmd.stderr(std::process::Stdio::inherit());\n\n    // Spawn the process and propagate its exit code.\n    let status = cmd.status().expect(\"Failed to execute rustc command\");\n    std::process::exit(status.code().unwrap_or(1)); // Exit with 1 if process was killed by signal\n}\n\nfn write_rustc_args(args_dir: &PathBuf, rustc_args: &RustcArgs) {\n    // Extract the crate name from the args to use as the filename.\n    // Skip non-sensical args when a build is completely fresh (rustc is invoked with --crate-name ___)\n    let crate_name = rustc_args\n        .args\n        .iter()\n        .skip_while(|arg| *arg != \"--crate-name\")\n        .nth(1);\n\n    if let Some(crate_name) = crate_name {\n        if crate_name != \"___\" {\n            std::fs::create_dir_all(args_dir)\n                .expect(\"Failed to create args directory for rustc wrapper\");\n\n            let crate_type = rustc_args","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/393d190a801ccb441d41923e232289b4f8a5c669/packages/cli/src/rustcwrapper.rs#L76-L112","documentation":"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.","triggerScenarios":"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.","commonSituations":"Running rustup update or toolchain cleanup concurrently with dx serve; ephemeral CI containers pruning toolchains; Nix-style environments where the rustc path is transient.","solutions":["Confirm `rustc --version` works in the environment dx runs in","Restart the dx build after toolchain changes settle","Pin one toolchain for the session (rust-toolchain.toml or rustup default) and avoid switching during builds","Check the project directory was not deleted/moved mid-build (the wrapper re-runs with a recorded cwd)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn rustc_available() -> bool {\n    std::process::Command::new(\"rustc\").arg(\"--version\").output().is_ok()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin the toolchain with rust-toolchain.toml for the duration of dx sessions","Don't run rustup update or toolchain removals while dx serve is active","If the project dir might move, restart builds rather than reusing running sessions"],"tags":["cli","rustc","build","process-spawn","environment"],"backgroundTag":null,"analyzedSha":"393d190a801ccb441d41923e232289b4f8a5c669","analyzedAt":"2026-08-16T11:27:45.815Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}