3 The `Cargo.toml` file for each package is called its *manifest*. Every manifest
4 file consists of the following sections:
6 * [`cargo-features`](unstable.md) — Unstable, nightly-only features.
7 * [`[package]`](#the-package-section) — Defines a package.
8 * [`name`](#the-name-field) — The name of the package.
9 * [`version`](#the-version-field) — The version of the package.
10 * [`authors`](#the-authors-field) — The authors of the package.
11 * [`edition`](#the-edition-field) — The Rust edition.
12 * [`description`](#the-description-field) — A description of the package.
13 * [`documentation`](#the-documentation-field) — URL of the package documentation.
14 * [`readme`](#the-readme-field) — Path to the package's README file.
15 * [`homepage`](#the-homepage-field) — URL of the package homepage.
16 * [`repository`](#the-repository-field) — URL of the package source repository.
17 * [`license`](#the-license-and-license-file-fields) — The package license.
18 * [`license-file`](#the-license-and-license-file-fields) — Path to the text of the license.
19 * [`keywords`](#the-keywords-field) — Keywords for the package.
20 * [`categories`](#the-categories-field) — Categories of the package.
21 * [`workspace`](#the-workspace-field) — Path to the workspace for the package.
22 * [`build`](#the-build-field) — Path to the package build script.
23 * [`links`](#the-links-field) — Name of the native library the package links with.
24 * [`exclude`](#the-exclude-and-include-fields) — Files to exclude when publishing.
25 * [`include`](#the-exclude-and-include-fields) — Files to include when publishing.
26 * [`publish`](#the-publish-field) — Can be used to prevent publishing the package.
27 * [`metadata`](#the-metadata-table) — Extra settings for external tools.
28 * [`default-run`](#the-default-run-field) — The default binary to run by [`cargo run`].
29 * [`autobins`](cargo-targets.md#target-auto-discovery) — Disables binary auto discovery.
30 * [`autoexamples`](cargo-targets.md#target-auto-discovery) — Disables example auto discovery.
31 * [`autotests`](cargo-targets.md#target-auto-discovery) — Disables test auto discovery.
32 * [`autobenches`](cargo-targets.md#target-auto-discovery) — Disables bench auto discovery.
33 * Target tables: (see [configuration](cargo-targets.md#configuring-a-target) for settings)
34 * [`[lib]`](cargo-targets.md#library) — Library target settings.
35 * [`[[bin]]`](cargo-targets.md#binaries) — Binary target settings.
36 * [`[[example]]`](cargo-targets.md#examples) — Example target settings.
37 * [`[[test]]`](cargo-targets.md#tests) — Test target settings.
38 * [`[[bench]]`](cargo-targets.md#benchmarks) — Benchmark target settings.
40 * [`[dependencies]`](specifying-dependencies.md) — Package library dependencies.
41 * [`[dev-dependencies]`](specifying-dependencies.md#development-dependencies) — Dependencies for examples, tests, and benchmarks.
42 * [`[build-dependencies]`](specifying-dependencies.md#build-dependencies) — Dependencies for build scripts.
43 * [`[target]`](specifying-dependencies.md#platform-specific-dependencies) — Platform-specific dependencies.
44 * [`[badges]`](#the-badges-section) — Badges to display on [crates.io].
45 * [`[features]`](features.md) — Conditional compilation features.
46 * [`[patch]`](#the-patch-section) — Override dependencies.
47 * [`[replace]`](#the-replace-section) — Override dependencies (deprecated).
48 * [`[profile]`](profiles.md) — Compiler settings and optimizations.
49 * [`[workspace]`](workspaces.md) — The workspace definition.
51 <a id="package-metadata"></a>
52 ### The `[package]` section
54 The first section in a `Cargo.toml` is `[package]`.
58 name = "hello_world" # the name of the package
59 version = "0.1.0" # the current version, obeying semver
60 authors = ["Alice <a@example.com>", "Bob <b@example.com>"]
63 The only fields required by Cargo are [`name`](#the-name-field) and
64 [`version`](#the-version-field). If publishing to a registry, the registry may
65 require additional fields. See the notes below and [the publishing
66 chapter][publishing] for requirements for publishing to [crates.io].
70 The package name is an identifier used to refer to the package. It is used
71 when listed as a dependency in another package, and as the default name of
72 inferred lib and bin targets.
74 The name must use only [alphanumeric] characters or `-` or `_`, and cannot be empty.
75 Note that [`cargo new`] and [`cargo init`] impose some additional restrictions on
76 the package name, such as enforcing that it is a valid Rust identifier and not
77 a keyword. [crates.io] imposes even more restrictions, such as
78 enforcing only ASCII characters, not a reserved name, not a special Windows
79 name such as "nul", is not too long, etc.
81 [alphanumeric]: ../../std/primitive.char.html#method.is_alphanumeric
83 #### The `version` field
85 Cargo bakes in the concept of [Semantic
86 Versioning](https://semver.org/), so make sure you follow some basic rules:
88 * Before you reach 1.0.0, anything goes, but if you make breaking changes,
89 increment the minor version. In Rust, breaking changes include adding fields to
90 structs or variants to enums.
91 * After 1.0.0, only make breaking changes when you increment the major version.
92 Don’t break the build.
93 * After 1.0.0, don’t add any new public API (no new `pub` anything) in patch-level
94 versions. Always increment the minor version if you add any new `pub` structs,
95 traits, fields, types, functions, methods or anything else.
96 * Use version numbers with three numeric parts such as 1.0.0 rather than 1.0.
98 #### The `authors` field
100 The `authors` field lists people or organizations that are considered the
101 "authors" of the package. The exact meaning is open to interpretation — it may
102 list the original or primary authors, current maintainers, or owners of the
103 package. These names will be listed on the crate's page on
104 [crates.io]. An optional email address may be included within angled
105 brackets at the end of each author.
107 > **Note**: [crates.io] requires at least one author to be listed.
109 #### The `edition` field
111 You can opt in to a specific [Rust Edition] for your package with the
112 `edition` key in `Cargo.toml`. If you don't specify the edition, it will
121 The `edition` key affects which edition your package is compiled with. Cargo
122 will always generate packages via [`cargo new`] with the `edition` key set to the
123 latest edition. Setting the `edition` key in `[package]` will affect all
124 targets/crates in the package, including test suites, benchmarks, binaries,
127 #### The `description` field
129 The description is a short blurb about the package. [crates.io] will display
130 this with your package. This should be plain text (not Markdown).
135 description = "A short description of my package"
138 > **Note**: [crates.io] requires the `description` to be set.
140 #### The `documentation` field
142 The `documentation` field specifies a URL to a website hosting the crate's
143 documentation. If no URL is specified in the manifest file, [crates.io] will
144 automatically link your crate to the corresponding [docs.rs] page.
149 documentation = "https://docs.rs/bitflags"
152 > **Note**: [crates.io] may not show certain sites if they are known to not be
153 > hosting documentation and are possibly of malicious intent e.g., ad tracking
154 > networks. At this time, the site `rust-ci.org` is not allowed.
156 #### The `readme` field
158 The `readme` field should be the path to a file in the package root (relative
159 to this `Cargo.toml`) that contains general information about the package.
160 This file will be transferred to the registry when you publish. [crates.io]
161 will interpret it as Markdown and render it on the crate's page.
169 #### The `homepage` field
171 The `homepage` field should be a URL to a site that is the home page for your
177 homepage = "https://serde.rs/"
180 #### The `repository` field
182 The `repository` field should be a URL to the source repository for your
188 repository = "https://github.com/rust-lang/cargo/"
191 #### The `license` and `license-file` fields
193 The `license` field contains the name of the software license that the package
194 is released under. The `license-file` field contains the path to a file
195 containing the text of the license (relative to this `Cargo.toml`).
197 [crates.io] interprets the `license` field as an [SPDX 2.1 license
198 expression][spdx-2.1-license-expressions]. The name must be a known license
199 from the [SPDX license list 3.6][spdx-license-list-3.6]. Parentheses are not
200 currently supported. See the [SPDX site] for more information.
202 SPDX license expressions support AND and OR operators to combine multiple
208 license = "MIT OR Apache-2.0"
211 Using `OR` indicates the user may choose either license. Using `AND` indicates
212 the user must comply with both licenses simultaneously. The `WITH` operator
213 indicates a license with a special exception. Some examples:
215 * `MIT OR Apache-2.0`
216 * `LGPL-2.1 AND MIT AND BSD-2-Clause`
217 * `GPL-2.0+ WITH Bison-exception-2.2`
219 If a package is using a nonstandard license, then the `license-file` field may
220 be specified in lieu of the `license` field.
225 license-file = "LICENSE.txt"
228 > **Note**: [crates.io] requires either `license` or `license-file` to be set.
230 [^slash]: Previously multiple licenses could be separated with a `/`, but that
233 #### The `keywords` field
235 The `keywords` field is an array of strings that describe this package. This
236 can help when searching for the package on a registry, and you may choose any
237 words that would help someone find this crate.
242 keywords = ["gamedev", "graphics"]
245 > **Note**: [crates.io] has a maximum of 5 keywords. Each keyword must be
246 > ASCII text, start with a letter, and only contain letters, numbers, `_` or
247 > `-`, and have at most 20 characters.
249 #### The `categories` field
251 The `categories` field is an array of strings of the categories this package
255 categories = ["command-line-utilities", "development-tools::cargo-plugins"]
258 > **Note**: [crates.io] has a maximum of 5 categories. Each category should
259 > match one of the strings available at <https://crates.io/category_slugs>, and
260 > must match exactly.
262 #### The `workspace` field
264 The `workspace` field can be used to configure the workspace that this package
265 will be a member of. If not specified this will be inferred as the first
266 Cargo.toml with `[workspace]` upwards in the filesystem. Setting this is
267 useful if the member is not inside a subdirectory of the workspace root.
272 workspace = "path/to/workspace/root"
275 This field cannot be specified if the manifest already has a `[workspace]`
276 table defined. That is, a crate cannot both be a root crate in a workspace
277 (contain `[workspace]`) and also be a member crate of another workspace
278 (contain `package.workspace`).
280 For more information, see the [workspaces chapter](workspaces.md).
282 <a id="package-build"></a>
283 #### The `build` field
285 The `build` field specifies a file in the package root which is a [build
286 script] for building native code. More information can be found in the [build
287 script guide][build script].
289 [build script]: build-scripts.md
297 The default is `"build.rs"`, which loads the script from a file named
298 `build.rs` in the root of the package. Use `build = "custom_build_name.rs"` to
299 specify a path to a different file or `build = false` to disable automatic
300 detection of the build script.
302 #### The `links` field
304 The `links` field specifies the name of a native library that is being linked
305 to. More information can be found in the [`links`][links] section of the build
308 [links]: build-scripts.md#the-links-manifest-key
316 #### The `exclude` and `include` fields
318 You can explicitly specify that a set of file patterns should be ignored or
319 included for the purposes of packaging. The patterns specified in the
320 `exclude` field identify a set of files that are not included, and the
321 patterns in `include` specify files that are explicitly included.
323 The patterns should be [gitignore]-style patterns. Briefly:
325 - `foo` matches any file or directory with the name `foo` anywhere in the
326 package. This is equivalent to the pattern `**/foo`.
327 - `/foo` matches any file or directory with the name `foo` only in the root of
329 - `foo/` matches any *directory* with the name `foo` anywhere in the package.
330 - Common glob patterns like `*`, `?`, and `[]` are supported:
331 - `*` matches zero or more characters except `/`. For example, `*.html`
332 matches any file or directory with the `.html` extension anywhere in the
334 - `?` matches any character except `/`. For example, `foo?` matches `food`,
336 - `[]` allows for matching a range of characters. For example, `[ab]`
337 matches either `a` or `b`. `[a-z]` matches letters a through z.
338 - `**/` prefix matches in any directory. For example, `**/foo/bar` matches the
339 file or directory `bar` anywhere that is directly under directory `foo`.
340 - `/**` suffix matches everything inside. For example, `foo/**` matches all
341 files inside directory `foo`, including all files in subdirectories below
343 - `/**/` matches zero or more directories. For example, `a/**/b` matches
344 `a/b`, `a/x/b`, `a/x/y/b`, and so on.
345 - `!` prefix negates a pattern. For example, a pattern of `src/**.rs` and
346 `!foo.rs` would match all files with the `.rs` extension inside the `src`
347 directory, except for any file named `foo.rs`.
349 If git is being used for a package, the `exclude` field will be seeded with
350 the `gitignore` settings from the repository.
355 exclude = ["build/**/*.o", "doc/**/*.html"]
361 include = ["src/**/*", "Cargo.toml"]
364 The options are mutually exclusive: setting `include` will override an
365 `exclude`. Note that `include` must be an exhaustive list of files as otherwise
366 necessary source files may not be included. The package's `Cargo.toml` is
367 automatically included.
369 The include/exclude list is also used for change tracking in some situations.
370 For targets built with `rustdoc`, it is used to determine the list of files to
371 track to determine if the target should be rebuilt. If the package has a
372 [build script] that does not emit any `rerun-if-*` directives, then the
373 include/exclude list is used for tracking if the build script should be re-run
374 if any of those files change.
376 [gitignore]: https://git-scm.com/docs/gitignore
378 #### The `publish` field
380 The `publish` field can be used to prevent a package from being published to a
381 package registry (like *crates.io*) by mistake, for instance to keep a package
382 private in a company.
390 The value may also be an array of strings which are registry names that are
391 allowed to be published to.
396 publish = ["some-registry-name"]
399 #### The `metadata` table
401 Cargo by default will warn about unused keys in `Cargo.toml` to assist in
402 detecting typos and such. The `package.metadata` table, however, is completely
403 ignored by Cargo and will not be warned about. This section can be used for
404 tools which would like to store package configuration in `Cargo.toml`. For
412 # Metadata used when generating an Android APK, for example.
413 [package.metadata.android]
414 package-name = "my-awesome-android-app"
415 assets = "path/to/static"
418 #### The `default-run` field
420 The `default-run` field in the `[package]` section of the manifest can be used
421 to specify a default binary picked by [`cargo run`]. For example, when there is
422 both `src/bin/a.rs` and `src/bin/b.rs`:
429 ### The `[badges]` section
431 [crates.io] can display various badges for build status, test coverage, etc. for
432 each crate. All badges are optional.
434 - The badges pertaining to build status that are currently available are
435 Appveyor, CircleCI, Cirrus CI, GitLab, Azure DevOps, Travis CI and Bitbucket
437 - Available badges pertaining to code test coverage are Codecov and Coveralls.
438 - There are also maintenance-related badges based on isitmaintained.com
439 which state the issue resolution time, percent of open issues, and future
440 maintenance intentions.
442 Most badge specifications require a `repository` key. It is expected to be in
448 # Appveyor: `repository` is required. `branch` is optional; default is `master`
449 # `service` is optional; valid values are `github` (default), `bitbucket`, and
450 # `gitlab`; `id` is optional; you can specify the appveyor project id if you
451 # want to use that instead. `project_name` is optional; use when the repository
452 # name differs from the appveyor project name.
453 appveyor = { repository = "...", branch = "master", service = "github" }
455 # Circle CI: `repository` is required. `branch` is optional; default is `master`
456 circle-ci = { repository = "...", branch = "master" }
458 # Cirrus CI: `repository` is required. `branch` is optional; default is `master`
459 cirrus-ci = { repository = "...", branch = "master" }
461 # GitLab: `repository` is required. `branch` is optional; default is `master`
462 gitlab = { repository = "...", branch = "master" }
464 # Azure DevOps: `project` is required. `pipeline` is required. `build` is optional; default is `1`
465 # Note: project = `organization/project`, pipeline = `name_of_pipeline`, build = `definitionId`
466 azure-devops = { project = "...", pipeline = "...", build="2" }
468 # Travis CI: `repository` in format "<user>/<project>" is required.
469 # `branch` is optional; default is `master`
470 travis-ci = { repository = "...", branch = "master" }
472 # Bitbucket Pipelines: `repository` is required. `branch` is required
473 bitbucket-pipelines = { repository = "...", branch = "master" }
475 # Codecov: `repository` is required. `branch` is optional; default is `master`
476 # `service` is optional; valid values are `github` (default), `bitbucket`, and
478 codecov = { repository = "...", branch = "master", service = "github" }
480 # Coveralls: `repository` is required. `branch` is optional; default is `master`
481 # `service` is optional; valid values are `github` (default) and `bitbucket`.
482 coveralls = { repository = "...", branch = "master", service = "github" }
484 # Is it maintained resolution time: `repository` is required.
485 is-it-maintained-issue-resolution = { repository = "..." }
487 # Is it maintained percentage of open issues: `repository` is required.
488 is-it-maintained-open-issues = { repository = "..." }
490 # Maintenance: `status` is required. Available options are:
491 # - `actively-developed`: New features are being added and bugs are being fixed.
492 # - `passively-maintained`: There are no plans for new features, but the maintainer intends to
493 # respond to issues that get filed.
494 # - `as-is`: The crate is feature complete, the maintainer does not intend to continue working on
495 # it or providing support, but it works for the purposes it was designed for.
496 # - `experimental`: The author wants to share it with the community but is not intending to meet
497 # anyone's particular use case.
498 # - `looking-for-maintainer`: The current maintainer would like to transfer the crate to someone
500 # - `deprecated`: The maintainer does not recommend using this crate (the description of the crate
501 # can describe why, there could be a better solution available or there could be problems with
502 # the crate that the author does not want to fix).
503 # - `none`: Displays no badge on crates.io, since the maintainer has not chosen to specify
504 # their intentions, potential crate users will need to investigate on their own.
505 maintenance = { status = "..." }
508 ### Dependency sections
510 See the [specifying dependencies page](specifying-dependencies.md) for
511 information on the `[dependencies]`, `[dev-dependencies]`,
512 `[build-dependencies]`, and target-specific `[target.*.dependencies]` sections.
514 ### The `[profile.*]` sections
516 The `[profile]` tables provide a way to customize compiler settings such as
517 optimizations and debug settings. See [the Profiles chapter](profiles.md) for
520 ### The `[patch]` Section
522 This section of Cargo.toml can be used to [override dependencies][replace] with
523 other copies. The syntax is similar to the `[dependencies]` section:
527 foo = { git = 'https://github.com/example/foo' }
528 bar = { path = 'my/local/bar' }
531 git = 'https://github.com/example/baz'
533 [patch.'https://github.com/example/baz']
534 baz = { git = 'https://github.com/example/patched-baz', branch = 'my-branch' }
537 The `[patch]` table is made of dependency-like sub-tables. Each key after
538 `[patch]` is a URL of the source that is being patched, or the name of a
539 registry. The name `crates-io` may be used to override the default registry
540 [crates.io]. The first `[patch]` in the example above demonstrates overriding
541 [crates.io], and the second `[patch]` demonstrates overriding a git source.
543 Each entry in these tables is a normal dependency specification, the same as
544 found in the `[dependencies]` section of the manifest. The dependencies listed
545 in the `[patch]` section are resolved and used to patch the source at the
546 URL specified. The above manifest snippet patches the `crates-io` source (e.g.
547 crates.io itself) with the `foo` crate and `bar` crate. It also
548 patches the `https://github.com/example/baz` source with a `my-branch` that
549 comes from elsewhere.
551 Sources can be patched with versions of crates that do not exist, and they can
552 also be patched with versions of crates that already exist. If a source is
553 patched with a crate version that already exists in the source, then the
554 source's original crate is replaced.
556 More information about overriding dependencies can be found in the [overriding
557 dependencies][replace] section of the documentation and [RFC 1969] for the
558 technical specification of this feature.
560 [RFC 1969]: https://github.com/rust-lang/rfcs/pull/1969
561 [replace]: specifying-dependencies.md#overriding-dependencies
563 #### Using `[patch]` with multiple versions
565 You can patch in multiple versions of the same crate with the `package` key used
566 to rename dependencies. For example let's say that the `serde` crate has a
567 bugfix that we'd like to use to its 1.\* series but we'd also like to prototype
568 using a 2.0.0 version of serde we have in our git repository. To configure this
573 serde = { git = 'https://github.com/serde-rs/serde' }
574 serde2 = { git = 'https://github.com/example/serde', package = 'serde', branch = 'v2' }
577 The first `serde = ...` directive indicates that serde 1.\* should be used from
578 the git repository (pulling in the bugfix we need) and the second `serde2 = ...`
579 directive indicates that the `serde` package should also be pulled from the `v2`
580 branch of `https://github.com/example/serde`. We're assuming here that
581 `Cargo.toml` on that branch mentions version 2.0.0.
583 Note that when using the `package` key the `serde2` identifier here is actually
584 ignored. We simply need a unique name which doesn't conflict with other patched
587 ### The `[replace]` Section
589 > **Note**: `[replace]` is deprecated. You should use the [`[patch]`][patch]
592 This section of Cargo.toml can be used to [override dependencies][replace] with
593 other copies. The syntax is similar to the `[dependencies]` section:
597 "foo:0.1.0" = { git = 'https://github.com/example/foo' }
598 "bar:1.0.2" = { path = 'my/local/bar' }
601 Each key in the `[replace]` table is a [package ID
602 specification](pkgid-spec.md), which allows arbitrarily choosing a node in the
603 dependency graph to override (the 3-part version number is required). The
604 value of each key is the same as the `[dependencies]` syntax for specifying
605 dependencies, except that you can't specify features. Note that when a crate
606 is overridden the copy it's overridden with must have both the same name and
607 version, but it can come from a different source (e.g., git or a local path).
609 More information about overriding dependencies can be found in the [overriding
610 dependencies][replace] section of the documentation.
612 [`cargo init`]: ../commands/cargo-init.md
613 [`cargo new`]: ../commands/cargo-new.md
614 [`cargo run`]: ../commands/cargo-run.md
615 [crates.io]: https://crates.io/
616 [docs.rs]: https://docs.rs/
617 [publishing]: publishing.md
618 [Rust Edition]: ../../edition-guide/index.html
619 [spdx-2.1-license-expressions]: https://spdx.org/spdx-specification-21-web-version#h.jxpfx0ykyb60
620 [spdx-license-list-3.6]: https://github.com/spdx/license-list-data/tree/v3.6
621 [SPDX site]: https://spdx.org/license-list
622 [patch]: #the-patch-section
627 "#the-project-layout": "../guide/project-layout.html",
628 "#examples": "cargo-targets.html#examples",
629 "#tests": "cargo-targets.html#tests",
630 "#integration-tests": "cargo-targets.html#integration-tests",
631 "#configuring-a-target": "cargo-targets.html#configuring-a-target",
632 "#target-auto-discovery": "cargo-targets.html#target-auto-discovery",
633 "#the-required-features-field": "cargo-targets.html#the-required-features-field",
634 "#building-dynamic-or-static-libraries": "cargo-targets.html#the-crate-type-field",
635 "#the-workspace-section": "workspaces.html#the-workspace-section",
636 "#virtual-manifest": "workspaces.html",
637 "#package-selection": "workspaces.html#package-selection",
638 "#the-features-section": "features.html#the-features-section",
639 "#rules": "features.html#rules",
640 "#usage-in-end-products": "features.html#usage-in-end-products",
641 "#usage-in-packages": "features.html#usage-in-packages",
643 var target = fragments[window.location.hash];
645 var url = window.location.toString();
646 var base = url.substring(0, url.lastIndexOf('/'));
647 window.location.replace(base + "/" + target);