Merge branch 'master' into feature/map-dir

This commit is contained in:
Mark McCaskey 2019-05-20 15:23:13 -07:00 committed by GitHub
commit 97a2237255
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 110 additions and 30 deletions

View File

@ -6,6 +6,7 @@ branches:
only: only:
- staging - staging
- trying - trying
- master
environment: environment:
matrix: matrix:
@ -17,6 +18,7 @@ environment:
cache: cache:
- 'C:\Users\appveyor\.cargo' - 'C:\Users\appveyor\.cargo'
- target - target
- wapm-cli-target
install: install:
# # Install LLVM # # Install LLVM
@ -47,7 +49,21 @@ install:
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) # - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
build_script: build_script:
- cargo build --release --verbose - cargo build --release --verbose
# Now we build wapm
- git submodule init
- git submodule update
# Cache wapm cli target in dir above to prevent breaking git submodule on windows
- if not exist wapm-cli-target mkdir wapm-cli-target
- move wapm-cli-target wapm-cli
- cd wapm-cli
- rename wapm-cli-target target
- cd ..
- cargo build --release --manifest-path wapm-cli/Cargo.toml --features telemetry
- cd wapm-cli
- rename target wapm-cli-target
- cd ..
- move wapm-cli\wapm-cli-target wapm-cli-target
test_script: test_script:
- cargo test --manifest-path lib/spectests/Cargo.toml --features clif - cargo test --manifest-path lib/spectests/Cargo.toml --features clif
@ -66,7 +82,7 @@ deploy:
description: 'WasmerInstaller' description: 'WasmerInstaller'
artifact: /.*\.exe/ artifact: /.*\.exe/
auth_token: auth_token:
secure: CaKtncy7S1PWxzDUQ0p2264pe3HwxzDn5VIyRizDaa72/SVfskNcoMjwwRh0ut22 secure: BbreGNDJy20922za7OhJG5TERzfX+dJSBQwttNTJkLvszbqMov6hhAtRb3P45hpf
provider: GitHub provider: GitHub
on: on:
branch: master branch: master

View File

@ -220,7 +220,7 @@ jobs:
name: "Pull dependencies" name: "Pull dependencies"
command: | command: |
git submodule init git submodule init
git submodule update --remote git submodule update
- restore_cache: - restore_cache:
keys: keys:
- v8-cargo-cache-darwin-nightly-{{ arch }}-{{ checksum "Cargo.lock" }} - v8-cargo-cache-darwin-nightly-{{ arch }}-{{ checksum "Cargo.lock" }}
@ -314,13 +314,15 @@ jobs:
tar xf clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz tar xf clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz
rustup toolchain install nightly rustup toolchain install nightly
rustup target add wasm32-wasi --toolchain nightly rustup target add wasm32-wasi --toolchain nightly
- run: |
rustup default nightly
make test-wasi-singlepass
make test-wasi-clif
- run: rustup default nightly-2019-04-11 - run: rustup default nightly-2019-04-11
- run: | - run: |
export LLVM_SYS_70_PREFIX="`pwd`/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04/" export LLVM_SYS_70_PREFIX="`pwd`/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04/"
make test make test
make test-singlepass make test-singlepass
make test-wasi-singlepass
make test-wasi-clif
make test-emscripten-clif make test-emscripten-clif
make test-emscripten-singlepass make test-emscripten-singlepass
- save_cache: - save_cache:

View File

@ -10,6 +10,7 @@ Blocks of changes will separated by version increments.
## 0.4.2 - 2019-05-16 ## 0.4.2 - 2019-05-16
- [#457](https://github.com/wasmerio/wasmer/pull/457) Implement file metadata for WASI, fix bugs in WASI clock code for Unix platforms
- [#416](https://github.com/wasmerio/wasmer/pull/416) Remote code loading framework - [#416](https://github.com/wasmerio/wasmer/pull/416) Remote code loading framework
- [#449](https://github.com/wasmerio/wasmer/pull/449) Fix bugs: opening host files in filestat and opening with write permissions unconditionally in path_open - [#449](https://github.com/wasmerio/wasmer/pull/449) Fix bugs: opening host files in filestat and opening with write permissions unconditionally in path_open
- [#442](https://github.com/wasmerio/wasmer/pull/442) Misc. WASI FS fixes and implement readdir - [#442](https://github.com/wasmerio/wasmer/pull/442) Misc. WASI FS fixes and implement readdir

View File

@ -487,3 +487,64 @@ pub fn host_file_type_to_wasi_file_type(file_type: fs::FileType) -> __wasi_filet
__WASI_FILETYPE_UNKNOWN __WASI_FILETYPE_UNKNOWN
} }
} }
pub fn get_stat_for_kind(kind: &Kind) -> Option<__wasi_filestat_t> {
match kind {
Kind::File { handle } => match handle {
WasiFile::HostFile(hf) => {
let md = hf.metadata().ok()?;
Some(__wasi_filestat_t {
st_filetype: host_file_type_to_wasi_file_type(md.file_type()),
st_size: md.len(),
st_atim: md
.accessed()
.ok()?
.duration_since(SystemTime::UNIX_EPOCH)
.ok()?
.as_nanos() as u64,
st_mtim: md
.modified()
.ok()?
.duration_since(SystemTime::UNIX_EPOCH)
.ok()?
.as_nanos() as u64,
st_ctim: md
.created()
.ok()
.and_then(|ct| ct.duration_since(SystemTime::UNIX_EPOCH).ok())
.map(|ct| ct.as_nanos() as u64)
.unwrap_or(0),
..__wasi_filestat_t::default()
})
}
},
Kind::Dir { path, .. } => {
let md = path.metadata().ok()?;
Some(__wasi_filestat_t {
st_filetype: host_file_type_to_wasi_file_type(md.file_type()),
st_size: md.len(),
st_atim: md
.accessed()
.ok()?
.duration_since(SystemTime::UNIX_EPOCH)
.ok()?
.as_nanos() as u64,
st_mtim: md
.modified()
.ok()?
.duration_since(SystemTime::UNIX_EPOCH)
.ok()?
.as_nanos() as u64,
st_ctim: md
.created()
.ok()
.and_then(|ct| ct.duration_since(SystemTime::UNIX_EPOCH).ok())
.map(|ct| ct.as_nanos() as u64)
.unwrap_or(0),
..__wasi_filestat_t::default()
})
}
_ => None,
}
}

View File

@ -9,7 +9,8 @@ use self::types::*;
use crate::{ use crate::{
ptr::{Array, WasmPtr}, ptr::{Array, WasmPtr},
state::{ state::{
host_file_type_to_wasi_file_type, Fd, InodeVal, Kind, WasiFile, WasiState, MAX_SYMLINKS, get_stat_for_kind, host_file_type_to_wasi_file_type, Fd, InodeVal, Kind, WasiFile,
WasiState, MAX_SYMLINKS,
}, },
ExitCode, ExitCode,
}; };
@ -187,7 +188,10 @@ pub fn clock_time_get(
precision: __wasi_timestamp_t, precision: __wasi_timestamp_t,
time: WasmPtr<__wasi_timestamp_t>, time: WasmPtr<__wasi_timestamp_t>,
) -> __wasi_errno_t { ) -> __wasi_errno_t {
debug!("wasi::clock_time_get"); debug!(
"wasi::clock_time_get clock_id: {}, precision: {}",
clock_id, precision
);
let memory = ctx.memory(0); let memory = ctx.memory(0);
let out_addr = wasi_try!(time.deref(memory)); let out_addr = wasi_try!(time.deref(memory));
@ -1082,7 +1086,7 @@ pub fn path_create_directory(
entries: Default::default(), entries: Default::default(),
}; };
let new_inode = state.fs.inodes.insert(InodeVal { let new_inode = state.fs.inodes.insert(InodeVal {
stat: __wasi_filestat_t::default(), stat: wasi_try!(get_stat_for_kind(&kind).ok_or(__WASI_EIO)),
is_preopened: false, is_preopened: false,
name: path_vec[0].clone(), name: path_vec[0].clone(),
kind, kind,
@ -1226,10 +1230,7 @@ pub fn path_filestat_get(
} }
let final_path_metadata = let final_path_metadata =
wasi_try!(cumulative_path.metadata().map_err(|_| __WASI_EIO)); wasi_try!(cumulative_path.metadata().map_err(|_| __WASI_EIO));
__wasi_filestat_t { wasi_try!(get_stat_for_kind(&state.fs.inodes[inode].kind).ok_or(__WASI_EIO))
st_filetype: host_file_type_to_wasi_file_type(final_path_metadata.file_type()),
..Default::default()
}
} }
} }
_ => { _ => {
@ -1535,7 +1536,7 @@ pub fn path_open(
// record lazily loaded or newly created fd // record lazily loaded or newly created fd
let new_inode = state.fs.inodes.insert(InodeVal { let new_inode = state.fs.inodes.insert(InodeVal {
stat: __wasi_filestat_t::default(), stat: wasi_try!(get_stat_for_kind(&kind).ok_or(__WASI_EIO)),
is_preopened: false, is_preopened: false,
name: file_name.clone(), name: file_name.clone(),
kind, kind,

View File

@ -24,9 +24,9 @@ pub struct __wasi_ciovec_t {
unsafe impl ValueType for __wasi_ciovec_t {} unsafe impl ValueType for __wasi_ciovec_t {}
pub type __wasi_clockid_t = u32; pub type __wasi_clockid_t = u32;
pub const __WASI_CLOCK_MONOTONIC: u32 = 0; pub const __WASI_CLOCK_REALTIME: u32 = 0;
pub const __WASI_CLOCK_PROCESS_CPUTIME_ID: u32 = 1; pub const __WASI_CLOCK_MONOTONIC: u32 = 1;
pub const __WASI_CLOCK_REALTIME: u32 = 2; pub const __WASI_CLOCK_PROCESS_CPUTIME_ID: u32 = 2;
pub const __WASI_CLOCK_THREAD_CPUTIME_ID: u32 = 3; pub const __WASI_CLOCK_THREAD_CPUTIME_ID: u32 = 3;
pub type __wasi_device_t = u64; pub type __wasi_device_t = u64;

View File

@ -23,7 +23,8 @@ pub fn platform_clock_res_get(
(clock_getres(unix_clock_id, &mut timespec_out), timespec_out) (clock_getres(unix_clock_id, &mut timespec_out), timespec_out)
}; };
resolution.set(timespec_out.tv_nsec as __wasi_timestamp_t); let t_out = (timespec_out.tv_sec * 1_000_000_000).wrapping_add(timespec_out.tv_nsec);
resolution.set(t_out as __wasi_timestamp_t);
// TODO: map output of clock_getres to __wasi_errno_t // TODO: map output of clock_getres to __wasi_errno_t
__WASI_ESUCCESS __WASI_ESUCCESS
@ -50,9 +51,8 @@ pub fn platform_clock_time_get(
) )
}; };
// TODO: adjust output by precision... let t_out = (timespec_out.tv_sec * 1_000_000_000).wrapping_add(timespec_out.tv_nsec);
time.set(t_out as __wasi_timestamp_t);
time.set(timespec_out.tv_nsec as __wasi_timestamp_t);
// TODO: map output of clock_gettime to __wasi_errno_t // TODO: map output of clock_gettime to __wasi_errno_t
__WASI_ESUCCESS __WASI_ESUCCESS

View File

@ -46,7 +46,7 @@ macro_rules! assert_wasi_output {
.map_err(|e| format!("{:?}", e)) .map_err(|e| format!("{:?}", e))
.expect("start function in wasi module"); .expect("start function in wasi module");
let _result = start.call(); start.call().expect("execute the wasm");
let output = capturer.end().unwrap().0; let output = capturer.end().unwrap().0;
let expected_output = include_str!($expected); let expected_output = include_str!($expected);

View File

@ -1,5 +1,4 @@
#[test] #[test]
#[ignore]
fn test_file_metadata() { fn test_file_metadata() {
assert_wasi_output!( assert_wasi_output!(
"../../wasitests/file_metadata.wasm", "../../wasitests/file_metadata.wasm",

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,2 +1,3 @@
is dir: false is dir: false
file info: FileType(FileType { mode: 33188 }) 419 Ok(SystemTime { tv_sec: 1558132188, tv_nsec: 545288295 }) Ok(SystemTime { tv_sec: 1558132188, tv_nsec: 545243056 }) Ok(SystemTime { tv_sec: 1558132191, tv_nsec: 359031112 }) filetype: false true false
file info: 456

View File

@ -6,12 +6,12 @@ fn main() {
fs::File::open("wasitests/file_metadata.rs").expect("could not find src file"); fs::File::open("wasitests/file_metadata.rs").expect("could not find src file");
let md = this_file.metadata().unwrap(); let md = this_file.metadata().unwrap();
println!("is dir: {}", md.is_dir()); println!("is dir: {}", md.is_dir());
let filetype = md.file_type();
println!( println!(
"file info: {:?} {} {:?} {:?} {:?}", "filetype: {} {} {}",
md.file_type(), filetype.is_dir(),
md.len(), filetype.is_file(),
md.modified(), filetype.is_symlink()
md.created(),
md.accessed()
); );
println!("file info: {}", md.len());
} }

Binary file not shown.

Binary file not shown.

View File

@ -1,2 +1 @@
file_metadata
create_dir create_dir

Binary file not shown.

Binary file not shown.