Skip to content

[rustdoc] Add new --book-location option to add a link to associated guide and generate it if local #139769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

GuillaumeGomez
Copy link
Member

This option adds the possibility to provide a path or a URL to the associated guide of this crate in the crate-level doc page. If the provided argument is a path, then the guide is generated using the mdbook crate.

It looks like this:

Screenshot From 2025-04-14 00-36-23

You can give it a try here.

It'll need an FCP before getting merged.

Also I need to add tests when the argument is a path but I'll wait for the feature form to be final before doing it to prevent doing it more than once. 😄

cc @notriddle
r? @camelid

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Apr 13, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 13, 2025

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @jsha

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Apr 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 14, 2025

The list of allowed third-party dependencies may have been modified! You must ensure that any new dependencies have compatible licenses before merging.

cc @davidtwco, @wesleywiser

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Apr 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 14, 2025

This PR modifies run-make tests.

cc @jieyouxu

@GuillaumeGomez
Copy link
Member Author

Finally fixed all tidy errors. :')

@@ -229,6 +229,22 @@ impl fmt::Debug for Options {
}
}

#[derive(Clone, Debug)]
pub(crate) enum PathOrURL {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pub(crate) enum PathOrURL {
pub(crate) enum PathOrUrl {

to follow idiom, and to be consistent with the style in this crate

@bors
Copy link
Collaborator

bors commented Apr 26, 2025

☔ The latest upstream changes (presumably #140336) made this pull request unmergeable. Please resolve the merge conflicts.

@camelid
Copy link
Member

camelid commented Apr 26, 2025

Whoops, missed this in my notifications, sorry 😅

It'll need an FCP before getting merged.

Any reason you're making it insta-stable? Seems like might as well go through the normal process of adding as an unstable flag first.

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Apr 26, 2025

Any reason you're making it insta-stable? Seems like might as well go through the normal process of adding as an unstable flag first.

Oh damn, not insta-stable. Very good catch, thanks!

It was already unstable. 😄

@@ -658,6 +658,14 @@ fn opts() -> Vec<RustcOptGroup> {
"disable the minification of CSS/JS files (perma-unstable, do not use with cached files)",
"",
),
opt(
Unstable,
Copy link
Member Author

Choose a reason for hiding this comment

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

@camelid: Just checked and the option is indeed unstable. 😉

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I was just confused because you said it'd need an FCP, which I thought we only required for stabilizations.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hum, well it's a big change in rustdoc (as is, scope expansion), so better be sure everyone agrees with this direction.

Copy link
Member

@camelid camelid left a comment

Choose a reason for hiding this comment

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

Looks good overall, but left some comments.

#[derive(Clone, Debug)]
pub(crate) enum PathOrURL {
Path(PathBuf),
URL(String),
Copy link
Member

Choose a reason for hiding this comment

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

Ditto here with tshepang's suggestion from above.

@@ -658,6 +658,14 @@ fn opts() -> Vec<RustcOptGroup> {
"disable the minification of CSS/JS files (perma-unstable, do not use with cached files)",
"",
),
opt(
Unstable,
Copy link
Member

Choose a reason for hiding this comment

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

Ah, I was just confused because you said it'd need an FCP, which I thought we only required for stabilizations.

Err(error) => return Err(format!("failed to load book: {error:?}")),
};
let output_dir = render_options.output.join("doc-book");
*book_dir = output_dir.join("index.html");
Copy link
Member

Choose a reason for hiding this comment

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

I don't like that this mutates the render_options.book_location to record the new path of the book. I think it'd better to have two separate fields, one for the source location of the book and one for the target location (None if the source was a URL).

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure to agree but not something I think is worth debating about so let's go. However: I'm gonna use PathOrUrl because otherwise you'd need to use two types to get the information, which is suboptimal imo.

@@ -28,6 +28,7 @@ const LICENSES: &[&str] = &[
"Apache-2.0",
"Apache-2.0/MIT",
"BSD-2-Clause OR Apache-2.0 OR MIT", // zerocopy
"CC0-1.0", // notify
Copy link
Member

Choose a reason for hiding this comment

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

Who's responsible for this license exceptions list? Feels like it'd be good to check that these exceptions are OK with someone who's more experienced in this area.

Copy link
Member Author

Choose a reason for hiding this comment

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

I know the right person for this. cc @wesleywiser :)

@@ -0,0 +1,7 @@
//@ compile-flags: -Zunstable-options --book-location https://somewhere.world
Copy link
Member

Choose a reason for hiding this comment

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

We should have another (run-make) test that tests the mdbook integration, especially since that's where most of the complexity of this PR is.

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you want to test exactly?

Comment on lines 834 to 838
## Generating link to guide

You can generate a link to a guide or generate the guide with `mdbook` using the `--book-location`
command line argument. It accepts either a URL or a path. If a path is provided, the book will
be generated.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
## Generating link to guide
You can generate a link to a guide or generate the guide with `mdbook` using the `--book-location`
command line argument. It accepts either a URL or a path. If a path is provided, the book will
be generated.
## Bundling or linking to a guide
You can generate a link to a guide or bundle an `mdbook` guide using the `--book-location`
command line argument. It accepts either a URL or a path. If a path is provided, the book will
be built with `mdbook`.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented May 7, 2025

☔ The latest upstream changes (presumably #140726) made this pull request unmergeable. Please resolve the merge conflicts.

@GuillaumeGomez
Copy link
Member Author

Fixed merge conflict.

@rust-log-analyzer

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs A-tidy Area: The tidy tool S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants