Skip to content
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

Start documenting rustc #209

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
- [Behavior considered undefined](behavior-considered-undefined.md)
- [Behavior not considered unsafe](behavior-not-considered-unsafe.md)

- [Tools](tools.md)
- [rustc](tools/rustc.md)
- [rustdoc](tools/rustdoc.md)

[Appendix: Influences](influences.md)

[Appendix: As-yet-undocumented Features](undocumented.md)
Expand Down
14 changes: 14 additions & 0 deletions src/tools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Tools

The official Rust tool suite contains a variety of tools for dealing with Rust
code and associated artifacts.

[`rustc`][rustc] is the Rust language compiler.

[`rustdoc`][rustdoc] is the documentation tool which generates documentation from Rust
source code.

`cargo` is the Rust package manager.

[rustc]: tools/rustc.html
[rustdoc]: tools/rustdoc.html
54 changes: 54 additions & 0 deletions src/tools/rustc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# `rustc`

The Rust compiler has many options and can accept a wide variety of arguments,
and its behavior can vary depending on the values of several environment
variables.

We document the compiler's command-line options, arguments, and operative
environment variables here.

Some discussions of environment variables exists in the [Linkage](linkage.html)
chapter and the [Operator expressions](expressions/operator-expr.html#overflow)
chapter.

## Lint options

-W, --warn OPT Set lint warnings
-A, --allow OPT Set lint allowed
-D, --deny OPT Set lint denied
-F, --forbid OPT Set lint forbidden
--cap-lints LEVEL
Set the most restrictive lint level. More restrictive
lints are capped at this level

## Codegen options

`rustc` provides many options for codegen, all accessible as arguments to the
`-C` option.

### Debug info

To produce output with debug info use the `-C debuginfo=val` option, where
`val` may be one of `0`, `1`, or `2`. The default is `0`.
- `0` means output no debug info
- `1` means output only line tables
- `2` means output full debug info with variable and type information

Providing the `-g` option is equivalent to `-C debuginfo=2`. If both `-g` and
`-C debuginfo` are provided, the compiler will complain.

### Optimization

To produce optimized output, use the `-C opt-level=val` option, where `val`
may be one of `0`, `1`, `2`, `3`. The nightly compiler will also accept `s`,
or `z`. The default is `0`.
- `0-3` direct `rustc` to optimize for execution speed with `0` meaning no
optimizations, and `3` meaning aggressive optimization.
- `s` and `z` direct `rustc` to optimize for output size, with `s` meaning
typical size optimizations and `z` meaning aggressive size optimizations.

Providing the option `-O` is equivalent to `-C opt-level=2`. If both `-O` and
`-C opt-level` are provided, the compiler will complain.

If `s` or `z` are provided on a non-nightly compiler, the compiler will
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't document nightly-only features in the Reference, to avoid having too large of a moving target to follow. Instead, said nightly features should be documented in the Unsafe Book inside the rust-lang/rust repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know, but the problem is rustup run stable rustc -C help says you can use s and z opt-levels. I thought it was worth mentioning you can't use those on non-nightlies.

I'm not married to the wording, obviously 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created rust-lang/rust#47651 for making non-nightlies stop reporting s and z options.

complain.
8 changes: 8 additions & 0 deletions src/tools/rustdoc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# `rustdoc`

`rustdoc` has many options and can accept a wide variety of arguments,
and its behavior can vary depending on the values of several environment
variables.

We document its command-line options, arguments, and operative environment
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just link to ../rustdoc/index.html for documenting rustdoc (and ../cargo/index.html for cargo)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh dang it, I didn't even know about those. I'll link to the references.

variables here.
6 changes: 0 additions & 6 deletions src/undocumented.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,14 @@ to shrink!
specified.
- [Flexible target specification] - Some---but not all---flags are documented
in [Conditional compilation]
- [Require parentheses for chained comparisons]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this supposed to be part of a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no: that feature is already documented here, so I'm just cleaning this list up.

- [`dllimport`] - one element mentioned but not explained at [FFI attributes]
- [define `crt_link`]
- [define `unaligned_access`]

[`libstd` facade]: https://github.com/rust-lang/rfcs/pull/40
[Trait reform]: https://github.com/rust-lang/rfcs/pull/48
[Attributes on `match` arms]: https://github.com/rust-lang/rfcs/pull/49
[Flexible target specification]: https://github.com/rust-lang/rfcs/pull/131
[Conditional compilation]: attributes.html#conditional-compilation
[Unambiguous function call syntax]: https://github.com/rust-lang/rfcs/pull/132
[Require parentheses for chained comparisons]: https://github.com/rust-lang/rfcs/pull/558
[Integer overflow not `unsafe`]: https://github.com/rust-lang/rfcs/pull/560
[`dllimport`]: https://github.com/rust-lang/rfcs/pull/1717
[FFI attributes]: attributes.html#ffi-attributes
[define `crt_link`]: https://github.com/rust-lang/rfcs/pull/1721
[define `unaligned_access`]: https://github.com/rust-lang/rfcs/pull/1725