diff --git a/Cargo.toml b/Cargo.toml index 87f1f7a..41576b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Meteor Detection Team"] description = "A Raspberry Pi based meteor detection system" [features] -# 默认features,在Linux上自动包含gpio +# 默认features default = [] # 如果在Linux上运行,则默认启用GPIO support @@ -14,6 +14,14 @@ default = [] [target.'cfg(target_os = "linux")'.features] default = ["gpio"] +# 树莓派特定target配置 +[target.'cfg(all(target_os = "linux", target_arch = "arm"))'.features] +default = ["gpio"] + +# 64位树莓派target配置 +[target.'cfg(all(target_os = "linux", target_arch = "aarch64"))'.features] +default = ["gpio"] + # 定义常规的features (全平台通用) gpio = ["rppal", "embedded-hal"] # Feature to enable GPIO functionality opencv-4-11-plus = [] # For OpenCV 4.11 and newer versions diff --git a/build.rs b/build.rs index 34d4e5c..f4c2399 100644 --- a/build.rs +++ b/build.rs @@ -8,11 +8,14 @@ fn main() { let supports_gpio = detect_gpio_support(); // 设置环境变量,告诉lib.rs是否有实际的GPIO支持 - // 注意:这只影响PLATFORM_SUPPORTS_GPIO的值,不影响依赖的启用 if supports_gpio { // 设置编译器配置,lib.rs会使用它 println!("cargo:rustc-env=HAS_GPIO_SUPPORT=true"); println!("cargo:warning=GPIO support detected, PLATFORM_SUPPORTS_GPIO will be true"); + + // 强制启用gpio feature,确保依赖包含rppal + println!("cargo:rustc-cfg=feature=\"gpio\""); + println!("cargo:warning=Also enabling gpio feature to include rppal dependency"); } else if cfg!(target_os = "linux") { // 特殊情况:Linux但没有GPIO支持 println!("cargo:rustc-env=HAS_GPIO_SUPPORT=false"); diff --git a/src/lib.rs b/src/lib.rs index 0251ecc..e756e8c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,6 +6,10 @@ pub const PLATFORM_SUPPORTS_GPIO: bool = option_env!("HAS_GPIO_SUPPORT").map_or( #[cfg(not(feature = "gpio"))] pub const PLATFORM_SUPPORTS_GPIO: bool = false; +// 强制在条件编译中使用rppal库,解决编译依赖问题 +#[cfg(all(feature = "gpio", target_os = "linux"))] +pub use rppal; + // 将所有模块重新导出,使它们对例子可见 pub mod camera; pub mod config; diff --git a/src/sensors/dht22.rs b/src/sensors/dht22.rs index 6bed672..6d9de0b 100644 --- a/src/sensors/dht22.rs +++ b/src/sensors/dht22.rs @@ -7,6 +7,10 @@ use std::sync::Mutex; #[cfg(feature = "gpio")] use rppal::gpio::{Gpio, Level, Mode, OutputPin}; +// 确保即使启用了gpio feature,但在非Linux平台上也不尝试使用rppal +#[cfg(all(feature = "gpio", not(target_os = "linux")))] +compile_error!("GPIO feature enabled but not on Linux platform"); + #[cfg(not(feature = "gpio"))] use rand::Rng;