Skip to content

Commit 202898d

Browse files
committed
Link dispatch instead of System outside of OSX/iOS.
Enable travis tests for linux to verify. This fixes #3.
1 parent ecf1197 commit 202898d

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ language: rust
22
rust:
33
- stable
44
- nightly
5-
os: osx
5+
os:
6+
- osx
7+
- linux
68
env:
79
- IOS_ARCHS=""
810
matrix:
@@ -14,3 +16,7 @@ matrix:
1416
sudo: false
1517
install: ./travis_install.sh
1618
script: ./travis_test.sh
19+
addons:
20+
apt:
21+
packages:
22+
- libdispatch-dev

src/ffi.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ pub type dispatch_time_t = u64;
2424
// dispatch_io_interval_flags_t
2525
pub type dispatch_queue_attr_t = *const dispatch_object_s;
2626

27-
#[link(name = "System", kind = "dylib")]
27+
#[cfg_attr(any(target_os = "macos", target_os = "ios"),
28+
link(name = "System", kind = "dylib"))]
29+
#[cfg_attr(not(any(target_os = "macos", target_os = "ios")),
30+
link(name = "dispatch", kind = "dylib"))]
2831
extern {
2932
static _dispatch_main_q: dispatch_object_s;
3033
static _dispatch_queue_attr_concurrent: dispatch_object_s;

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,21 @@ pub enum QueueAttribute {
6666
}
6767

6868
impl QueueAttribute {
69+
#[cfg(not(all(test, target_os = "linux")))]
6970
fn as_raw(&self) -> dispatch_queue_attr_t {
7071
match *self {
7172
QueueAttribute::Serial => DISPATCH_QUEUE_SERIAL,
7273
QueueAttribute::Concurrent => DISPATCH_QUEUE_CONCURRENT,
7374
}
7475
}
76+
77+
#[cfg(all(test, target_os = "linux"))]
78+
fn as_raw(&self) -> dispatch_queue_attr_t {
79+
// The Linux tests use Ubuntu's libdispatch-dev package, which is
80+
// apparently really old from before OSX 10.7.
81+
// Back then, the attr for dispatch_queue_create must be NULL.
82+
ptr::null()
83+
}
7584
}
7685

7786
/// The priority of a global concurrent queue.

travis_test.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
set -eu
44

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

0 commit comments

Comments
 (0)