cargo fix --edition --target x86_64-pc-windows-gnu+
cargo fix --edition --features foo
diff --git a/src/doc/man/cargo-fix.adoc b/src/doc/man/cargo-fix.adoc index 2a7ff56a64f..0cc8c3da4f8 100644 --- a/src/doc/man/cargo-fix.adoc +++ b/src/doc/man/cargo-fix.adoc @@ -28,14 +28,18 @@ executing: cargo fix --edition -which behaves the same as `cargo check --all-targets`. Similarly if you'd like -to fix code for different platforms you can do: +which behaves the same as `cargo check --all-targets`. - cargo fix --edition --target x86_64-pc-windows-gnu +`cargo fix` is only capable of fixing code that is normally compiled with +`cargo check`. If code is conditionally enabled with optional features, you +will need to enable those features for that code to be analyzed: + + cargo fix --edition --features foo -or if your crate has optional features: +Similarly, other `cfg` expressions like platform-specific code will need to +pass `--target` to fix code for the given target. - cargo fix --edition --no-default-features --features foo + cargo fix --edition --target x86_64-pc-windows-gnu If you encounter any problems with `cargo fix` or otherwise have any questions or feature requests please don't hesitate to file an issue at diff --git a/src/doc/man/cargo-package.adoc b/src/doc/man/cargo-package.adoc index 788f55f9b0d..ba1c1b5d69a 100644 --- a/src/doc/man/cargo-package.adoc +++ b/src/doc/man/cargo-package.adoc @@ -33,6 +33,9 @@ steps: about the current VCS checkout hash if available (not included with `--allow-dirty`). . Extract the `.crate` file and build it to verify it can build. + - This will rebuild your package from scratch to ensure that it can be + built from a pristine state. The `--no-verify` flag can be used to skip + this step. . Check that build scripts did not modify any source files. The list of files included can be controlled with the `include` and `exclude` diff --git a/src/doc/man/cargo-rustc.adoc b/src/doc/man/cargo-rustc.adoc index 7ba60cb19e1..e3ef3e5fc72 100644 --- a/src/doc/man/cargo-rustc.adoc +++ b/src/doc/man/cargo-rustc.adoc @@ -25,8 +25,8 @@ flags. include::description-one-target.adoc[] To pass flags to all compiler processes spawned by Cargo, use the `RUSTFLAGS` -environment variable or the `build.rustflags` -linkcargo:reference/config.html[config value]. +linkcargo:reference/environment-variables.html[environment variable] or the +`build.rustflags` linkcargo:reference/config.html[config value]. == OPTIONS diff --git a/src/doc/man/cargo-rustdoc.adoc b/src/doc/man/cargo-rustdoc.adoc index 61dfcb413db..96f37252aaa 100644 --- a/src/doc/man/cargo-rustdoc.adoc +++ b/src/doc/man/cargo-rustdoc.adoc @@ -25,8 +25,8 @@ flags. include::description-one-target.adoc[] To pass flags to all rustdoc processes spawned by Cargo, use the -`RUSTDOCFLAGS` environment variable or the `build.rustdocflags` configuration -option. +`RUSTDOCFLAGS` linkcargo:reference/environment-variables.html[environment variable] +or the `build.rustdocflags` linkcargo:reference/config.html[config value]. == OPTIONS diff --git a/src/doc/man/generated/cargo-bench.html b/src/doc/man/generated/cargo-bench.html index c6e03d01ca5..c25ebe82798 100644 --- a/src/doc/man/generated/cargo-bench.html +++ b/src/doc/man/generated/cargo-bench.html @@ -213,7 +213,8 @@
Space or comma separated list of features to activate. These features only
apply to the current directory’s package. Features of direct dependencies
-may be enabled with <dep-name>/<feature-name>
syntax.
<dep-name>/<feature-name>
syntax. This flag may be
+specified multiple times, which enables all specified features.
This may also be specified with the build.target
config value.
Note that specifying this flag makes Cargo run in a different mode where the +target artifacts are placed in a separate directory. See the +build cache documentation for more details.
+Space or comma separated list of features to activate. These features only
apply to the current directory’s package. Features of direct dependencies
-may be enabled with <dep-name>/<feature-name>
syntax.
<dep-name>/<feature-name>
syntax. This flag may be
+specified multiple times, which enables all specified features.
This may also be specified with the build.target
config value.
Note that specifying this flag makes Cargo run in a different mode where the +target artifacts are placed in a separate directory. See the +build cache documentation for more details.
+Space or comma separated list of features to activate. These features only
apply to the current directory’s package. Features of direct dependencies
-may be enabled with <dep-name>/<feature-name>
syntax.
<dep-name>/<feature-name>
syntax. This flag may be
+specified multiple times, which enables all specified features.
This may also be specified with the build.target
config value.
Note that specifying this flag makes Cargo run in a different mode where the +target artifacts are placed in a separate directory. See the +build cache documentation for more details.
+This may also be specified with the build.target
config value.
Note that specifying this flag makes Cargo run in a different mode where the +target artifacts are placed in a separate directory. See the +build cache documentation for more details.
+Space or comma separated list of features to activate. These features only
apply to the current directory’s package. Features of direct dependencies
-may be enabled with <dep-name>/<feature-name>
syntax.
<dep-name>/<feature-name>
syntax. This flag may be
+specified multiple times, which enables all specified features.
This may also be specified with the build.target
config value.
Note that specifying this flag makes Cargo run in a different mode where the +target artifacts are placed in a separate directory. See the +build cache documentation for more details.
+This may also be specified with the build.target
config value.
Note that specifying this flag makes Cargo run in a different mode where the +target artifacts are placed in a separate directory. See the +build cache documentation for more details.
+which behaves the same as cargo check --all-targets
. Similarly if you’d like
-to fix code for different platforms you can do:
which behaves the same as cargo check --all-targets
.
cargo fix
is only capable of fixing code that is normally compiled with
+cargo check
. If code is conditionally enabled with optional features, you
+will need to enable those features for that code to be analyzed:
cargo fix --edition --target x86_64-pc-windows-gnu+
cargo fix --edition --features foo
or if your crate has optional features:
+Similarly, other cfg
expressions like platform-specific code will need to
+pass --target
to fix code for the given target.
cargo fix --edition --no-default-features --features foo+
cargo fix --edition --target x86_64-pc-windows-gnu
Space or comma separated list of features to activate. These features only
apply to the current directory’s package. Features of direct dependencies
-may be enabled with <dep-name>/<feature-name>
syntax.
<dep-name>/<feature-name>
syntax. This flag may be
+specified multiple times, which enables all specified features.
This may also be specified with the build.target
config value.
Note that specifying this flag makes Cargo run in a different mode where the +target artifacts are placed in a separate directory. See the +build cache documentation for more details.
+Space or comma separated list of features to activate. These features only
apply to the current directory’s package. Features of direct dependencies
-may be enabled with <dep-name>/<feature-name>
syntax.
<dep-name>/<feature-name>
syntax. This flag may be
+specified multiple times, which enables all specified features.
This may also be specified with the build.target
config value.
Note that specifying this flag makes Cargo run in a different mode where the +target artifacts are placed in a separate directory. See the +build cache documentation for more details.
+Space or comma separated list of features to activate. These features only
apply to the current directory’s package. Features of direct dependencies
-may be enabled with <dep-name>/<feature-name>
syntax.
<dep-name>/<feature-name>
syntax. This flag may be
+specified multiple times, which enables all specified features.
Extract the .crate
file and build it to verify it can build.
This will rebuild your package from scratch to ensure that it can be
+built from a pristine state. The --no-verify
flag can be used to skip
+this step.
Check that build scripts did not modify any source files.
@@ -117,6 +126,11 @@This may also be specified with the build.target
config value.
Note that specifying this flag makes Cargo run in a different mode where the +target artifacts are placed in a separate directory. See the +build cache documentation for more details.
+Space or comma separated list of features to activate. These features only
apply to the current directory’s package. Features of direct dependencies
-may be enabled with <dep-name>/<feature-name>
syntax.
<dep-name>/<feature-name>
syntax. This flag may be
+specified multiple times, which enables all specified features.
This may also be specified with the build.target
config value.
Note that specifying this flag makes Cargo run in a different mode where the +target artifacts are placed in a separate directory. See the +build cache documentation for more details.
+Space or comma separated list of features to activate. These features only
apply to the current directory’s package. Features of direct dependencies
-may be enabled with <dep-name>/<feature-name>
syntax.
<dep-name>/<feature-name>
syntax. This flag may be
+specified multiple times, which enables all specified features.
Space or comma separated list of features to activate. These features only
apply to the current directory’s package. Features of direct dependencies
-may be enabled with <dep-name>/<feature-name>
syntax.
<dep-name>/<feature-name>
syntax. This flag may be
+specified multiple times, which enables all specified features.
This may also be specified with the build.target
config value.
Note that specifying this flag makes Cargo run in a different mode where the +target artifacts are placed in a separate directory. See the +build cache documentation for more details.
+--lib
, --bin
, etc, must be used to select which
target is compiled.
To pass flags to all compiler processes spawned by Cargo, use the RUSTFLAGS
-environment variable or the build.rustflags
-config value.
+environment variable or the
+build.rustflags
config value.
@@ -137,7 +137,8 @@ Space or comma separated list of features to activate. These features only
apply to the current directory’s package. Features of direct dependencies
-may be enabled with <dep-name>/<feature-name>
syntax.
<dep-name>/<feature-name>
syntax. This flag may be
+specified multiple times, which enables all specified features.
This may also be specified with the build.target
config value.
Note that specifying this flag makes Cargo run in a different mode where the +target artifacts are placed in a separate directory. See the +build cache documentation for more details.
+--lib
, --bin
, etc, must be used to select which
target is compiled.
To pass flags to all rustdoc processes spawned by Cargo, use the
-RUSTDOCFLAGS
environment variable or the build.rustdocflags
configuration
-option.
+RUSTDOCFLAGS
environment variable
+or the build.rustdocflags
config value.
@@ -152,7 +152,8 @@ Space or comma separated list of features to activate. These features only
apply to the current directory’s package. Features of direct dependencies
-may be enabled with <dep-name>/<feature-name>
syntax.
<dep-name>/<feature-name>
syntax. This flag may be
+specified multiple times, which enables all specified features.
This may also be specified with the build.target
config value.
Note that specifying this flag makes Cargo run in a different mode where the +target artifacts are placed in a separate directory. See the +build cache documentation for more details.
+Space or comma separated list of features to activate. These features only
apply to the current directory’s package. Features of direct dependencies
-may be enabled with <dep-name>/<feature-name>
syntax.
<dep-name>/<feature-name>
syntax. This flag may be
+specified multiple times, which enables all specified features.
This may also be specified with the build.target
config value.
Note that specifying this flag makes Cargo run in a different mode where the +target artifacts are placed in a separate directory. See the +build cache documentation for more details.
+target/debug/
| Contains debug build output.
+target/release/
| Contains release build output (with `--release` flag).
+
+When building for another target with `--target`, the output is placed in a
+directory with the name of the target:
+
+Directory | Example
+----------|--------
+target/<triple>/debug/
| target/thumbv7em-none-eabihf/debug/
+target/<triple>/release/
| target/thumbv7em-none-eabihf/release/
+
+> **Note**: When not using `--target`, this has a consequence that Cargo will
+> share your dependencies with build scripts and proc macros. [`RUSTFLAGS`]
+> will be shared with every `rustc` invocation. With the `--target` flag,
+> build scripts and proc macros are built separately (for the host
+> architecture), and do not share `RUSTFLAGS`.
+
+Within the profile directory (`debug` or `release`), artifacts are placed into
+the following directories:
+
+Directory | Description
+----------|------------
+target/debug/
| Contains the output of the package being built (the `[[bin]]` executables and `[lib]` library targets).
+target/debug/examples/
| Contains examples (`[[example]]` targets).
+
+Some commands place their output in dedicated directories in the top level of
+the `target` directory:
+
+Directory | Description
+----------|------------
+target/doc/
| Contains rustdoc documentation ([`cargo doc`]).
+target/package/
| Contains the output of the [`cargo package`] and [`cargo publish`] commands.
+
+Cargo also creates several other directories and files needed for the build
+process. Their layout is considered internal to Cargo, and is subject to
+change. Some of these directories are:
+
+Directory | Description
+----------|------------
+target/debug/deps/
| Dependencies and other artifacts.
+target/debug/incremental/
| `rustc` [incremental output], a cache used to speed up subsequent builds.
+target/debug/build/
| Output from [build scripts].
+
+### Dep-info files
+
+Next to each compiled artifact is a file called a "dep info" file with a `.d`
+suffix. This file is a Makefile-like syntax that indicates all of the file
+dependencies required to rebuild the artifact. These are intended to be used
+with external build systems so that they can detect if Cargo needs to be
+re-executed. The paths in the file are absolute by default. See the
+[`build.dep-info-basedir`] config option to use relative paths.
+
+```Makefile
+# Example dep-info file found in target/debug/foo.d
+/path/to/myproj/target/debug/foo: /path/to/myproj/src/lib.rs /path/to/myproj/src/main.rs
+```
+
+### Shared cache
+
+A third party tool, [sccache], can be used to share built dependencies across
+different workspaces.
+
+To setup `sccache`, install it with `cargo install sccache` and set
+`RUSTC_WRAPPER` environmental variable to `sccache` before invoking Cargo. If
+you use bash, it makes sense to add `export RUSTC_WRAPPER=sccache` to
+`.bashrc`. Alternatively, you can set [`build.rustc-wrapper`] in the [Cargo
+configuration][config]. Refer to sccache documentation for more details.
+
+[`RUSTFLAGS`]: ../reference/config.md#buildrustflags
+[`build.dep-info-basedir`]: ../reference/config.md#builddep-info-basedir
+[`build.target-dir`]: ../reference/config.md#buildtarget-dir
+[`cargo doc`]: ../commands/cargo-doc.md
+[`cargo package`]: ../commands/cargo-package.md
+[`cargo publish`]: ../commands/cargo-publish.md
+[build scripts]: ../reference/build-scripts.md
[config]: ../reference/config.md
+[environment variable]: ../reference/environment-variables.md
+[incremental output]: ../reference/profiles.md#incremental
+[sccache]: https://github.com/mozilla/sccache
diff --git a/src/doc/src/guide/project-layout.md b/src/doc/src/guide/project-layout.md
index 6c9f4a7719c..4869924c688 100644
--- a/src/doc/src/guide/project-layout.md
+++ b/src/doc/src/guide/project-layout.md
@@ -3,21 +3,34 @@
Cargo uses conventions for file placement to make it easy to dive into a new
Cargo package:
-```
+```text
.
├── Cargo.lock
├── Cargo.toml
-├── benches
-│ └── large-input.rs
-├── examples
-│ └── simple.rs
-├── src
-│ ├── bin
-│ │ └── another_executable.rs
+├── src/
│ ├── lib.rs
-│ └── main.rs
-└── tests
- └── some-integration-tests.rs
+│ ├── main.rs
+│ └── bin/
+│ ├── named-executable.rs
+│ ├── another-executable.rs
+│ └── multi-file-executable/
+│ ├── main.rs
+│ └── some_module.rs
+├── benches/
+│ ├── large-input.rs
+│ └── multi-file-bench/
+│ ├── main.rs
+│ └── bench_module.rs
+├── examples/
+│ ├── simple.rs
+│ └── multi-file-example/
+│ ├── main.rs
+│ └── ex_module.rs
+└── tests/
+ ├── some-integration-tests.rs
+ └── multi-file-test/
+ ├── main.rs
+ └── test_module.rs
```
* `Cargo.toml` and `Cargo.lock` are stored in the root of your package (*package
@@ -25,11 +38,22 @@ Cargo package:
* Source code goes in the `src` directory.
* The default library file is `src/lib.rs`.
* The default executable file is `src/main.rs`.
-* Other executables can be placed in `src/bin/*.rs`.
-* Integration tests go in the `tests` directory (unit tests go in each file
- they're testing).
-* Examples go in the `examples` directory.
+ * Other executables can be placed in `src/bin/`.
* Benchmarks go in the `benches` directory.
+* Examples go in the `examples` directory.
+* Integration tests go in the `tests` directory.
+
+If a binary, example, bench, or integration test consists of multiple source
+files, place a `main.rs` file along with the extra modules within a
+subdirectory of the `src/bin`, `examples`, `benches`, or `tests` directory.
+The name of the executable will be the directory name.
+
+You can learn more about Rust's module system in [the book][book-modules].
+
+See [Configuring a target] for more details on manually configuring targets.
+See [Target auto-discovery] for more information on controlling how Cargo
+automatically infers target names.
-These are explained in more detail in the [manifest
-description](../reference/manifest.md#the-project-layout).
+[book-modules]: ../../book/ch07-00-managing-growing-projects-with-packages-crates-and-modules.html
+[Configuring a target]: ../reference/cargo-targets.md#configuring-a-target
+[Target auto-discovery]: ../reference/cargo-targets.md#target-auto-discovery
diff --git a/src/doc/src/images/profile-selection.svg b/src/doc/src/images/profile-selection.svg
new file mode 100644
index 00000000000..4975383bf76
--- /dev/null
+++ b/src/doc/src/images/profile-selection.svg
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/src/doc/src/index.md b/src/doc/src/index.md
index b33385c4823..17595ff9cd9 100644
--- a/src/doc/src/index.md
+++ b/src/doc/src/index.md
@@ -25,6 +25,10 @@ The reference covers the details of various areas of Cargo.
**[Frequently Asked Questions](faq.md)**
+**Appendicies:**
+* [Glossary](appendix/glossary.md)
+* [Git Authentication](appendix/git-authentication.md)
+
[rust]: https://www.rust-lang.org/
[crates.io]: https://crates.io/
[GitHub]: https://github.com/rust-lang/cargo/tree/master/src/doc
diff --git a/src/doc/src/reference/build-scripts.md b/src/doc/src/reference/build-scripts.md
index 4800e229cc7..3bdbb6254f2 100644
--- a/src/doc/src/reference/build-scripts.md
+++ b/src/doc/src/reference/build-scripts.md
@@ -176,7 +176,7 @@ of `feature=`). Or an arbitrary key/value pair may be used with an `=` symbol
like `cargo:rustc-cfg=my_component="foo"`. The key should be a Rust
identifier, the value should be a string.
-[cargo features]: manifest.md#the-features-section
+[cargo features]: features.md
[conditional compilation]: ../../reference/conditional-compilation.md
[option-cfg]: ../../rustc/command-line-arguments.md#option-cfg
@@ -240,11 +240,14 @@ cross-compiling, so keep that in consideration of the impact on compile time.
When rebuilding a package, Cargo does not necessarily know if the build script
needs to be run again. By default, it takes a conservative approach of always
-re-running the build script if any file within the package is changed. For
-most cases, this is not a good choice, so it is recommended that every build
-script emit at least one of the `rerun-if` instructions (described below). If
-these are emitted, then Cargo will only re-run the script if the given value
-has changed.
+re-running the build script if any file within the package is changed (or the
+list of files controlled by the [`exclude` and `include` fields]). For most
+cases, this is not a good choice, so it is recommended that every build script
+emit at least one of the `rerun-if` instructions (described below). If these
+are emitted, then Cargo will only re-run the script if the given value has
+changed.
+
+[`exclude` and `include` fields]: manifest.md#the-exclude-and-include-fields
#### `cargo:rerun-if-changed=PATH`
diff --git a/src/doc/src/reference/cargo-targets.md b/src/doc/src/reference/cargo-targets.md
new file mode 100644
index 00000000000..4be13c3529f
--- /dev/null
+++ b/src/doc/src/reference/cargo-targets.md
@@ -0,0 +1,372 @@
+## Cargo Targets
+
+Cargo packages consist of *targets* which correspond to source files which can
+be compiled into a crate. Packages can have [library](#library),
+[binary](#binaries), [example](#examples), [test](#tests), and
+[benchmark](#benchmarks) targets. The list of targets can be configured in the
+`Cargo.toml` manifest, often [inferred automatically](#target-auto-discovery)
+by the [directory layout][package layout] of the source files.
+
+See [Configuring a target](#configuring-a-target) below for details on
+configuring the settings for a target.
+
+### Library
+
+The library target defines a "library" that can be used and linked by other
+libraries and executables. The filename defaults to `src/lib.rs`, and the name
+of the library defaults to the name of the package. A package can have only
+one library. The settings for the library can be [customized] in the `[lib]`
+table in `Cargo.toml`.
+
+```toml
+# Example of customizing the library in Cargo.toml.
+[lib]
+crate-type = ["cdylib"]
+bench = false
+```
+
+### Binaries
+
+Binary targets are executables programs that can be run after being compiled.
+The default binary filename is `src/main.rs`, which defaults to the name of
+the package. Additional binaries are stored in the [`src/bin/`
+directory][package layout]. The settings for each binary can be [customized]
+in the `[[bin]]` tables in `Cargo.toml`.
+
+Binaries can use the public API of the package's library. They are also linked
+with the [`[dependencies]`][dependencies] defined in `Cargo.toml`.
+
+You can run individual binaries with the [`cargo run`] command with the `--bin
+