rust-lang / rust-lang/rustup

`rustup run` also searches PATH

Open
#3,387 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
22h 40m
Merged PRs (30d)
46

Description

Problem
; rustup run 1.69 whoami
jyn

This seems ... undesirable. In particular, it means that rustup which and rustup run differ in behavior:

; rustup which whoami
error: not a file: '/Users/jyn/.local/lib/rustup/toolchains/1.69-aarch64-apple-darwin/bin/whoami'

As far as I can tell, the only difference is that rustup run sets RUSTUP_TOOLCHAIN and DYLD_FALLBACK_LIBRARY_PATH:

; rustup run nightly python3 -c $'import os \nfor k,v in os.environ.items(): print(k, v)'  | sort -u | diff - <(python3 -c $'import os \nfor k,v in os.environ.items(): print(k, v)' | sort -u)
8d7
< DYLD_FALLBACK_LIBRARY_PATH /Users/jyn/.local/lib/rustup/toolchains/nightly-aarch64-apple-darwin/lib:/Users/jyn/lib:/usr/local/lib:/usr/lib
29,30d27
< RUSTUP_TOOLCHAIN nightly-aarch64-apple-darwin
< RUST_RECURSION_COUNT 1
49c46
< _ /Users/jyn/.local/lib/cargo/bin/rustup
---
> _ /Applications/Xcode.app/Contents/Developer/usr/bin/python3
my original use case, although it's pretty complicated

i am writing a new rustc_driver tool that goes in the sysroot. i want to be able to run it as cargo +nightly foo instead of PATH=$PATH:$(rustc +nightly --print sysroot)/bin cargo +nightly foo. to that end, i've put a shell script in ~/.cargo/bin/cargo-foo that emulates a rustup proxy:

#!/bin/sh
me=$(basename $0)
exec rustup run "$RUSTUP_TOOLCHAIN" $me "$@"

This works fine if the tool is actually present in the sysroot. However, if it's not present, rustup falls back to path and re-executes this same script, eventually leading to a recursion error that it's nested too deeply. I would like to instead give a hard error. Today, i have to workaround rustup's behavior with more calls:

# Make sure this is actually installed for the given toolchain. `rustup run` falls back to PATH,
# which will recursively invoke this script; that's not what we want.
if ! rustup which $me --toolchain $RUSTUP_TOOLCHAIN 2>/dev/null; then
    printf "\033[31;1merror:\033[0m '$me' is not installed for the toolchain '$RUSTUP_TOOLCHAIN'\n"
    exit 1
fi

it would be nice to be able to avoid that.

Steps

rustup run 1.69 whoami (or any installed toolchain)

Possible Solution(s)
  • Break hard; only look in toolchains/1.69/bin
  • Add a feature flag to remove the PATH lookup
  • Document the difference somewhere
Notes

No response

Rustup version
rustup 1.26.0 (5af9b9484 2023-04-05)
Installed toolchains
Default host: aarch64-apple-darwin
rustup home:  /Users/jyn/.local/lib/rustup

installed toolchains
--------------------

nightly-2022-12-07-aarch64-apple-darwin
nightly-2023-03-14-aarch64-apple-darwin
nightly-2023-04-12-aarch64-apple-darwin
nightly-aarch64-apple-darwin (default)
1.60-aarch64-apple-darwin
1.64-aarch64-apple-darwin
1.65-aarch64-apple-darwin
1.68-aarch64-apple-darwin
1.69-aarch64-apple-darwin
stage1
stage2
1.60.0-aarch64-apple-darwin

installed targets for active toolchain
--------------------------------------

aarch64-apple-darwin
aarch64-unknown-linux-gnu

active toolchain
----------------

1.69-aarch64-apple-darwin (overridden by '/Users/jyn/src/redacted/rust-toolchain.toml')
rustc 1.69.0 (84c898d65 2023-04-16)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the rustup run and rustup which command paths and reproduce rustup run 1.69 whoami using a command found on PATH but absent from the toolchain bin directory. Compare the lookup behavior and existing tests, then establish the intended policy among hard failure, an opt-out, or documentation; done means the selected behavior is implemented and covered by regression tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.