@@ -73,11 +73,11 @@ examples, etc.
73
73
74
74
#### The ` build ` field (optional)
75
75
76
- This field specifies a file in the package root which is a [ build script] [ 1 ] for
77
- building native code. More information can be found in the build script
78
- [ guide] [ 1 ] .
76
+ This field specifies a file in the package root which is a [ build script] for
77
+ building native code. More information can be found in the [ build script
78
+ guide] [ build script ] .
79
79
80
- [ 1 ] : reference/build-scripts.html
80
+ [ build script ] : reference/build-scripts.html
81
81
82
82
``` toml
83
83
[package ]
@@ -121,15 +121,39 @@ may be replaced by docs.rs links.
121
121
122
122
#### The ` exclude ` and ` include ` fields (optional)
123
123
124
- You can explicitly specify to Cargo that a set of [ globs] [ globs ] should be
125
- ignored or included for the purposes of packaging and rebuilding a package. The
126
- globs specified in the ` exclude ` field identify a set of files that are not
127
- included when a package is published as well as ignored for the purposes of
128
- detecting when to rebuild a package, and the globs in ` include ` specify files
129
- that are explicitly included.
130
-
131
- If a VCS is being used for a package, the ` exclude ` field will be seeded with
132
- the VCS’ ignore settings (` .gitignore ` for git for example).
124
+ You can explicitly specify that a set of file patterns should be ignored or
125
+ included for the purposes of packaging. The patterns specified in the
126
+ ` exclude ` field identify a set of files that are not included, and the
127
+ patterns in ` include ` specify files that are explicitly included.
128
+
129
+ The patterns should be [ gitignore] -style patterns. Briefly:
130
+
131
+ - ` foo ` matches any file or directory with the name ` foo ` anywhere in the
132
+ package. This is equivalent to the pattern ` **/foo ` .
133
+ - ` /foo ` matches any file or directory with the name ` foo ` only in the root of
134
+ the package.
135
+ - ` foo/ ` matches any * directory* with the name ` foo ` anywhere in the package.
136
+ - Common glob patterns like ` * ` , ` ? ` , and ` [] ` are supported:
137
+ - ` * ` matches zero or more characters except ` / ` . For example, ` *.html `
138
+ matches any file or directory with the ` .html ` extension anywhere in the
139
+ package.
140
+ - ` ? ` matches any character except ` / ` . For example, ` foo? ` matches ` food ` ,
141
+ but not ` foo ` .
142
+ - ` [] ` allows for matching a range of characters. For example, ` [ab] `
143
+ matches either ` a ` or ` b ` . ` [a-z] ` matches letters a through z.
144
+ - ` **/ ` prefix matches in any directory. For example, ` **/foo/bar ` matches the
145
+ file or directory ` bar ` anywhere that is directly under directory ` foo ` .
146
+ - ` /** ` suffix matches everything inside. For example, ` foo/** ` matches all
147
+ files inside directory ` foo ` , including all files in subdirectories below
148
+ ` foo ` .
149
+ - ` /**/ ` matches zero or more directories. For example, ` a/**/b ` matches
150
+ ` a/b ` , ` a/x/b ` , ` a/x/y/b ` , and so on.
151
+ - ` ! ` prefix negates a pattern. For example, a pattern of ` src/**.rs ` and
152
+ ` !foo.rs ` would match all files with the ` .rs ` extension inside the ` src `
153
+ directory, except for any file named ` foo.rs ` .
154
+
155
+ If git is being used for a package, the ` exclude ` field will be seeded with
156
+ the ` gitignore ` settings from the repository.
133
157
134
158
``` toml
135
159
[package ]
@@ -148,21 +172,14 @@ The options are mutually exclusive: setting `include` will override an
148
172
necessary source files may not be included. The package's ` Cargo.toml ` is
149
173
automatically included.
150
174
151
- [ globs ] : https://docs.rs/glob/0.2.11/glob/struct.Pattern.html
152
-
153
- #### Migrating to ` gitignore ` -like pattern matching
175
+ The include/exclude list is also used for change tracking in some situations.
176
+ For targets built with ` rustdoc ` , it is used to determine the list of files to
177
+ track to determine if the target should be rebuilt. If the package has a
178
+ [ build script] that does not emit any ` rerun-if-* ` directives, then the
179
+ include/exclude list is used for tracking if the build script should be re-run
180
+ if any of those files change.
154
181
155
- The current interpretation of these configs is based on UNIX Globs, as
156
- implemented in the [ ` glob ` crate] ( https://crates.io/crates/glob ) . We want
157
- Cargo's ` include ` and ` exclude ` configs to work as similar to ` gitignore ` as
158
- possible. [ The ` gitignore ` specification] ( https://git-scm.com/docs/gitignore ) is
159
- also based on Globs, but has a bunch of additional features that enable easier
160
- pattern writing and more control. Therefore, we are migrating the interpretation
161
- for the rules of these configs to use the [ ` ignore `
162
- crate] ( https://crates.io/crates/ignore ) , and treat them each rule as a single
163
- line in a ` gitignore ` file. See [ the tracking
164
- issue] ( https://github.com/rust-lang/cargo/issues/4268 ) for more details on the
165
- migration.
182
+ [ gitignore ] : https://git-scm.com/docs/gitignore
166
183
167
184
#### The ` publish ` field (optional)
168
185
@@ -615,6 +632,8 @@ and also be a member crate of another workspace (contain `package.workspace`).
615
632
Most of the time workspaces will not need to be dealt with as ` cargo new ` and
616
633
` cargo init ` will handle workspace configuration automatically.
617
634
635
+ [ globs ] : https://docs.rs/glob/0.2.11/glob/struct.Pattern.html
636
+
618
637
#### Virtual Manifest
619
638
620
639
In workspace manifests, if the ` package ` table is present, the workspace root
0 commit comments