Rust Compiling error: failed to run custom build command for ... could not execute process /tmp/.. Permission denied (os error 13)

Compiling crates with cargo under usual user as well as under root is causing error 'Permission denied' here:

cargo install cargo-generate
     Compiling linux-raw-sys v0.9.4
  error: failed to run custom build command for `parking_lot_core v0.9.10`
  Caused by:
    could not execute process `/tmp/cargo-installPvWuHp/release/build/parking_lot_core-4e2177c1fa154ab2/build-script-build` (never executed)
  Caused by:
    Permission denied (os error 13)
  warning: build failed, waiting for other jobs to finish...
  error: failed to compile `cargo-generate v0.23.3`, intermediate artifacts can be found at `/tmp/cargo-installPvWuHp`.
  To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.

The reason could be flag `noexec` on /tmp mountpoint, check your fstab

cat /etc/fstab | grep tmpfs
tmpfs                        /tmp    tmpfs    defaults,noexec,nosuid    0    0

There are two ways to solve an issue: 1) setting CARGO_TARGET_DIR to point path that actually has permissions to execute, 2) remount /tmp without noexec flag (not recommended).

Permissions issue is solving like this:

mkdir ../rust_temp_dir
CARGO_TARGET_DIR=/path_holding_your_project/rust_temp_dir cargo install wasm-pack

#or you can export this variable
export CARGO_TARGET_DIR=/path_holding_your_project/rust_temp_dir

cargo install cargo-generate

cargo install wasm-pack

Section
Category