我有一个 rust 项目,其中包含mysql -crate 依赖项,我想让它独立于操作系统。
所以我尝试了: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 crate 本身,在 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`
所以我的问题是,在这种情况下我如何处理操作系统依赖关系?