Bug: default store directory does not respect `CARGO_TARGET_DIR`
Description of the issue
Description:
Nextest always tries to create the store directory at the workspace root, which fails if the workspace is read-only.
Steps to reproduce:
- Go to any existing project, ensure the
targetdirectory is clean (or at leasttarget/nextestdoes not exist) - Launch a Docker container that mounts the current workspace as read only, and sets
CARGO_TARGET_DIR. :docker run --rm -e CARGO_TARGET_DIR=/target -v "$(pwd):/checkout:ro" -it rust bash - Install nextest:
cargo install cargo-nextest cd /checkout- Try running tests normally:
cargo test. This should work - Try running tests via nextest:
cargo nextest run. This fails with something like:
error: failed to create store dir at `/checkout/target/nextest/default`
Caused by:
Read-only file system (os error 30)
Expected outcome
By default, rather than using a path relative to the workspace root, nextest should create its store directory within CARGO_TARGET_DIR if it is set.
Actual result
Unable to create the file (see above)
Nextest version
cargo-nextest 0.9.87 (fee71ad7b 2024-12-17)
release: 0.9.87
commit-hash: fee71ad7ba08be06519cf9eeb495c6fce0a2e888
commit-date: 2024-12-17
host: aarch64-unknown-linux-gnu
Additional context
No response
Thanks -- yeah, this has been a problem for a while. I'd definitely like to change the default at some point, but that would have to be a carefully-managed behavior change. I think for now we should let you set the target directory to be the same as CARGO_TARGET_DIR.
Would some form of environment interpolation in config be possible? Maybe the default could change to be store.dir = "${CARGO_TARGET_DIR:-target}/nextest" which would probably be correct in most cases.
Yeah -- though in this other case we decided to let you say relative-to = "target", which we should probably be consistent with.
https://nexte.st/docs/ci-features/archiving/#adding-extra-files-to-an-archive
So you'd say
store.dir = { path = "nextest", relative-to = "target" }
and we'd eventually make this the default.
I have a build container that mounts the root dir and writes all of its output to the folder target_builder by setting CARGO_TARGET_DIR. At the same time, it is possible to build locally with default settings (i.e. using target as target dir) - even in parallel - because the target folders don't conflict.
There are occasions where it is quite useful to be able to do that, so it would be nice if the store.dir setting would respect the environment variable.
To work around that, I use a wrapping bash script that checks for CARGO_TARGET_DIR and calls nextest with the according config file, but that is quite ugly.
Absolutely agreed that this is an issue -- please submit a PR!
I've started on this in https://github.com/nextest-rs/nextest/pull/2154. I would love somebody's help completing this (in particular, writing tests for this). I'm also not sure how temporary target directories should be handled, and would appreciate ideas there as well.