cargo metadata

NAME

cargo-metadata - Machine-readable metadata about the current package

SYNOPSIS

cargo metadata [OPTIONS]

DESCRIPTION

Output the resolved dependencies of a package, the concrete used versionsincluding overrides, in JSON to stdout.

It is recommended to include the —format-version flag to future-proofyour code to ensure the output is in the format you are expecting.

See the cargo_metadata cratefor a Rust API for reading the metadata.

OUTPUT FORMAT

The output has the following format:

  1. {
  2. /* Array of all packages in the workspace.
  3. It also includes all feature-enabled dependencies unless --no-deps is used.
  4. */
  5. "packages": [
  6. {
  7. /* The name of the package. */
  8. "name": "my-package",
  9. /* The version of the package. */
  10. "version": "0.1.0",
  11. /* The Package ID, a unique identifier for referring to the package. */
  12. "id": "my-package 0.1.0 (path+file:///path/to/my-package)",
  13. /* The license value from the manifest, or null. */
  14. "license": "MIT/Apache-2.0",
  15. /* The license-file value from the manifest, or null. */
  16. "license_file": "LICENSE",
  17. /* The description value from the manifest, or null. */
  18. "description": "Package description.",
  19. /* The source ID of the package. This represents where
  20. a package is retrieved from.
  21. This is null for path dependencies and workspace members.
  22. For other dependencies, it is a string with the format:
  23. - "registry+URL" for registry-based dependencies.
  24. Example: "registry+https://github.com/rust-lang/crates.io-index"
  25. - "git+URL" for git-based dependencies.
  26. Example: "git+https://github.com/rust-lang/cargo?rev=5e85ba14aaa20f8133863373404cb0af69eeef2c#5e85ba14aaa20f8133863373404cb0af69eeef2c"
  27. */
  28. "source": null,
  29. /* Array of dependencies declared in the package's manifest. */
  30. "dependencies": [
  31. {
  32. /* The name of the dependency. */
  33. "name": "bitflags",
  34. /* The source ID of the dependency. May be null, see
  35. description for the package source.
  36. */
  37. "source": "registry+https://github.com/rust-lang/crates.io-index",
  38. /* The version requirement for the dependency.
  39. Dependencies without a version requirement have a value of "*".
  40. */
  41. "req": "^1.0",
  42. /* The dependency kind.
  43. "dev", "build", or null for a normal dependency.
  44. */
  45. "kind": null,
  46. /* If the dependency is renamed, this is the new name for
  47. the dependency as a string. null if it is not renamed.
  48. */
  49. "rename": null,
  50. /* Boolean of whether or not this is an optional dependency. */
  51. "optional": false,
  52. /* Boolean of whether or not default features are enabled. */
  53. "uses_default_features": true,
  54. /* Array of features enabled. */
  55. "features": [],
  56. /* The target platform for the dependency.
  57. null if not a target dependency.
  58. */
  59. "target": "cfg(windows)",
  60. /* A string of the URL of the registry this dependency is from.
  61. If not specified or null, the dependency is from the default
  62. registry (crates.io).
  63. */
  64. "registry": null
  65. }
  66. ],
  67. /* Array of Cargo targets. */
  68. "targets": [
  69. {
  70. /* Array of target kinds.
  71. - lib targets list the `crate-type` values from the
  72. manifest such as "lib", "rlib", "dylib",
  73. "proc-macro", etc. (default ["lib"])
  74. - binary is ["bin"]
  75. - example is ["example"]
  76. - integration test is ["test"]
  77. - benchmark is ["bench"]
  78. - build script is ["custom-build"]
  79. */
  80. "kind": [
  81. "bin"
  82. ],
  83. /* Array of crate types.
  84. - lib and example libraries list the `crate-type` values
  85. from the manifest such as "lib", "rlib", "dylib",
  86. "proc-macro", etc. (default ["lib"])
  87. - all other target kinds are ["bin"]
  88. */
  89. "crate_types": [
  90. "bin"
  91. ],
  92. /* The name of the target. */
  93. "name": "my-package",
  94. /* Absolute path to the root source file of the target. */
  95. "src_path": "/path/to/my-package/src/main.rs",
  96. /* The Rust edition of the target.
  97. Defaults to the package edition.
  98. */
  99. "edition": "2018",
  100. /* Array of required features.
  101. This property is not included if no required features are set.
  102. */
  103. "required-features": ["feat1"],
  104. /* Whether or not this target has doc tests enabled, and
  105. the target is compatible with doc testing.
  106. */
  107. "doctest": false
  108. }
  109. ],
  110. /* Set of features defined for the package.
  111. Each feature maps to an array of features or dependencies it
  112. enables.
  113. */
  114. "features": {
  115. "default": [
  116. "feat1"
  117. ],
  118. "feat1": [],
  119. "feat2": []
  120. },
  121. /* Absolute path to this package's manifest. */
  122. "manifest_path": "/path/to/my-package/Cargo.toml",
  123. /* Package metadata.
  124. This is null if no metadata is specified.
  125. */
  126. "metadata": {
  127. "docs": {
  128. "rs": {
  129. "all-features": true
  130. }
  131. }
  132. },
  133. /* Array of authors from the manifest.
  134. Empty array if no authors specified.
  135. */
  136. "authors": [
  137. "Jane Doe <user@example.com>"
  138. ],
  139. /* Array of categories from the manifest. */
  140. "categories": [
  141. "command-line-utilities"
  142. ],
  143. /* Array of keywords from the manifest. */
  144. "keywords": [
  145. "cli"
  146. ],
  147. /* The readme value from the manifest or null if not specified. */
  148. "readme": "README.md",
  149. /* The repository value from the manifest or null if not specified. */
  150. "repository": "https://github.com/rust-lang/cargo",
  151. /* The default edition of the package.
  152. Note that individual targets may have different editions.
  153. */
  154. "edition": "2018",
  155. /* Optional string that is the name of a native library the package
  156. is linking to.
  157. */
  158. "links": null,
  159. }
  160. ],
  161. /* Array of members of the workspace.
  162. Each entry is the Package ID for the package.
  163. */
  164. "workspace_members": [
  165. "my-package 0.1.0 (path+file:///path/to/my-package)",
  166. ],
  167. /* The resolved dependency graph, with the concrete versions and features
  168. selected. The set depends on the enabled features.
  169. This is null if --no-deps is specified.
  170. */
  171. "resolve": {
  172. /* Array of nodes within the dependency graph.
  173. Each node is a package.
  174. */
  175. "nodes": [
  176. {
  177. /* The Package ID of this node. */
  178. "id": "my-package 0.1.0 (path+file:///path/to/my-package)",
  179. /* The dependencies of this package, an array of Package IDs. */
  180. "dependencies": [
  181. "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)"
  182. ],
  183. /* The dependencies of this package. This is an alternative to
  184. "dependencies" which contains additional information. In
  185. particular, this handles renamed dependencies.
  186. */
  187. "deps": [
  188. {
  189. /* The name of the dependency's library target.
  190. If this is a renamed dependency, this is the new
  191. name.
  192. */
  193. "name": "bitflags",
  194. /* The Package ID of the dependency. */
  195. "pkg": "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)"
  196. }
  197. ],
  198. /* Array of features enabled on this package. */
  199. "features": [
  200. "default"
  201. ]
  202. }
  203. ],
  204. /* The root package of the workspace.
  205. This is null if this is a virtual workspace. Otherwise it is
  206. the Package ID of the root package.
  207. */
  208. "root": "my-package 0.1.0 (path+file:///path/to/my-package)"
  209. },
  210. /* The absolute path to the build directory where Cargo places its output. */
  211. "target_directory": "/path/to/my-package/target",
  212. /* The version of the schema for this metadata structure.
  213. This will be changed if incompatible changes are ever made.
  214. */
  215. "version": 1,
  216. /* The absolute path to the root of the workspace. */
  217. "workspace_root": "/path/to/my-package"
  218. }

OPTIONS

Output Options

  • —no-deps
  • Output information only about the workspace members and don’t fetchdependencies.

  • —format-versionVERSION

  • Specify the version of the output format to use. Currently 1 is the onlypossible value.

Feature Selection

When no feature options are given, the default feature is activated forevery selected package.

  • —featuresFEATURES
  • Space or comma separated list of features to activate. These features onlyapply to the current directory’s package. Features of direct dependenciesmay be enabled with <dep-name>/<feature-name> syntax.

  • —all-features

  • Activate all available features of all selected packages.

  • —no-default-features

  • Do not activate the default feature of the current directory’spackage.

Display Options

  • -v
  • —verbose
  • Use verbose output. May be specified twice for "very verbose" output whichincludes extra output such as dependency warnings and build script output.May also be specified with the term.verboseconfig value.

  • -q

  • —quiet
  • No output printed to stdout.

  • —colorWHEN

  • Control when colored output is used. Valid values:
  • auto (default): Automatically detect if color support is available on theterminal.

  • always: Always display colors.

  • never: Never display colors.

May also be specified with the term.colorconfig value.

Manifest Options

  • —manifest-pathPATH
  • Path to the Cargo.toml file. By default, Cargo searches in the currentdirectory or any parent directory for the Cargo.toml file.

  • —frozen

  • —locked
  • Either of these flags requires that the Cargo.lock file isup-to-date. If the lock file is missing, or it needs to be updated, Cargo willexit with an error. The —frozen flag also prevents Cargo fromattempting to access the network to determine if it is out-of-date.

These may be used in environments where you want to assert that theCargo.lock file is up-to-date (such as a CI build) or want to avoid networkaccess.

  • —offline
  • Prevents Cargo from accessing the network for any reason. Without thisflag, Cargo will stop with an error if it needs to access the network andthe network is not available. With this flag, Cargo will attempt toproceed without the network if possible.

Beware that this may result in different dependency resolution than onlinemode. Cargo will restrict itself to crates that are downloaded locally, evenif there might be a newer version as indicated in the local copy of the index.See the cargo-fetch(1) command to download dependencies before goingoffline.

May also be specified with the net.offline config value.

Common Options

  • -h
  • —help
  • Prints help information.

  • -ZFLAG…​

  • Unstable (nightly-only) flags to Cargo. Run cargo -Z help fordetails.

ENVIRONMENT

See the reference fordetails on environment variables that Cargo reads.

Exit Status

  • 0
  • Cargo succeeded.

  • 101

  • Cargo failed to complete.

EXAMPLES

  • Output JSON about the current package:
  1. cargo metadata --format-version=1

SEE ALSO

cargo(1)