{"id":"9176b40e599f7db8","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.\n        Please 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\\.\n        Please update the `build` setting in the manifest at `(.+?)` and point to a path inside the root of the package\\.","errorType":"exception","errorClass":"anyhow::Error","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/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_package/mod.rs#L721-L757","documentation":"During packaging, every target with is_custom_build() (a build = \"build.rs\" script) has its src_path normalized and checked to be both an existing file and to start_with(pkg.root()). If it is missing or escapes the package root, error_custom_build_file_not_in_package builds a message explaining that module/macro resource resolution is path-relative and bails. This prevents publishing crates whose build script would not behave identically when unpacked.","triggerScenarios":"`cargo package` with `build = \"../../shared/build.rs\"` or `build = \"build.rs\"` when the file does not exist, or a build script path pointing outside the crate via `..`.","commonSituations":"Workspace crates that share a build script via a relative `..` path (forbidden for publishing); deleted build.rs without removing the `build = ` key; typo in the build path; symlinks that resolve outside the package root.","solutions":["Move the build script inside the package: `build = \"build.rs\"` with the file at the crate root","Create the missing build.rs file, or remove the `build = ` field from Cargo.toml if no build script is needed","If the script is shared across workspace members, copy it into each crate (or generate it) so the published package is self-contained"],"exampleFix":"# before\n# Cargo.toml: build = \"../shared/build.rs\"\ncargo package   # -> error\n# after\ncp ../shared/build.rs ./build.rs\n# Cargo.toml: build = \"build.rs\"\ncargo package","handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn validate_build_script(root: &Path, build_rel: Option<&str>) -> Result<(), String> {\n    let Some(rel) = build_rel else { return Ok(()); };\n    let abs = root.join(rel);\n    if !abs.is_file() || !abs.starts_with(root) {\n        return Err(format!(\"build script `{rel}` missing or outside package root\"));\n    }\n    Ok(())\n}","typeGuard":"import { existsSync, statSync } from 'fs';\nimport { join, resolve, relative } from 'path';\nfunction buildScriptInPackage(root: string, rel: string): boolean {\n  const abs = join(root, rel);\n  if (!existsSync(abs) || !statSync(abs).isFile()) return false;\n  const rel2 = relative(root, resolve(abs));\n  return !rel2.startsWith('..');\n}","tryCatchPattern":null,"preventionTips":["Keep build.rs inside the crate root (build = \"build.rs\")","Never reference a shared workspace build script via `..` in a publishable crate","CI lint: assert build script path is_file() and startswith(pkg_root)"],"tags":["cargo-package","build-script","manifest","packaging","portability"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}