Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't build after running flamegraph (MacOS) #229

Open
roxgib opened this issue Sep 29, 2022 · 4 comments
Open

Can't build after running flamegraph (MacOS) #229

roxgib opened this issue Sep 29, 2022 · 4 comments

Comments

@roxgib
Copy link

roxgib commented Sep 29, 2022

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.

@djc
Copy link
Contributor

djc commented Oct 3, 2022

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!

@popematt
Copy link

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
Copy link
Contributor

djc commented Dec 14, 2022

@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!

@zbentley
Copy link
Contributor

zbentley commented Feb 3, 2024

The --root argument to cargo flamegraph avoids this issue. If cargo itself is run with sudo, all of its bookkeeping side effects (like the lockfile) before running flamegraph are also run as root, which breaks things.

Instead, the README-recommended invocation of e.g. cargo flamegraph --root --bin somebin will cause flamegraph to internally use sudo only where it is required, after cargo has finished its build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants