|
1 | 1 | # Build cache
|
2 | 2 |
|
3 |
| -Cargo stores the output of a build into the "target" directory. By default, |
4 |
| -this is the directory named `target` in the root of your |
5 |
| -[*workspace*][def-workspace]. To change the location, you can set the |
| 3 | +Cargo stores the output of a build into the "target" and "build" directories. By default, |
| 4 | +both directories point to a directory named `target` in the root of your |
| 5 | +[*workspace*][def-workspace]. To change the location of the target-dir, you can set the |
6 | 6 | `CARGO_TARGET_DIR` [environment variable], the [`build.target-dir`] config
|
7 |
| -value, or the `--target-dir` command-line flag. |
| 7 | +value, or the `--target-dir` command-line flag. To change the location of the build-dir, you can set the |
| 8 | +`CARGO_BUILD_BUILD_DIR` [environment variable] or the [`build.build-dir`] config value. |
| 9 | + |
| 10 | +Artifacts are split in two catagories: |
| 11 | +* Final build artifacts |
| 12 | + * Final build artifacts are output meant for end users of Cargo |
| 13 | + * e.g. binaries for bin crates, output of `cargo doc`, Cargo `--timings` reports |
| 14 | + * Stored in the target-dir |
| 15 | +* Intermediate build artifacts |
| 16 | + * Intermediate build artifacts are internal to Cargo and the Rust compiler |
| 17 | + * End users will generally not need to interact with intermediate build artifacts |
| 18 | + * Stored in the Cargo build-dir |
8 | 19 |
|
9 | 20 | The directory layout depends on whether or not you are using the `--target`
|
10 | 21 | flag to build for a specific platform. If `--target` is not specified, Cargo
|
@@ -53,15 +64,15 @@ Directory | Description
|
53 | 64 | <code style="white-space: nowrap">target/doc/</code> | Contains rustdoc documentation ([`cargo doc`]).
|
54 | 65 | <code style="white-space: nowrap">target/package/</code> | Contains the output of the [`cargo package`] and [`cargo publish`] commands.
|
55 | 66 |
|
56 |
| -Cargo also creates several other directories and files needed for the build |
57 |
| -process. Their layout is considered internal to Cargo, and is subject to |
| 67 | +Cargo also creates several other directories and files in the build-dir needed for the build |
| 68 | +process. The build-dir layout is considered internal to Cargo, and is subject to |
58 | 69 | change. Some of these directories are:
|
59 | 70 |
|
60 | 71 | Directory | Description
|
61 | 72 | ----------|------------
|
62 |
| -<code style="white-space: nowrap">target/debug/deps/</code> | Dependencies and other artifacts. |
63 |
| -<code style="white-space: nowrap">target/debug/incremental/</code> | `rustc` [incremental output], a cache used to speed up subsequent builds. |
64 |
| -<code style="white-space: nowrap">target/debug/build/</code> | Output from [build scripts]. |
| 73 | +<code style="white-space: nowrap">build-dir/debug/deps/</code> | Dependencies and other artifacts. |
| 74 | +<code style="white-space: nowrap">build-dir/debug/incremental/</code> | `rustc` [incremental output], a cache used to speed up subsequent builds. |
| 75 | +<code style="white-space: nowrap">build-dir/debug/build/</code> | Output from [build scripts]. |
65 | 76 |
|
66 | 77 | ## Dep-info files
|
67 | 78 |
|
@@ -92,6 +103,7 @@ configuration][config]. Refer to sccache documentation for more details.
|
92 | 103 | [`build.dep-info-basedir`]: ../reference/config.md#builddep-info-basedir
|
93 | 104 | [`build.rustc-wrapper`]: ../reference/config.md#buildrustc-wrapper
|
94 | 105 | [`build.target-dir`]: ../reference/config.md#buildtarget-dir
|
| 106 | +[`build.build-dir`]: ../reference/config.md#buildbuild-dir |
95 | 107 | [`cargo doc`]: ../commands/cargo-doc.md
|
96 | 108 | [`cargo package`]: ../commands/cargo-package.md
|
97 | 109 | [`cargo publish`]: ../commands/cargo-publish.md
|
|
0 commit comments