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

rust-mode doesn't find rustfmt by default #450

Open
GaryBlackbourne opened this issue Jun 30, 2022 · 5 comments
Open

rust-mode doesn't find rustfmt by default #450

GaryBlackbourne opened this issue Jun 30, 2022 · 5 comments
Labels

Comments

@GaryBlackbourne
Copy link

I have installed rust following the guide on rusts website, and installed rust-mode through melpa. When I put the autoformat on save hook into my .emacs file, it failed to find rustfmt in my ~/.cargo/bin directory even if this is part of my PATH variable.

I fixed this with creating a simlink in my /usr/local/bin directory, and now, it seems to work. I think it might be good to add this to README or otherwise make it work with default install.

@yugaego
Copy link

yugaego commented Jul 1, 2022

I too remember getting this error message:
Could not locate executable "rustfmt".

I think your approach to fix the issue is fine. More approaches follow.

  1. Note there's also a customizable variable rust-rustfmt-bin, which is set to rustfmt by default. This variable can be changed to the full path to the rustfmt executable.
    Now I wonder, might be ~/.cargo/bin/rustfmt would be a better default (with similar change for rust-cargo-bin)?

  2. Or add rustfmt directory to Emacs' exec-path variable (PATH and Emacs is a separate topic you can quite easily find information about).
    For instance,

(add-to-list 'exec-path "~/.cargo/bin")

As for the README or code changes, I suspect this repo maintainers would be glad to consider/accept PRs with the improvements. Or consider adding a Wiki note on this. Though might be Discussions, if enabled, could be a better place for the topic we're in now.

@brotzeit
Copy link
Contributor

brotzeit commented Jul 1, 2022

Now I wonder, might be ~/.cargo/bin/rustfmt would be a better default (with similar change for rust-cargo-bin)?

We've already had this discussion several times and I've also changed it several times over the last years =)

As you already mentioned, this is an emacs issue not rust-mode.

Have you guys tried https://github.com/purcell/exec-path-from-shell ?

@yugaego
Copy link

yugaego commented Jul 1, 2022

We've already had this discussion several times and I've also changed it several times over the last years

Not surprised.

Have you guys tried https://github.com/purcell/exec-path-from-shell ?

I tried it, but now happily live without it. BTW, my previous message contains a link to the SO thread that suggests this package among the other things.

@brotzeit
Copy link
Contributor

brotzeit commented Jul 1, 2022

I wonder why this still wasn't fixed in emacs. doom-emacs seem to have solved it.

@yugaego
Copy link

yugaego commented Jul 11, 2022

doom-emacs seem to have solved it.

Looks like doom-emacs generates a file with correct environment variables. There's an interesting comparison to exec-path-from-shell below in that file too.

why this still wasn't fixed in emacs

I see this topic was mentioned several times on the dev/bug mailing lists and an overall impression I got:

  • no-one submitted actual patches.
  • it's by design that Emacs starts with the variables of the shell it's launched from. AFAIU, the Mac OS users are affected the most, because Mac GUI applications do not inherit shell variables by default (there're tweaks).

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

No branches or pull requests

3 participants