Skip to content

Commit 99b93d3

Browse files
authored
feat: add a ci job for windows builds (#60)
1 parent f5ca3b2 commit 99b93d3

File tree

7 files changed

+43
-15
lines changed

7 files changed

+43
-15
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ jobs:
5050
rustfmt --check "$file"
5151
done
5252
53+
build-windows:
54+
name: Build the project (Windows)
55+
runs-on: windows-latest
56+
env:
57+
RUSTFLAGS: -D warnings
58+
steps:
59+
- uses: actions/checkout@v4
60+
- uses: dtolnay/rust-toolchain@stable
61+
with:
62+
toolchain: stable
63+
64+
- name: Build the project with all the features
65+
run: cargo build --all-features
66+
67+
- name: Build the project with nusb support
68+
run: cargo build --no-default-features --features nusb
69+
70+
- name: Build the examples
71+
run: cargo build --examples
72+
5373
build:
5474
name: Build the project
5575
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ default = ["rusb"]
2828
[dependencies]
2929
rand = "0.9"
3030
bitflags = "2.4"
31-
rusb = { version = "0.9", optional = true }
32-
nusb = { version = "0.1", optional = true }
3331
structure = "0.1"
3432
aes = "0.8"
3533
block-modes = "0.9"
3634
hmac = "0.12"
3735
sha-1 = "0.10"
3836

37+
[target.'cfg(windows)'.dependencies]
38+
rusb = { version = "0.9" }
39+
40+
[target.'cfg(not(windows))'.dependencies]
41+
rusb = { version = "0.9", optional = true }
42+
nusb = { version = "0.1", optional = true }
43+
3944
[dev-dependencies]
4045
hex = "0.4"

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ challenge_response = { version = "0", default-features = false, features = ["nus
5050
The `nusb` backend has the advantage of not depending on `libusb`, thus making it easier to add
5151
`challenge_response` to your dependencies.
5252

53+
> [!NOTE]
54+
> The `nusb` feature is not available on Windows. If configured, the library will default to using the `rusb` backend instead.
55+
5356
### Perform a Challenge-Response (HMAC-SHA1 mode)
5457

5558
If you are using a YubiKey, you can configure the HMAC-SHA1 Challenge-Response

src/error.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(feature = "rusb")]
1+
#[cfg(any(feature = "rusb", target_os = "windows"))]
22
use rusb::Error as usbError;
33
use std::error;
44
use std::fmt;
@@ -7,7 +7,7 @@ use std::io::Error as ioError;
77
#[derive(Debug)]
88
pub enum ChallengeResponseError {
99
IOError(ioError),
10-
#[cfg(feature = "rusb")]
10+
#[cfg(any(feature = "rusb", target_os = "windows"))]
1111
UsbError(usbError),
1212
CommandNotSupported,
1313
DeviceNotFound,
@@ -23,7 +23,7 @@ impl fmt::Display for ChallengeResponseError {
2323
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2424
match *self {
2525
ChallengeResponseError::IOError(ref err) => write!(f, "IO error: {}", err),
26-
#[cfg(feature = "rusb")]
26+
#[cfg(any(feature = "rusb", target_os = "windows"))]
2727
ChallengeResponseError::UsbError(ref err) => write!(f, "USB error: {}", err),
2828
ChallengeResponseError::DeviceNotFound => write!(f, "Device not found"),
2929
ChallengeResponseError::OpenDeviceError => write!(f, "Can not open device"),
@@ -40,7 +40,7 @@ impl fmt::Display for ChallengeResponseError {
4040
impl error::Error for ChallengeResponseError {
4141
fn cause(&self) -> Option<&dyn error::Error> {
4242
match *self {
43-
#[cfg(feature = "rusb")]
43+
#[cfg(any(feature = "rusb", target_os = "windows"))]
4444
ChallengeResponseError::UsbError(ref err) => Some(err),
4545
_ => None,
4646
}
@@ -53,7 +53,7 @@ impl From<ioError> for ChallengeResponseError {
5353
}
5454
}
5555

56-
#[cfg(feature = "rusb")]
56+
#[cfg(any(feature = "rusb", target_os = "windows"))]
5757
impl From<usbError> for ChallengeResponseError {
5858
fn from(err: usbError) -> ChallengeResponseError {
5959
ChallengeResponseError::UsbError(err)

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#[cfg(not(any(feature = "rusb", feature = "nusb")))]
44
compile_error!("Either the rusb or nusb feature must be enabled for this crate");
55

6-
#[cfg(feature = "nusb")]
6+
#[cfg(all(feature = "nusb", not(feature = "rusb"), not(target_os = "windows")))]
77
extern crate nusb;
8-
#[cfg(feature = "rusb")]
8+
#[cfg(any(feature = "rusb", target_os = "windows"))]
99
extern crate rusb;
1010

1111
#[macro_use]

src/usb.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use config::Command;
55
use error::ChallengeResponseError;
66
use sec::crc16;
77

8-
#[cfg(feature = "rusb")]
8+
#[cfg(any(feature = "rusb", target_os = "windows"))]
99
pub type BackendType = rusb::RUSBBackend;
10-
#[cfg(all(feature = "nusb", not(feature = "rusb")))]
10+
#[cfg(all(feature = "nusb", not(feature = "rusb"), not(target_os = "windows")))]
1111
pub type BackendType = nusb::NUSBBackend;
1212

1313
/// If using a variable-length challenge, the challenge must be stricly smaller than this value.
@@ -27,9 +27,9 @@ const PRODUCT_ID: [u16; 11] = [
2727
0x4211, // NitroKey
2828
];
2929

30-
#[cfg(all(feature = "nusb", not(feature = "rusb")))]
30+
#[cfg(all(feature = "nusb", not(feature = "rusb"), not(target_os = "windows")))]
3131
pub mod nusb;
32-
#[cfg(feature = "rusb")]
32+
#[cfg(any(feature = "rusb", target_os = "windows"))]
3333
pub mod rusb;
3434

3535
/// The size of the payload when writing a request to the usb interface.

src/usb/rusb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ impl Backend<DeviceHandle<Context>, u8> for RUSBBackend {
8080
#[cfg(any(target_os = "macos", target_os = "windows"))]
8181
fn close_device(
8282
&self,
83-
mut handle: DeviceHandle<Context>,
84-
interfaces: Vec<u8>,
83+
_handle: DeviceHandle<Context>,
84+
_interfaces: Vec<u8>,
8585
) -> Result<(), ChallengeResponseError> {
8686
Ok(())
8787
}

0 commit comments

Comments
 (0)