{"record":{"id":"35e56f692ae664dc","repo":"rust-lang/cargo","slug":"this-may-cause-issue-during-packaging-as-module","errorCode":null,"errorMessage":"{}This may cause issue during packaging, as modules resolution and resources included via macros are often relative to the path of source files.\nPlease update the `build` setting in the manifest at `{}` and point to a path inside the root of the package.","messagePattern":"(.+?)This may cause issue during packaging, as modules resolution and resources included via macros are often relative to the path of source files\\.\nPlease update the `build` setting in the manifest at `(.+?)` and point to a path inside the root of the package\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ops/cargo_package/mod.rs","lineNumber":739,"sourceCode":"        if path.is_file() {\n            format!(\n                \"the source file of {description_name} doesn't appear to be a path inside of the package.\\n\\\n            It is at `{}`, whereas the root the package is `{}`.\\n\",\n                path.display(),\n                pkg.root().display()\n            )\n        } else {\n            format!(\"the source file of {description_name} doesn't appear to exist.\\n\",)\n        }\n    };\n    let msg = format!(\n        \"{}\\\n        This may cause issue during packaging, as modules resolution and resources included via macros are often relative to the path of source files.\\n\\\n        Please update the `build` setting in the manifest at `{}` and point to a path inside the root of the package.\",\n        tip,\n        pkg.manifest_path().display()\n    );\n    anyhow::bail!(msg)\n}\n\n/// Construct `Cargo.lock` for the package to be published.\nfn build_lock(\n    ws: &Workspace<'_>,\n    opts: &PackageOpts<'_>,\n    publish_pkg: &Package,\n    local_reg: Option<&TmpRegistry<'_>>,\n) -> CargoResult<String> {\n    let gctx = ws.gctx();\n    let mut orig_resolve = ops::load_pkg_lockfile(ws)?;\n\n    let mut tmp_ws = Workspace::ephemeral(publish_pkg.clone(), ws.gctx(), None, true)?;\n\n    // The local registry is an overlay used for simulating workspace packages\n    // that are supposed to be in the published registry, but that aren't there\n    // yet.\n    if let Some(local_reg) = local_reg {","sourceCodeStart":721,"sourceCodeEnd":757,"githubUrl":"https://github.com/rust-lang/cargo/blob/495c385d0875c4ba51eb72ea0448a2d4c018b8d4/src/ops/cargo_package/mod.rs#L721-L757","documentation":"Thrown by `error_custom_build_file_not_in_package` during packaging when a custom build target's `src_path` (typically `build.rs`) either does not exist as a file or does not reside inside the package root. Cargo enforces this because module resolution and macro-included resources are resolved relative to source file paths, so an external build script would break inside the packaged `.crate`.","triggerScenarios":"Calling `cargo package` when the `[package] build = \"...\"` setting in Cargo.toml points to a path outside the package root directory, or to a file that does not exist. The check uses `abs_custom_build_path.starts_with(pkg.root())` and `is_file()`.","commonSituations":"Sharing a build script across multiple crates via a relative path like `../shared_build.rs`; moving `build.rs` but not updating the manifest; pointing `build` at an absolute path.","solutions":["Move the build script inside the package root (e.g. to the package root or `src/`).","Update the `build = \"...\"` key in Cargo.toml to the correct in-package relative path.","If the build script is shared, duplicate it into each crate or use a build-dependency crate instead."],"exampleFix":"# Cargo.toml (before)\n[package]\nbuild = \"../shared/build.rs\"\n\n# Cargo.toml (after)\n[package]\nbuild = \"build.rs\"","handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn validate_build_script_path(pkg_root: &Path, build_path: &str) -> Result<(), String> {\n    let abs = pkg_root.join(build_path);\n    if !abs.is_file() { return Err(format!(\"build script `{}` does not exist\", build_path)); }\n    if !abs.starts_with(pkg_root) { return Err(format!(\"build script `{}` is outside package root\", build_path)); }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep build.rs inside the package root directory.","Avoid relative paths like `../` in the `build` manifest key.","Run `cargo package` locally before publishing to catch path errors."],"tags":["cargo-package","build-script","manifest","path-validation"],"backgroundTag":null,"analyzedSha":"495c385d0875c4ba51eb72ea0448a2d4c018b8d4","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}