Skip to content

Commit 7470eb0

Browse files
authored
docs: move docs building process to contributor guide (#15854)
### What does this PR try to resolve? Pull <https://github.com/rust-lang/cargo/blob/71eb84f21aef43c07580c6aed6f806a6299f5042/src/doc/README.md> into our contributor guide for visibility. Also a writing guideline is added to the chapter, as well as some minor polish. This is created after seeing the contributing frictions in <#15838 (comment)>. ### How to test and review this PR? ``` mdbook serve src/doc/contrib ```
2 parents e3f6477 + af9f4f6 commit 7470eb0

File tree

3 files changed

+115
-68
lines changed

3 files changed

+115
-68
lines changed

src/doc/README.md

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,7 @@
1-
# Cargo documentation
2-
3-
This directory contains Cargo's documentation. There are two parts, [The Cargo
4-
Book] which is built with [mdbook] and the man pages, which are built with
5-
[mdman].
6-
7-
[The Cargo Book]: https://doc.rust-lang.org/cargo/
8-
[mdBook]: https://github.com/rust-lang/mdBook
9-
[mdman]: https://github.com/rust-lang/cargo/tree/master/crates/mdman/
10-
11-
### Building the book
12-
13-
Building the book requires [mdBook]. To get it:
14-
15-
```console
16-
$ cargo install mdbook
17-
```
18-
19-
To build the book:
20-
21-
```console
22-
$ mdbook build
23-
```
24-
25-
`mdbook` provides a variety of different commands and options to help you work
26-
on the book:
27-
28-
* `mdbook build --open`: Build the book and open it in a web browser.
29-
* `mdbook serve`: Launches a web server on localhost. It also automatically
30-
rebuilds the book whenever any file changes and automatically reloads your
31-
web browser.
32-
33-
The book contents are driven by the [`SUMMARY.md`](src/SUMMARY.md) file, and
34-
every file must be linked there.
35-
36-
### Building the man pages
37-
38-
The man pages use a tool called [mdman] to convert markdown to a man page
39-
format. Check out the documentation at
40-
[`mdman/doc/`](../../crates/mdman/doc/)
41-
for more details.
42-
43-
The man pages are converted from a templated markdown (located in the
44-
[`src/doc/man/`](man)
45-
directory) to three different formats:
46-
47-
1. Troff-style man pages, saved in [`src/etc/man/`](../etc/man).
48-
2. Markdown (with some HTML) for the Cargo Book, saved in
49-
[`src/doc/src/commands/`](src/commands).
50-
3. Plain text (needed for embedded man pages on platforms without man such as
51-
Windows), saved in [`src/doc/man/generated_txt/`](man/generated_txt).
52-
53-
To rebuild the man pages, run `cargo build-man` inside the workspace.
54-
55-
### SemVer chapter tests
56-
57-
There is a script to verify that the examples in the SemVer chapter work as
58-
intended. To run the tests, run `cargo +stable run -p semver-check`.
1+
## Contributing
592

60-
Note that these tests run on the most recent stable release because they
61-
validate the output of the compiler diagnostics. The output can change between
62-
releases, so we pin to a specific release to avoid frequent and unexpected
63-
breakage.
3+
To contribute to Cargo's documentation. See <https://rust-lang.github.io/cargo/contrib/>.
644

65-
## Contributing
5+
For docs specific topics, see <https://rust-lang.github.io/cargo/contrib/documentation>.
666

67-
We'd love your help with improving the documentation! Please feel free to
68-
[open issues](https://github.com/rust-lang/cargo/issues) about anything, and
69-
send in PRs for things you'd like to fix or change. If your change is large,
70-
please open an issue first, so we can make sure that it's something we'd
71-
accept before you go through the work of getting a PR together.
7+
For API doc, see <https://docs.rs/cargo>.

src/doc/contrib/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@
2424
- [Writing Tests](./tests/writing.md)
2525
- [Benchmarking and Profiling](./tests/profiling.md)
2626
- [Crater](./tests/crater.md)
27+
- [Documentation](./documentation/index.md)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Documentation
2+
3+
Cargo has several types of documentation that contributors work with:
4+
5+
* [The Cargo Book]
6+
* The primary user-facing Cargo documentation
7+
* Source at <https://github.com/rust-lang/cargo/tree/master/src/doc>
8+
* Built with [mdbook]
9+
* Published through ["the doc publishing process"]
10+
* Man pages
11+
* Man pages of the `cargo` command
12+
* Built with [mdman]
13+
* Published through ["the doc publishing process"]
14+
* [Contributor guide]
15+
* This guide itself
16+
* Source at <https://github.com/rust-lang/cargo/tree/master/src/doc/contrib>
17+
* Published independently on GitHub Pages at
18+
<https://rust-lang.github.io/cargo/contrib>
19+
when committing to the master branch.
20+
21+
[The Cargo Book]: https://doc.rust-lang.org/cargo/
22+
[Crate API docs]: https://docs.rs/cargo
23+
[Contributor guide]: https://rust-lang.github.io/cargo/contrib
24+
[mdBook]: https://github.com/rust-lang/mdBook
25+
[mdman]: https://github.com/rust-lang/cargo/tree/master/crates/mdman/
26+
["the doc publishing process"]: ../process/release.md#docs-publishing
27+
28+
## Building the book
29+
30+
Building the book requires [mdBook]. To get it:
31+
32+
```console
33+
$ cargo install mdbook
34+
```
35+
36+
To build the book:
37+
38+
```console
39+
$ mdbook build
40+
```
41+
42+
`mdbook` provides a variety of different commands and options to help you work
43+
on the book:
44+
45+
* `mdbook build --open`: Build the book and open it in a web browser.
46+
* `mdbook serve`: Launches a web server on localhost. It also automatically
47+
rebuilds the book whenever any file changes and automatically reloads your
48+
web browser.
49+
50+
The book contents are driven by a `SUMMARY.md` file,
51+
and every file must be linked there.
52+
See <https://rust-lang.github.io/mdBook/> for its usage.
53+
54+
## Building the man pages
55+
56+
The man pages use a tool called [mdman] to convert Markdown templates into several output formats.
57+
See <https://github.com/rust-lang/cargo/tree/master/crates/mdman/doc>
58+
for usage details and template syntax.
59+
60+
The templates are located in
61+
<https://github.com/rust-lang/cargo/tree/master/src/doc/man>
62+
and are converted into three formats:
63+
64+
1. Troff man pages --- used by the `cargo help` command,
65+
and by distributions to provide man pages which people can install,
66+
saved in <https://github.com/rust-lang/cargo/tree/master/src/etc/man>.
67+
2. Plain text --- used for embedded help on platforms without `man` (such as Windows),
68+
saved in <https://github.com/rust-lang/cargo/tree/master/src/doc/man/generated_txt>.
69+
3. Markdown (with some HTML) --- used for the Cargo Book,
70+
saved in <https://github.com/rust-lang/cargo/tree/master/src/doc/src/commands>.
71+
72+
To rebuild the man pages, run `cargo build-man` inside the workspace.
73+
74+
## Writing guidelines
75+
76+
Cargo's documentation is a collective effort,
77+
so there isn't a single fixed writing style.
78+
We recommend following the style of the surrounding text to keep things consistent.
79+
80+
A few important guidelines:
81+
82+
* The [Cargo Commands](https://doc.rust-lang.org/nightly/cargo/commands/index.html)
83+
chapters in the book are generated from man page templates.
84+
To update them, see the [Building the man pages](#building-the-man-pages) section.
85+
Do not edit the generated Markdown files directly.
86+
* Links to pages under <https://doc.rust-lang.org/> should use relative paths.
87+
This ensures versioned docs are redirected correctly.
88+
For example, if you are at <https://doc.rust-lang.org/cargo/reference/config.html>
89+
and want to link to <https://doc.rust-lang.org/rustc/codegen-options/index.html>,
90+
you should write the link as `../../rustc/codegen-options/index.html`.
91+
This rule doesn't apply if you specifically want to link to docs of a fixed version or channel.
92+
* When renaming or removing any headings or pages,
93+
make sure to set up proper redirects via the [`output.html.redirect`] mdbook option.
94+
* If a section refers to a concept explained elsewhere
95+
(like profiles, features, or workspaces), link to it.
96+
That keeps the book navigable without duplicating content.
97+
98+
[[`output.html.redirect`]]: https://rust-lang.github.io/mdBook/format/configuration/renderers.html#outputhtmlredirect
99+
100+
## SemVer chapter tests
101+
102+
There is a script to verify that the examples in [the SemVer chapter] work as
103+
intended. To run the tests, run `cargo +stable run -p semver-check`.
104+
105+
Note that these tests run on the most recent stable release because they
106+
validate the output of the compiler diagnostics. The output can change between
107+
releases, so we pin to a specific release to avoid frequent and unexpected
108+
breakage.
109+
110+
[the SemVer chapter]: https://doc.rust-lang.org/nightly/cargo/reference/semver.html

0 commit comments

Comments
 (0)