rust-lang/cargo · error

This may cause issue during packaging, as modules…

Error message

{}This may cause issue during packaging, as modules resolution and resources included via macros are often relative to the path of source files.
Please update the `build` setting in the manifest at `{}` and point to a path inside the root of the package.

What it means

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`.

Solutions

  1. Move the build script inside the package root (e.g. to the package root or `src/`).
  2. Update the `build = "..."` key in Cargo.toml to the correct in-package relative path.
  3. If the build script is shared, duplicate it into each crate or use a build-dependency crate instead.

Example fix

# Cargo.toml (before)
[package]
build = "../shared/build.rs"

# Cargo.toml (after)
[package]
build = "build.rs"
Defensive patterns

Strategy: validation

Validate before calling

use std::path::Path;
fn validate_build_script_path(pkg_root: &Path, build_path: &str) -> Result<(), String> {
    let abs = pkg_root.join(build_path);
    if !abs.is_file() { return Err(format!("build script `{}` does not exist", build_path)); }
    if !abs.starts_with(pkg_root) { return Err(format!("build script `{}` is outside package root", build_path)); }
    Ok(())
}

Prevention

When it happens

Trigger: 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()`.

Common situations: 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.

Related errors


AI-assisted analysis of rust-lang/cargo@495c385d08 (2026-08-11). Data as JSON: /api/errors/35e56f692ae664dc. Report an issue: GitHub.

Appendix: source

Thrown at src/ops/cargo_package/mod.rs:739

        if path.is_file() {
            format!(
                "the source file of {description_name} doesn't appear to be a path inside of the package.\n\
            It is at `{}`, whereas the root the package is `{}`.\n",
                path.display(),
                pkg.root().display()
            )
        } else {
            format!("the source file of {description_name} doesn't appear to exist.\n",)
        }
    };
    let msg = format!(
        "{}\
        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.",
        tip,
        pkg.manifest_path().display()
    );
    anyhow::bail!(msg)
}

/// Construct `Cargo.lock` for the package to be published.
fn build_lock(
    ws: &Workspace<'_>,
    opts: &PackageOpts<'_>,
    publish_pkg: &Package,
    local_reg: Option<&TmpRegistry<'_>>,
) -> CargoResult<String> {
    let gctx = ws.gctx();
    let mut orig_resolve = ops::load_pkg_lockfile(ws)?;

    let mut tmp_ws = Workspace::ephemeral(publish_pkg.clone(), ws.gctx(), None, true)?;

    // The local registry is an overlay used for simulating workspace packages
    // that are supposed to be in the published registry, but that aren't there
    // yet.
    if let Some(local_reg) = local_reg {

View on GitHub (pinned to 495c385d08)