Skip to content

Commit d85563a

Browse files
authored
Auto-select the nusb backend on Linux (#134)
Linux auto-selects hidra's nusb backend via a target-specific dependency; CI collapses to a single Linux variant. Uses published hidra 0.0.2 (macOS run-loop fix).
1 parent b9519fa commit d85563a

3 files changed

Lines changed: 19 additions & 27 deletions

File tree

.github/workflows/push.yml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ jobs:
5656
~/.cargo/registry
5757
./target
5858
key: test-cargo-registry
59-
- name: Run tests (hidraw backend)
59+
- name: Run tests
6060
run: cargo test --workspace --lib --bins --verbose
61-
- name: Run tests (nusb backend)
62-
run: cargo test --workspace --lib --bins --features nusb --verbose
6361

6462
wasm:
6563
runs-on: ubuntu-latest
@@ -84,31 +82,19 @@ jobs:
8482
fail-fast: false
8583
matrix:
8684
include:
87-
# Two Linux variants: the default hidraw backend and the nusb backend.
85+
# Linux always uses hidra's nusb backend (auto-selected in Cargo.toml).
8886
- TARGET: x86_64-unknown-linux-gnu
8987
OS: ubuntu-latest
90-
FEATURES: ""
91-
LABEL: hidraw
92-
- TARGET: x86_64-unknown-linux-gnu
93-
OS: ubuntu-latest
94-
FEATURES: "nusb"
95-
LABEL: nusb
9688
- TARGET: x86_64-apple-darwin
9789
OS: macos-latest
98-
FEATURES: ""
99-
LABEL: ""
10090
- TARGET: x86_64-pc-windows-msvc
10191
OS: windows-latest
102-
FEATURES: ""
103-
LABEL: ""
10492
needs: test
10593
runs-on: ${{ matrix.OS }}
10694
env:
10795
NAME: sinowisp
10896
TARGET: ${{ matrix.TARGET }}
10997
OS: ${{ matrix.OS }}
110-
FEATURES: ${{ matrix.FEATURES }}
111-
LABEL: ${{ matrix.LABEL }}
11298
steps:
11399
- uses: actions/checkout@v6
114100
- name: Cargo cache
@@ -117,11 +103,11 @@ jobs:
117103
path: |
118104
~/.cargo/registry
119105
./target
120-
key: build-cargo-registry-${{matrix.TARGET}}-${{matrix.LABEL}}
106+
key: build-cargo-registry-${{matrix.TARGET}}
121107
- name: Install rust target
122108
run: rustup target add $TARGET
123109
- name: Run build
124-
run: cargo build --release --verbose --target $TARGET ${FEATURES:+--features "$FEATURES"}
110+
run: cargo build --release --verbose --target $TARGET
125111
- name: Compress
126112
run: |
127113
mkdir -p ./artifacts
@@ -136,14 +122,13 @@ jobs:
136122
else
137123
TAG=$GITHUB_SHA
138124
fi
139-
# include the backend label in the artifact name when set (Linux)
140-
ARTIFACT=$NAME-$TARGET${LABEL:+-$LABEL}-$TAG
125+
ARTIFACT=$NAME-$TARGET-$TAG
141126
mv ./target/$TARGET/release/$EXEC ./$EXEC
142127
tar -czf ./artifacts/$ARTIFACT.tar.gz $EXEC
143128
- name: Archive artifact
144129
uses: actions/upload-artifact@v7
145130
with:
146-
name: result-${{ matrix.TARGET }}${{ matrix.LABEL && format('-{0}', matrix.LABEL) || '' }}
131+
name: result-${{ matrix.TARGET }}
147132
path: |
148133
./artifacts
149134

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ cli = [
2727
"dep:log",
2828
]
2929
# Switch hidra to its nusb-based USB backend instead of the per-OS native one.
30+
# Linux always uses nusb (auto-selected via the target-specific dependency
31+
# below); this feature exists to opt into nusb on macOS/Windows as well.
3032
nusb = ["hidra/nusb"]
3133

3234
[[bin]]
@@ -35,10 +37,10 @@ path = "src/main.rs"
3537
required-features = ["cli"]
3638

3739
[dependencies]
38-
# Pure-Rust HID. On Linux the default is the hidraw backend; the `nusb`
39-
# feature switches to the nusb-based backend (the hidapi `linux-static-libusb`
40-
# equivalent).
41-
hidra = "0.0.1"
40+
# Pure-Rust HID. On macOS/Windows this uses hidra's native per-OS backend; on
41+
# Linux the nusb backend is auto-selected via the target-specific dependency
42+
# below (the hidapi `linux-static-libusb` equivalent). wasm uses WebHID.
43+
hidra = "0.0.2"
4244
ihex = "3.0"
4345
thiserror = "2.0"
4446
phf = { version = "0.11", features = ["macros"] }
@@ -59,6 +61,11 @@ default-features = false
5961
features = ["stderr", "colors", "timestamps"]
6062
optional = true
6163

64+
# On Linux there is no native hidraw path we want; always use hidra's nusb
65+
# backend. Cargo features are additive, so this is unconditional on Linux.
66+
[target.'cfg(target_os = "linux")'.dependencies]
67+
hidra = { version = "0.0.2", features = ["nusb"] }
68+
6269
[dev-dependencies]
6370
assert_cmd = "2.0.17"
6471
chrono = "0.4.41"

0 commit comments

Comments
 (0)