Skip to content

Commit 4c35895

Browse files
committed
Update documentation for include/exclude.
1 parent 6b6ddaa commit 4c35895

File tree

1 file changed

+52
-24
lines changed

1 file changed

+52
-24
lines changed

src/doc/src/reference/manifest.md

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,57 @@ links = "foo"
342342
<a id="the-exclude-and-include-fields-optional"></a>
343343
#### The `exclude` and `include` fields
344344

345-
You can explicitly specify that a set of file patterns should be ignored or
346-
included for the purposes of packaging. The patterns specified in the
347-
`exclude` field identify a set of files that are not included, and the
348-
patterns in `include` specify files that are explicitly included.
345+
The `exclude` and `include` fields can be used to explicitly specify which
346+
files are included when packaging a project to be [published][publishing],
347+
and certain kinds of change tracking (described below).
348+
The patterns specified in the `exclude` field identify a set of files that are
349+
not included, and the patterns in `include` specify files that are explicitly
350+
included.
351+
You may run [`cargo package --list`][`cargo package`] to verify which files will
352+
be included in the package.
353+
354+
```toml
355+
[package]
356+
# ...
357+
exclude = ["/ci", "images/", ".*"]
358+
```
359+
360+
```toml
361+
[package]
362+
# ...
363+
include = ["/src", "COPYRIGHT", "/examples", "!/examples/big_example"]
364+
```
365+
366+
The default if neither field is specified is to include all files from the
367+
root of the package, except for the exclusions listed below.
368+
369+
If `include` is not specified, then the following files will be excluded:
370+
371+
* If the package is not in a git repository, all "hidden" files starting with
372+
a dot will be skipped.
373+
* If the package is in a git repository, any files that are ignored by the
374+
[gitignore] rules of the repository and global git configuration will be
375+
skipped.
376+
377+
Regardless of whether `exclude` or `include` is specified, the following files
378+
are always excluded:
379+
380+
* Any sub-packages will be skipped (any subdirectory that contains a
381+
`Cargo.toml` file).
382+
* A directory named `target` in the root of the package will be skipped.
383+
384+
The following files are always included:
385+
386+
* The `Cargo.toml` file of the package itself is always included, it does not
387+
need to be listed in `include`.
388+
* A minimized `Cargo.lock` is automatically included if the package contains a
389+
binary or example target, see [`cargo package`] for more information.
390+
* If a [`license-file`](#the-license-and-license-file-fields) is specified, it
391+
is always included.
392+
393+
The options are mutually exclusive; setting `include` will override an
394+
`exclude`. If you need to have exclusions to a set of `include` files, use the
395+
`!` operator described below.
349396

350397
The patterns should be [gitignore]-style patterns. Briefly:
351398

@@ -373,26 +420,6 @@ The patterns should be [gitignore]-style patterns. Briefly:
373420
`!foo.rs` would match all files with the `.rs` extension inside the `src`
374421
directory, except for any file named `foo.rs`.
375422

376-
If git is being used for a package, the `exclude` field will be seeded with
377-
the `gitignore` settings from the repository.
378-
379-
```toml
380-
[package]
381-
# ...
382-
exclude = ["build/**/*.o", "doc/**/*.html"]
383-
```
384-
385-
```toml
386-
[package]
387-
# ...
388-
include = ["src/**/*", "Cargo.toml"]
389-
```
390-
391-
The options are mutually exclusive: setting `include` will override an
392-
`exclude`. Note that `include` must be an exhaustive list of files as otherwise
393-
necessary source files may not be included. The package's `Cargo.toml` is
394-
automatically included.
395-
396423
The include/exclude list is also used for change tracking in some situations.
397424
For targets built with `rustdoc`, it is used to determine the list of files to
398425
track to determine if the target should be rebuilt. If the package has a
@@ -518,6 +545,7 @@ more detail.
518545

519546
[`cargo init`]: ../commands/cargo-init.md
520547
[`cargo new`]: ../commands/cargo-new.md
548+
[`cargo package`]: ../commands/cargo-package.md
521549
[`cargo run`]: ../commands/cargo-run.md
522550
[crates.io]: https://crates.io/
523551
[docs.rs]: https://docs.rs/

0 commit comments

Comments
 (0)