Skip to content

Commit 260a100

Browse files
authored
Merge pull request #167 from xobs/add-basic-udev-option
Add `linux-native-basic-udev` feature
2 parents c45aecf + 7c67945 commit 260a100

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

.github/workflows/rust.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,28 @@ jobs:
8989
- name: Verify package
9090
run: cargo package --no-default-features --features linux-native --verbose
9191

92+
build-linux-native-basic-udev:
93+
runs-on: ubuntu-latest
94+
env:
95+
DEBIAN_FRONTEND: noninteractive
96+
steps:
97+
- name: Checkout repository and submodules
98+
uses: actions/checkout@v4
99+
with:
100+
submodules: recursive
101+
- name: Install dependencies
102+
run: |
103+
sudo apt-get update -y
104+
sudo apt-get install -y libudev-dev
105+
- name: Install Rust toolchain
106+
uses: dtolnay/rust-toolchain@stable
107+
- name: Build
108+
run: cargo build --no-default-features --features linux-native-basic-udev --verbose
109+
- name: Run tests
110+
run: cargo test --no-default-features --features linux-native-basic-udev --verbose
111+
- name: Verify package
112+
run: cargo package --no-default-features --features linux-native-basic-udev --verbose
113+
92114
build-windows:
93115
runs-on: windows-latest
94116
steps:
@@ -121,6 +143,22 @@ jobs:
121143
- name: Verify package
122144
run: cargo package --no-default-features --features windows-native --verbose
123145

146+
build-linux-on-windows:
147+
runs-on: windows-latest
148+
steps:
149+
- name: Checkout repository and submodules
150+
uses: actions/checkout@v4
151+
with:
152+
submodules: recursive
153+
- name: Install Rust toolchain
154+
uses: dtolnay/rust-toolchain@stable
155+
- name: Install Linux target
156+
run: rustup target add arm-unknown-linux-musleabihf
157+
- name: Build
158+
run: cargo build --target arm-unknown-linux-musleabihf --no-default-features --features linux-native-basic-udev --verbose
159+
- name: Verify package
160+
run: cargo package --target arm-unknown-linux-musleabihf --no-default-features --features linux-native-basic-udev --verbose
161+
124162
build-macos:
125163
runs-on: macos-latest
126164
steps:

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ linux-static-hidraw = []
4848
linux-shared-libusb = []
4949
linux-shared-hidraw = []
5050
linux-native = ["dep:udev", "dep:nix"]
51+
linux-native-basic-udev = ["dep:basic-udev", "dep:nix"]
5152
illumos-static-libusb = []
5253
illumos-shared-libusb = []
5354
macos-shared-device = []
@@ -69,6 +70,7 @@ cfg-if = "1"
6970

7071
[target.'cfg(target_os = "linux")'.dependencies]
7172
udev = { version = "0.8", optional = true }
73+
basic-udev = { version = "0.1", optional = true }
7274
nix = { version = "0.27", optional = true, features = ["fs", "ioctl", "poll"] }
7375

7476
[target.'cfg(windows)'.dependencies]

build.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn compile_linux() {
4949
// First check the features enabled for the crate.
5050
// Only one linux backend should be enabled at a time.
5151

52-
let avail_backends: [(&'static str, Box<dyn Fn()>); 5] = [
52+
let avail_backends: [(&'static str, Box<dyn Fn()>); 6] = [
5353
(
5454
"LINUX_STATIC_HIDRAW",
5555
Box::new(|| {
@@ -106,6 +106,15 @@ fn compile_linux() {
106106
// The udev crate takes care of finding its library
107107
}),
108108
),
109+
(
110+
"LINUX_NATIVE_BASIC_UDEV",
111+
Box::new(|| {
112+
// Enable `feature="linux-native"` to reuse the existing
113+
// linux-native code. It is considered an error in
114+
// basic-udev if this fails to compile.
115+
println!("cargo:rustc-cfg=feature=\"linux-native\"");
116+
}),
117+
),
109118
];
110119

111120
let mut backends = avail_backends

src/linux_native.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
33
mod ioctl;
44

5+
#[cfg(feature = "linux-native-basic-udev")]
6+
use basic_udev as udev;
7+
58
use std::{
69
cell::{Cell, Ref, RefCell},
710
ffi::{CStr, CString, OsStr, OsString},

0 commit comments

Comments
 (0)