我是 Rust 的新手,我想构建和运行我的项目。我使用类似的东西:

cd %project_path%
cargo run

我希望能够在一行中写入 cargo run -path %project_path%,因为我想创建一个不允许更改工作目录的构建脚本。似乎 cargo 没有任何 -path-target 键,它们将定义目标目录,我总是收到消息

最佳答案

几乎所有 --manifest-path path/to/Cargo.toml 子命令的 cargo 选项允许将其指向要使用的特定 Cargo.toml 文件,覆盖搜索当前目录及其父目录以查找名为 0x231343 的文件的默认设置。

顺便提一下,unix-y 命令通常采用 Cargo.toml-h 参数,该参数打印有关其命令行选项的信息,--helpcargo 也不异常(exception)。例如。

$ cargo run --help
Run the main binary of the local package (src/main.rs)

Usage:
    cargo run [options] [--] [<args>...]

Options:
    -h, --help              Print this message
    --bin NAME              Name of the bin target to run
    --example NAME          Name of the example target to run
    -j N, --jobs N          The number of jobs to run in parallel
    --release               Build artifacts in release mode, with optimizations
    --features FEATURES     Space-separated list of features to also build
    --no-default-features   Do not build the `default` feature
    --target TRIPLE         Build for the target triple
    --manifest-path PATH    Path to the manifest to execute
    -v, --verbose           Use verbose output
    -q, --quiet             No output printed to stdout
    --color WHEN            Coloring: auto, always, never

If neither `--bin` nor `--example` are given, then if the project only has one
bin target it will be run. Otherwise `--bin` specifies the bin target to run,
and `--example` specifies the example target to run. At most one of `--bin` or
`--example` can be provided.

All of the trailing arguments are passed to the binary to run. If you're passing
arguments to both Cargo and the binary, the ones after `--` go to the binary,

关于rust - 如何指定 Cargo.toml 的路径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35112929/

10-13 08:55