Skip to content

Commit

Permalink
Replace nix with yanix crate
Browse files Browse the repository at this point in the history
Having introduced `yanix` crate as an in-house replacement for the
`nix` crate, this commit makes the necessary changes to `wasi-common`
to depend _only_ on `yanix` crate.
  • Loading branch information
Jakub Konka committed Nov 28, 2019
1 parent f187cef commit 2b4551b
Show file tree
Hide file tree
Showing 27 changed files with 770 additions and 1,115 deletions.
1 change: 0 additions & 1 deletion crates/wasi-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ num = { version = "0.2.0", default-features = false }
wig = { path = "wig" }

[target.'cfg(unix)'.dependencies]
nix = "0.15"
yanix = { path = "yanix" }

[target.'cfg(windows)'.dependencies]
Expand Down
33 changes: 19 additions & 14 deletions crates/wasi-common/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::wasi;
use std::convert::Infallible;
use std::num::TryFromIntError;
use std::{fmt, str};
use std::{ffi, fmt, str};
use thiserror::Error;

#[derive(Clone, Copy, Debug, Error, Eq, PartialEq)]
Expand Down Expand Up @@ -107,7 +107,7 @@ pub enum Error {
Wasi(WasiError),
Io(std::io::Error),
#[cfg(unix)]
Nix(nix::Error),
Nix(yanix::Error),
#[cfg(windows)]
Win(winx::winerror::WinError),
}
Expand All @@ -119,8 +119,8 @@ impl From<WasiError> for Error {
}

#[cfg(unix)]
impl From<nix::Error> for Error {
fn from(err: nix::Error) -> Self {
impl From<yanix::Error> for Error {
fn from(err: yanix::Error) -> Self {
Self::Nix(err)
}
}
Expand Down Expand Up @@ -149,6 +149,12 @@ impl From<str::Utf8Error> for Error {
}
}

impl From<&ffi::NulError> for Error {
fn from(_: &ffi::NulError) -> Self {
Self::Wasi(WasiError::EILSEQ)
}
}

#[cfg(windows)]
impl From<winx::winerror::WinError> for Error {
fn from(err: winx::winerror::WinError) -> Self {
Expand All @@ -162,16 +168,15 @@ impl Error {
Self::Wasi(no) => no.as_raw_errno(),
Self::Io(e) => errno_from_ioerror(e.to_owned()),
#[cfg(unix)]
Self::Nix(err) => err
.as_errno()
.map_or_else(
|| {
log::debug!("Unknown nix errno: {}", err);
Self::ENOSYS
},
crate::sys::host_impl::errno_from_nix,
)
.as_wasi_errno(),
Self::Nix(err) => {
use yanix::Error::*;
let err = match err {
Errno(errno) => crate::sys::host_impl::errno_from_nix(*errno),
NulError(err) => err.into(),
TryFromIntError(err) => (*err).into(),
};
err.as_wasi_errno()
}
#[cfg(windows)]
Self::Win(err) => crate::sys::host_impl::errno_from_win(*err),
}
Expand Down
33 changes: 19 additions & 14 deletions crates/wasi-common/src/old/snapshot_0/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::old::snapshot_0::wasi;
use std::convert::Infallible;
use std::num::TryFromIntError;
use std::{fmt, str};
use std::{ffi, fmt, str};
use thiserror::Error;

#[derive(Clone, Copy, Debug, Error, Eq, PartialEq)]
Expand Down Expand Up @@ -107,7 +107,7 @@ pub enum Error {
Wasi(WasiError),
Io(std::io::Error),
#[cfg(unix)]
Nix(nix::Error),
Nix(yanix::Error),
#[cfg(windows)]
Win(winx::winerror::WinError),
}
Expand All @@ -119,8 +119,8 @@ impl From<WasiError> for Error {
}

#[cfg(unix)]
impl From<nix::Error> for Error {
fn from(err: nix::Error) -> Self {
impl From<yanix::Error> for Error {
fn from(err: yanix::Error) -> Self {
Self::Nix(err)
}
}
Expand Down Expand Up @@ -149,6 +149,12 @@ impl From<str::Utf8Error> for Error {
}
}

impl From<&ffi::NulError> for Error {
fn from(_: &ffi::NulError) -> Self {
Self::Wasi(WasiError::EILSEQ)
}
}

#[cfg(windows)]
impl From<winx::winerror::WinError> for Error {
fn from(err: winx::winerror::WinError) -> Self {
Expand All @@ -162,16 +168,15 @@ impl Error {
Self::Wasi(no) => no.as_raw_errno(),
Self::Io(e) => errno_from_ioerror(e.to_owned()),
#[cfg(unix)]
Self::Nix(err) => err
.as_errno()
.map_or_else(
|| {
log::debug!("Unknown nix errno: {}", err);
Self::ENOSYS
},
crate::old::snapshot_0::sys::host_impl::errno_from_nix,
)
.as_wasi_errno(),
Self::Nix(err) => {
use yanix::Error::*;
let err = match err {
Errno(errno) => crate::sys::host_impl::errno_from_nix(*errno),
NulError(err) => err.into(),
TryFromIntError(err) => (*err).into(),
};
err.as_wasi_errno()
}
#[cfg(windows)]
Self::Win(err) => crate::old::snapshot_0::sys::host_impl::errno_from_win(*err),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wasi-common/src/old/snapshot_0/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cfg_if! {
pub(crate) use self::unix::*;

pub(crate) fn errno_from_host(err: i32) -> wasi::__wasi_errno_t {
host_impl::errno_from_nix(nix::errno::from_i32(err)).as_wasi_errno()
host_impl::errno_from_nix(yanix::errno::Errno::from_i32(err)).as_wasi_errno()
}
} else if #[cfg(windows)] {
mod windows;
Expand Down
Loading

0 comments on commit 2b4551b

Please sign in to comment.