在 Cargo.toml 中使用 `not` 关键字作为条件依赖是否有效?
Is it valid to use the `not` keyword for conditional dependency in Cargo.toml?
在 Cargo.toml 中使用 cfg(not(...))
声明依赖项的语法是否有效?
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
websocket = "0.23.0"
[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
version = "0.3.22"
features = [
"ErrorEvent",
"MessageEvent",
"WebSocket",
]
我收到以下代码的错误 can't find crate "websocket"
:
macro_rules! if_not_wasm {
($($i:item)*) => ($(
#[cfg(not(target_arch = "wasm"))] $i
)*)
}
macro_rules! if_wasm {
($($i:item)*) => ($(
#[cfg(target_arch = "wasm")] $i
)*)
}
if_not_wasm! {
extern crate websocket;
}
if_wasm! {
extern crate web_sys;
}
if_wasm!
中的导入按预期工作,但 if_not_wasm!
错误。我是 运行 这个 .cargo/config
:
[build]
target = "wasm32-unknown-unknown"
您的宏规则条件似乎只需要 wasm32
,而不是 wasm
。
在 Cargo.toml 中使用 cfg(not(...))
声明依赖项的语法是否有效?
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
websocket = "0.23.0"
[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
version = "0.3.22"
features = [
"ErrorEvent",
"MessageEvent",
"WebSocket",
]
我收到以下代码的错误 can't find crate "websocket"
:
macro_rules! if_not_wasm {
($($i:item)*) => ($(
#[cfg(not(target_arch = "wasm"))] $i
)*)
}
macro_rules! if_wasm {
($($i:item)*) => ($(
#[cfg(target_arch = "wasm")] $i
)*)
}
if_not_wasm! {
extern crate websocket;
}
if_wasm! {
extern crate web_sys;
}
if_wasm!
中的导入按预期工作,但 if_not_wasm!
错误。我是 运行 这个 .cargo/config
:
[build]
target = "wasm32-unknown-unknown"
您的宏规则条件似乎只需要 wasm32
,而不是 wasm
。