{"record":{"id":"5c910746d4ea630d","repo":"cross-rs/cross","slug":"unable-to-find-native-dockerfile-named-dockerfile-name-for","errorCode":null,"errorMessage":"unable to find native dockerfile named {dockerfile_name} for target {target}.","messagePattern":"unable to find native dockerfile named (.+?) for target (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xtask/src/build_docker_image.rs","lineNumber":211,"sourceCode":"        docker_build.current_dir(&docker_root);\n\n        let docker_platform = platform.docker_platform();\n        let mut dockerfile = dockerfile.clone();\n        docker_build.args([\"--platform\", &docker_platform]);\n        let uppercase_triple = target.name.to_ascii_uppercase().replace('-', \"_\");\n        docker_build.args([\n            \"--build-arg\",\n            &format!(\"CROSS_TARGET_TRIPLE={}\", uppercase_triple),\n        ]);\n        // add our platform, and determine if we need to use a native docker image\n        if has_native_image(docker_platform.as_str(), target, msg_info)? {\n            let dockerfile_name = match target.sub.as_deref() {\n                Some(sub) => format!(\"Dockerfile.native.{sub}\"),\n                None => \"Dockerfile.native\".to_owned(),\n            };\n            let dockerfile_path = docker_root.join(&dockerfile_name);\n            if !dockerfile_path.exists() {\n                eyre::bail!(\n                    \"unable to find native dockerfile named {dockerfile_name} for target {target}.\"\n                );\n            }\n            dockerfile = dockerfile_path.to_utf8()?.to_string();\n        }\n\n        if push {\n            docker_build.arg(\"--push\");\n        } else if engine.kind.supports_output_flag() && no_output {\n            docker_build.args([\"--output\", \"type=tar,dest=/dev/null\"]);\n        } else if no_output {\n            msg_info.fatal(\"cannot specify `--no-output` with engine that does not support the `--output` flag\", 1);\n        } else if has_buildkit {\n            docker_build.arg(\"--load\");\n        }\n\n        let mut tags = vec![];\n","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/cross-rs/cross/blob/8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27/xtask/src/build_docker_image.rs#L193-L229","documentation":"In build_docker_image, when a target is built with a native (non-cross) toolchain, the task derives the dockerfile name as `Dockerfile.native` or `Dockerfile.native.<sub>` (from target.sub), joins it with docker_root, and requires the file to exist. If it does not, the task bails with this error naming the exact expected filename and target.","triggerScenarios":"target.sub is Some(sub) producing Dockerfile.native.<sub>, or None producing Dockerfile.native, and docker_root does not contain that file (checked with .exists()).","commonSituations":"Building a native target whose `sub` variant has no dedicated Dockerfile.native.<sub> yet; a checkout missing the native dockerfiles; configuring a target sub-name that doesn't match any file; docker_root misconfigured to the wrong directory.","solutions":["Create the expected `Dockerfile.native` (or `Dockerfile.native.<sub>`) in docker_root","Verify the target's `sub` field matches an existing Dockerfile.native.<sub> filename, or unset the sub","Confirm docker_root points at the directory containing the native dockerfiles in your checkout"],"exampleFix":"// before\ntarget.sub = Some(\"musl\") // no Dockerfile.native.musl exists\n// after\nadd docker/Dockerfile.native.musl // or run with a sub that has a dockerfile","handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn native_dockerfile_exists(docker_root: &Path, sub: Option<&str>) -> bool {\n    let name = match sub {\n        Some(s) => format!(\"Dockerfile.native.{s}\"),\n        None => \"Dockerfile.native\".to_owned(),\n    };\n    docker_root.join(name).exists()\n}\n// check before invoking xtask\nassert!(native_dockerfile_exists(&docker_root, target.sub.as_deref()));","typeGuard":null,"tryCatchPattern":"let out = build_docker_image(target, ...);\nif let Err(e) = out {\n    if e.to_string().contains(\"unable to find native dockerfile\") {\n        eprintln!(\"Missing native dockerfile for {} - add it or drop the sub target\", target);\n    } else { return Err(e); }\n}","preventionTips":["Add Dockerfile.native.<sub> together with any new target sub variant","Keep Dockerfile.native present as the default fallback in docker_root","Verify the target's sub name against existing filenames before running the build","List `ls docker/Dockerfile.native*` in CI before the build step to fail fast with a clear message"],"tags":["docker","build","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27","analyzedAt":"2026-09-13T15:10:43.988Z","contentChangedAt":"2026-09-13T15:10:43.988Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}