rustup: rustup doc does not work on Windows/WSL

Problem On Windows, using WSL 2, rustup doc --std (or any other rustup doc command) opens firefox correctly (because I have BROWSER=firefox.exe), but the browser does not load a file; the browser is empty/blank.

I found the rustup docs here:

~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/share/doc/rust/html/index.html

I could open this manually like this:

firefox.exe file://///wsl$/Ubuntu/home/kobenauf/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/share/doc/rust/html/index.html

Or like this:

firefox.exe `wslpath -w ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/share/doc/rust/html/index.html`

Possible Solution(s) Consider making rustup doc aware of how to open files on WSL so they open the docs as expected.

Notes

Output of rustup --version: rustup 1.21.1 (7832b2ebe 2019-12-20)

Output of rustup show: Default host: x86_64-unknown-linux-gnu rustup home: /home/kobenauf/.rustup

installed toolchains

stable-x86_64-unknown-linux-gnu nightly-x86_64-unknown-linux-gnu (default)

installed targets for active toolchain

wasm32-unknown-unknown x86_64-pc-windows-gnu x86_64-unknown-linux-gnu

active toolchain

nightly-x86_64-unknown-linux-gnu (default) rustc 1.42.0-nightly (689fca01c 2020-01-17)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 13
  • Comments: 30 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Dear all,

I found an easy way to solve this question.

Adding the prompt below in .zshrc or .bashrc:

export BROWSER="/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"

It works for me. Maybe you should alter the real executing path of browser. ❤️

If you’re in Windows11 with wslg, then just install firefox in your WSL Ubuntu, and run “rustup doc”.

The wslg will open the firefox brower in WSL with the right content for you. Works like a charm!

If the system xdg-open is correctly updated on WSL, then that seems like the safest option frankly.

That’s the standard operating procedure (if there is such a thing). WSL users wrap their xdg-open. It’s (probably) a stretch for xdg-open(1) proper to change their ways; it isn’t xdg-util’s problem, at least arguably. If opener::open() wants to act as the xplat intermediary, that’s fine. WSL is “another platform”. That is probably where the “if (wsl)” would go, if the crate is insistent on rolling it’s own xdg-open equivalent for the Real Linux™ (meaning, freedesktop.org) case rather than spawning the real thing.

Example solution I came up with:

#!/bin/bash

if [ "$#"  -lt 1 ]; then
        echo "$0: no args"
        exit 1
fi

OPEN_PATH=`wslpath -w $1 2>/dev/null`

if [ $? -eq 0 ]; then
        wslview $OPEN_PATH
else
        wslview $1
fi

Write this bash to a script (e.g. $HOME/bin/wsl_browser.sh), then export BROWSER="$HOME/bin/wsl_browser.sh" and sudo ln -s $HOME/bin/wsl_browser.sh /usr/local/bin/xdg-open and seems to get rid of most problems I have at CLI. Haven’t found a use-case to keep any form of a real xdg-open around on wsl.

Well currently users can’t just swap out their xdg-open, because we’re shipping our own xdg-open, though we could change the opener crate to try using the system xdg-open first before falling back to our own xdg-open. Of course, it would be nice if this worked out-of-the-box, so @kinnison’s suggestion seems like a viable option. Basically, we would use the wslpath command in our modified xdg-open to convert from a WSL path to a Windows path, whenever the script tries to launch an .exe.

@paulirotta check your wsl version. If it is 1, then this is the known issue with newer glibc, and you either need to downgrade glibc or upgrade wsl. However, you’ve commented on an unrelated bug sso I’m going to delete your comment, and mine both in a few minutes.