当我使用 serde 构建我的驱动程序时(default-features = false
按照文档)我得到:
error[E0152]: duplicate lang item in crate `std` (which `serde` depends on): `panic_impl`
|
= note: the lang item is first defined in crate `wdk_panic` (which `drv` depends on)
= note: first definition in `wdk_panic` loaded from \\?\C:\Users\user\git\drv\driver\target\debug\deps\libwdk_panic-4cc9693e0f1d2bfe.rmeta
= note: second definition in `std` loaded from \\?\C:\Users\user\.rustup\toolchains\nightly-2024-10-26-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\libstd-60ed92c773e701f8.rlib
我按照以下说明在我的驱动程序项目中使用 serde
[package]
name = "drv"
version = "0.0.2"
edition = "2021"
build = "build.rs"
[package.metadata.wdk.driver-model]
driver-type = "WDM"
[lib]
crate-type = ["cdylib"]
test = false
[features]
default = []
nightly = ["wdk/nightly", "wdk-sys/nightly"]
[dependencies]
wdk = "0.3.0"
wdk-alloc = "0.3.0"
wdk-sys = "0.3.0"
wdk-build = "0.3.0"
wdk-panic = "0.3.0"
shared_no_std = { path = "../shared_no_std" }
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
serde_json = {version = "1.0.132", default-features = false, features = ["alloc"] }
[profile.dev]
panic = "abort"
lto = true
[profile.release]
panic = "abort"
lto = true
[build-dependencies]
wdk-build = "0.3.0"
在我的lib.rs
:
#![no_std]
extern crate alloc;
#[cfg(not(test))]
extern crate wdk_panic;
use wdk_panic as _;
use core::core_callback_notify_ps;
use ::core::ptr::null_mut;
use wdk::{nt_success, println};
#[cfg(not(test))]
use wdk_alloc::WdkAllocator;
mod ffi;
mod utils;
mod device_comms;
mod core;
#[cfg(not(test))]
#[global_allocator]
static GLOBAL_ALLOCATOR: WdkAllocator = WdkAllocator;
我认为我已经设置好了一切,可以no_std
从 serde 中使用 - 我还检查了删除本地 crate 的依赖项shared_no_std
,但仍然出现相同的错误。它似乎是通过 serde 从 std 重新实现 panic_impl?
我还将以下内容添加到我的shared_no_std(按照一个堆栈溢出答案,但这没有任何改变,在此之前我只是声明它是no_std):
#![cfg_attr(not(feature = "std"), no_std)]
输出cargo tree -i serde -e features
PS C:\Users\User\git\drv\driver> cargo tree -i serde -e features
serde v1.0.215
└── serde_json v1.0.132
└── serde_json feature "alloc"
├── drv v0.0.2 (C:\Users\User\git\drv\driver)
│ └── drv feature "default" (command-line)
└── shared_no_std v0.0.2 (C:\Users\User\git\drv\shared_no_std)
└── drv v0.0.2 (C:\Users\User\git\drv\driver) (*)
├── serde feature "alloc"
│ ├── drv v0.0.2 (C:\Users\User\git\drv\driver) (*)
│ └── shared_no_std v0.0.2 (C:\Users\User\git\drv\shared_no_std) (*)
│ └── serde_json feature "alloc" (*)
├── serde feature "derive"
│ ├── drv v0.0.2 (C:\Users\User\git\drv\driver) (*)
│ └── shared_no_std v0.0.2 (C:\Users\User\git\drv\shared_no_std) (*)
└── serde feature "serde_derive"
└── serde feature "derive" (*)
serde v1.0.215
├── semver v1.0.23
│ ├── semver feature "default"
│ │ └── cargo_metadata v0.18.1
│ │ └── cargo_metadata feature "default"
│ │ └── wdk-build v0.3.0
│ │ └── wdk-build feature "default"
│ │ └── drv v0.0.2 (C:\Users\User\git\drv\driver) (*)
│ │ [build-dependencies]
│ │ ├── drv v0.0.2 (C:\Users\User\git\drv\driver) (*)
│ │ ├── wdk v0.3.0
│ │ │ ├── wdk feature "alloc"
│ │ │ │ └── wdk feature "default"
│ │ │ │ └── drv v0.0.2 (C:\Users\User\git\drv\driver) (*)
│ │ │ └── wdk feature "default" (*)
│ │ ├── wdk-alloc v0.3.0
│ │ │ └── wdk-alloc feature "default"
│ │ │ └── drv v0.0.2 (C:\Users\User\git\drv\driver) (*)
│ │ └── wdk-sys v0.3.0
│ │ └── wdk-sys feature "default"
│ │ ├── drv v0.0.2 (C:\Users\User\git\drv\driver) (*)
│ │ ├── wdk v0.3.0 (*)
│ │ └── wdk-alloc v0.3.0 (*)
│ │ [build-dependencies]
│ │ └── wdk-sys v0.3.0 (*)
│ ├── semver feature "serde"
│ │ └── cargo_metadata v0.18.1 (*)
│ └── semver feature "std"
│ └── semver feature "default" (*)
└── serde_json v1.0.132
├── serde_json feature "default"
│ ├── cargo_metadata v0.18.1 (*)
│ └── wdk-build v0.3.0 (*)
│ [build-dependencies]
│ └── wdk-sys v0.3.0 (*)
├── serde_json feature "std"
│ └── serde_json feature "default" (*)
└── serde_json feature "unbounded_depth"
└── cargo_metadata v0.18.1 (*)
├── serde feature "default"
│ ├── camino v1.1.9
│ │ ├── camino feature "default"
│ │ │ ├── cargo_metadata v0.18.1 (*)
│ │ │ └── wdk-build v0.3.0 (*)
│ │ ├── camino feature "serde"
│ │ │ └── camino feature "serde1"
│ │ │ └── cargo_metadata v0.18.1 (*)
│ │ └── camino feature "serde1" (*)
│ ├── cargo-platform v0.1.8
│ │ └── cargo-platform feature "default"
│ │ └── cargo_metadata v0.18.1 (*)
│ ├── cargo_metadata v0.18.1 (*)
│ └── wdk-build v0.3.0 (*)
├── serde feature "derive"
│ ├── camino v1.1.9 (*)
│ ├── cargo_metadata v0.18.1 (*)
│ └── wdk-build v0.3.0 (*)
├── serde feature "serde_derive"
│ └── serde feature "derive" (*)
└── serde feature "std"
├── serde feature "default" (*)
└── serde_json feature "std" (*)
wdk-build
从 中删除[dependencies]
(仅保留在 中[build-dependencies]
)。此包应该在构建期间使用,而不是在运行时使用,并且它使用非#![no_std]
包和功能。