Skip to content

Commit

Permalink
Link dispatch instead of System outside of OSX/iOS.
Browse files Browse the repository at this point in the history
Enable travis tests for linux to verify.
This fixes #4.
  • Loading branch information
SSheldon committed May 8, 2016
1 parent ecf1197 commit 8bf13e2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ language: rust
rust:
- stable
- nightly
os: osx
os:
- osx
- linux
env:
- IOS_ARCHS=""
matrix:
Expand All @@ -14,3 +16,7 @@ matrix:
sudo: false
install: ./travis_install.sh
script: ./travis_test.sh
addons:
apt:
packages:
- libdispatch-dev
5 changes: 4 additions & 1 deletion src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ pub type dispatch_time_t = u64;
// dispatch_io_interval_flags_t
pub type dispatch_queue_attr_t = *const dispatch_object_s;

#[link(name = "System", kind = "dylib")]
#[cfg_attr(any(target_os = "macos", target_os = "ios"),
link(name = "System", kind = "dylib"))]
#[cfg_attr(not(any(target_os = "macos", target_os = "ios")),
link(name = "dispatch", kind = "dylib"))]
extern {
static _dispatch_main_q: dispatch_object_s;
static _dispatch_queue_attr_concurrent: dispatch_object_s;
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,21 @@ pub enum QueueAttribute {
}

impl QueueAttribute {
#[cfg(not(all(test, target_os = "linux")))]
fn as_raw(&self) -> dispatch_queue_attr_t {
match *self {
QueueAttribute::Serial => DISPATCH_QUEUE_SERIAL,
QueueAttribute::Concurrent => DISPATCH_QUEUE_CONCURRENT,
}
}

#[cfg(all(test, target_os = "linux"))]
fn as_raw(&self) -> dispatch_queue_attr_t {
// The Linux tests use Ubuntu's libdispatch-dev package, which is
// apparently really old from before OSX 10.7.
// Back then, the attr for dispatch_queue_create must be NULL.
ptr::null()
}
}

/// The priority of a global concurrent queue.
Expand Down
11 changes: 8 additions & 3 deletions travis_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

set -eu

if [ -z "$IOS_ARCHS" ]; then
if [ -n "$IOS_ARCHS" ]; then
./rust-test-ios
elif [ "$TRAVIS_OS_NAME" = "linux" ]; then
cargo build --verbose
cargo test --verbose
# The Ubuntu libdispatch doesn't seem to be in great shape,
# so just run a quick smoke test of the basic cases.
cargo test --verbose test_serial_queue
else
./rust-test-ios
cargo build --verbose
cargo test --verbose
fi

0 comments on commit 8bf13e2

Please sign in to comment.