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