cross-rs/cross · error
unix paths cannot handle windows prefix
Error message
unix paths cannot handle windows prefix {prefix:?}. What it means
`as_posix_relative` converts a Path to a POSIX-style relative string, but it cannot represent Windows path prefixes (drive letters like `C:` or UNC `\\server\share`). If the path's components include a `Component::Prefix`, it bails because such a path has no valid POSIX relative form.
Solutions
- Pass a relative path (relative to the working directory) instead of an absolute Windows path.
- Use a forward-slash path without the drive prefix, e.g. `target` instead of `C:\project\target`.
- Run the invocation from a Unix-style environment (WSL) where paths have no Windows prefix.
Example fix
// before (cross config) [target.x86_64-pc-windows-gnu] # path passed: C:\project\target // after # run from project root and pass relative path: target
Defensive patterns
Strategy: validation
Validate before calling
function isAbsolutePathWithPrefix(p) {
return /^[A-Za-z]:[\\/]/.test(p) || /^\\\\[^\\]/.test(p); // C:\ or \\server\share
}
// before calling as_posix_relative, ensure the path has no drive/UNC prefix Try / catch
try {
return path.asPosixRelative(p);
} catch (e) {
if (String(e.message).includes('windows prefix')) {
throw new Error(`Path ${p} must be relative and free of drive/UNC prefixes`);
}
throw e;
} Prevention
- Always pass relative paths where POSIX-relative paths are required.
- Avoid hardcoding `C:\` paths in cross configuration.
- Test builds on Windows early to catch prefix-carrying paths.
When it happens
Trigger: Calling `as_posix_relative` on an absolute Windows path (e.g. `C:\Users\me\project` or a UNC path) that was passed to code expecting a relative Unix-style path.
Common situations: Running cross on Windows or with Windows-originated paths (CARGO_TARGET_DIR, config paths) where a relative path is required inside the container; hardcoded `C:\...` paths in cross config files.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- unable to find provided nix-store directory
- Could not get UserName.
- workspace_root can't end in `..`
- source is pointing to a directory instead of its contents
- artifact path does not start with , skipping
AI-assisted analysis of cross-rs/cross@8c1a8aa4b6 (2026-09-13).
Data as JSON: /api/errors/4feba72572cb2c6e.
Report an issue: GitHub.
Appendix: source
Thrown at src/file.rs:95
}
}
impl PathExt for Path {
fn as_posix_relative(&self) -> Result<String> {
if cfg!(target_os = "windows") {
let push = |p: &mut String, c: &str| {
if !p.is_empty() && p != "/" {
p.push('/');
}
p.push_str(c);
};
// iterate over components to join them
let mut output = String::new();
for component in self.components() {
match component {
Component::Prefix(prefix) => {
eyre::bail!("unix paths cannot handle windows prefix {prefix:?}.")
}
Component::RootDir => output = "/".to_owned(),
Component::CurDir => push(&mut output, "."),
Component::ParentDir => push(&mut output, ".."),
Component::Normal(path) => push(&mut output, path.to_utf8()?),
}
}
Ok(output)
} else {
self.to_utf8().map(|x| x.to_owned())
}
}
#[cfg(not(target_family = "windows"))]
fn as_posix_absolute(&self) -> Result<String> {
absolute_path(self)?.to_utf8().map(ToOwned::to_owned)
}
View on GitHub (pinned to 8c1a8aa4b6)