Skip to content

Commit 7245698

Browse files
author
Roman Zaynetdinov
committed
Support building on macOS
1 parent 2507a76 commit 7245698

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

.travis.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ rust:
66
- beta
77
- nightly
88

9+
os:
10+
- linux
11+
- osx
12+
913
addons:
1014
apt:
1115
packages:
@@ -20,7 +24,7 @@ before_script:
2024
env:
2125
global:
2226
- TRAVIS_CARGO_NIGHTLY_FEATURE=""
23-
- PATH=$HOME/.local/bin:$PATH
27+
- PATH="$(python -m site --user-base)/bin:$PATH"
2428
- secure: "Ez5eIIgmsfNoV9NQ9H6KrAYX/Dxx6EUQEyyLMoSFvgJuMaPsyWlsDQDKbl9G+aNDNdSWYtYVFc4/fCW+H7a13HjVwB2CH2mChHSeguO8FSAkWns8tkZ+71SKL5/hg3Ig2m+kvfDjjV1O8seFEgTDP3enHFoRTmBSZHeNryo1ITM="
2529

2630
script:
@@ -34,8 +38,8 @@ script:
3438
travis-cargo --only stable doc -- --features=tokio
3539
3640
after_success:
37-
- travis-cargo --only stable doc-upload
38-
- travis-cargo coveralls --no-sudo --verify
41+
- '[ $TRAVIS_OS_NAME == linux ] && travis-cargo --only stable doc-upload'
42+
- '[ $TRAVIS_OS_NAME == linux ] && travis-cargo coveralls --no-sudo --verify'
3943

4044
notifications:
4145
webhooks: http://rust-embedded-bot.herokuapp.com/travis

src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pub enum Error {
1010
Unexpected(String),
1111
/// Invalid Path
1212
InvalidPath(String),
13+
/// Operation not supported on target os
14+
Unsupported(String),
1315
}
1416

1517
impl ::std::error::Error for Error {
@@ -18,6 +20,7 @@ impl ::std::error::Error for Error {
1820
Error::Io(ref e) => e.description(),
1921
Error::Unexpected(_) => "An Unexpected Error Occurred",
2022
Error::InvalidPath(_) => "A Provided Path was invalid",
23+
Error::Unsupported(_) => "Operation is not supported on target os",
2124
}
2225
}
2326

@@ -35,6 +38,7 @@ impl fmt::Display for Error {
3538
Error::Io(ref e) => e.fmt(f),
3639
Error::Unexpected(ref s) => write!(f, "Unexpected: {}", s),
3740
Error::InvalidPath(ref s) => write!(f, "Invalid Path: {}", s),
41+
Error::Unsupported(ref s) => write!(f, "Operation not supported on target os: {}", s),
3842
}
3943
}
4044
}

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ use mio::Evented;
6161
#[cfg(feature = "mio-evented")]
6262
use mio::unix::EventedFd;
6363

64+
#[cfg(any(target_os = "linux", target_os = "android"))]
6465
use nix::sys::epoll::*;
6566
use nix::unistd::close;
6667

@@ -469,6 +470,7 @@ impl PinPoller {
469470
}
470471

471472
/// Create a new PinPoller for the provided pin number
473+
#[cfg(any(target_os = "linux", target_os = "android"))]
472474
pub fn new(pin_num: u64) -> Result<PinPoller> {
473475
let devfile: File = try!(File::open(&format!("/sys/class/gpio/gpio{}/value", pin_num)));
474476
let devfile_fd = devfile.as_raw_fd();
@@ -494,6 +496,11 @@ impl PinPoller {
494496
}
495497
}
496498

499+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
500+
pub fn new(pin_num: u64) -> Result<PinPoller> {
501+
Err(Error::Unsupported("PinPoller".into()))
502+
}
503+
497504
/// Block until an interrupt occurs
498505
///
499506
/// This call will block until an interrupt occurs. The types
@@ -511,6 +518,7 @@ impl PinPoller {
511518
/// has occurred, but you could end up reading the same value multiple
512519
/// times as the value has changed back between when the interrupt
513520
/// occurred and the current time.
521+
#[cfg(any(target_os = "linux", target_os = "android"))]
514522
pub fn poll(&mut self, timeout_ms: isize) -> Result<Option<u8>> {
515523
try!(flush_input_from_file(&mut self.devfile, 255));
516524
let dummy_event = EpollEvent {
@@ -524,6 +532,11 @@ impl PinPoller {
524532
_ => Some(try!(get_value_from_file(&mut self.devfile))),
525533
})
526534
}
535+
536+
#[cfg(not(any(target_os = "linux", target_os = "android")))]
537+
pub fn poll(&mut self, timeout_ms: isize) -> Result<Option<u8>> {
538+
Err(Error::Unsupported("PinPoller".into()))
539+
}
527540
}
528541

529542
impl Drop for PinPoller {

0 commit comments

Comments
 (0)