Cargo: `cargo doc --open` doesn't work in WSL

Created on 3 Nov 2019  路  7Comments  路  Source: rust-lang/cargo

I'm using ubuntu(WSL) in windows, and I found this problem.

At the beginning, without any configuration, I got some error message. Following the error message, I set BROSWER environmental variable, and the error was gone and browser is opened. However nothing appear, seems it open browser but forget pass the "*.html".

I'm sure it the BROWSER is set correctly, because follow command /usr/bin/sensible-browser xxx/inndex.html works well in shell.

C-bug Command-doc O-windows

Most helpful comment

A short-term solution is to run explorer.exe . or point it to your project path, navigate to /target/doc/{package_name}, and then double-click index.html.

All 7 comments

I think it's due to the fact that the browsers gets called with the WSL path to the file. So a browser on windows won't be able to open a link from the linux filesystem. Maybe cargo should detect that we're on WSL and use the windows default browser and convert the path?

A short-term solution is to run explorer.exe . or point it to your project path, navigate to /target/doc/{package_name}, and then double-click index.html.

This appears to be a bug in wslview which is fixed in wslu (https://github.com/wslutilities/wslu/issues/133) but not yet in Ubuntu's non-standard wslu package (https://bugs.launchpad.net/ubuntu/+source/wslu/+bug/1888869).

Over the course of investigating this, I found that cargo invokes the opener::open() function from the opener crate to open the link. I'm assuming a fix ought to go there, unless the author decides its out of scope. I've filed an issue there: https://github.com/Seeker14491/opener/issues/8

It would be really nice to have this fixed since more and more Windows users are using WSL to develop their projects.
The workaround with opening the index.html manually works fine for now.

Yeah I presented to my team to show them Rust and the windows users were confused when cargo doc didn't work for them out of the box - not a good look

Yeah I presented to my team to show them Rust and the windows users were confused when cargo doc didn't work for them out of the box - not a good look

Don't know which editor/IDE your team is using but in case of VSCode, there is an extension which provides in-editor preview of the docs. It currently has a bug but I already reported it and if that's sorted, it should be a nice alternative for your Windows users.
Right here: https://github.com/JScearcy/rust-doc-viewer/issues/18

Was this page helpful?
0 / 5 - 0 ratings