]> git.proxmox.com Git - rustc.git/blob - src/tools/cargo/src/doc/src/commands/cargo-package.md
New upstream version 1.70.0+dfsg2
[rustc.git] / src / tools / cargo / src / doc / src / commands / cargo-package.md
1 # cargo-package(1)
2
3
4
5
6 ## NAME
7
8 cargo-package --- Assemble the local package into a distributable tarball
9
10 ## SYNOPSIS
11
12 `cargo package` [_options_]
13
14 ## DESCRIPTION
15
16 This command will create a distributable, compressed `.crate` file with the
17 source code of the package in the current directory. The resulting file will
18 be stored in the `target/package` directory. This performs the following
19 steps:
20
21 1. Load and check the current workspace, performing some basic checks.
22 - Path dependencies are not allowed unless they have a version key. Cargo
23 will ignore the path key for dependencies in published packages.
24 `dev-dependencies` do not have this restriction.
25 2. Create the compressed `.crate` file.
26 - The original `Cargo.toml` file is rewritten and normalized.
27 - `[patch]`, `[replace]`, and `[workspace]` sections are removed from the
28 manifest.
29 - `Cargo.lock` is automatically included if the package contains an
30 executable binary or example target. [cargo-install(1)](cargo-install.html) will use the
31 packaged lock file if the `--locked` flag is used.
32 - A `.cargo_vcs_info.json` file is included that contains information
33 about the current VCS checkout hash if available (not included with
34 `--allow-dirty`).
35 3. Extract the `.crate` file and build it to verify it can build.
36 - This will rebuild your package from scratch to ensure that it can be
37 built from a pristine state. The `--no-verify` flag can be used to skip
38 this step.
39 4. Check that build scripts did not modify any source files.
40
41 The list of files included can be controlled with the `include` and `exclude`
42 fields in the manifest.
43
44 See [the reference](../reference/publishing.html) for more details about
45 packaging and publishing.
46
47 ### .cargo_vcs_info.json format
48
49 Will generate a `.cargo_vcs_info.json` in the following format
50
51 ```javascript
52 {
53 "git": {
54 "sha1": "aac20b6e7e543e6dd4118b246c77225e3a3a1302"
55 },
56 "path_in_vcs": ""
57 }
58 ```
59
60 `path_in_vcs` will be set to a repo-relative path for packages
61 in subdirectories of the version control repository.
62
63 ## OPTIONS
64
65 ### Package Options
66
67 <dl>
68
69 <dt class="option-term" id="option-cargo-package--l"><a class="option-anchor" href="#option-cargo-package--l"></a><code>-l</code></dt>
70 <dt class="option-term" id="option-cargo-package---list"><a class="option-anchor" href="#option-cargo-package---list"></a><code>--list</code></dt>
71 <dd class="option-desc">Print files included in a package without making one.</dd>
72
73
74 <dt class="option-term" id="option-cargo-package---no-verify"><a class="option-anchor" href="#option-cargo-package---no-verify"></a><code>--no-verify</code></dt>
75 <dd class="option-desc">Don’t verify the contents by building them.</dd>
76
77
78 <dt class="option-term" id="option-cargo-package---no-metadata"><a class="option-anchor" href="#option-cargo-package---no-metadata"></a><code>--no-metadata</code></dt>
79 <dd class="option-desc">Ignore warnings about a lack of human-usable metadata (such as the description
80 or the license).</dd>
81
82
83 <dt class="option-term" id="option-cargo-package---allow-dirty"><a class="option-anchor" href="#option-cargo-package---allow-dirty"></a><code>--allow-dirty</code></dt>
84 <dd class="option-desc">Allow working directories with uncommitted VCS changes to be packaged.</dd>
85
86
87 </dl>
88
89 ### Package Selection
90
91 By default, when no package selection options are given, the packages selected
92 depend on the selected manifest file (based on the current working directory if
93 `--manifest-path` is not given). If the manifest is the root of a workspace then
94 the workspaces default members are selected, otherwise only the package defined
95 by the manifest will be selected.
96
97 The default members of a workspace can be set explicitly with the
98 `workspace.default-members` key in the root manifest. If this is not set, a
99 virtual workspace will include all workspace members (equivalent to passing
100 `--workspace`), and a non-virtual workspace will include only the root crate itself.
101
102 <dl>
103
104 <dt class="option-term" id="option-cargo-package--p"><a class="option-anchor" href="#option-cargo-package--p"></a><code>-p</code> <em>spec</em>…</dt>
105 <dt class="option-term" id="option-cargo-package---package"><a class="option-anchor" href="#option-cargo-package---package"></a><code>--package</code> <em>spec</em>…</dt>
106 <dd class="option-desc">Package only the specified packages. See <a href="cargo-pkgid.html">cargo-pkgid(1)</a> for the
107 SPEC format. This flag may be specified multiple times and supports common Unix
108 glob patterns like <code>*</code>, <code>?</code> and <code>[]</code>. However, to avoid your shell accidentally
109 expanding glob patterns before Cargo handles them, you must use single quotes or
110 double quotes around each pattern.</dd>
111
112
113 <dt class="option-term" id="option-cargo-package---workspace"><a class="option-anchor" href="#option-cargo-package---workspace"></a><code>--workspace</code></dt>
114 <dd class="option-desc">Package all members in the workspace.</dd>
115
116
117
118
119 <dt class="option-term" id="option-cargo-package---exclude"><a class="option-anchor" href="#option-cargo-package---exclude"></a><code>--exclude</code> <em>SPEC</em>…</dt>
120 <dd class="option-desc">Exclude the specified packages. Must be used in conjunction with the
121 <code>--workspace</code> flag. This flag may be specified multiple times and supports
122 common Unix glob patterns like <code>*</code>, <code>?</code> and <code>[]</code>. However, to avoid your shell
123 accidentally expanding glob patterns before Cargo handles them, you must use
124 single quotes or double quotes around each pattern.</dd>
125
126
127 </dl>
128
129
130 ### Compilation Options
131
132 <dl>
133
134 <dt class="option-term" id="option-cargo-package---target"><a class="option-anchor" href="#option-cargo-package---target"></a><code>--target</code> <em>triple</em></dt>
135 <dd class="option-desc">Package for the given architecture. The default is the host architecture. The general format of the triple is
136 <code>&lt;arch&gt;&lt;sub&gt;-&lt;vendor&gt;-&lt;sys&gt;-&lt;abi&gt;</code>. Run <code>rustc --print target-list</code> for a
137 list of supported targets. This flag may be specified multiple times.</p>
138 <p>This may also be specified with the <code>build.target</code>
139 <a href="../reference/config.html">config value</a>.</p>
140 <p>Note that specifying this flag makes Cargo run in a different mode where the
141 target artifacts are placed in a separate directory. See the
142 <a href="../guide/build-cache.html">build cache</a> documentation for more details.</dd>
143
144
145
146 <dt class="option-term" id="option-cargo-package---target-dir"><a class="option-anchor" href="#option-cargo-package---target-dir"></a><code>--target-dir</code> <em>directory</em></dt>
147 <dd class="option-desc">Directory for all generated artifacts and intermediate files. May also be
148 specified with the <code>CARGO_TARGET_DIR</code> environment variable, or the
149 <code>build.target-dir</code> <a href="../reference/config.html">config value</a>.
150 Defaults to <code>target</code> in the root of the workspace.</dd>
151
152
153
154 </dl>
155
156 ### Feature Selection
157
158 The feature flags allow you to control which features are enabled. When no
159 feature options are given, the `default` feature is activated for every
160 selected package.
161
162 See [the features documentation](../reference/features.html#command-line-feature-options)
163 for more details.
164
165 <dl>
166
167 <dt class="option-term" id="option-cargo-package--F"><a class="option-anchor" href="#option-cargo-package--F"></a><code>-F</code> <em>features</em></dt>
168 <dt class="option-term" id="option-cargo-package---features"><a class="option-anchor" href="#option-cargo-package---features"></a><code>--features</code> <em>features</em></dt>
169 <dd class="option-desc">Space or comma separated list of features to activate. Features of workspace
170 members may be enabled with <code>package-name/feature-name</code> syntax. This flag may
171 be specified multiple times, which enables all specified features.</dd>
172
173
174 <dt class="option-term" id="option-cargo-package---all-features"><a class="option-anchor" href="#option-cargo-package---all-features"></a><code>--all-features</code></dt>
175 <dd class="option-desc">Activate all available features of all selected packages.</dd>
176
177
178 <dt class="option-term" id="option-cargo-package---no-default-features"><a class="option-anchor" href="#option-cargo-package---no-default-features"></a><code>--no-default-features</code></dt>
179 <dd class="option-desc">Do not activate the <code>default</code> feature of the selected packages.</dd>
180
181
182 </dl>
183
184
185 ### Manifest Options
186
187 <dl>
188
189 <dt class="option-term" id="option-cargo-package---manifest-path"><a class="option-anchor" href="#option-cargo-package---manifest-path"></a><code>--manifest-path</code> <em>path</em></dt>
190 <dd class="option-desc">Path to the <code>Cargo.toml</code> file. By default, Cargo searches for the
191 <code>Cargo.toml</code> file in the current directory or any parent directory.</dd>
192
193
194
195 <dt class="option-term" id="option-cargo-package---frozen"><a class="option-anchor" href="#option-cargo-package---frozen"></a><code>--frozen</code></dt>
196 <dt class="option-term" id="option-cargo-package---locked"><a class="option-anchor" href="#option-cargo-package---locked"></a><code>--locked</code></dt>
197 <dd class="option-desc">Either of these flags requires that the <code>Cargo.lock</code> file is
198 up-to-date. If the lock file is missing, or it needs to be updated, Cargo will
199 exit with an error. The <code>--frozen</code> flag also prevents Cargo from
200 attempting to access the network to determine if it is out-of-date.</p>
201 <p>These may be used in environments where you want to assert that the
202 <code>Cargo.lock</code> file is up-to-date (such as a CI build) or want to avoid network
203 access.</dd>
204
205
206 <dt class="option-term" id="option-cargo-package---offline"><a class="option-anchor" href="#option-cargo-package---offline"></a><code>--offline</code></dt>
207 <dd class="option-desc">Prevents Cargo from accessing the network for any reason. Without this
208 flag, Cargo will stop with an error if it needs to access the network and
209 the network is not available. With this flag, Cargo will attempt to
210 proceed without the network if possible.</p>
211 <p>Beware that this may result in different dependency resolution than online
212 mode. Cargo will restrict itself to crates that are downloaded locally, even
213 if there might be a newer version as indicated in the local copy of the index.
214 See the <a href="cargo-fetch.html">cargo-fetch(1)</a> command to download dependencies before going
215 offline.</p>
216 <p>May also be specified with the <code>net.offline</code> <a href="../reference/config.html">config value</a>.</dd>
217
218
219
220 </dl>
221
222 ### Miscellaneous Options
223
224 <dl>
225 <dt class="option-term" id="option-cargo-package--j"><a class="option-anchor" href="#option-cargo-package--j"></a><code>-j</code> <em>N</em></dt>
226 <dt class="option-term" id="option-cargo-package---jobs"><a class="option-anchor" href="#option-cargo-package---jobs"></a><code>--jobs</code> <em>N</em></dt>
227 <dd class="option-desc">Number of parallel jobs to run. May also be specified with the
228 <code>build.jobs</code> <a href="../reference/config.html">config value</a>. Defaults to
229 the number of logical CPUs. If negative, it sets the maximum number of
230 parallel jobs to the number of logical CPUs plus provided value.
231 Should not be 0.</dd>
232
233
234 <dt class="option-term" id="option-cargo-package---keep-going"><a class="option-anchor" href="#option-cargo-package---keep-going"></a><code>--keep-going</code></dt>
235 <dd class="option-desc">Build as many crates in the dependency graph as possible, rather than aborting
236 the build on the first one that fails to build. Unstable, requires
237 <code>-Zunstable-options</code>.</dd>
238
239
240 </dl>
241
242 ### Display Options
243
244 <dl>
245 <dt class="option-term" id="option-cargo-package--v"><a class="option-anchor" href="#option-cargo-package--v"></a><code>-v</code></dt>
246 <dt class="option-term" id="option-cargo-package---verbose"><a class="option-anchor" href="#option-cargo-package---verbose"></a><code>--verbose</code></dt>
247 <dd class="option-desc">Use verbose output. May be specified twice for “very verbose” output which
248 includes extra output such as dependency warnings and build script output.
249 May also be specified with the <code>term.verbose</code>
250 <a href="../reference/config.html">config value</a>.</dd>
251
252
253 <dt class="option-term" id="option-cargo-package--q"><a class="option-anchor" href="#option-cargo-package--q"></a><code>-q</code></dt>
254 <dt class="option-term" id="option-cargo-package---quiet"><a class="option-anchor" href="#option-cargo-package---quiet"></a><code>--quiet</code></dt>
255 <dd class="option-desc">Do not print cargo log messages.
256 May also be specified with the <code>term.quiet</code>
257 <a href="../reference/config.html">config value</a>.</dd>
258
259
260 <dt class="option-term" id="option-cargo-package---color"><a class="option-anchor" href="#option-cargo-package---color"></a><code>--color</code> <em>when</em></dt>
261 <dd class="option-desc">Control when colored output is used. Valid values:</p>
262 <ul>
263 <li><code>auto</code> (default): Automatically detect if color support is available on the
264 terminal.</li>
265 <li><code>always</code>: Always display colors.</li>
266 <li><code>never</code>: Never display colors.</li>
267 </ul>
268 <p>May also be specified with the <code>term.color</code>
269 <a href="../reference/config.html">config value</a>.</dd>
270
271
272 </dl>
273
274 ### Common Options
275
276 <dl>
277
278 <dt class="option-term" id="option-cargo-package-+toolchain"><a class="option-anchor" href="#option-cargo-package-+toolchain"></a><code>+</code><em>toolchain</em></dt>
279 <dd class="option-desc">If Cargo has been installed with rustup, and the first argument to <code>cargo</code>
280 begins with <code>+</code>, it will be interpreted as a rustup toolchain name (such
281 as <code>+stable</code> or <code>+nightly</code>).
282 See the <a href="https://rust-lang.github.io/rustup/overrides.html">rustup documentation</a>
283 for more information about how toolchain overrides work.</dd>
284
285
286 <dt class="option-term" id="option-cargo-package---config"><a class="option-anchor" href="#option-cargo-package---config"></a><code>--config</code> <em>KEY=VALUE</em> or <em>PATH</em></dt>
287 <dd class="option-desc">Overrides a Cargo configuration value. The argument should be in TOML syntax of <code>KEY=VALUE</code>,
288 or provided as a path to an extra configuration file. This flag may be specified multiple times.
289 See the <a href="../reference/config.html#command-line-overrides">command-line overrides section</a> for more information.</dd>
290
291
292 <dt class="option-term" id="option-cargo-package--C"><a class="option-anchor" href="#option-cargo-package--C"></a><code>-C</code> <em>PATH</em></dt>
293 <dd class="option-desc">Changes the current working directory before executing any specified operations. This affects
294 things like where cargo looks by default for the project manifest (<code>Cargo.toml</code>), as well as
295 the directories searched for discovering <code>.cargo/config.toml</code>, for example. This option must
296 appear before the command name, for example <code>cargo -C path/to/my-project build</code>.</p>
297 <p>This option is only available on the <a href="https://doc.rust-lang.org/book/appendix-07-nightly-rust.html">nightly
298 channel</a> and
299 requires the <code>-Z unstable-options</code> flag to enable (see
300 <a href="https://github.com/rust-lang/cargo/issues/10098">#10098</a>).</dd>
301
302
303 <dt class="option-term" id="option-cargo-package--h"><a class="option-anchor" href="#option-cargo-package--h"></a><code>-h</code></dt>
304 <dt class="option-term" id="option-cargo-package---help"><a class="option-anchor" href="#option-cargo-package---help"></a><code>--help</code></dt>
305 <dd class="option-desc">Prints help information.</dd>
306
307
308 <dt class="option-term" id="option-cargo-package--Z"><a class="option-anchor" href="#option-cargo-package--Z"></a><code>-Z</code> <em>flag</em></dt>
309 <dd class="option-desc">Unstable (nightly-only) flags to Cargo. Run <code>cargo -Z help</code> for details.</dd>
310
311
312 </dl>
313
314
315 ## ENVIRONMENT
316
317 See [the reference](../reference/environment-variables.html) for
318 details on environment variables that Cargo reads.
319
320
321 ## EXIT STATUS
322
323 * `0`: Cargo succeeded.
324 * `101`: Cargo failed to complete.
325
326
327 ## EXAMPLES
328
329 1. Create a compressed `.crate` file of the current package:
330
331 cargo package
332
333 ## SEE ALSO
334 [cargo(1)](cargo.html), [cargo-publish(1)](cargo-publish.html)