Coder Social home page Coder Social logo

wasdk's Introduction

Build Status

WebAssembly SDK

A toolkit for creating WebAssembly modules.

Installing Wasdk

Installing from NPM

npm install wasdk

Installing from GitHub

This is recommended if you want to contribute to the wasdk project.

Clone this repository and run:

npm run installdeps

and to build sources:

npm run build

To download all necessary pre-compiled binaries for your operating system, which includes: Emscripten, Binaryen, SpiderMonkey, LLVM and Clang:

wasdk sdk --install

And clean up (built sourced and download binaries):

npm run clean

Usage

Wasdk includes a variety of tools which accessible through the wasdk command:

Compiling Modules

wasdk ez test/malloc.json -o malloc.js

This producs several files:

  • malloc.asm.js: asm.js code
  • malloc.wasm: WebAssembly Binary
  • malloc.wast WebAssembly Text
  • malloc.js: Node / Browser runtime environment.

Running Modules

wasdk js dist/wasm-shell.js malloc.wasm

This creates a lightweight WebAssembly environemnt and runs the malloc.wasm file. At the moment, this only works with the malloc.wasm file.

Viewing WebAssembly Compiled Machine Code

Use the disassemble command to view the compiled machine code for a WebAssembly program. This code is generated by the ION compiler (used in the Firefox Web Browser). It should be fairly similar to the code produced by other browser engines.

wasdk disassemble test/universe.wast
(module
  (export "answer" (func $answer))
  (func $answer (result i32)
    (return (i32.const 42))
  )
)

Compiled x86/AMD64 Code:

Total Code Size: 5.00 Bytes
100.00%    5          Func 0:
Func 0:
  sub rsp, 8                                        ; 0x000050 48 83 ec 08
  mov eax, 0x2a                                     ; 0x000054 b8 2a 00 00 00
  nop                                               ; 0x000059 66 90
  add rsp, 8                                        ; 0x00005b 48 83 c4 08
  ret                                               ; 0x00005f c3

SDK Management

wasdk sdk --install
wasdk sdk --clean

Testing

npm test

wasdk's People

Contributors

mbebenita avatar yurydelendik 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wasdk's Issues

Can't reproduce the builds from https://wasdk.github.io/WasmFiddle

This code

int fib(int n) {
  if(n<0)
	return -1;
  else if (n==0)
	return 0;
  else if (n==1)
	return 1;
  else if (n>1)
	return fib(n-1) + fib(n-2);
	return 0;
}

In the WasmFiddle return this functioning wasm :

0061 736d 0100 0000 0186 8080 8000 0160
017f 017f 0382 8080 8000 0100 0484 8080
8000 0170 0000 0583 8080 8000 0100 0106
8180 8080 0000 0790 8080 8000 0206 6d65
6d6f 7279 0200 0366 6962 0000 0ac3 8080
8000 01bd 8080 8000 0101 7f41 0021 0102
4002 4020 0041 0048 0d00 0240 2000 450d
0041 0121 0120 0041 0147 0d02 0b20 010f
0b41 7f0f 0b20 0041 7f6a 1000 2000 417e
6a10 006a 0b

This does a perfect job.

wasdk ez hello.c -o hello.js

returns :

INFO:root:generating system asset: is_vanilla.txt... (this will be cached in "/Users/fabien/.emscripten_cache/is_vanilla.txt" for subsequent builds)
INFO:root: - ok
WARNING:root:(Emscripten: settings file has changed, clearing cache)
INFO:root:(Emscripten: Running sanity checks)
WARNING:root:Assigning a non-existent settings attribute "BINARYEN_IMPRECISE"
WARNING:root: - did you mean one of BINARYEN_PASSES, BINARYEN_METHOD, BINARYEN_MEM_MAX?
WARNING:root: - perhaps a typo in emcc's  -s X=Y  notation?
WARNING:root: - (see src/settings.js for valid values)

( I understand that it looks like the issue you closed, but I have no error, just a result that is not working properly)

And produces this code :

0061 736d 0100 0000 000c 0664 796c 696e
6b80 80c0 0200 0189 8080 8000 0260 017f
017f 6000 0002 c180 8080 0004 0365 6e76
0a6d 656d 6f72 7942 6173 6503 7f00 0365
6e76 066d 656d 6f72 7902 0080 0203 656e
7605 7461 626c 6501 7000 0003 656e 7609
7461 626c 6542 6173 6503 7f00 0384 8080
8000 0300 0101 068b 8080 8000 027f 0141
000b 7f01 4100 0b07 ab80 8080 0003 125f
5f70 6f73 745f 696e 7374 616e 7469 6174
6500 020b 7275 6e50 6f73 7453 6574 7300
0104 5f66 6962 0000 0981 8080 8000 000a
f180 8080 0003 c980 8080 0001 017f 027f
0240 2000 4100 4804 4041 7f21 0005 0240
0240 0240 2000 0e02 0001 020b 4100 2100
0c03 0b41 0121 000c 020b 2000 417f 6a10
0021 0120 0041 7e6a 1000 2001 6a0f 0b0b
2000 0b0b 8380 8080 0000 010b 9580 8080
0000 0240 2300 2402 2302 4180 80c0 026a
2403 1001 0b0b

So, I tried to write a configuration file :

{
    "compilerOptions": {
    },
    "output": "hello.wasm",
    "files": [
        "hello.c"
    ],
    "options": {
        "ALLOW_MEMORY_GROWTH": 0,
        "RELOCATABLE": 1,
        "SIDE_MODULE": 1,
        "EXPORTED_RUNTIME_METHODS": [],
        "EXPORTED_FUNCTIONS": [],
        "VERBOSE": 1
    }
}

If I understand correctly, I need "SIDE_MODULE": 1, to generate only the small module. But it is not compatible with ALLOW_MEMORY_GROWTH.

It return those warnings :

WARNING:root:Assigning a non-existent settings attribute "BINARYEN_IMPRECISE"
WARNING:root: - did you mean one of BINARYEN_PASSES, BINARYEN_METHOD, BINARYEN_MEM_MAX?
WARNING:root: - perhaps a typo in emcc's  -s X=Y  notation?
WARNING:root: - (see src/settings.js for valid values)
VERBOSE is on, this generates a lot of output and can slow down compilation

I don't understand the first one since I did set it. Doesn't it goes into the compilerOptions ? The options are the ones from https://github.com/kripken/emscripten/blob/master/src/settings.js right ?

Then I realised by reading the source https://github.com/wasdk/wasdk/blob/master/src/wasdk.ts that only a few of those elements are possible. And that "BINARYEN_IMPRECISE=1" is a default.

In short : I'm a bit lost.

I know this may seems lazy but : what's the correct command to reproduce the WasmFiddle code ? (and how to set the language target to C++14 and the optimisations to "s" ?)

That would be awesome to have a documentation about it.

Error trying to compile

Hi, first of all, very good job with the Fiddle! It works very smoothly!
I am now trying to use the API locally, I installed it with npm install, but when I try to build a c file to wasm I am getting some errors, maybe you have some ideas.
I had to add sudo on Mac after installing wasdk with npm install -g

$ sudo wasdk ez fib.c -o fib.js
WARNING:root:Assigning a non-existent settings attribute "BINARYEN_IMPRECISE"
WARNING:root: - did you mean one of BINARYEN_PASSES, BINARYEN_METHOD, BINARYEN_MEM_MAX?
WARNING:root: - perhaps a typo in emcc's  -s X=Y  notation?
WARNING:root: - (see src/settings.js for valid values)
Unknown option '--emit-jsified-potential-traps'
Traceback (most recent call last):
  File "/usr/local/lib/node_modules/wasdk/bin/emscripten/emcc", line 13, in <module>
    emcc.run()
  File "/usr/local/lib/node_modules/wasdk/bin/emscripten/emcc.py", line 2169, in run
    subprocess.check_call(cmd)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/local/lib/node_modules/wasdk/bin/binaryen/bin/asm2wasm', '/Users/wcarvalho/projects/webassembly/fib.asm.js', '--total-memory=16777216', '--emit-jsified-potential-traps', '-O3', '--table-max=-1', '--mem-max=-1', '-o', '/Users/wcarvalho/projects/webassembly/fib.wasm']' returned non-zero exit status 1
/usr/local/lib/node_modules/wasdk/dist/wasdk.js:317
        shared_1.fail("Compilation error: " + res.error.toString());
                                                       ^

TypeError: Cannot read property 'toString' of undefined
    at ezCompile (/usr/local/lib/node_modules/wasdk/dist/wasdk.js:317:56)
    at Object.<anonymous> (/usr/local/lib/node_modules/wasdk/dist/wasdk.js:53:5)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)

Cheers!

Weird memory access Error

When you run the function ToMatrix twice, it gives memory access error, makes no sense.
I simplified the bug as much as possible, to reproduce it just use the following.
https://wasdk.github.io/WasmFiddle/

###############C++14###############
#include <math.h> 

void ToMatrix(double** M,double* V,int length)
{
  for (int i = 0; i < length; i++)
	{
		for (int j = 0; j < length; j++)
		{
			M[i][j] = V[i * length + j];
		}
	}
}

void myfunc(double* AT, int length)
{
	double** Matrix = new double* [length];
	for (int i = 0; i < length; i++)
	{
		Matrix[i] = new double[length];
  }
  
  ToMatrix(Matrix,AT,length);
	////Error comes when you do it twice
	ToMatrix(Matrix,AT,length);
	///
}
###############Javascript###############
var wasmModule = new WebAssembly.Module(wasmCode);
wasmInstance = new WebAssembly.Instance(wasmModule, wasmImports);

matrix1 = [[12,-51,4],[6,167,-68],[-4,24,-41]]
InputArray = new Float64Array(wasmInstance.exports.memory.buffer,0,9)
for (var i = 0; i < 3; i++) 
	{
	  for (var j = 0; j < 3; j++) 
	{
	  InputArray[3*i+j] = matrix1[i][j]
	}
}
log(InputArray)
wasmInstance.exports._Z6myfuncPdi(0,3);

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.