Skip to content

Conversation

@anki-code
Copy link

@anki-code anki-code commented Nov 28, 2025

Resolve #4622

Test:

docker run --rm -it rust

apt update && apt install -y python3 python3-pip && pip install --break-system-packages xonsh

xonsh

git clone -b xonsh_shell3 https://github.com/anki-code/rustup && cd rustup/

# https://rust-lang.github.io/rustup/dev-guide/
cargo build
mkdir home
$RUSTUP_HOME='home' $CARGO_HOME='home' target/debug/rustup-init --no-modify-path -y
source /rustup/home/env.xsh

$PATH.pop(0)  # remove '/usr/local/cargo/bin' from container
which cargo
# /rustup/home/bin/cargo
cargo --version
# cargo 1.91.1

Copy link
Contributor

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please stop reopening the PR, which loses all the context.

@anki-code
Copy link
Author

I believe this PR should work. Thanks for review.
(I've faced first time with that "Squash and merge" button is not the solution and "Update branch" button doing something bad. Also there is no clarifications what to do and what to not do in the dev guide so I stepped on all the rakes here, haha)

@anki-code anki-code requested a review from djc November 28, 2025 10:16
@djc djc requested a review from rami3l November 28, 2025 11:21
@rami3l rami3l self-assigned this Nov 28, 2025

impl UnixShell for Xonsh {
fn does_exist(&self, process: &Process) -> bool {
process.var("XONSHRC").is_ok() || utils::find_cmd(&["xonsh"], process).is_some()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe mirroring fish's implementation would be better here. Is there a particular reason to check for XONSHRC instead?

Copy link
Author

@anki-code anki-code Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of xonsh is not POSIX compatible it keeps path to bash or zsh in the SHELL env var for compatibility (dependent on OS etc). So we need to detect here that we're in xonsh. Checking for XONSHRC env variable is good enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anki-code It should be noted however that $SHELL, which usually signifies the login shell, can be set to a non-POSIX shell. This is already the case for other shells such as fish in this file. What do you think about that?

PS: I agree that most of the time this won't matter since the second catch-all will usually trigger.

Copy link
Author

@anki-code anki-code Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rami3l The big picture:

  1. $SHELL can contain any shell and xonsh can be installed as a login shell as well and can set the path to xonsh to $SHELL.
  2. But most of tools in the world expect that $SHELL is POSIX. They blindfold grab the value of $SHELL and run POSIX commands there and have errors as result and this can follows to unexpected consequences. This is why it's preferred way to keep POSIX shell in the $SHELL forever.
  3. Some shells like zsh and maybe fish has POSIX-compatible mode. They detect POSIX commands and run them mostly without errors. This is why they set itselfs to the $SHELL.
  4. So this is why using $SHELL value is not the path for shell checking.

Copy link
Member

@rami3l rami3l Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most of tools in the world expect that $SHELL is POSIX

@anki-code I doubt whether that is the case.

I use fish as my login shell and it doesn't have a POSIX-compatibility mode, so I think myself can count as a data point. From my experience, shell script writers would trust sh as authentically POSIX rather than $SHELL.

Also, a quick GitHub global search seems to support this idea.

However, I guess it's okay to merge it while leaving this thread open. We can always come back when either approach is proven suboptimal, and then we can replace the existing with yours if applicable, for example.

Copy link
Author

@anki-code anki-code Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use fish as my login shell

You're lucky. My first result from search shows that there is no support for non-posix + support fish so I believe this code will fail or have consequences for non-posix.

Try next examples from search and you'll see that people have no thoughts about this could be another shell. So the probability to have fail with non POSIX in $SHELL exists. I read a report where someone catch Linux distro freezing after rebooting with new $SHELL. So if it's work to you you're lucky. Or may be fish as pretty old shell has more support.

@anki-code anki-code requested a review from rami3l November 28, 2025 17:31
Copy link
Member

@rami3l rami3l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anki-code Many thanks for making this PR!

Could you just squash these commits into one so we can merge it?

@anki-code
Copy link
Author

@rami3l done

@anki-code anki-code requested a review from rami3l December 2, 2025 10:28
@rami3l rami3l enabled auto-merge December 2, 2025 10:35
@rami3l rami3l added this pull request to the merge queue Dec 2, 2025
Merged via the queue into rust-lang:main with commit 2d9fc7a Dec 2, 2025
29 checks passed
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

Successfully merging this pull request may close these issues.

Xonsh shell support in rustup

3 participants