rust
rust copied to clipboard
Add version switcher script for std docs
The goal of this PR is to add a UI which allows to switch between the different versions of the hosted libraries docs on doc.rust-lang.org.
It comes from this discussion.
r? @Mark-Simulacrum
The job mingw-check failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
configure: rust.debug-assertions := True
configure: rust.overflow-checks := True
configure: llvm.assertions := True
configure: dist.missing-tools := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure:
configure: run `python /checkout/x.py --help`
Attempting with retry: make prepare
---
* highest error code: E0790
Found 506 error codes
Found 0 error(s) in error codes
Done!
tidy error: /checkout/src/doc/version-switcher.js:130: line longer than 100 chars
some tidy checks failed
Build completed unsuccessfully in 0:00:11
@bors try so we can produce a sample set of documentation on dev-doc.
:hourglass: Trying commit dab8165d6a1a8935ad102abccdf9cd2199d34a74 with merge f129e33cb1c13b17c19290f4903b011c07edb0ce...
:sunny: Try build successful - checks-actions
Build commit: f129e33cb1c13b17c19290f4903b011c07edb0ce (f129e33cb1c13b17c19290f4903b011c07edb0ce)
@bors try -- looks like we need a slight adjustment to be able to build a release, cherry picked the commit from https://github.com/rust-lang/rust/pull/101952 here.
:hourglass: Trying commit f1140894115b8e306e5ed8e84df8a4bbabbf6f1b with merge 83e89a338d2e9e4adf115a978fed92380bc53424...
The job mingw-check failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
configure: rust.debug-assertions := True
configure: rust.overflow-checks := True
configure: llvm.assertions := True
configure: dist.missing-tools := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure:
configure: run `python /checkout/x.py --help`
Attempting with retry: make prepare
---
skip untracked path cpu-usage.csv during rustfmt invocations
skip untracked path src/doc/book/ during rustfmt invocations
skip untracked path src/doc/rust-by-example/ during rustfmt invocations
skip untracked path src/llvm-project/ during rustfmt invocations
Diff in /checkout/src/tools/build-manifest/src/main.rs at line 545:
let t = Target::from_compressed_tar(self, &tarball_name!(fallback_target));
// Fallbacks must always be available.
if !t.available {
- eprintln!("{:?} not available for fallback", tarball_name!(fallback_target));
+ eprintln!(
+ "{:?} not available for fallback",
+ tarball_name!(fallback_target)
continue;
}
return t;
return t;
Running `"/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt" "--config-path" "/checkout" "--edition" "2021" "--unstable-features" "--skip-children" "--check" "/checkout/src/tools/tidy/src/debug_artifacts.rs" "/checkout/src/tools/build-manifest/src/manifest.rs" "/checkout/src/tools/tidy/src/pal.rs" "/checkout/src/tools/build-manifest/src/versions.rs" "/checkout/src/tools/build-manifest/src/checksum.rs" "/checkout/src/tools/tidy/src/primitive_docs.rs" "/checkout/src/bootstrap/install.rs" "/checkout/src/tools/build-manifest/src/main.rs"` failed.
If you're running `tidy`, try again with `--bless`. Or, if you just want to format code, run `./x.py fmt` instead.
:sunny: Try build successful - checks-actions
Build commit: 83e89a338d2e9e4adf115a978fed92380bc53424 (83e89a338d2e9e4adf115a978fed92380bc53424)
@bors try
Adjusted to use dev-doc + nightly for the source of the version switcher file.
:hourglass: Trying commit 970af13a317a9be8c4556b8da9b89bc8b8be8a58 with merge 8aa7abbffd996766c55d3aa9861074906ba7ddcd...
The job mingw-check failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
configure: rust.debug-assertions := True
configure: rust.overflow-checks := True
configure: llvm.assertions := True
configure: dist.missing-tools := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure:
configure: run `python /checkout/x.py --help`
Attempting with retry: make prepare
---
skip untracked path cpu-usage.csv during rustfmt invocations
skip untracked path src/doc/book/ during rustfmt invocations
skip untracked path src/doc/rust-by-example/ during rustfmt invocations
skip untracked path src/llvm-project/ during rustfmt invocations
Diff in /checkout/src/tools/build-manifest/src/main.rs at line 545:
let t = Target::from_compressed_tar(self, &tarball_name!(fallback_target));
// Fallbacks must always be available.
if !t.available {
- eprintln!("{:?} not available for fallback", tarball_name!(fallback_target));
+ eprintln!(
+ "{:?} not available for fallback",
+ tarball_name!(fallback_target)
continue;
}
return t;
return t;
Running `"/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt" "--config-path" "/checkout" "--edition" "2021" "--unstable-features" "--skip-children" "--check" "/checkout/src/tools/build-manifest/src/main.rs" "/checkout/src/tools/tidy/src/primitive_docs.rs" "/checkout/src/tools/tidy/src/debug_artifacts.rs" "/checkout/src/tools/build-manifest/src/manifest.rs" "/checkout/src/tools/tidy/src/pal.rs" "/checkout/src/tools/build-manifest/src/versions.rs" "/checkout/src/tools/build-manifest/src/checksum.rs" "/checkout/src/tools/replace-version-placeholder/src/main.rs"` failed.
If you're running `tidy`, try again with `--bless`. Or, if you just want to format code, run `./x.py fmt` instead.
:sunny: Try build successful - checks-actions
Build commit: 8aa7abbffd996766c55d3aa9861074906ba7ddcd (8aa7abbffd996766c55d3aa9861074906ba7ddcd)
OK, this is now live in its current form at https://dev-doc.rust-lang.org/nightly/std/.
Some initial thoughts:
- We should have the current version pre-selected
- The numbered version and the channel should probably share the 'slot' (i.e., nightly docs built for 1.66 should default to showing something like '1.66.0 - nightly').
We should have the current version pre-selected
Good idea!
The numbered version and the channel should probably share the 'slot' (i.e., nightly docs built for 1.66 should default to showing something like '1.66.0 - nightly').
How would it work when we generate docs for stable and beta? This is really where my big confusion is coming from at the moment.
I fixed formatting, applied your suggestions. Now remains to clarify about the version.
:umbrella: The latest upstream changes (presumably #101799) made this pull request unmergeable. Please resolve the merge conflicts.
The job mingw-check failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
Compiling toml v0.5.9
error[E0308]: mismatched types
--> doc.rs:447:13
|
447 | builder.src.join("src/doc/switcher.inc"),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&OsStr`, found struct `PathBuf`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `bootstrap` due to previous error
failed to run: /checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path /checkout/src/bootstrap/Cargo.toml
Build completed unsuccessfully in 0:01:05
The version is now computed into the JS script directly. So the easy way to handle this now would be to have something like:
const script = document.createElement("script");
script.src = "/version-switcher.js";
document.head.append(script);
inserted into main.js or something along the line?
:umbrella: The latest upstream changes (presumably #102121) made this pull request unmergeable. Please resolve the merge conflicts.
@bors try
@bors try
@bors try
:hourglass: Trying commit 415fa7e57e0bbe18b95cd40aea37cd02f56540fd with merge 47571822b519c0511afd228bac8d84c62ad200dd...
:sunny: Try build successful - checks-actions
Build commit: 47571822b519c0511afd228bac8d84c62ad200dd (47571822b519c0511afd228bac8d84c62ad200dd)
Published to dev-doc the latest contents.

I think we should flip nightly/beta/stable so that we have them in version order and include the version number by each name (e.g., 1.66.0 - nightly).
I will try and look at the injection of this into past releases but IMO it would be good to get some style/design eyes on the general concept of this bar from @rust-lang/rustdoc, which can be done in parallel with that. Once T-rustdoc is happy with this I would suggest landing this PR so we're gaining experience and testing on nightly, and then we (I) can in parallel help with rolling out to the bar to older releases.
I switched the order as suggested. For older releases, I think the simplest way to do it is to insert this JS directly at the beginning of main.js.
Layout breaks when the text wraps.

Fixed it. We also had a weird case with the 1.59 where I think the sidebar was in a "middle state" between updates.
I really like the idea! My only concern is that the visual design doesn't feel right. The banner's a little intrusive, and the text preceding feels too long. What about something like this instead?

FYI I started a Zulip thread to talk about the UI, and more importantly the expected use cases and tasks: https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Version.20switching.20for.20std.20docs