jedisct1/as-wasi

calling `.stat()` on a `Descriptor` does not include correct file details

Closed this issue · 6 comments

details:

wasm runtime: wasmer v0.4.2
assemblyscript version: v0.6
wasa version: master branch, commit f4162e73b6cbc3efd59f5cadd26b8b5b579b268f
// The entry file of your WebAssembly module.
import "allocator/arena"
import {
  Console as console,
  FileSystem as fs 
} from '../wasa/assembly/wasa'

export function _start (): void {
  let file = fs.open('./package.json')
  let fileDetails = file.stat()
  console.log(fileDetails.file_size.toString()) // always prints 0
  console.log(fileDetails.file_type.toString()) // always prints 0
  console.log(fileDetails.modification_time.toString()) // always prints 0.0
}

a few things come to mind...

  • this could most certainly be user error...
  • this could be an issue with the underlying runtime, so if that's the case, please punt this issue :)
  • could it be an issue converting to strings for printing? (other tests i've done say probably not?)

or it could be something else! :)

Hi Austin!

I'm quite surprised that the Wasa master branch still works with Assemblyscript 0.6 since quite a lot of changes have been made to cope with the recently introduced runtimes :)

Anyway. First, make sure that the directory has been preopened. With wasmer, this can be achieved by adding --dir . to the command-line. Or else, even the current directory will not be accessible.

Wasmer support for Wasi is still a work in progress. I don't have my laptop to try this on right now, but can you try with Lucet or Wasmtime? The have a more complete Wasi implementation.

@jedisct1 i'm struggling with Wasmtime at the moment but I will report back once it's working. I was using the --dir flag with wasmer but it's very possible that it's the underlying wasmer runtime. i've run into some other areas where not everything wasi related has been implemented.

I also tried upgrading to post assemblyscript@0.6.0 and noticed the String encoding/decoding API has changed a bit so I submitted a PR #4 making some changes.

appreciated the quick response!! :)

i did get this example to run with lucet lucet-wasi --dir ./:/ optimized.so and got the same result (with further testing with read and writing files to not work at all with lucet!)

ugh... did not not notice there was a newer version of wasmer available. v0.5.0 and this fixes things. should have started there. lesson learned.

Lucet doesn't seem to like absolute paths, but relative paths should work just fine, including for reading and writing files:

let fp = FileSystem.open("test.txt", "w")!;
fp.writeString("test");
fp.close();

Seems to work as expected.
Do you have example code that reads/writes files but doesn't work with Lucet? (besides using absolute paths)

@jedisct1 apologies! just seeing this! the lucet command i wrote above was a typo, the command i actualy ran was the following with relative paths. not sure if this is what you had meant? anyways, my preference is to use wasmer at the moment, so i'm not to concerened. very much appreciated your patience on this :0

lucet-wasi --dir ./:./ optimized.so