DioxusLabs/dioxus · error

DX_RUSTC env var must be set

Error message

DX_RUSTC env var must be set

What it means

`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.

Source

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

/// Is `dx` being used as a rustc wrapper?
///
/// This is primarily used to intercept cargo, enabling fast hot-patching by caching the environment
/// cargo setups up for the user's current project.
///
/// In a different world we could simply rely on cargo printing link args and the rustc command, but
/// it doesn't seem to output that in a reliable, parseable, cross-platform format (ie using command
/// files on windows...), so we're forced to do this interception nonsense.
pub fn is_wrapping_rustc() -> bool {
    std::env::var(DX_RUSTC_WRAPPER_ENV_VAR).is_ok()
}

/// Run rustc directly, but output the result to a per-crate file in the args directory.
///
/// <https://doc.rust-lang.org/cargo/reference/config.html#buildrustc>
pub fn run_rustc() -> ExitCode {
    let args_dir: PathBuf = std::env::var(DX_RUSTC_WRAPPER_ENV_VAR)
        .expect("DX_RUSTC env var must be set")
        .into();

    // Cargo invokes a workspace wrapper like: `wrapper-name rustc [args...]`
    // We skip our own executable name (`wrapper-name`) to get the args passed to us.
    let captured_args = args().skip(1).collect::<Vec<_>>();

    let rustc_args = RustcArgs {
        args: captured_args.clone(),
        envs: vars().collect::<_>(),
        cwd: std::env::current_dir().expect("Failed to get current dir"),
    };

    // Always persist the captured rustc invocation, even for link steps.
    // The tip crate's bin target is typically only observed during the final link invocation,
    // so returning early before writing would lose the exact args/envs we need for fat-link replay.
    write_rustc_args(&args_dir, &rustc_args);

    // If we are being asked to link, delegate to the linker action after capturing.

View on GitHub (pinned to 24f6a829df)

Solutions

  1. 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.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/cli/src/rustcwrapper.rs:56 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23). Data as JSON: /api/errors/64f48637851b1a49. Report an issue: GitHub.