DioxusLabs/dioxus · error
Failed to create args directory for rustc wrapper
Error message
Failed to create args directory for rustc wrapper
What it means
The rustc wrapper persists every crate's rustc invocation as JSON files under an args directory; create_dir_all on that directory failed before writing. Typical causes are permissions, a read-only filesystem, or a stale root-owned target tree.
Source
Thrown at packages/cli/src/rustcwrapper.rs:110
// 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
.args
.iter()
.skip_while(|arg| *arg != "--crate-type")
.nth(1)
.map(|s| s.as_str());
let serialized_args =
serde_json::to_string(rustc_args).expect("Failed to serialize rustc args");
// Write args with an explicit target suffix: {crate_name}.lib.json or
// {crate_name}.bin.json. This avoids the ambiguity of a bare {crate_name}.json
// and ensures lib+bin crates don't overwrite each other.
let suffix = match crate_type {
Some("lib" | "rlib") => "lib",
Some("bin") => "bin",
_ => "bin", // proc-macro, cdylib, etc. — treat as binView on GitHub (pinned to 393d190a80)
Solutions
- Fix ownership of the target directory: `sudo chown -R $(id -u):$(id -g) target`
- Move CARGO_TARGET_DIR to a writable location or remount the volume read-write
- Clean stale artifacts with `cargo clean` (or delete the dioxus args dir) and rebuild
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the target dir is creatable/writable before building
fn target_writable(target_dir: &std::path::Path) -> bool {
let probe = target_dir.join(".write-probe");
std::fs::create_dir_all(target_dir).is_ok()
&& std::fs::write(&probe, b"").is_ok()
&& std::fs::remove_file(&probe).is_ok()
} Prevention
- Never mix sudo and normal-user dx builds in the same target dir
- Check target dir ownership after any root-run build and chown it back
- Point CARGO_TARGET_DIR at a writable location in containers/CI
When it happens
Trigger: dx build/dx serve where the dioxus rustc-args directory under target cannot be created: read-only mounts in CI/sandboxes, root-owned files from earlier sudo runs, or filesystem errors.
Common situations: Running `sudo dx build` once then building as a normal user; containerized builds over read-only volumes; antivirus/indexers locking target dirs on Windows.
Related errors
- Failed to write rustc args to file
- failed to create output dir
- Failed to read name of css module file `{}`.
- esbuild failed: {stderr}
- Failed to run linker
AI-assisted analysis of DioxusLabs/dioxus@393d190a80 (2026-08-16).
Data as JSON: /api/errors/7ef6122f8350778e.
Report an issue: GitHub.