All Projects → RyanLamansky → Dotnet Webassembly

RyanLamansky / Dotnet Webassembly

Licence: apache-2.0
Create, read, modify, write and execute WebAssembly (WASM) files from .NET-based applications.

Programming Languages

csharp
926 projects

Projects that are alternatives of or similar to Dotnet Webassembly

Blog Core
Modular blog using Blazor with clean domain-driven design patterns
Stars: ✭ 345 (-35.51%)
Mutual labels:  dotnet-standard, dotnet-core, webassembly
Jwebassembly
Java bytecode to WebAssembly compiler
Stars: ✭ 426 (-20.37%)
Mutual labels:  webassembly, wasm
Dotnet Win32 Service
Helper classes to set up and run as windows services directly on .net core. A ServiceBase alternative.
Stars: ✭ 425 (-20.56%)
Mutual labels:  dotnet-standard, dotnet-core
Zwitterion
A web dev server that lets you import anything*
Stars: ✭ 514 (-3.93%)
Mutual labels:  webassembly, wasm
Bootstrapblazor
A set of enterprise-class UI components based on Bootstrap and Blazor
Stars: ✭ 403 (-24.67%)
Mutual labels:  webassembly, wasm
Alexa Skills Dotnet
An Amazon Alexa Skills SDK for .NET
Stars: ✭ 412 (-22.99%)
Mutual labels:  dotnet-standard, dotnet-core
Vim.wasm
Vim editor ported to WebAssembly
Stars: ✭ 4,915 (+818.69%)
Mutual labels:  webassembly, wasm
Lucet
Lucet, the Sandboxing WebAssembly Compiler.
Stars: ✭ 4,006 (+648.79%)
Mutual labels:  webassembly, wasm
Wasm And Rust
WebAssembly and Rust: A Web Love Story
Stars: ✭ 476 (-11.03%)
Mutual labels:  webassembly, wasm
Netfabric.hyperlinq
High performance LINQ implementation with minimal heap allocations. Supports enumerables, async enumerables, arrays and Span<T>.
Stars: ✭ 479 (-10.47%)
Mutual labels:  dotnet-standard, dotnet-core
Uno
Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
Stars: ✭ 6,029 (+1026.92%)
Mutual labels:  webassembly, wasm
Linqtotwitter
LINQ Provider for the Twitter API (C# Twitter Library)
Stars: ✭ 401 (-25.05%)
Mutual labels:  dotnet-standard, dotnet-core
Rustynes
👾 An NES emulator by Rust and WebAssembly
Stars: ✭ 399 (-25.42%)
Mutual labels:  webassembly, wasm
Ink
Parity's ink! to write smart contracts
Stars: ✭ 407 (-23.93%)
Mutual labels:  webassembly, wasm
Storage
💿 Storage abstractions with implementations for .NET/.NET Standard
Stars: ✭ 380 (-28.97%)
Mutual labels:  dotnet-standard, dotnet-core
Camaro
camaro is an utility to transform XML to JSON, using Node.js binding to native XML parser pugixml, one of the fastest XML parser around.
Stars: ✭ 438 (-18.13%)
Mutual labels:  webassembly, wasm
Awesome Wasm Runtimes
A list of webassemby runtimes
Stars: ✭ 490 (-8.41%)
Mutual labels:  webassembly, wasm
Awesome Yew
😎 A curated list of awesome things related to Yew / WebAssembly.
Stars: ✭ 353 (-34.02%)
Mutual labels:  webassembly, wasm
Wac
WebAssembly interpreter in C
Stars: ✭ 372 (-30.47%)
Mutual labels:  webassembly, wasm
Asmble
Compile WebAssembly to JVM and other WASM tools
Stars: ✭ 466 (-12.9%)
Mutual labels:  webassembly, wasm

WebAssembly for .NET

NuGet

A library able to create, read, modify, write and execute WebAssembly (WASM) files from .NET-based applications. Execution does not use an interpreter or a 3rd party library: WASM instructions are mapped to their .NET equivalents and converted to native machine language by the .NET JIT compiler.

Available on NuGet at https://www.nuget.org/packages/WebAssembly .

Getting Started

  • Use the WebAssembly.Module class to create, read, modify, and write WebAssembly (WASM) binary files.
    • Module.ReadFromBinary reads a stream into an instance, which can then be inspected and modified through its properties.
    • WriteToBinary on a module instance writes binary WASM to the provided stream.
    • There are no known issues with this functionality and the API is stable.
  • Use the WebAssembly.Runtime.Compile class to execute WebAssembly (WASM) binary files using the .NET JIT compiler.
    • This part of the API is in "beta" status and may require changes to improve compliance with WASM standards.

Please report an issue if you encounter an assembly that works in browsers but not with this library.

Sample: Create and execute a WebAssembly file in memory

using System;
using WebAssembly; // Acquire from https://www.nuget.org/packages/WebAssembly
using WebAssembly.Instructions;
using WebAssembly.Runtime;

// We need this later to call the code we're generating.
public abstract class Sample
{
    // Sometimes you can use C# dynamic instead of building an abstract class like this.
    public abstract int Demo(int value);
}

static class Program
{
    static void Main()
    {
        // Module can be used to create, read, modify, and write WebAssembly files.
        var module = new Module(); // In this case, we're creating a new one.

        // Types are function signatures: the list of parameters and returns.
        module.Types.Add(new WebAssemblyType // The first added type gets index 0.
        {
            Parameters = new[]
            {
                WebAssemblyValueType.Int32, // This sample takes a single Int32 as input.
                // Complex types can be passed by sending them in pieces.
            },
            Returns = new[]
            {
                // Multiple returns are supported by the binary format.
                // Standard currently allows a count of 0 or 1, though.
                WebAssemblyValueType.Int32,
            },
        });
        // Types can be re-used for multiple functions to reduce WASM size.

        // The function list associates a function index to a type index.
        module.Functions.Add(new Function // The first added function gets index 0.
        {
            Type = 0, // The index for the "type" value added above.
        });

        // Code must be passed in the exact same order as the Functions above.
        module.Codes.Add(new FunctionBody
        {
            Code = new Instruction[]
            {
                new LocalGet(0), // The parameters are the first locals, in order.
                // We defined the first parameter as Int32, so now an Int32 is at the top of the stack.
                new Int32CountOneBits(), // Returns the count of binary bits set to 1.
                // It takes the Int32 from the top of the stack, and pushes the return value.
                // So, in the end, there is still a single Int32 on the stack.
                new End(), // All functions must end with "End".
                // The final "End" also delivers the returned value.
            },
        });

        // Exports enable features to be accessed by external code.
        // Typically this means JavaScript, but this library adds .NET execution capability, too.
        module.Exports.Add(new Export
        {
            Kind = ExternalKind.Function,
            Index = 0, // This should match the function index from above.
            Name = "Demo", // Anything legal in Unicode is legal in an export name.
        });

        // We now have enough for a usable WASM file, which we could save with module.WriteToBinary().
        // Below, we show how the Compile feature can be used for .NET-based execution.
        // For stream-based compilation, WebAssembly.Compile should be used.
        var instanceCreator = module.Compile<Sample>();

        // Instances should be wrapped in a "using" block for automatic disposal.
        // This sample doesn't import anything, so we pass an empty import dictionary.
        using (var instance = instanceCreator(new ImportDictionary()))
        {
            // FYI, instanceCreator can be used multiple times to create independent instances.
            Console.WriteLine(instance.Exports.Demo(0)); // Binary 0, result 0
            Console.WriteLine(instance.Exports.Demo(1)); // Binary 1, result 1,
            Console.WriteLine(instance.Exports.Demo(42));  // Binary 101010, result 3
        } // Automatically release the WebAssembly instance here.
    }
}

Current Development Objectives

  • Improve official specification compliance, using Google Chrome as the reference for correct behavior.
  • Improve exceptions thrown from problems found during compilation or execution.
  • Provide a mechanism to replace the System.Reflection.Emit.AssemblyBuilder-affiliated methods with replacements so that something like Mono.Cecil can be used to produce a DLL.
  • If https://github.com/dotnet/corefx/issues/4491 is fixed, use it to enable saving DLLs.
  • Remove the compiler's Data section segment size limit of 4128768 bytes.
  • Add support for new WebAssembly features as they become standardized.

Other Information

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].