diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2017-12-19 15:23:50 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2017-12-19 15:23:50 +0000 |
commit | b68db41543d16d862e07ddbd143f43b92533d60b (patch) | |
tree | ab1f601bc9e67bc31ef833dcebc973b9ee899b67 /src | |
parent | 291d618322a360e2b3ac99ca7c1fde19ba6b4b2c (diff) | |
parent | 709cbdf12cacb6ecf42cca9000d1d46380b6ba62 (diff) | |
download | nix-b68db41543d16d862e07ddbd143f43b92533d60b.zip |
Merge #799
799: Fix nix on Dragonfly r=Susurrus a=mneumann
This commit replaces pull request https://github.com/nix-rust/nix/pull/684. It fixes building `nix` on DragonFly. All tests pass. This requires most recent libc to build: https://github.com/rust-lang/libc/pull/851.
Diffstat (limited to 'src')
-rw-r--r-- | src/errno.rs | 26 | ||||
-rw-r--r-- | src/errno_dragonfly.c | 3 | ||||
-rw-r--r-- | src/fcntl.rs | 1 | ||||
-rw-r--r-- | src/sys/socket/ffi.rs | 48 | ||||
-rw-r--r-- | src/unistd.rs | 7 |
5 files changed, 52 insertions, 33 deletions
diff --git a/src/errno.rs b/src/errno.rs index aa152170..1f88ec78 100644 --- a/src/errno.rs +++ b/src/errno.rs @@ -1,4 +1,6 @@ -use libc::{self, c_int}; +#[cfg(not(target_os = "dragonfly"))] +use libc; +use libc::c_int; use std::{fmt, io, error}; use {Error, Result}; @@ -12,11 +14,23 @@ cfg_if! { libc::__error() } } else if #[cfg(target_os = "dragonfly")] { - unsafe fn errno_location() -> *mut c_int { - // FIXME: Replace with errno-dragonfly crate as this is no longer the correct - // implementation. - extern { fn __dfly_error() -> *mut c_int; } - __dfly_error() + // DragonFly uses a thread-local errno variable, but #[thread_local] is + // feature-gated and not available in stable Rust as of this writing + // (Rust 1.21.0). We have to use a C extension to access it + // (src/errno_dragonfly.c). + // + // Tracking issue for `thread_local` stabilization: + // + // https://github.com/rust-lang/rust/issues/29594 + // + // Once this becomes stable, we can remove build.rs, + // src/errno_dragonfly.c, and use: + // + // extern { #[thread_local] static errno: c_int; } + // + #[link(name="errno_dragonfly", kind="static")] + extern { + pub fn errno_location() -> *mut c_int; } } else if #[cfg(any(target_os = "android", target_os = "netbsd", diff --git a/src/errno_dragonfly.c b/src/errno_dragonfly.c new file mode 100644 index 00000000..32fb4dab --- /dev/null +++ b/src/errno_dragonfly.c @@ -0,0 +1,3 @@ +#include <errno.h> + +int *errno_location() { return &errno; } diff --git a/src/fcntl.rs b/src/fcntl.rs index 86375e4a..5abf65ac 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -48,7 +48,6 @@ libc_bitflags!( O_DIRECTORY; /// Implicitly follow each `write()` with an `fdatasync()`. #[cfg(any(target_os = "android", - target_os = "dragonfly", target_os = "ios", target_os = "linux", target_os = "macos", diff --git a/src/sys/socket/ffi.rs b/src/sys/socket/ffi.rs index 265a97c9..d91b130e 100644 --- a/src/sys/socket/ffi.rs +++ b/src/sys/socket/ffi.rs @@ -5,32 +5,32 @@ pub use libc::{socket, listen, bind, accept, connect, setsockopt, sendto, recvfr use libc::{c_int, c_void, socklen_t, ssize_t}; -#[cfg(not(target_os = "macos"))] -use libc::size_t; - -#[cfg(not(target_os = "linux"))] -use libc::c_uint; - use sys::uio::IoVec; -#[cfg(target_os = "linux")] -pub type type_of_cmsg_len = size_t; - -#[cfg(not(target_os = "linux"))] -pub type type_of_cmsg_len = socklen_t; - -// OSX always aligns struct cmsghdr as if it were a 32-bit OS -#[cfg(target_os = "macos")] -pub type type_of_cmsg_data = c_uint; - -#[cfg(not(target_os = "macos"))] -pub type type_of_cmsg_data = size_t; - -#[cfg(target_os = "linux")] -pub type type_of_msg_iovlen = size_t; - -#[cfg(not(target_os = "linux"))] -pub type type_of_msg_iovlen = c_uint; +cfg_if! { + if #[cfg(target_os = "dragonfly")] { + use libc::c_uint; + pub type type_of_cmsg_len = socklen_t; + pub type type_of_cmsg_data = c_int; + pub type type_of_msg_iovlen = c_uint; + } else if #[cfg(target_os = "linux")] { + use libc::size_t; + pub type type_of_cmsg_len = size_t; + pub type type_of_cmsg_data = size_t; + pub type type_of_msg_iovlen = size_t; + } else if #[cfg(target_os = "macos")] { + use libc::c_uint; + pub type type_of_cmsg_len = socklen_t; + // OSX always aligns struct cmsghdr as if it were a 32-bit OS + pub type type_of_cmsg_data = c_uint; + pub type type_of_msg_iovlen = c_uint; + } else { + use libc::{c_uint, size_t}; + pub type type_of_cmsg_len = socklen_t; + pub type type_of_cmsg_data = size_t; + pub type type_of_msg_iovlen = c_uint; + } +} // Private because we don't expose any external functions that operate // directly on this type; we just use it internally at FFI boundaries. diff --git a/src/unistd.rs b/src/unistd.rs index f35eab9d..7a1c56c7 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -630,8 +630,11 @@ pub fn execvp(filename: &CString, args: &[CString]) -> Result<Void> { /// /// This function is similar to `execve`, except that the program to be executed /// is referenced as a file descriptor instead of a path. -#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", - target_os = "netbsd", target_os = "openbsd", target_os = "linux"))] +#[cfg(any(target_os = "android", + target_os = "freebsd", + target_os = "linux", + target_os = "netbsd", + target_os = "openbsd"))] #[inline] pub fn fexecve(fd: RawFd, args: &[CString], env: &[CString]) -> Result<Void> { let args_p = to_exec_array(args); |