Skip to content

Using unstable cargo build-dir feature leads to cryptic errors #1688

Open
@yuki0iq

Description

@yuki0iq

Checklist

Describe your issue

This cargo PR introduced build.build-dir option that can be used to store intermediate artifacts not in <project>/target, but in any other location. I use this option to store artifacts at a XDG cache directory, at /home/yuki/.cache/cargo.

However, cross does not mount this directory inside its container, and it's inaccessible in docker. This leads to strange behavior:

$ cross test --target x86_64-unknown-linux-gnu
error: failed to create directory `/home/yuki/.cache`

Caused by:
  Permission denied (os error 13)

Adding verbosity reveals the issue: the CARGO_HOME is proxied correctly, but build-dir is never even mentioned.

$ cross test --target x86_64-unknown-linux-gnu -v
+ cargo metadata --format-version 1 --filter-platform x86_64-unknown-linux-gnu
+ rustc --print sysroot
+ /usr/bin/docker
+ /usr/bin/docker version -f '{{ .Server.Os }},,,{{ .Server.Arch }}'
+ /usr/bin/docker info -f {{.SecurityOptions}}
+ rustup toolchain list
+ rustup target list --toolchain nightly-x86_64-unknown-linux-gnu
+ rustup component list --toolchain nightly-x86_64-unknown-linux-gnu
+ /usr/bin/docker run --userns host -e LITHIUM_BACKEND -e LITHIUM_THREAD_LOCAL -e 'XARGO_HOME=/home/yuki/.xargo' -e 'CARGO_HOME=/home/yuki/.local/share/cargo' -e 'CROSS_RUST_SYSROOT=/home/yuki/.local/share/rustup/toolchains/nightly-x86_64-unknown-linux-gnu' -e 'CARGO_TARGET_DIR=/target' -e 'CROSS_RUNNER=' -e TERM -e 'USER=yuki' -e 'CROSS_RUSTC_MAJOR_VERSION=1' -e 'CROSS_RUSTC_MINOR_VERSION=89' -e 'CROSS_RUSTC_PATCH_VERSION=0' --name cross-nightly-x86_64-unknown-linux-gnu-43377-5d707b07e-x86_64-unknown-linux-gnu-12d30-1748974214080 --rm --user 1000:1000 -v /home/yuki/.xargo:/home/yuki/.xargo:z -v /home/yuki/.local/share/cargo:/home/yuki/.local/share/cargo:z -v /home/yuki/.local/share/cargo/bin -v /home/yuki/kek/Mirror/lithium:/home/yuki/kek/Mirror/lithium:z -v /home/yuki/.local/share/rustup/toolchains/nightly-x86_64-unknown-linux-gnu:/home/yuki/.local/share/rustup/toolchains/nightly-x86_64-unknown-linux-gnu:z,ro -v /home/yuki/kek/Mirror/lithium/target:/target:z -w /home/yuki/kek/Mirror/lithium -t ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main sh -c 'PATH="$PATH":"/home/yuki/.local/share/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin" cargo test --target x86_64-unknown-linux-gnu -v'
error: failed to create directory `/home/yuki/.cache`

Caused by:
  Permission denied (os error 13)
+ rustup component list --toolchain nightly-x86_64-unknown-linux-gnu

These examples use host target as it's the simplest target I could imagine, but even without explicitly selecting target this issue persists.

What target(s) are you cross-compiling for?

No response

Which operating system is the host (e.g computer cross is on) running?

  • macOS
  • Windows
  • Linux / BSD
  • other OS (specify in description)

What architecture is the host?

  • x86_64 / AMD64
  • arm32
  • arm64 (including Mac M1)

What container engine is cross using?

  • docker
  • podman
  • other container engine (specify in description)

cross version

cross 0.2.5 (51f46f2 2025-05-24)

Example

Relevant configuration is:

$ printenv CARGO_HOME
/home/yuki/.local/share/cargo
$ printenv RUSTUP_HOME
/home/yuki/.local/share/rustup
$ cat $CARGO_HOME/config.toml
cargo-features = ["build-dir"]

[unstable]
build-dir = true

[build]
build-dir = "/home/yuki/.cache/cargo/"

Commenting out the last line reverts the build-dir behavior and makes cargo store all intermediate artifarts inside target/, which makes this issue disappear.

Additional information / notes

Additional links on build.build-dir:

The source code at 51f46f2 (2025-06-03T18:15Z tip of main branch) does not reference neither config.toml nor build-dir.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions