cross-rs/cross · error
workspace_root can't end in `..`
Error message
workspace_root can't end in `..`
What it means
`docker_package_name` (src/docker/custom.rs:233) derives the default Docker image name from `metadata.workspace_root.file_name()`. `Path::file_name()` returns None when the path ends in `..`, a root, or is empty, so the code calls `expect("workspace_root can't end in `..`")` to fail fast with an explanatory message instead of silently producing a bad image name.
Solutions
- Run cross from inside the project directory or pass a canonicalized manifest path (`realpath Cargo.toml`)
- Ensure workspace_root resolves to a real directory name, not a `..` component
- If invoking programmatically, canonicalize the path with `std::fs::canonicalize` before passing it
Example fix
// before cross build --target x86_64-unknown-linux-musl # run from /repo/sub/.. // after cd /repo && cross build --target x86_64-unknown-linux-musl
Defensive patterns
Strategy: validation
Validate before calling
let root = std::fs::canonicalize(&workspace_root)?; assert!(root.file_name().is_some(), "workspace_root must end in a real directory name, not `..`");
Type guard
fn has_file_name(p: &std::path::Path) -> bool { p.file_name().is_some() } Prevention
- Always run cross from inside the project directory
- Canonicalize paths (realpath) before passing --manifest-path or setting CARGO_MANIFEST_DIR
- Avoid composing workspace paths with trailing `..` in scripts/CI
When it happens
Trigger: Calling cargo metadata / cross with a workspace_root PathBuf whose final component is `..` (e.g. `--manifest-path` or cwd resolving to `foo/..`), or an empty/root path from a corrupted metadata result.
Common situations: Running cross from or pointing at a path like `/path/to/project/..` (via shell `cd ..` composed paths, symlinks resolved oddly, or CARGO_MANIFEST_DIR set to a `..`-terminated path); building Docker images for the project then fails.
Related errors
- source is pointing to a directory instead of its contents
- artifact path does not start with , skipping
- Refusing to push without tag or branch. Specify a…
- unexpected progress type: expected plain, auto, or tty and…
- cannot make definite Image from unqualified PossibleImage
AI-assisted analysis of cross-rs/cross@8c1a8aa4b6 (2026-09-13).
Data as JSON: /api/errors/4a872ac1c1aa854d.
Report an issue: GitHub.
Appendix: source
Thrown at src/docker/custom.rs:233
match self {
Dockerfile::File { runs_with, .. } => runs_with,
Dockerfile::Custom { runs_with, .. } => runs_with,
}
}
}
fn docker_package_name(metadata: &CargoMetadata) -> String {
// a valid image name consists of the following:
// - lowercase ASCII letters
// - digits
// - a period
// - 1-2 underscores
// - 1 or more hyphens (dashes)
docker_tag_name(
&metadata
.workspace_root
.file_name()
.expect("workspace_root can't end in `..`")
.to_string_lossy(),
)
}
fn docker_tag_name(file_name: &str) -> String {
// a valid image name consists of the following:
// - lowercase ASCII letters
// - digits
// - a period
// - 1-2 underscores
// - 1 or more hyphens (dashes)
let mut result = String::new();
let mut consecutive_underscores = 0;
for c in file_name.chars() {
match c {
'a'..='z' | '0'..='9' | '.' | '-' => {
consecutive_underscores = 0;
result.push(c);View on GitHub (pinned to 8c1a8aa4b6)