Merge pull request #87 from wasmerio/hotfix/support-monotonic-clock

use libc clock constants and add macos build
This commit is contained in:
Mackenzie Clark 2019-01-01 17:02:36 -08:00 committed by GitHub
commit 92e3717f8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 5 deletions

View File

@ -22,6 +22,39 @@ jobs:
- target/debug/deps
key: v4-test-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }}
test-macos:
macos:
xcode: "9.0"
steps:
- checkout
- restore_cache:
keys:
- v4-cargo-cache-darwin-{{ arch }}-{{ checksum "Cargo.lock" }}
- run:
name: Install CMAKE
command: |
curl -O https://cmake.org/files/v3.4/cmake-3.4.1-Darwin-x86_64.tar.gz
tar xf cmake-3.4.1-Darwin-x86_64.tar.gz
export PATH="`pwd`/cmake-3.4.1-Darwin-x86_64/CMake.app/Contents/bin:$PATH"
- run:
name: Install Rust
command: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
export PATH="$HOME/.cargo/bin:$PATH"
cargo --version
rustup component add rustfmt
- run:
name: Execute tests
command: |
export PATH="`pwd`/cmake-3.4.1-Darwin-x86_64/CMake.app/Contents/bin:$PATH"
export PATH="$HOME/.cargo/bin:$PATH"
# We increase the ulimit for fixing cargo unclosed files in mac
ulimit -n 8000
sudo sysctl -w kern.maxfiles=655360 kern.maxfilesperproc=327680
make test
make lint
test-and-build:
docker:
- image: circleci/rust:latest
@ -175,6 +208,10 @@ workflows:
filters:
branches:
ignore: master
- test-macos:
filters:
branches:
ignore: master
- test-and-build:
filters:
branches:

View File

@ -7,6 +7,22 @@ use time;
use crate::webassembly::Instance;
#[cfg(target_os = "linux")]
use libc::{CLOCK_MONOTONIC, CLOCK_MONOTONIC_COARSE, CLOCK_REALTIME};
#[cfg(target_os = "macos")]
use libc::{CLOCK_MONOTONIC, CLOCK_REALTIME};
#[cfg(target_os = "macos")]
const CLOCK_MONOTONIC_COARSE: libc::clockid_t = 6;
// some assumptions about the constants when targeting windows
#[cfg(target_os = "windows")]
const CLOCK_REALTIME: libc::clockid_t = 0;
#[cfg(target_os = "windows")]
const CLOCK_MONOTONIC: libc::clockid_t = 1;
#[cfg(target_os = "windows")]
const CLOCK_MONOTONIC_COARSE: libc::clockid_t = 6;
/// emscripten: _gettimeofday
pub extern "C" fn _gettimeofday(tp: c_int, tz: c_int, instance: &mut Instance) -> c_int {
debug!("emscripten::_gettimeofday {} {}", tp, tz);
@ -32,7 +48,11 @@ pub extern "C" fn _gettimeofday(tp: c_int, tz: c_int, instance: &mut Instance) -
}
/// emscripten: _clock_gettime
pub extern "C" fn _clock_gettime(clk_id: c_int, tp: c_int, instance: &mut Instance) -> c_int {
pub extern "C" fn _clock_gettime(
clk_id: libc::clockid_t,
tp: c_int,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::_clock_gettime {} {}", clk_id, tp);
#[repr(C)]
struct GuestTimeSpec {
@ -41,9 +61,15 @@ pub extern "C" fn _clock_gettime(clk_id: c_int, tp: c_int, instance: &mut Instan
}
let timespec = match clk_id {
0 => time::get_time(),
1 => panic!("Monotonic clock is not supported."),
_ => panic!("Clock is not supported."),
CLOCK_REALTIME => time::get_time(),
CLOCK_MONOTONIC | CLOCK_MONOTONIC_COARSE => {
let precise_ns = time::precise_time_ns();
time::Timespec::new(
(precise_ns / 1000000000) as i64,
(precise_ns % 1000000000) as i32,
)
}
_ => panic!("Clock with id \"{}\" is not supported.", clk_id),
};
unsafe {
@ -55,7 +81,11 @@ pub extern "C" fn _clock_gettime(clk_id: c_int, tp: c_int, instance: &mut Instan
}
/// emscripten: ___clock_gettime
pub extern "C" fn ___clock_gettime(clk_id: c_int, tp: c_int, instance: &mut Instance) -> c_int {
pub extern "C" fn ___clock_gettime(
clk_id: libc::clockid_t,
tp: c_int,
instance: &mut Instance,
) -> c_int {
debug!("emscripten::___clock_gettime {} {}", clk_id, tp);
_clock_gettime(clk_id, tp, instance)
}