{"id":"ca977566f105ed6e","repo":"rust-lang/cargo","slug":"malformed-output-when-learning-about-crate-type","errorCode":null,"errorMessage":"malformed output when learning about crate-type {} information\n{}","messagePattern":"malformed output when learning about crate-type (.+?) information\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/compiler/build_context/target_info.rs","lineNumber":679,"sourceCode":"///\n/// This function can not handle more than one file per type (with wasm32-unknown-emscripten, there\n/// are two files for bin (`.wasm` and `.js`)).\nfn parse_crate_type(\n    crate_type: &CrateType,\n    cmd: &ProcessBuilder,\n    output: &str,\n    error: &str,\n    lines: &mut str::Lines<'_>,\n) -> CargoResult<Option<(String, String)>> {\n    let not_supported = error.lines().any(|line| {\n        (line.contains(\"unsupported crate type\") || line.contains(\"unknown crate type\"))\n            && line.contains(&format!(\"crate type `{}`\", crate_type))\n    });\n    if not_supported {\n        return Ok(None);\n    }\n    let Some(line) = lines.next() else {\n        anyhow::bail!(\n            \"malformed output when learning about crate-type {} information\\n{}\",\n            crate_type,\n            output_err_info(cmd, output, error)\n        )\n    };\n    let mut parts = line.trim().split(\"___\");\n    let prefix = parts.next().unwrap();\n    let Some(suffix) = parts.next() else {\n        return error_missing_print_output(\"file-names\", cmd, output, error);\n    };\n\n    Ok(Some((prefix.to_string(), suffix.to_string())))\n}\n\n/// Helper for creating an error message for missing output from a certain `--print` request.\nfn error_missing_print_output<T>(\n    request: &str,\n    cmd: &ProcessBuilder,","sourceCodeStart":661,"sourceCodeEnd":697,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/compiler/build_context/target_info.rs#L661-L697","documentation":"In parse_crate_type (target_info.rs:664-692), Cargo runs `rustc --print=...` and reads crate-type information line by line. After confirming the crate type is supported (no 'unsupported crate type' in stderr), it expects at least one more line of output; if `lines.next()` is None, the rustc output is malformed/truncated and Cargo bails naming the crate-type and the captured output.","triggerScenarios":"A custom rustc (or rustc wrapper) that returns success for `--print` but emits fewer lines than Cargo expects; a broken/raced rustc installation; a misbehaving `RUSTC_WRAPPER`/`RUSTC` override; partial rustc output due to a signal/timeout.","commonSituations":"Using sccache or a custom rustc wrapper that mangles --print output; corrupted toolchain install; concurrent builds racing on a shared target dir; very old or patched rustc.","solutions":["Inspect the full error (Cargo prints rustc stdout/stderr) to see what rustc actually returned.","Disable rustc wrappers temporarily (`unset RUSTC_WRAPPER RUSTC_WORKSPACE_WRAPPER`) to isolate the cause.","Reinstall/repair the toolchain with `rustup toolchain install`.","If using a custom target JSON, ensure the crate-type list is valid."],"exampleFix":"// before\n$ RUSTC_WRAPPER=./broken-wrapper cargo build\nerror: malformed output when learning about crate-type cdylib information\n\n// after\n$ unset RUSTC_WRAPPER && cargo build","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Run a smoke test of rustc --print in CI; surface wrapper problems early\nmatch std::process::Command::new(rustc)\n    .args([\"--print\", \"crate-type\", \"--\", \"-\"])\n    .output()\n{\n    Ok(o) if !o.stdout.is_empty() => { /* ok */ }\n    _ => eprintln!(\"rustc --print output looks broken; check wrappers/install\"),\n}","preventionTips":["Pin rustc/rustc-wrapper versions in CI.","Smoke-test `rustc --print` output when adding a new wrapper.","Keep toolchain installs intact (rustup repair / reinstall)."],"tags":["cargo","build","rustc","toolchain","wrapper"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}