【问题标题】:What's the different between "cargo build" and "cargo -- build"?“cargo build”和“cargo -- build”有什么区别?
【发布时间】:2021-08-26 10:33:58
【问题描述】:

我使用这个命令cargo -- build --features ffi遇到了问题,构建的库不包含我想要的符号。

调试了一整天,终于发现cargo build --features ffibuild之前没有--)可以了。

我搜索了一段时间,并没有找到单个--的用法,所以关于它何时使用以及有或没有这个--有什么不同?

【问题讨论】:

  • @SergioTulentsev 感谢您的帮助,看来答案并没有解决我的困惑,如果货物遵循相同的 BASH 约定,这两个命令应该没有区别...
  • Cargo 确实遵循与 bash 相同的约定,这意味着在 cargo -- build --features ffi 中,--features 参数未被解析,因此被忽略,因为 cargo build 忽略了额外的位置参数。
  • @psionic12 我提交了拉取请求,这显然是货物错误github.com/rust-lang/cargo/pull/9561
  • @Inline 太棒了。

标签: rust rust-cargo


【解决方案1】:

正如@Sergio 已经指出的那样,双破折号(--)通常表示选项参数的结尾,之后只能跟随位置参数(有关更多详细信息,请参阅this answer)。

在这种特殊情况下,cargobuild 之间的双破折号似乎非常有问题,因为它的行为不一致:

# Intended behavior, `--features ffi` is an option
cargo build --features ffi --
# Fails because no positional arguments are expected
cargo build -- --features ffi
# Silently ignores the positional `--features ffi`
cargo -- build --features ffi

不过,多亏了@Inline 的bug fix,我们应该期待这个陷阱将成为过去。

【讨论】:

    猜你喜欢
    • 2022-11-06
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 2018-10-18
    • 2022-07-04
    • 1970-01-01
    • 2021-04-11
    • 2019-09-10
    相关资源
    最近更新 更多