Skip to content

Commit 3912a20

Browse files
committed
Merge #631
631: Allow nix to compile on android r=Susurrus Fixes #313
2 parents 9e51647 + 552fccf commit 3912a20

File tree

9 files changed

+120
-27
lines changed

9 files changed

+120
-27
lines changed

.travis.yml

+2-14
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ matrix:
2323
- env: TARGET=armv7-linux-androideabi DISABLE_TESTS=1
2424
rust: 1.13.0
2525
- env: TARGET=i686-linux-android DISABLE_TESTS=1
26-
rust: 1.13.0
26+
rust: 1.18.0
2727
- env: TARGET=x86_64-linux-android DISABLE_TESTS=1
28-
rust: 1.13.0
28+
rust: 1.18.0
2929

3030
# iOS
3131
- env: TARGET=aarch64-apple-ios DISABLE_TESTS=1
@@ -104,18 +104,6 @@ matrix:
104104
rust: nightly
105105

106106
allow_failures:
107-
# Android (in the process of fixing these, so they're allowed to fail for now)
108-
- env: TARGET=aarch64-linux-android DISABLE_TESTS=1
109-
rust: 1.13.0
110-
- env: TARGET=arm-linux-androideabi DISABLE_TESTS=1
111-
rust: 1.13.0
112-
- env: TARGET=armv7-linux-androideabi DISABLE_TESTS=1
113-
rust: 1.13.0
114-
- env: TARGET=i686-linux-android DISABLE_TESTS=1
115-
rust: 1.13.0
116-
- env: TARGET=x86_64-linux-android DISABLE_TESTS=1
117-
rust: 1.13.0
118-
119107
# iOS is still being worked on, so for now don't block on compilation failures
120108
- env: TARGET=aarch64-apple-ios DISABLE_TESTS=1
121109
rust: 1.13.0

CHANGELOG.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3535
- Introduced wrapper types for gid_t, pid_t, and uid_t as Gid, Pid, and Uid
3636
respectively. Various functions have been changed to use these new types as
3737
arguments. ([#629](https://github.com/nix-rust/nix/pull/629))
38+
- Promoted all Android targets to Tier 2 support
3839

3940
### Removed
4041
- Removed io::Error from nix::Error and conversion from nix::Error to Errno
@@ -45,8 +46,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4546
Now compiles on Linux/MIPS ([#538](https://github.com/nix-rust/nix/pull/538)),
4647
`Linux/PPC` ([#553](https://github.com/nix-rust/nix/pull/553)),
4748
`MacOS/x86_64,i686` ([#553](https://github.com/nix-rust/nix/pull/553)),
48-
`NetBSD/x64_64` ([#538](https://github.com/nix-rust/nix/pull/538)), and
49-
`FreeBSD/x86_64,i686` ([#536](https://github.com/nix-rust/nix/pull/536)).
49+
`NetBSD/x64_64` ([#538](https://github.com/nix-rust/nix/pull/538)),
50+
`FreeBSD/x86_64,i686` ([#536](https://github.com/nix-rust/nix/pull/536)), and
51+
`Android` ([#631](https://github.com/nix-rust/nix/pull/631)).
52+
- `bind` and `errno_location` now work correctly on `Android`
53+
([#631](https://github.com/nix-rust/nix/pull/631))
5054

5155
## [0.8.1] 2017-04-16
5256

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ limitations. Support for platforms is split into two tiers:
4646
*do not* block the inclusion of new code. Testing may be run, but
4747
failures in tests don't block the inclusion of new code.
4848

49-
The following targets are all supported by nix on Rust 1.13.0 or newer:
49+
The following targets are all supported by nix on Rust 1.13.0 or newer (unless
50+
otherwise noted):
5051

5152
Tier 1:
5253
* i686-unknown-linux-gnu
@@ -68,18 +69,18 @@ Tier 1:
6869
Tier 2:
6970
* i686-unknown-freebsd
7071
* x86_64-unknown-netbsd
72+
* aarch64-linux-android
73+
* arm-linux-androideabi
74+
* armv7-linux-androideabi
75+
* i686-linux-android (requires Rust >= 1.18)
76+
* x86_64-linux-android (requires Rust >= 1.18)
7177

7278
Tier 3:
7379
* aarch64-apple-ios
74-
* aarch64-linux-android
75-
* arm-linux-androideabi
7680
* armv7-apple-ios
77-
* armv7-linux-androideabi
7881
* armv7s-apple-ios
7982
* i386-apple-ios
80-
* i686-linux-android
8183
* x86_64-apple-ios
82-
* x86_64-linux-android
8384

8485
## Usage
8586

src/errno.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,18 @@ unsafe fn errno_location() -> *mut c_int {
3535
__errno()
3636
}
3737

38-
#[cfg(any(target_os = "linux", target_os = "android"))]
38+
#[cfg(target_os = "linux")]
3939
unsafe fn errno_location() -> *mut c_int {
4040
extern { fn __errno_location() -> *mut c_int; }
4141
__errno_location()
4242
}
4343

44+
#[cfg(target_os = "android")]
45+
unsafe fn errno_location() -> *mut c_int {
46+
extern { fn __errno() -> *mut c_int; }
47+
__errno()
48+
}
49+
4450
/// Sets the platform-specific errno to no-error
4551
unsafe fn clear() -> () {
4652
*errno_location() = 0;

src/macros.rs

+52
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@
1919
/// }
2020
/// }
2121
/// ```
22+
///
23+
/// Example with casting, due to a mistake in libc. In this example, the
24+
/// various flags have different types, so we cast the broken ones to the right
25+
/// type.
26+
///
27+
/// ```
28+
/// libc_bitflags!{
29+
/// pub flags SaFlags: libc::c_ulong {
30+
/// SA_NOCLDSTOP as libc::c_ulong,
31+
/// SA_NOCLDWAIT,
32+
/// SA_NODEFER as libc::c_ulong,
33+
/// SA_ONSTACK,
34+
/// SA_RESETHAND as libc::c_ulong,
35+
/// SA_RESTART as libc::c_ulong,
36+
/// SA_SIGINFO,
37+
/// }
38+
/// }
39+
/// ```
2240
macro_rules! libc_bitflags {
2341
// (non-pub) Exit rule.
2442
(@call_bitflags
@@ -130,6 +148,22 @@ macro_rules! libc_bitflags {
130148
}
131149
};
132150

151+
// Munch last ident and cast it to the given type.
152+
(@accumulate_flags
153+
$prefix:tt,
154+
[$($flags:tt)*];
155+
$flag:ident as $ty:ty
156+
) => {
157+
libc_bitflags! {
158+
@accumulate_flags
159+
$prefix,
160+
[
161+
$($flags)*
162+
const $flag = libc::$flag as $ty;
163+
];
164+
}
165+
};
166+
133167
// Munch an ident; covers terminating comma case.
134168
(@accumulate_flags
135169
$prefix:tt,
@@ -147,6 +181,24 @@ macro_rules! libc_bitflags {
147181
}
148182
};
149183

184+
// Munch an ident and cast it to the given type; covers terminating comma
185+
// case.
186+
(@accumulate_flags
187+
$prefix:tt,
188+
[$($flags:tt)*];
189+
$flag:ident as $ty:ty, $($tail:tt)*
190+
) => {
191+
libc_bitflags! {
192+
@accumulate_flags
193+
$prefix,
194+
[
195+
$($flags)*
196+
const $flag = libc::$flag as $ty;
197+
];
198+
$($tail)*
199+
}
200+
};
201+
150202
// (non-pub) Entry rule.
151203
(
152204
$(#[$attr:meta])*

src/sys/signal.rs

+30
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ pub const SIGIOT : Signal = SIGABRT;
198198
pub const SIGPOLL : Signal = SIGIO;
199199
pub const SIGUNUSED : Signal = SIGSYS;
200200

201+
#[cfg(not(target_os = "android"))]
201202
libc_bitflags!{
202203
pub flags SaFlags: libc::c_int {
203204
SA_NOCLDSTOP,
@@ -210,6 +211,35 @@ libc_bitflags!{
210211
}
211212
}
212213

214+
// On 64-bit android, sa_flags is c_uint while on 32-bit android, it is
215+
// c_ulong.
216+
// FIXME: https://github.com/rust-lang/libc/pull/511
217+
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
218+
libc_bitflags!{
219+
pub flags SaFlags: libc::c_ulong {
220+
SA_NOCLDSTOP as libc::c_ulong,
221+
SA_NOCLDWAIT as libc::c_ulong,
222+
SA_NODEFER as libc::c_ulong,
223+
SA_ONSTACK as libc::c_ulong,
224+
SA_RESETHAND as libc::c_ulong,
225+
SA_RESTART as libc::c_ulong,
226+
SA_SIGINFO as libc::c_ulong,
227+
}
228+
}
229+
230+
#[cfg(all(target_os = "android", target_pointer_width = "64"))]
231+
libc_bitflags!{
232+
pub flags SaFlags: libc::c_uint {
233+
SA_NOCLDSTOP as libc::c_uint,
234+
SA_NOCLDWAIT as libc::c_uint,
235+
SA_NODEFER as libc::c_uint,
236+
SA_ONSTACK as libc::c_uint,
237+
SA_RESETHAND as libc::c_uint,
238+
SA_RESTART as libc::c_uint,
239+
SA_SIGINFO as libc::c_uint,
240+
}
241+
}
242+
213243
#[repr(i32)]
214244
#[derive(Clone, Copy, PartialEq)]
215245
pub enum SigmaskHow {

src/sys/socket/consts.rs

-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ mod os {
4040
pub const SO_LINGER: c_int = libc::SO_LINGER;
4141
pub const SO_MARK: c_int = libc::SO_MARK;
4242
pub const SO_OOBINLINE: c_int = libc::SO_OOBINLINE;
43-
#[cfg(not(target_arch="arm"))]
4443
pub const SO_PASSCRED: c_int = libc::SO_PASSCRED;
4544
pub const SO_PEEK_OFF: c_int = libc::SO_PEEK_OFF;
46-
#[cfg(not(target_arch="arm"))]
4745
pub const SO_PEERCRED: c_int = libc::SO_PEERCRED;
4846
pub const SO_PRIORITY: c_int = libc::SO_PRIORITY;
4947
pub const SO_PROTOCOL: c_int = libc::SO_PROTOCOL;
@@ -57,7 +55,6 @@ mod os {
5755
pub const SO_REUSEPORT: c_int = libc::SO_REUSEPORT;
5856
pub const SO_RXQ_OVFL: c_int = libc::SO_RXQ_OVFL;
5957
pub const SO_SNDBUF: c_int = libc::SO_SNDBUF;
60-
#[cfg(not(target_arch="arm"))]
6158
pub const SO_SNDBUFFORCE: c_int = libc::SO_SNDBUFFORCE;
6259
pub const SO_TIMESTAMP: c_int = libc::SO_TIMESTAMP;
6360
pub const SO_TYPE: c_int = libc::SO_TYPE;

src/sys/socket/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ pub fn listen(sockfd: RawFd, backlog: usize) -> Result<()> {
394394
/// Bind a name to a socket
395395
///
396396
/// [Further reading](http://man7.org/linux/man-pages/man2/bind.2.html)
397+
#[cfg(not(all(target_os="android", target_pointer_width="64")))]
397398
pub fn bind(fd: RawFd, addr: &SockAddr) -> Result<()> {
398399
let res = unsafe {
399400
let (ptr, len) = addr.as_ffi_pair();
@@ -403,6 +404,21 @@ pub fn bind(fd: RawFd, addr: &SockAddr) -> Result<()> {
403404
Errno::result(res).map(drop)
404405
}
405406

407+
/// Bind a name to a socket
408+
///
409+
/// [Further reading](http://man7.org/linux/man-pages/man2/bind.2.html)
410+
// Android has some weirdness. Its 64-bit bind takes a c_int instead of a
411+
// socklen_t
412+
#[cfg(all(target_os="android", target_pointer_width="64"))]
413+
pub fn bind(fd: RawFd, addr: &SockAddr) -> Result<()> {
414+
let res = unsafe {
415+
let (ptr, len) = addr.as_ffi_pair();
416+
ffi::bind(fd, ptr, len as c_int)
417+
};
418+
419+
Errno::result(res).map(drop)
420+
}
421+
406422
/// Accept a connection on a socket
407423
///
408424
/// [Further reading](http://man7.org/linux/man-pages/man2/accept.2.html)

src/sys/termios.rs

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ mod ffi {
3939
pub use self::non_android::*;
4040

4141
// On Android before 5.0, Bionic directly inline these to ioctl() calls.
42-
#[inline]
4342
#[cfg(all(target_os = "android", not(target_arch = "mips")))]
4443
mod android {
4544
use libc;

0 commit comments

Comments
 (0)