rust-lang / rust-enhanced

The official Sublime Text 4 package for the Rust Programming Language
MIT License
780 stars 104 forks source link

Rust-enhanced cannot find cargo on MacOS #447

Open miguelbarao opened 3 years ago

miguelbarao commented 3 years ago

Sublime Text 3 (Build 3211)

Rust Enhanced Version 2.22

Operating system MacOS 10.15.7

Actual behavior

After installing Rust Enhanced, it is not working in the editor and running rust code with Cmd+B shows a message in the sublime console:

FileNotFoundError: [Errno 2] No such file or directory: 'cargo'

cargo was installed with rustup and is in my path. It works in the terminal. Is there a specific path that needs to be define somewhere? I did the same install steps in Linux and it's working correctly.

Complete traceback of the error:

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 1050, in run_
    return self.run(**args)
  File "/Users/john/Library/Application Support/Sublime Text 3/Installed Packages/Rust Enhanced.sublime-package/cargo_build.py", line 53, in run
  File "/Users/john/Library/Application Support/Sublime Text 3/Installed Packages/Rust Enhanced.sublime-package/cargo_build.py", line 74, in _detect_auto_build
  File "/Users/john/Library/Application Support/Sublime Text 3/Installed Packages/Rust Enhanced.sublime-package/rust/target_detect.py", line 35, in determine_targets
  File "/Users/john/Library/Application Support/Sublime Text 3/Installed Packages/Rust Enhanced.sublime-package/rust/util.py", line 136, in get_cargo_metadata
  File "/Users/john/Library/Application Support/Sublime Text 3/Installed Packages/Rust Enhanced.sublime-package/rust/rust_proc.py", line 97, in slurp_json
  File "/Users/john/Library/Application Support/Sublime Text 3/Installed Packages/Rust Enhanced.sublime-package/rust/rust_proc.py", line 79, in _slurp
  File "/Users/john/Library/Application Support/Sublime Text 3/Installed Packages/Rust Enhanced.sublime-package/rust/rust_proc.py", line 234, in run
  File "./python3.3/subprocess.py", line 819, in __init__
  File "./python3.3/subprocess.py", line 1448, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: 'cargo'
ehuss commented 3 years ago

PATHs on macOS are tricky. I'm guessing you are launching Sublime from Spotlight or Finder. Those only inherit the environment from the system, and doesn't include anything set in your shell startup.

RustEnhanced uses shellenv to slurp the environment from your shell settings. Make sure that rust_include_shell_env is enabled in the RustEnhanced settings (that is the default, so it should be enabled unless you disabled it). I also think Sublime has some built-in support for sourcing your shell startup, but I don't remember how that works.

Are you maybe using zsh? I haven't tested that, and it is possible shellenv doesn't support it.

There are some workarounds:

miguelbarao commented 3 years ago

Yes, rust_include_shell_env is set to true and I'm on zsh. Setting rust_env to the example provided in the default configuration did the trick. Maybe a note could be added to the install instructions specifically for MacOS.

Thanks for the help!

detly commented 3 years ago

Is rust_env available in the current build of the plugin available on Package Control? It's not a recognised setting for me, and setting rust_env does not appear to have any effect. (I'm not on OS X, but I am using Cargo/Rustup without having $PATH set by the shell.)

detly commented 3 years ago

I'm sorry, this was resolved by removing and reinstalling the plugin. The rest of the issue lies with the language server plugin.