Cargo树-显示依赖关系图的树可视化
cargo tree
[options]
此命令将显示终端的依赖关系树。依赖“兰德”软件包的简单项目示例:
myproject v0.1.0 (/myproject)
└── rand v0.7.3
├── getrandom v0.1.14
│ ├── cfg-if v0.1.10
│ └── libc v0.2.68
├── libc v0.2.68 (*)
├── rand_chacha v0.2.2
│ ├── ppv-lite86 v0.2.6
│ └── rand_core v0.5.1
│ └── getrandom v0.1.14 (*)
└── rand_core v0.5.1 (*)
[build-dependencies]
└── cc v1.0.50
标有(*)
已被“消除重复”。包的依赖关系已经在图中的其他地方显示,因此不再重复。使用--no-dedupe
选项来重复重复。
这个-e
标志可用于选择要显示的依赖项类型。“features”类更改输出,以显示每个依赖项启用的特性。例如cargo tree -e features
:
myproject v0.1.0 (/myproject)
└── log feature "serde"
└── log v0.4.8
├── serde v1.0.106
└── cfg-if feature "default"
└── cfg-if v0.1.10
在这棵树上,myproject
取决于log
和serde
特色log
反过来取决于cfg-if
具有“默认”功能。使用时-e features
使用它可能会有所帮助-i
标志以显示功能如何流入包中。有关更多详细信息,请参见下面的示例。
-i
spec--invert
spec- Show the reverse dependencies for the given package. This flag will invert
the tree and display the packages that depend on the given package.
Note that in a workspace, by default it will only display the package's reverse dependencies inside the tree of the workspace member in the current directory. The
--workspace
flag can be used to extend it so that it will show the package's reverse dependencies across the entire workspace. The-p
flag can be used to display the package's reverse dependencies only with the subtree of the package given to-p
. --prune
spec- Prune the given package from the display of the dependency tree.
--depth
depth- Maximum display depth of the dependency tree. A depth of 1 displays the direct dependencies, for example.
--no-dedupe
- Do not de-duplicate repeated dependencies. Usually, when a package has already
displayed its dependencies, further occurrences will not re-display its
dependencies, and will include a
(*)
to indicate it has already been shown. This flag will cause those duplicates to be repeated. -d
--duplicates
- Show only dependencies which come in multiple versions (implies
--invert
). When used with the-p
flag, only shows duplicates within the subtree of the given package.It can be beneficial for build times and executable sizes to avoid building that same package multiple times. This flag can help identify the offending packages. You can then investigate if the package that depends on the duplicate with the older version can be updated to the newer version so that only one instance is built.
-e
kinds--edges
kinds- The dependency kinds to display. Takes a comma separated list of values:
all
— Show all edge kinds.normal
— Show normal dependencies.build
— Show build dependencies.dev
— Show development dependencies.features
— Show features enabled by each dependency. If this is the only kind given, then it will automatically include the other dependency kinds.no-normal
— Do not include normal dependencies.no-build
— Do not include build dependencies.no-dev
— Do not include development dependencies.no-proc-macro
— Do not include procedural macro dependencies.
The
normal
,build
,dev
, andall
dependency kinds cannot be mixed withno-normal
,no-build
, orno-dev
dependency kinds.The default is
normal,build,dev
. --target
triple- Filter dependencies matching the given target-triple. The default is the host
platform. Use the value
all
to include all targets.
--charset
charset- Chooses the character set to use for the tree. Valid values are "utf8" or "ascii". Default is "utf8".
-f
format--format
format- Set the format string for each package. The default is "{p}".
This is an arbitrary string which will be used to display each package. The following strings will be replaced with the corresponding value:
{p}
— The package name.{l}
— The package license.{r}
— The package repository URL.{f}
— Comma-separated list of package features that are enabled.{lib}
— The name, as used in ause
statement, of the package's library.
--prefix
prefix- Sets how each line is displayed. The prefix value can be one of:
indent
(default) — Shows each line indented as a tree.depth
— Show as a list, with the numeric depth printed before each entry.none
— Show as a flat list.
默认情况下,如果未提供包选择选项,则选择的包取决于选择的清单文件(如果需要,则基于当前工作目录)--manifest-path
未给出)。如果清单是工作区的根目录,则会选择工作区默认成员,否则只会选择清单定义的包。
可以使用workspace.default-members
输入根清单。如果未设置,虚拟工作区将包括所有工作区成员(相当于传递)--workspace
),非虚拟工作区将只包括根箱子本身。
-p
spec...--package
spec...- Display only the specified packages. See cargo-pkgid(1) for the
SPEC format. This flag may be specified multiple times and supports common Unix
glob patterns like
*
,?
and[]
. However, to avoid your shell accidentally expanding glob patterns before Cargo handles them, you must use single quotes or double quotes around each pattern. --workspace
- Display all members in the workspace.
--exclude
SPEC...- Exclude the specified packages. Must be used in conjunction with the
--workspace
flag. This flag may be specified multiple times and supports common Unix glob patterns like*
,?
and[]
. However, to avoid your shell accidentally expanding glob patterns before Cargo handles them, you must use single quotes or double quotes around each pattern.
--manifest-path
path- Path to the
Cargo.toml
file. By default, Cargo searches for theCargo.toml
file in the current directory or any parent directory. --frozen
--locked
- Either of these flags requires that the
Cargo.lock
file is up-to-date. If the lock file is missing, or it needs to be updated, Cargo will exit with an error. The--frozen
flag also prevents Cargo from attempting to access the network to determine if it is out-of-date.These may be used in environments where you want to assert that the
Cargo.lock
file is up-to-date (such as a CI build) or want to avoid network access. --offline
- Prevents Cargo from accessing the network for any reason. Without this
flag, Cargo will stop with an error if it needs to access the network and
the network is not available. With this flag, Cargo will attempt to
proceed without the network if possible.
Beware that this may result in different dependency resolution than online mode. Cargo will restrict itself to crates that are downloaded locally, even if 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 going offline.
May also be specified with the
net.offline
config value.
功能标志允许您控制启用哪些功能。如果未提供任何功能选项,则default
为每个选定的软件包激活该功能。
查看the features documentation更多细节。
--features
features- Space or comma separated list of features to activate. Features of workspace
members may be enabled with
package-name/feature-name
syntax. This flag may be specified multiple times, which enables all specified features. --all-features
- Activate all available features of all selected packages.
--no-default-features
- Do not activate the
default
feature of the selected packages.
-v
--verbose
- Use verbose output. May be specified twice for "very verbose" output which
includes extra output such as dependency warnings and build script output.
May also be specified with the
term.verbose
config value. -q
--quiet
- Do not print cargo log messages.
May also be specified with the
term.quiet
config value. --color
when- Control when colored output is used. Valid values:
auto
(default): Automatically detect if color support is available on the terminal.always
: Always display colors.never
: Never display colors.
May also be specified with the
term.color
config value.
+
toolchain- If Cargo has been installed with rustup, and the first argument to
cargo
begins with+
, it will be interpreted as a rustup toolchain name (such as+stable
or+nightly
). See the rustup documentation for more information about how toolchain overrides work. -h
--help
- Prints help information.
-Z
flag- Unstable (nightly-only) flags to Cargo. Run
cargo -Z help
for details.
查看the reference有关Cargo读取的环境变量的详细信息。
0
:Cargo成功。101
:Cargo未能完成。
-
在当前目录中显示包的目录树:
货运树
-
显示所有依赖于
syn
包:货运树-i syn
-
显示每个软件包上启用的功能:
Cargo树--格式“{p}{f}”
-
显示多次生成的所有包。如果树中出现多个semver不兼容的版本(如1.0.0和2.0.0),可能会发生这种情况。
cargo tree -d
-
解释为什么为
syn
包:cargo tree -e features -i syn
这个
-e features
标志用于显示特征。这个-i
标志用于反转图形,以便显示依赖于syn
.这将显示什么的示例:syn v1.0.17 ├── syn feature "clone-impls" │ └── syn feature "default" │ └── rustversion v1.0.2 │ └── rustversion feature "default" │ └── myproject v0.1.0 (/myproject) │ └── myproject feature "default" (command-line) ├── syn feature "default" (*) ├── syn feature "derive" │ └── syn feature "default" (*) ├── syn feature "full" │ └── rustversion v1.0.2 (*) ├── syn feature "parsing" │ └── syn feature "default" (*) ├── syn feature "printing" │ └── syn feature "default" (*) ├── syn feature "proc-macro" │ └── syn feature "default" (*) └── syn feature "quote" ├── syn feature "printing" (*) └── syn feature "proc-macro" (*)
要阅读此图,您可以从根目录中查看每个功能的链,以了解其包含的原因。例如,“完整”功能由
rustversion
箱子,包括从myproject
(具有默认功能),以及myproject
是在命令行上选择的包。所有其他的syn
功能由“默认”功能添加(“引用”由“打印”和“proc宏”添加,两者都是默认功能)。如果交叉引用已消除重复的
(*)
输入,用--no-dedupe
标记以获取完整输出。