Cargo.toml OS 板条箱的依赖

Cargo.toml OS Dependency for Crate

我有一个 Rust 项目,其中包含 mysql-crate 依赖项,我想让它 os 独立。

所以我尝试了:Cargo.toml

[package]
name = "test"
version = "0.1.0"
authors = ["daMaex"]

[dependencies]
ws = "*"
clap = "*"
env_logger = "*"

[target.'cfg(any(unix, macos))'.dependencies.mysql]
version = "*"
default-features = false
features = ["socket"]

[target.'cfg(windows)'.dependencies.mysql]
version = "*"
default-features = false
features = ["pipe"]

[features]
default = []
ssl = []

错误已经发生在一个最小的 main 上:src/main.rs

fn main () {
}

但是构建失败。在 macos/unix 它总是想编译管道并得到一个未解析的导入:

error[E0432]: unresolved import `std::os::windows::io::RawHandle`
  --> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/named_pipe-0.2.2/src/lib.rs:38:5
   |
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Could not find `windows` in `std::os`

对于 mysql 板条箱本身,Windows 也是如此:

error[E0432]: unresolved import `std::os::unix`
  --> C:\Users\user\.cargo\registry\src\github.com-1ecc6299db9ec823\mysql-7.1.2\src\io.rs:24:5
   |
24 | use std::os::unix as unix;
   |     ^^^^^^^^^^^^^^^^^^^^^ no `unix` in `std::os`

所以我的问题是,在这种情况下我该如何处理 OS-依赖关系?

我觉得这像是 cargo 错误。 一个相关问题是 Cannot declare different version of dependencies in mutually exclusive targets #3195

编辑:根据 code.

,它更像是一个不受支持的功能,而不是一个错误