当使用 serde 构建我的驱动程序时(
default-features = false
,根据 docs),我得到:
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 `sanctum` depends on)
= note: first definition in `wdk_panic` loaded from \\?\C:\Users\user\git\sanctum\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 = "sanctum"
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;
我认为我已将所有内容设置为使用 serde 中的
no_std
- 我还检查了删除本地板条箱 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\sanctum\driver> cargo tree -i serde -e features
serde v1.0.215
└── serde_json v1.0.132
└── serde_json feature "alloc"
├── sanctum v0.0.2 (C:\Users\User\git\sanctum\driver)
│ └── sanctum feature "default" (command-line)
└── shared_no_std v0.0.2 (C:\Users\User\git\sanctum\shared_no_std)
└── sanctum v0.0.2 (C:\Users\User\git\sanctum\driver) (*)
├── serde feature "alloc"
│ ├── sanctum v0.0.2 (C:\Users\User\git\sanctum\driver) (*)
│ └── shared_no_std v0.0.2 (C:\Users\User\git\sanctum\shared_no_std) (*)
│ └── serde_json feature "alloc" (*)
├── serde feature "derive"
│ ├── sanctum v0.0.2 (C:\Users\User\git\sanctum\driver) (*)
│ └── shared_no_std v0.0.2 (C:\Users\User\git\sanctum\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"
│ │ └── sanctum v0.0.2 (C:\Users\User\git\sanctum\driver) (*)
│ │ [build-dependencies]
│ │ ├── sanctum v0.0.2 (C:\Users\User\git\sanctum\driver) (*)
│ │ ├── wdk v0.3.0
│ │ │ ├── wdk feature "alloc"
│ │ │ │ └── wdk feature "default"
│ │ │ │ └── sanctum v0.0.2 (C:\Users\User\git\sanctum\driver) (*)
│ │ │ └── wdk feature "default" (*)
│ │ ├── wdk-alloc v0.3.0
│ │ │ └── wdk-alloc feature "default"
│ │ │ └── sanctum v0.0.2 (C:\Users\User\git\sanctum\driver) (*)
│ │ └── wdk-sys v0.3.0
│ │ └── wdk-sys feature "default"
│ │ ├── sanctum v0.0.2 (C:\Users\User\git\sanctum\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]
板条箱和功能。