Skip to content

Commit

Permalink
Fix build errors on nightly
Browse files Browse the repository at this point in the history
Workaround for a regression in upstream rust-lang/rust.
  • Loading branch information
Jakub Konka committed Nov 25, 2019
1 parent c45f709 commit d824db3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 6 deletions.
9 changes: 9 additions & 0 deletions crates/wasi-common/src/old/snapshot_0/sys/unix/bsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub(crate) mod fdentry_impl {
pub(crate) mod host_impl {
use super::super::host_impl::dirent_filetype_from_host;
use crate::old::snapshot_0::{wasi, Result};
use std::convert::TryFrom;

pub(crate) const O_RSYNC: nix::fcntl::OFlag = nix::fcntl::OFlag::O_SYNC;

Expand All @@ -38,4 +39,12 @@ pub(crate) mod host_impl {
entry.d_type = d_type;
Ok(entry)
}

pub(crate) fn stdev_from_nix(dev: nix::libc::dev_t) -> Result<wasi::__wasi_device_t> {
wasi::__wasi_device_t::try_from(dev).map_err(Into::into)
}

pub(crate) fn stino_from_nix(ino: nix::libc::ino_t) -> Result<wasi::__wasi_inode_t> {
wasi::__wasi_device_t::try_from(ino).map_err(Into::into)
}
}
5 changes: 2 additions & 3 deletions crates/wasi-common/src/old/snapshot_0/sys/unix/host_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,15 @@ pub(crate) fn filetype_from_nix(sflags: nix::sys::stat::SFlag) -> FileType {
pub(crate) fn filestat_from_nix(
filestat: nix::sys::stat::FileStat,
) -> Result<wasi::__wasi_filestat_t> {
use std::convert::TryFrom;
fn filestat_to_timestamp(secs: u64, nsecs: u64) -> Result<wasi::__wasi_timestamp_t> {
secs.checked_mul(1_000_000_000)
.and_then(|sec_nsec| sec_nsec.checked_add(nsecs))
.ok_or(Error::EOVERFLOW)
}

let filetype = nix::sys::stat::SFlag::from_bits_truncate(filestat.st_mode);
let dev = wasi::__wasi_device_t::try_from(filestat.st_dev)?;
let ino = wasi::__wasi_inode_t::try_from(filestat.st_ino)?;
let dev = stdev_from_nix(filestat.st_dev)?;
let ino = stino_from_nix(filestat.st_ino)?;
let atim = filestat_to_timestamp(filestat.st_atime as u64, filestat.st_atime_nsec as u64)?;
let ctim = filestat_to_timestamp(filestat.st_ctime as u64, filestat.st_ctime_nsec as u64)?;
let mtim = filestat_to_timestamp(filestat.st_mtime as u64, filestat.st_mtime_nsec as u64)?;
Expand Down
10 changes: 10 additions & 0 deletions crates/wasi-common/src/old/snapshot_0/sys/unix/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,15 @@ pub(crate) mod fdentry_impl {
}

pub(crate) mod host_impl {
use crate::old::snapshot_0::{wasi, Result};

pub(crate) const O_RSYNC: nix::fcntl::OFlag = nix::fcntl::OFlag::O_RSYNC;

pub(crate) fn stdev_from_nix(dev: nix::libc::dev_t) -> Result<wasi::__wasi_device_t> {
Ok(wasi::__wasi_device_t::from(dev))
}

pub(crate) fn stino_from_nix(ino: nix::libc::ino_t) -> Result<wasi::__wasi_inode_t> {
Ok(wasi::__wasi_device_t::try_from(ino))
}
}
11 changes: 11 additions & 0 deletions crates/wasi-common/src/sys/unix/bsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,16 @@ pub(crate) mod fdentry_impl {
}

pub(crate) mod host_impl {
use crate::{wasi, Result};
use std::convert::TryFrom;

pub(crate) const O_RSYNC: nix::fcntl::OFlag = nix::fcntl::OFlag::O_SYNC;

pub(crate) fn stdev_from_nix(dev: nix::libc::dev_t) -> Result<wasi::__wasi_device_t> {
wasi::__wasi_device_t::try_from(dev).map_err(Into::into)
}

pub(crate) fn stino_from_nix(ino: nix::libc::ino_t) -> Result<wasi::__wasi_inode_t> {
wasi::__wasi_device_t::try_from(ino).map_err(Into::into)
}
}
5 changes: 2 additions & 3 deletions crates/wasi-common/src/sys/unix/host_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,15 @@ pub(crate) fn filetype_from_nix(sflags: nix::sys::stat::SFlag) -> FileType {
pub(crate) fn filestat_from_nix(
filestat: nix::sys::stat::FileStat,
) -> Result<wasi::__wasi_filestat_t> {
use std::convert::TryFrom;
fn filestat_to_timestamp(secs: u64, nsecs: u64) -> Result<wasi::__wasi_timestamp_t> {
secs.checked_mul(1_000_000_000)
.and_then(|sec_nsec| sec_nsec.checked_add(nsecs))
.ok_or(Error::EOVERFLOW)
}

let filetype = nix::sys::stat::SFlag::from_bits_truncate(filestat.st_mode);
let dev = wasi::__wasi_device_t::try_from(filestat.st_dev)?;
let ino = wasi::__wasi_inode_t::try_from(filestat.st_ino)?;
let dev = stdev_from_nix(filestat.st_dev)?;
let ino = stino_from_nix(filestat.st_ino)?;
let atim = filestat_to_timestamp(filestat.st_atime as u64, filestat.st_atime_nsec as u64)?;
let ctim = filestat_to_timestamp(filestat.st_ctime as u64, filestat.st_ctime_nsec as u64)?;
let mtim = filestat_to_timestamp(filestat.st_mtime as u64, filestat.st_mtime_nsec as u64)?;
Expand Down
10 changes: 10 additions & 0 deletions crates/wasi-common/src/sys/unix/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,15 @@ pub(crate) mod fdentry_impl {
}

pub(crate) mod host_impl {
use crate::{wasi, Result};

pub(crate) const O_RSYNC: nix::fcntl::OFlag = nix::fcntl::OFlag::O_RSYNC;

pub(crate) fn stdev_from_nix(dev: nix::libc::dev_t) -> Result<wasi::__wasi_device_t> {
Ok(wasi::__wasi_device_t::from(dev))
}

pub(crate) fn stino_from_nix(ino: nix::libc::ino_t) -> Result<wasi::__wasi_inode_t> {
Ok(wasi::__wasi_device_t::try_from(ino))
}
}

0 comments on commit d824db3

Please sign in to comment.