Skip to content

Instantly share code, notes, and snippets.

@paxswill
Last active April 18, 2021 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paxswill/287b6029773f5126507eb6e8944114d6 to your computer and use it in GitHub Desktop.
Save paxswill/287b6029773f5126507eb6e8944114d6 to your computer and use it in GitHub Desktop.
RUSTUP_HOME and CARGO_HOME for Visual Studio Code (and others)

The VS Code Rust plugin assumes RUSTUP_HOME and CARGO_HOME are their default values, which presented a problem for me as I had them installed under /opt. To get around this I added a quick shim script that defines those variables before execing the real executables. Then I created symlinks with the name of each tool pointing to my shim in an location in PATH. In other words, /usr/local/bin looks like this:

/usr/local/bin/
├── cargo -> rustup-shim
├── cargo-clippy -> rustup-shim
├── cargo-fmt -> rustup-shim
├── cargo-miri -> rustup-shim
├── clippy-driver -> rustup-shim
├── rls -> rustup-shim
├── rustc -> rustup-shim
├── rustdoc -> rustup-shim
├── rustfmt -> rustup-shim
├── rust-gdb -> rustup-shim
├── rust-lldb -> rustup-shim
├── rustup -> rustup-shim
└── rustup-shim

Just edit the script below with your values of RUSTUP_HOME and CARGO_HOME. A one-liner to create the symlinks would look like:

for F in ${CARGO_HOME}/bin/*; do sudo ln -s rustup-shim /usr/local/bin/$(basename $F); done
#!/bin/sh
export RUSTUP_HOME=/opt/rustup
export CARGO_HOME=/opt/cargo
exec "${CARGO_HOME}/bin/$(basename "$0")" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment