flamegraph-rs / flamegraph

Easy flamegraphs for Rust projects and everything else, without Perl or pipes <3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't build after running flamegraph (MacOS)

roxgib opened this issue · comments

After running sudo cargo flamegraph (which runs fine) I get one of the following two errors from cargo build --release:

error: linking with `cc` failed: exit status: 1
[_massive list of files omitted_]
 = note: ld: can't write output file: ~/project/target/release/deps/project-47ba9299aacab074 for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: could not compile `project` due to previous error; 
error: failed to open: ~project/target/release/.cargo-lock
Caused by:
  Permission denied (os error 13)

But running sudo cargo flamegraph again works fine. I assume it's leaving a lock on some files which prevents access. cargo clean hits the same problem, so I have to manually delete the target directory and rebuild. Might be related to using sudo, but unfortunately this seems to be required on MacOS.

Yeah, I'm afraid you just have to sudo cargo clean before you rebuild without sudo, and I don't think there's an easy way around that. PRs welcome for improving the documentation around this, though!

Another workaround is to run cargo build with the same build options that you are going to use for cargo flamegraph immediately before running sudo cargo flamegraph. That way nothing needs to be rebuilt while running sudo cargo flamegraph.

@djc Just so that I'm understanding it correctly, the only thing that needs to run as root is running dtrace. Building as root and writing the final flamegraph as root are unintended side-effects, right?

@djc Just so that I'm understanding it correctly, the only thing that needs to run as root is running dtrace. Building as root and writing the final flamegraph as root are unintended side-effects, right?

I think so!