Skip to content

Commit

Permalink
Fix cross-compilation for Microsoft windows
Browse files Browse the repository at this point in the history
  • Loading branch information
X3n0m0rph59 committed Dec 17, 2023
1 parent 40e0a80 commit 30d3849
Show file tree
Hide file tree
Showing 36 changed files with 142 additions and 31 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
token: ${{ secrets.GITHUB_TOKEN }}
components: clippy
- run: cargo clippy --all
tests:
Expand All @@ -45,6 +44,5 @@ jobs:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
toolchain: ${{ matrix.rust }}
- run: cargo build --all
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions eruption/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ resolver = "2"

[features]
default = ["dbus-ipc", "openrgb_bridge", "udev", "evdev-rs"]
windows = [
"dbus-ipc",
"winapi",
"usb_enumeration",
"windows-named-pipe",
"hwaccel",
]
windows = ["dbus-ipc", "winapi", "usb_enumeration", "windows-named-pipe"]
dbus-ipc = ["dbus", "dbus-tree"]
mimalloc_allocator = ["mimalloc"]
openrgb_bridge = ["openrgb"]
Expand Down
46 changes: 28 additions & 18 deletions eruption/src/hwdevices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use std::u8;
use std::{any::Any, sync::Arc, thread};
use std::{path::PathBuf, time::Duration};

use cfg_if::cfg_if;
#[cfg(not(target_os = "windows"))]
use evdev_rs::enums::EV_KEY;
use eyre::eyre;
Expand All @@ -41,6 +42,7 @@ use udev::Enumerator;

use crate::constants;
use crate::hwdevices::{keyboards::*, mice::*, misc::*};
use crate::util::ratelimited;

mod util;

Expand Down Expand Up @@ -1058,7 +1060,9 @@ pub trait DeviceExt: DeviceInfoExt + DeviceZoneAllocationExt {
/// Get the device status
fn device_status(&self) -> Result<DeviceStatus>;

#[cfg(not(target_os = "windows"))]
fn get_evdev_input_rx(&self) -> &Option<flume::Receiver<Option<evdev_rs::InputEvent>>>;
#[cfg(not(target_os = "windows"))]
fn set_evdev_input_rx(&mut self, rx: Option<flume::Receiver<Option<evdev_rs::InputEvent>>>);

fn get_device_class(&self) -> DeviceClass;
Expand Down Expand Up @@ -1285,27 +1289,33 @@ pub fn probe_devices() -> Result<Vec<Device>> {

for device in declared_devices {
if device.class == "openrgb" {
info!(
"Binding device: {} ({})",
device.name,
device.device_file.display()
);
cfg_if! {
if #[cfg(openrgb_bridge )] {
info!(
"Binding device: {} ({})",
device.name,
device.device_file.display()
);

{
let mut pending_devices = crate::DEVICES_PENDING_INIT.0.lock().unwrap();
*pending_devices += 1;

crate::DEVICES_PENDING_INIT.1.notify_all();
}

{
let mut pending_devices = crate::DEVICES_PENDING_INIT.0.lock().unwrap();
*pending_devices += 1;
let device = openrgb_bridge::OpenRgbBridge::bind(
device.device_file.to_string_lossy().to_string(),
);

crate::DEVICES_PENDING_INIT.1.notify_all();
// non pnp devices are currently always 'misc' devices
devices.push(Arc::new(RwLock::new(
Box::new(device) as Box<dyn DeviceExt + Sync + Send>
)));
} else {
ratelimited::warn!("The OpenRGB virtual bridge device is not available in this build of Eruption");
}
}

let device = openrgb_bridge::OpenRgbBridge::bind(
device.device_file.to_string_lossy().to_string(),
);

// non pnp devices are currently always 'misc' devices
devices.push(Arc::new(RwLock::new(
Box::new(device) as Box<dyn DeviceExt + Sync + Send>
)));
} else if device.class == "serial" {
info!(
"Binding non-pnp serial LEDs device: {} ({})",
Expand Down
4 changes: 4 additions & 0 deletions eruption/src/hwdevices/keyboards/corsair_strafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub enum DialMode {
#[derive(Clone)]
/// Device specific code for the Corsair STRAFE series keyboards
pub struct CorsairStrafe {
#[cfg(not(target_os = "windows"))]
pub evdev_rx: Option<Receiver<Option<evdev_rs::InputEvent>>>,

pub is_initialized: bool,
Expand Down Expand Up @@ -130,6 +131,7 @@ impl CorsairStrafe {
debug!("Bound driver: Corsair STRAFE Gaming Keyboard");

Self {
#[cfg(not(target_os = "windows"))]
evdev_rx: None,

is_initialized: false,
Expand Down Expand Up @@ -863,10 +865,12 @@ impl DeviceExt for CorsairStrafe {
None
}

#[cfg(not(target_os = "windows"))]
fn get_evdev_input_rx(&self) -> &Option<flume::Receiver<Option<evdev_rs::InputEvent>>> {
&self.evdev_rx
}

#[cfg(not(target_os = "windows"))]
fn set_evdev_input_rx(&mut self, rx: Option<flume::Receiver<Option<evdev_rs::InputEvent>>>) {
self.evdev_rx = rx;
}
Expand Down
2 changes: 2 additions & 0 deletions eruption/src/hwdevices/keyboards/generic_keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,12 @@ impl DeviceExt for GenericKeyboard {
None
}

#[cfg(not(target_os = "windows"))]
fn get_evdev_input_rx(&self) -> &Option<flume::Receiver<Option<evdev_rs::InputEvent>>> {
&None
}

#[cfg(not(target_os = "windows"))]
fn set_evdev_input_rx(&mut self, _rx: Option<flume::Receiver<Option<evdev_rs::InputEvent>>>) {
// do nothing
}
Expand Down
4 changes: 4 additions & 0 deletions eruption/src/hwdevices/keyboards/roccat_magma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub enum DialMode {
#[derive(Clone)]
/// Device specific code for the ROCCAT Magma series keyboards
pub struct RoccatMagma {
#[cfg(not(target_os = "windows"))]
pub evdev_rx: Option<Receiver<Option<evdev_rs::InputEvent>>>,

pub is_initialized: bool,
Expand Down Expand Up @@ -130,6 +131,7 @@ impl RoccatMagma {
debug!("Bound driver: ROCCAT Magma");

Self {
#[cfg(not(target_os = "windows"))]
evdev_rx: None,

is_initialized: false,
Expand Down Expand Up @@ -973,10 +975,12 @@ impl DeviceExt for RoccatMagma {
None
}

#[cfg(not(target_os = "windows"))]
fn get_evdev_input_rx(&self) -> &Option<flume::Receiver<Option<evdev_rs::InputEvent>>> {
&self.evdev_rx
}

#[cfg(not(target_os = "windows"))]
fn set_evdev_input_rx(&mut self, rx: Option<flume::Receiver<Option<evdev_rs::InputEvent>>>) {
self.evdev_rx = rx;
}
Expand Down
4 changes: 4 additions & 0 deletions eruption/src/hwdevices/keyboards/roccat_pyro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub enum DialMode {
#[derive(Clone)]
/// Device specific code for the ROCCAT Pyro series keyboards
pub struct RoccatPyro {
#[cfg(not(target_os = "windows"))]
pub evdev_rx: Option<Receiver<Option<evdev_rs::InputEvent>>>,

pub is_initialized: bool,
Expand Down Expand Up @@ -129,6 +130,7 @@ impl RoccatPyro {
debug!("Bound driver: ROCCAT Pyro");

Self {
#[cfg(not(target_os = "windows"))]
evdev_rx: None,

is_initialized: false,
Expand Down Expand Up @@ -834,10 +836,12 @@ impl DeviceExt for RoccatPyro {
None
}

#[cfg(not(target_os = "windows"))]
fn get_evdev_input_rx(&self) -> &Option<flume::Receiver<Option<evdev_rs::InputEvent>>> {
&self.evdev_rx
}

#[cfg(not(target_os = "windows"))]
fn set_evdev_input_rx(&mut self, rx: Option<flume::Receiver<Option<evdev_rs::InputEvent>>>) {
self.evdev_rx = rx;
}
Expand Down
4 changes: 4 additions & 0 deletions eruption/src/hwdevices/keyboards/roccat_vulcan_1xx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub enum DialMode {
#[derive(Clone)]
/// Device specific code for the ROCCAT Vulcan 100/12x series keyboards
pub struct RoccatVulcan1xx {
#[cfg(not(target_os = "windows"))]
pub evdev_rx: Option<Receiver<Option<evdev_rs::InputEvent>>>,

pub is_initialized: bool,
Expand Down Expand Up @@ -135,6 +136,7 @@ impl RoccatVulcan1xx {
debug!("Bound driver: ROCCAT Vulcan 100/12x AIMO");

Self {
#[cfg(not(target_os = "windows"))]
evdev_rx: None,

is_initialized: false,
Expand Down Expand Up @@ -1042,10 +1044,12 @@ impl DeviceExt for RoccatVulcan1xx {
None
}

#[cfg(not(target_os = "windows"))]
fn get_evdev_input_rx(&self) -> &Option<flume::Receiver<Option<evdev_rs::InputEvent>>> {
&self.evdev_rx
}

#[cfg(not(target_os = "windows"))]
fn set_evdev_input_rx(&mut self, rx: Option<flume::Receiver<Option<evdev_rs::InputEvent>>>) {
self.evdev_rx = rx;
}
Expand Down
4 changes: 4 additions & 0 deletions eruption/src/hwdevices/keyboards/roccat_vulcan_2_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub enum DialMode {
#[derive(Clone)]
/// Device specific code for the ROCCAT Vulcan 100/12x series keyboards
pub struct RoccatVulcan2Max {
#[cfg(not(target_os = "windows"))]
pub evdev_rx: Option<Receiver<Option<evdev_rs::InputEvent>>>,

pub is_initialized: bool,
Expand Down Expand Up @@ -137,6 +138,7 @@ impl RoccatVulcan2Max {
debug!("Bound driver: ROCCAT Vulcan II Max");

Self {
#[cfg(not(target_os = "windows"))]
evdev_rx: None,

is_initialized: false,
Expand Down Expand Up @@ -798,10 +800,12 @@ impl DeviceExt for RoccatVulcan2Max {
None
}

#[cfg(not(target_os = "windows"))]
fn get_evdev_input_rx(&self) -> &Option<flume::Receiver<Option<evdev_rs::InputEvent>>> {
&self.evdev_rx
}

#[cfg(not(target_os = "windows"))]
fn set_evdev_input_rx(&mut self, rx: Option<flume::Receiver<Option<evdev_rs::InputEvent>>>) {
self.evdev_rx = rx;
}
Expand Down
4 changes: 4 additions & 0 deletions eruption/src/hwdevices/keyboards/roccat_vulcan_pro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub enum DialMode {
#[derive(Clone)]
/// Device specific code for the ROCCAT Vulcan Pro series keyboards
pub struct RoccatVulcanPro {
#[cfg(not(target_os = "windows"))]
pub evdev_rx: Option<Receiver<Option<evdev_rs::InputEvent>>>,

pub is_initialized: bool,
Expand Down Expand Up @@ -133,6 +134,7 @@ impl RoccatVulcanPro {
debug!("Bound driver: ROCCAT Vulcan Pro");

Self {
#[cfg(not(target_os = "windows"))]
evdev_rx: None,

is_initialized: false,
Expand Down Expand Up @@ -841,10 +843,12 @@ impl DeviceExt for RoccatVulcanPro {
None
}

#[cfg(not(target_os = "windows"))]
fn get_evdev_input_rx(&self) -> &Option<flume::Receiver<Option<evdev_rs::InputEvent>>> {
&self.evdev_rx
}

#[cfg(not(target_os = "windows"))]
fn set_evdev_input_rx(&mut self, rx: Option<flume::Receiver<Option<evdev_rs::InputEvent>>>) {
self.evdev_rx = rx;
}
Expand Down
4 changes: 4 additions & 0 deletions eruption/src/hwdevices/keyboards/roccat_vulcan_pro_tkl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pub enum DialMode {
#[derive(Clone)]
/// Device specific code for the ROCCAT Vulcan Pro TKL series keyboards
pub struct RoccatVulcanProTKL {
#[cfg(not(target_os = "windows"))]
pub evdev_rx: Option<Receiver<Option<evdev_rs::InputEvent>>>,

pub is_initialized: bool,
Expand Down Expand Up @@ -137,6 +138,7 @@ impl RoccatVulcanProTKL {
debug!("Bound driver: ROCCAT Vulcan Pro TKL");

Self {
#[cfg(not(target_os = "windows"))]
evdev_rx: None,

is_initialized: false,
Expand Down Expand Up @@ -850,10 +852,12 @@ impl DeviceExt for RoccatVulcanProTKL {
None
}

#[cfg(not(target_os = "windows"))]
fn get_evdev_input_rx(&self) -> &Option<flume::Receiver<Option<evdev_rs::InputEvent>>> {
&self.evdev_rx
}

#[cfg(not(target_os = "windows"))]
fn set_evdev_input_rx(&mut self, rx: Option<flume::Receiver<Option<evdev_rs::InputEvent>>>) {
self.evdev_rx = rx;
}
Expand Down
4 changes: 4 additions & 0 deletions eruption/src/hwdevices/keyboards/roccat_vulcan_tkl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pub enum DialMode {
#[derive(Clone)]
/// Device specific code for the ROCCAT Vulcan TKL series keyboards
pub struct RoccatVulcanTKL {
#[cfg(not(target_os = "windows"))]
pub evdev_rx: Option<Receiver<Option<evdev_rs::InputEvent>>>,

pub is_initialized: bool,
Expand Down Expand Up @@ -134,6 +135,7 @@ impl RoccatVulcanTKL {
debug!("Bound driver: ROCCAT Vulcan TKL");

Self {
#[cfg(not(target_os = "windows"))]
evdev_rx: None,

is_initialized: false,
Expand Down Expand Up @@ -975,10 +977,12 @@ impl DeviceExt for RoccatVulcanTKL {
None
}

#[cfg(not(target_os = "windows"))]
fn get_evdev_input_rx(&self) -> &Option<flume::Receiver<Option<evdev_rs::InputEvent>>> {
&self.evdev_rx
}

#[cfg(not(target_os = "windows"))]
fn set_evdev_input_rx(&mut self, rx: Option<flume::Receiver<Option<evdev_rs::InputEvent>>>) {
self.evdev_rx = rx;
}
Expand Down
4 changes: 4 additions & 0 deletions eruption/src/hwdevices/keyboards/wooting_two_he_arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ pub struct DeviceInfo {
#[derive(Clone)]
/// Device specific code for the Wooting Two HE (ARM) series keyboards
pub struct WootingTwoHeArm {
#[cfg(not(target_os = "windows"))]
pub evdev_rx: Option<Receiver<Option<evdev_rs::InputEvent>>>,

pub is_initialized: bool,
Expand Down Expand Up @@ -158,6 +159,7 @@ impl WootingTwoHeArm {
debug!("Bound driver: Wooting Two HE (ARM)");

Self {
#[cfg(not(target_os = "windows"))]
evdev_rx: None,

is_initialized: false,
Expand Down Expand Up @@ -882,10 +884,12 @@ impl DeviceExt for WootingTwoHeArm {
None
}

#[cfg(not(target_os = "windows"))]
fn get_evdev_input_rx(&self) -> &Option<flume::Receiver<Option<evdev_rs::InputEvent>>> {
&self.evdev_rx
}

#[cfg(not(target_os = "windows"))]
fn set_evdev_input_rx(&mut self, rx: Option<flume::Receiver<Option<evdev_rs::InputEvent>>>) {
self.evdev_rx = rx;
}
Expand Down
Loading

0 comments on commit 30d3849

Please sign in to comment.