Skip to content

Commit

Permalink
Merge #1285
Browse files Browse the repository at this point in the history
1285: Add fuchsia support r=asomers a=amanda-tait

This change adds support for the Fuchsia operating system to the nix
crate. Fuchsia developers have a use case for nix, particularly its safe
interfaces to the recvmsg(2) and sendmsg(2). Adding support requires:
* incrementing the libc dependency to 0.2.74
* conditionally not compiling nix functionality which depends on libc functionality
  that does not exist for Fuchsia

Co-authored-by: Tamir Duberstein <tamird@google.com>
Co-authored-by: Amanda Tait <atait@google.com>
  • Loading branch information
3 people committed Dec 16, 2020
2 parents 0fd17fc + e401edb commit 199f83d
Show file tree
Hide file tree
Showing 17 changed files with 222 additions and 112 deletions.
9 changes: 7 additions & 2 deletions .cirrus.yml
Expand Up @@ -116,7 +116,7 @@ task:
TARGET: x86_64-unknown-linux-musl
TOOLCHAIN: 1.40.0
container:
image: rust:1.36
image: rust:1.40
setup_script:
- rustup toolchain install $TOOLCHAIN
- rustup target add --toolchain $TOOLCHAIN $TARGET
Expand Down Expand Up @@ -160,13 +160,18 @@ task:
- name: NetBSD x86_64
env:
TARGET: x86_64-unknown-netbsd
- name: Fuchsia x86_64
env:
TARGET: x86_64-fuchsia
CHECK_TESTS: true
container:
image: rust:1.36
image: rust:1.40
setup_script:
- rustup target add $TARGET
script:
- cargo +$TOOLCHAIN check --target $TARGET
- cargo +$TOOLCHAIN check --target $TARGET --release
- 'if [ "$CHECK_TESTS" == true ]; then cargo +$TOOLCHAIN check --all-targets --target $TARGET; fi'
# TODO: check the tests, too. The old Travis CI setup didn't do that, so
# they don't build on all platforms.
before_cache_script: rm -rf $CARGO_HOME/registry/index
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Added `mremap` (#[1306](https://github.com/nix-rust/nix/pull/1306))

- Added limited Fuchsia support (#[1285](https://github.com/nix-rust/nix/pull/1285))

### Fixed
### Changed

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -26,6 +26,7 @@ targets = [
"x86_64-unknown-openbsd",
"x86_64-unknown-netbsd",
"x86_64-unknown-dragonfly",
"x86_64-fuchsia",
"x86_64-unknown-redox"
]

Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -81,6 +81,7 @@ Tier 2:
* x86_64-unknown-netbsd

Tier 3:
* x86_64-fuchsia
* x86_64-unknown-redox

## Usage
Expand Down
192 changes: 128 additions & 64 deletions src/errno.rs
Expand Up @@ -20,7 +20,8 @@ cfg_if! {
}
} else if #[cfg(any(target_os = "linux",
target_os = "redox",
target_os = "dragonfly"))] {
target_os = "dragonfly",
target_os = "fuchsia"))] {
unsafe fn errno_location() -> *mut c_int {
libc::__errno_location()
}
Expand Down Expand Up @@ -188,192 +189,254 @@ fn desc(errno: Errno) -> &'static str {
EHOSTDOWN => "Host is down",
EHOSTUNREACH => "No route to host",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ECHRNG => "Channel number out of range",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EL2NSYNC => "Level 2 not synchronized",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EL3HLT => "Level 3 halted",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EL3RST => "Level 3 reset",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ELNRNG => "Link number out of range",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EUNATCH => "Protocol driver not attached",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ENOCSI => "No CSI structure available",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EL2HLT => "Level 2 halted",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EBADE => "Invalid exchange",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EBADR => "Invalid request descriptor",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EXFULL => "Exchange full",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ENOANO => "No anode",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EBADRQC => "Invalid request code",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EBADSLT => "Invalid slot",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EBFONT => "Bad font file format",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ENOSTR => "Device not a stream",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ENODATA => "No data available",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ETIME => "Timer expired",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ENOSR => "Out of streams resources",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ENONET => "Machine is not on the network",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ENOPKG => "Package not installed",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EREMOTE => "Object is remote",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ENOLINK => "Link has been severed",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EADV => "Advertise error",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ESRMNT => "Srmount error",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ECOMM => "Communication error on send",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EPROTO => "Protocol error",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EMULTIHOP => "Multihop attempted",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EDOTDOT => "RFS specific error",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EBADMSG => "Not a data message",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EOVERFLOW => "Value too large for defined data type",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ENOTUNIQ => "Name not unique on network",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EBADFD => "File descriptor in bad state",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EREMCHG => "Remote address changed",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ELIBACC => "Can not access a needed shared library",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ELIBBAD => "Accessing a corrupted shared library",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ELIBSCN => ".lib section in a.out corrupted",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ELIBMAX => "Attempting to link in too many shared libraries",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ELIBEXEC => "Cannot exec a shared library directly",

#[cfg(any(target_os = "linux", target_os = "android", target_os = "openbsd"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia", target_os = "openbsd"))]
EILSEQ => "Illegal byte sequence",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ERESTART => "Interrupted system call should be restarted",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ESTRPIPE => "Streams pipe error",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EUSERS => "Too many users",

#[cfg(any(target_os = "linux", target_os = "android",
target_os = "netbsd", target_os = "redox"))]
target_os = "fuchsia", target_os = "netbsd",
target_os = "redox"))]
EOPNOTSUPP => "Operation not supported on transport endpoint",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ESTALE => "Stale file handle",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EUCLEAN => "Structure needs cleaning",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ENOTNAM => "Not a XENIX named type file",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ENAVAIL => "No XENIX semaphores available",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EISNAM => "Is a named type file",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EREMOTEIO => "Remote I/O error",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EDQUOT => "Quota exceeded",

#[cfg(any(target_os = "linux", target_os = "android",
target_os = "openbsd", target_os = "dragonfly"))]
target_os = "fuchsia", target_os = "openbsd",
target_os = "dragonfly"))]
ENOMEDIUM => "No medium found",

#[cfg(any(target_os = "linux", target_os = "android", target_os = "openbsd"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia", target_os = "openbsd"))]
EMEDIUMTYPE => "Wrong medium type",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ECANCELED => "Operation canceled",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ENOKEY => "Required key not available",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EKEYEXPIRED => "Key has expired",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EKEYREVOKED => "Key has been revoked",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EKEYREJECTED => "Key was rejected by service",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
EOWNERDEAD => "Owner died",

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
ENOTRECOVERABLE => "State not recoverable",

#[cfg(all(target_os = "linux", not(target_arch="mips")))]
#[cfg(any(all(target_os = "linux", not(target_arch="mips")),
target_os = "fuchsia"))]
ERFKILL => "Operation not possible due to RF-kill",

#[cfg(all(target_os = "linux", not(target_arch="mips")))]
#[cfg(any(all(target_os = "linux", not(target_arch="mips")),
target_os = "fuchsia"))]
EHWPOISON => "Memory page has hardware error",

#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
Expand Down Expand Up @@ -567,7 +630,8 @@ fn desc(errno: Errno) -> &'static str {
}
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android",
target_os = "fuchsia"))]
mod consts {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(i32)]
Expand Down
2 changes: 1 addition & 1 deletion src/features.rs
Expand Up @@ -97,7 +97,7 @@ mod os {
#[cfg(any(target_os = "macos", target_os = "freebsd",
target_os = "dragonfly", target_os = "ios",
target_os = "openbsd", target_os = "netbsd",
target_os = "redox"))]
target_os = "redox", target_os = "fuchsia"))]
mod os {
/// Check if the OS supports atomic close-on-exec for sockets
pub fn socket_atomic_cloexec() -> bool {
Expand Down

0 comments on commit 199f83d

Please sign in to comment.