mirror of
https://github.com/fluencelabs/wasmer
synced 2025-04-25 02:12:13 +00:00
Merge pull request #87 from wasmerio/hotfix/support-monotonic-clock
use libc clock constants and add macos build
This commit is contained in:
commit
92e3717f8c
@ -22,6 +22,39 @@ jobs:
|
|||||||
- target/debug/deps
|
- target/debug/deps
|
||||||
key: v4-test-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }}
|
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:
|
test-and-build:
|
||||||
docker:
|
docker:
|
||||||
- image: circleci/rust:latest
|
- image: circleci/rust:latest
|
||||||
@ -175,6 +208,10 @@ workflows:
|
|||||||
filters:
|
filters:
|
||||||
branches:
|
branches:
|
||||||
ignore: master
|
ignore: master
|
||||||
|
- test-macos:
|
||||||
|
filters:
|
||||||
|
branches:
|
||||||
|
ignore: master
|
||||||
- test-and-build:
|
- test-and-build:
|
||||||
filters:
|
filters:
|
||||||
branches:
|
branches:
|
||||||
|
@ -7,6 +7,22 @@ use time;
|
|||||||
|
|
||||||
use crate::webassembly::Instance;
|
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
|
/// emscripten: _gettimeofday
|
||||||
pub extern "C" fn _gettimeofday(tp: c_int, tz: c_int, instance: &mut Instance) -> c_int {
|
pub extern "C" fn _gettimeofday(tp: c_int, tz: c_int, instance: &mut Instance) -> c_int {
|
||||||
debug!("emscripten::_gettimeofday {} {}", tp, tz);
|
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
|
/// 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);
|
debug!("emscripten::_clock_gettime {} {}", clk_id, tp);
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
struct GuestTimeSpec {
|
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 {
|
let timespec = match clk_id {
|
||||||
0 => time::get_time(),
|
CLOCK_REALTIME => time::get_time(),
|
||||||
1 => panic!("Monotonic clock is not supported."),
|
CLOCK_MONOTONIC | CLOCK_MONOTONIC_COARSE => {
|
||||||
_ => panic!("Clock is not supported."),
|
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 {
|
unsafe {
|
||||||
@ -55,7 +81,11 @@ pub extern "C" fn _clock_gettime(clk_id: c_int, tp: c_int, instance: &mut Instan
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// emscripten: ___clock_gettime
|
/// 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);
|
debug!("emscripten::___clock_gettime {} {}", clk_id, tp);
|
||||||
_clock_gettime(clk_id, tp, instance)
|
_clock_gettime(clk_id, tp, instance)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user