diff --git a/.travis.yml b/.travis.yml index 1d7f39a..086ddb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,9 @@ language: rust rust: - stable - nightly -os: osx +os: + - osx + - linux env: - IOS_ARCHS="" matrix: @@ -14,3 +16,7 @@ matrix: sudo: false install: ./travis_install.sh script: ./travis_test.sh +addons: + apt: + packages: + - libdispatch-dev diff --git a/src/ffi.rs b/src/ffi.rs index 4c22147..d3636f8 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -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; diff --git a/src/lib.rs b/src/lib.rs index 87b8945..eb78e1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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. diff --git a/travis_test.sh b/travis_test.sh index 1964fe0..7c12f44 100755 --- a/travis_test.sh +++ b/travis_test.sh @@ -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