Cargo: Permission denied error on cargo build --release

Created on 5 Dec 2017  路  8Comments  路  Source: rust-lang/cargo

after executing cargo build --release I got the following error:

error: could not rename dep info: "/home/yaa110/Projects/aaa/target/release/deps/encoding_index_tests-6a08ce72af4801d1.d"

Caused by:
  Permission denied (os error 13)
warning: build failed, waiting for other jobs to finish...
error: could not rename dep info: "/home/yaa110/Projects/aaa/target/release/deps/lazy_static-41dddc66c4a9078e.d"

Caused by:
  Permission denied (os error 13)
warning: build failed, waiting for other jobs to finish...
error: could not rename dep info: "/home/yaa110/Projects/aaa/target/release/deps/quote-b0341732fb2262ed.d"

Caused by:
  Permission denied (os error 13)
warning: build failed, waiting for other jobs to finish...
error: An unknown error occurred

Caused by:
  Permission denied (os error 13)

To learn more, run the command again with --verbose.
make: *** [Makefile:12: generate] Error 101

I deleted target folder but it did not help. However, cargo run works fine and compiles the project.

  • cargo -V cargo 0.23.0 (61fa02415 2017-11-22
  • rustc -V rustc 1.22.1 (05e2e1c41 2017-11-22)
  • rustup -V rustup 1.7.0 (813f7b7a8 2017-10-30)
  • OS Arch linux 64bit (stable-x86_64-unknown-linux-gnu)

Most helpful comment

This is a known problem with docker: you have to coordinate UIDs inside and outside the container, otherwise everything done by the daemon ends up being owned by root

All 8 comments

Do you know why these permission denied errors might be happening? Are you running inside of docker or something like that for example? Any other nonstandard filesystem things going on?

Also check SELinux, which might feel compelled to deny for some reason

@alexcrichton project files are mounted as a volume in a docker container (via -v) and cargo build --release works fine in the container (Ubuntu 16.04 64bit with the same rust versions as host OS). However, I couldn't build the project in host OS.

@lukaslueg SELinux is not enabled

Removing both Cargo.lock and target folder solved the problem.

The problem could be repeated using the following commands:

#!/bin/bash -l
cargo new testp --bin
cd testp
echo 'lazy_static = "1.0.0"' >> Cargo.toml
echo '#!/bin/bash -l' > build-in-docker.sh
echo 'cd /prg && cargo build --release' >> build-in-docker.sh
chmod +x build-in-docker.sh
docker run --rm -v $(pwd):/prg --name="prg-make" --entrypoint /prg/build-in-docker.sh -it yaa110/ubuntu-rustup
cargo build --release

After running build command in docker, the user and group of Cargo.lock and target folder is changed to root, so a permission denied error is expected. The problem is not related to Cargo.

This is a known problem with docker: you have to coordinate UIDs inside and outside the container, otherwise everything done by the daemon ends up being owned by root

Ah ok, thanks for the diagnosis @lukaslueg!

I also get the same error when using flatpak-builder and than running cargo build. Removing all the builder files (.flatpak-builder/ and buildDir) fixes the issue.

Was this page helpful?
0 / 5 - 0 ratings