{"record":{"id":"64f48637851b1a49","repo":"DioxusLabs/dioxus","slug":"dx-rustc-env-var-must-be-set","errorCode":null,"errorMessage":"DX_RUSTC env var must be set","messagePattern":"DX_RUSTC env var must be set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/rustcwrapper.rs","lineNumber":56,"sourceCode":"\n/// Is `dx` being used as a rustc wrapper?\n///\n/// This is primarily used to intercept cargo, enabling fast hot-patching by caching the environment\n/// cargo setups up for the user's current project.\n///\n/// In a different world we could simply rely on cargo printing link args and the rustc command, but\n/// it doesn't seem to output that in a reliable, parseable, cross-platform format (ie using command\n/// files on windows...), so we're forced to do this interception nonsense.\npub fn is_wrapping_rustc() -> bool {\n    std::env::var(DX_RUSTC_WRAPPER_ENV_VAR).is_ok()\n}\n\n/// Run rustc directly, but output the result to a per-crate file in the args directory.\n///\n/// <https://doc.rust-lang.org/cargo/reference/config.html#buildrustc>\npub fn run_rustc() -> ExitCode {\n    let args_dir: PathBuf = std::env::var(DX_RUSTC_WRAPPER_ENV_VAR)\n        .expect(\"DX_RUSTC env var must be set\")\n        .into();\n\n    // Cargo invokes a workspace wrapper like: `wrapper-name rustc [args...]`\n    // We skip our own executable name (`wrapper-name`) to get the args passed to us.\n    let captured_args = args().skip(1).collect::<Vec<_>>();\n\n    let rustc_args = RustcArgs {\n        args: captured_args.clone(),\n        envs: vars().collect::<_>(),\n        cwd: std::env::current_dir().expect(\"Failed to get current dir\"),\n    };\n\n    // Always persist the captured rustc invocation, even for link steps.\n    // The tip crate's bin target is typically only observed during the final link invocation,\n    // so returning early before writing would lose the exact args/envs we need for fat-link replay.\n    write_rustc_args(&args_dir, &rustc_args);\n\n    // If we are being asked to link, delegate to the linker action after capturing.","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/DioxusLabs/dioxus/blob/24f6a829df0dfa203961a98ea4cae21c2ff27e28/packages/cli/src/rustcwrapper.rs#L38-L74","documentation":"`run_rustc` is the rustc wrapper entry point and expects the `DX_RUSTC` env var (the directory for captured args, set up by `dx`) to exist. If it panics with this message, the wrapper was invoked without `dx`'s environment setup — i.e. rustc wrapper ran outside a dx-managed build.","triggerScenarios":"Thrown at packages/cli/src/rustcwrapper.rs:56 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Run the build through the `dx` CLI so it sets the DX_RUSTC environment variable, or set DX_RUSTC to the rustc path manually when invoking the wrapper yourself."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"24f6a829df0dfa203961a98ea4cae21c2ff27e28","analyzedAt":"2026-08-23T07:10:14.078Z","contentChangedAt":"2026-08-23T07:10:14.078Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}