GithubHelp home page GithubHelp logo

ericsink / wasm2cil Goto Github PK

View Code? Open in Web Editor NEW
278.0 23.0 23.0 2.93 MB

A "compiler" that can take a WebAssembly/WASI module and convert it to a .NET assembly

License: Apache License 2.0

C 96.18% Shell 0.03% F# 3.40% C# 0.38% Rust 0.01%

wasm2cil's Introduction

wasm2cil

This is a .NET compiler for WebAssembly modules, including support for WASI.

Specifically, it can take a WebAssembly module and translate it into a .NET assembly on disk.

The resulting DLL is not interpreted -- it contains the same functions as the WebAssembly module, translated from Wasm instructions to CIL instructions.

This is designed to be used with Clang 8 and wasi-sysroot. In that sense, this provides a way to compile C/C++ for .NET, using Wasm as a halfway point. Like an alternative to pinvoke.

(Rust should hopefully work too, but I haven't tried that yet.)

All of this is very much a work in progress.

But the current status is that some basic things do work. Working test apps in this repo include a small ray tracer and a basic port of SQLite. The latter can read and write SQLite database files that seem to be fully interoperable with "regular" SQLite builds.

Still, I suggest you not try using this for anything serious yet.

The subdirectories of this repo have README files with a bit more info.

See my blog entry for more information.

wasm2cil's People

Contributors

ericsink avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wasm2cil's Issues

Is this project dead?

It'd be a shame if this project was dead.
Getting native .NET libraries from other languages would be awesome.

Even just getting stock Sqlite as a native library for in-memory SQL handling would be spectacular.

Wrap compiler into dotnet tool

Hi, as I figure out currently to play around with wasm2cil need to clone project and build via dotnet run command

Will be great to publish compiler to a NuGet and give a ability to install compiler as dotnet tool like:

dotnet tool install wasm2cil -g
# and use it like that
dotnet-wasm2cil

Missing wasi-libc implementations

Here's a list of missing features from wasi-libc (as of Feb 23). This could be used to track issues:

Flags

  • __WASI_SIGNAL_NONE

Structs

  • __wasi_dirent_t
  • __wasi_event_fd_readwrite_t
  • __wasi_event_t
  • __wasi_prestat_u_t

Methods

  • __wasi_clock_res_get()
  • __wasi_clock_time_get() (Partially implemented)
  • __wasi_fd_advise()
  • __wasi_fd_allocate()
  • __wasi_fd_close()
  • __wasi_fd_datasync()
  • __wasi_fd_fdstat_set_flags()
  • __wasi_fd_fdstat_set_rights()
  • __wasi_fd_filestat_get()
  • __wasi_fd_filestat_set_size()
  • __wasi_fd_filestat_set_times()
  • __wasi_fd_pread()
  • __wasi_fd_prestat_dir_name() (Partially implemented)
  • __wasi_fd_pwrite()
  • __wasi_fd_readdir()
  • __wasi_fd_renumber()
  • __wasi_fd_seek() (Partially implemented)
  • __wasi_fd_sync() (Partially implemented)
  • __wasi_fd_tell()
  • __wasi_path_filestat_set_times()
  • __wasi_path_link()
  • __wasi_path_open()
  • __wasi_path_readlink()
  • __wasi_path_rename()
  • __wasi_path_symlink()
  • __wasi_proc_raise()
  • __wasi_random_get() (Partially implemented)
  • __wasi_sched_yield()
  • __wasi_sock_recv()
  • __wasi_sock_send()
  • __wasi_sock_shutdown()
  • __wasi_subscription_clock_t
  • __wasi_subscription_fd_readwrite_t
  • __wasi_subscription_t
  • __wasi_subscription_u_u_t

Support for imported functions that aren't provided by wasi

I might be missing something but I can't figure out how to load a module that has a set of imports that look like this:

  (import "env" "myfunc" (func $myfunc (type $t1)))
  (import "wasi_unstable" "fd_close" (func $__wasi_fd_close (type $t2)))
  (import "wasi_unstable" "fd_seek" (func $__wasi_fd_seek (type $t3)))
  (import "wasi_unstable" "fd_fdstat_get" (func $__wasi_fd_fdstat_get (type $t4)))
  (import "wasi_unstable" "fd_write" (func $__wasi_fd_write (type $t5)))

The idea is that myfunc would be provided by a separate .NET assembly. I assume that gen_assembly would need to be modified to accept multiple assemblies for this to be possible?

Exports are not used

It seems like the compiler completely ignores the exports section, leading to quite a lot of functions missing in my code. This is because they actually have the same function body and LLVM (or the linker, not sure) deduplicates them. However that single remaining function is then exported with both names to the user. wasm2cil does not look at the export section at all it seems and simply exports all functions with their internal name, leading to one or more of my functions missing each.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.