Comments (15)
You can try this:
% cd aeneas/src
% v3c-wasi -shadow-stack-size=1m -heap-size=500m -output=/tmp */*.v3 $VIRGIL_LOC/lib/util/*.v3 $VIRGIL_LOC/lib/asm/*/*.v3
The generated .wasm
file does run, but file loading is broken atm, so it can't load any files yet. Not very useful for a compiler, I know :-)
from virgil.
Also a very worthwhile option is -rt.symtab
, which will generate a names section.
from virgil.
I was able to get it compiling, but not fully working (I guess because the file issue you commented). We can keep this issue open until aenea.wasm
is able to fully work in a Wasm/WASI context :)
Not sure if this may help or not, but usually when having WASI applications you may want to provide them with a --dir=.
or --mapdir=.:/
(for example) so the runtime can access files/directories on that dir.
from virgil.
I'd love to play a bit more on this. I got aenea.wasm
but nothing outputted once I ran it with a wasm runtime.
Any advice on how to continue this effort forward? What's pending to have? (any guidance would be welcome!)
from virgil.
Hmm, that's weird. If I compile Aeneas
with v3c-wasi
and run that Aeneas.wasm
on node, I get:
[~/virgil]% v3c-wasi $AENEAS_SOURCES
[~/virgil]% node --no-warnings --experimental-wasi-unstable-preview1 rt/wasi_snapshot_preview1/wasi.node.mjs Aeneas.wasm -help
Aeneas III-6.1505
Usage: v3c (-run|-test|-version|-target=<target>) [options] <v3 files>
LANGUAGE OPTIONS
-legacy-cast[=(true|false)]
Enable legacy cast semantics (int.! == int.view) for the Virgil language.
SHARED OPTIONS
-opt=<string>
Set optimization configuration options.
-maxr=<int>
Limit the maximum number of return values in normalization.
-maxp=<int>
Limit the maximum number of parameters in normalization.
-maxd=<int>
Set the maximum number of data slots allowed for auto-unboxing data types.
...
This also works in wizard
, but doesn't work in wasm3
. That seems to be because wasm3
passes the the module name as the first argument to a module (which causes Aeneas to not recognize further options).
from virgil.
That seems to be because wasm3 passes the the module name as the first argument to a module (which causes Aeneas to not recognize further options).
This is a common practice in most server-side Wasm/WASI runtimes. I believe Wasmer, wasmtime, WasmEdge, and wasm3 all do that (this is, so the binary can recognize the program being run).
Could it be possible to support this in Virgil?
This would imply that wasmer Aeneas.wasm
or wasm3 Aeneas.wasm
(or other runtime) would work without any modifications in the runtime itself
from virgil.
Done. I fixed the RiRuntime.v3
for WASI to skip the first argument. (Also fixed wizard
to pass the .wasm
filename as the first argument). This works now in node
, wasm3
, and wizard
. Didn't try wasmer
yet.
from virgil.
What remains is for me to fixup fileLoad()
in rt/wasi_snapshot_preview1/System.v3
, and I think the compiler will work. Mostly the issue is just getting the file size properly and loading the data into the array.
from virgil.
Thanks for the fix. I recompiled and I verified this actually works with wasm3 (via wax wasm3 Aeneas.wasm
).
However, I can't get it to work with Wasmer or Wasmtime. I'm really not sure what's going on at first sight. I'm inclined to think it might be a small bug on the WASI impl in Virgil, since the behavior seen in Wasmer or Wasmtime is the same: no output. I assumed the first argument thing will fix it, but doesn't seem to be the case.
I inspected the module and everything seems fine compared to other WASI modules that run properly in all runtimes.
$ wasmer inspect Aeneas.wasm
Type: wasm
Size: 1.9 MB
Imports:
Functions:
"wasi_snapshot_preview1"."args_sizes_get": [I32, I32] -> [I32]
"wasi_snapshot_preview1"."args_get": [I32, I32] -> [I32]
"wasi_snapshot_preview1"."path_open": [I32, I32, I32, I32, I32, I64, I64, I32, I32] -> [I32]
"wasi_snapshot_preview1"."fd_close": [I32] -> [I32]
"wasi_snapshot_preview1"."fd_seek": [I32, I64, I32, I32] -> [I32]
"wasi_snapshot_preview1"."fd_write": [I32, I32, I32, I32] -> [I32]
"wasi_snapshot_preview1"."fd_read": [I32, I32, I32, I32] -> [I32]
"wasi_snapshot_preview1"."clock_time_get": [I32, I64, I32] -> [I32]
Memories:
Tables:
Globals:
Exports:
Functions:
"_start": [] -> [I32]
Memories:
"memory": not shared (8020 pages..8020 pages)
Tables:
Globals:
What remains is for me to fixup fileLoad() in rt/wasi_snapshot_preview1/System.v3
Awesome, I'd really love to get it fully working!
from virgil.
Oh, I noticed one small difference.
Other WASI modules (generated with Rust), always call proc_exit
at the end of main with the desired exit code.
Imports:
Functions:
"wasi_snapshot_preview1"."proc_exit": [I32] -> []
While the Wasm/WASI generated module (Aeneas.wasm), doesn't even import this function.
It might be the case that the stdout is not even flushed?
from virgil.
Yeah, I noticed that wasmtime
sometimes doesn't flush stdout. Maybe calling proc_exit
will fix it; I plan to add that to the RiRuntime
interface for the wasm targets, as this is the proper contact point between the compiler and the runtime system.
from virgil.
from virgil.
Small update: I just tested the latest master with the commit you pointed @titzer, but it still doesn't work with wasmer or wasmtime.
I'm now a bit confused on what's going on :/
from virgil.
I tried to take on the challenge again!
Here's how to try it locally!
git clone https://github.com/titzer/virgil.git
cd virgil
export VIRGIL_LOC=$(pwd)
export PATH=$PATH:$(pwd)/bin/:$(pwd)/bin/dev
# make sure that java is available in your path
v3c-wasi -shadow-stack-size=1m -heap-size=500m -output=/tmp */*.v3 $VIRGIL_LOC/lib/util/*.v3 \
$VIRGIL_LOC/lib/asm/x86-64/X86_64Assembler.v3 \
$VIRGIL_LOC/lib/asm/arm/ArmAssembler.v3 \
$VIRGIL_LOC/lib/asm/x86/X86Assembler.v3 \
$VIRGIL_LOC/lib/asm/mips/MipsAssembler.v3
The file is now being generated properly: /tmp/Aeneas.wasm
.
However, I'm not sure how to run it with Wasmer, I'm trying the following but it doesn't work:
git clone https://github.com/titzer/virgil.git
cd virgil
cd apps/HelloWorld
wasmer run /tmp/Aeneas.wasm --dir=. -- HelloWorld.v3
But it outputs:
File not found: HelloWorld.v3
Any hints on what I may be doing wrong @titzer ?
from virgil.
I think that the problem is in rt/wasi_snapshot_preview1/System.v3
that doesn't use WASI file operations properly. I had meant to debug that, but I've gotten sidetracked. It's one of the more annoying things about WASI, IMHO, that all file system operations have to be relative to an open directory and then that file descriptor number must be coordinated with the embedding.
from virgil.
Related Issues (20)
- `System.puts` at compile time causes compilation to fail on native target (linux) compiler HOT 3
- Unable to run v3c on Ubuntu 20.04.2 on Windows 10 HOT 3
- Value of `null`? HOT 10
- .NET CLR target HOT 1
- Add Windows batch scripts for JAR and WASM target HOT 1
- Supporting `unsafe` as a keyword? HOT 2
- Mutability of `def var` fields in subclasses HOT 3
- Support socket flags/options
- Improve type system and type inference rules HOT 4
- Change system and pointer APIs to pervasively use the `Range` type HOT 2
- Copy/modify initialization expression - `with`?
- Weakening `private` to file scope HOT 4
- Shard testsuite and parallelize
- Support Windows 64 bit
- Most of documentation files seem to be empty HOT 1
- CI Scripts don't report failure properly
- Editors and IDEs support? HOT 4
- Sponsorship HOT 7
- Can it compile to a dll/so? HOT 3
- Please enable Github discussion HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from virgil.