diff --git a/runner/build.sh b/runner/build.sh index 32599dd..02e89c9 100755 --- a/runner/build.sh +++ b/runner/build.sh @@ -3,4 +3,13 @@ # "Compile rust source and put it as a tested contract" mkdir -p out -rustc $1 -o out/contract.js -O --target wasm32-unknown-emscripten \ No newline at end of file + +file=$1 +if [ ${file: -3} == ".rs" ] +then + # Rust is compiled with rustc + rustc $file -o out/contract.js -O --target wasm32-unknown-emscripten +else + # c/c++ can be compiled directly by emcc + emcc $file -Os -s WASM=1 -s SIDE_MODULE=1 -o out/contract.wasm +fi \ No newline at end of file diff --git a/runner/index.html b/runner/index.html index 283754b..9a1e765 100644 --- a/runner/index.html +++ b/runner/index.html @@ -35,7 +35,7 @@ env.DYNAMICTOP_PTR = env.DYNAMICTOP_PTR || 0; env.STACKTOP = env.STACKTOP || 0; - env.STACK_MAX = env.STACK_MAX || 0; + env.STACK_MAX = env.STACK_MAX || 5*1024*1024; env.enlargeMemory = env.enlargeMemory || function() { throw "error enlarging memory"; }; env.getTotalMemory = env.getTotalMemory || function() { return 65536 * 256; }; env.abortOnCannotGrowMemory = env.abortOnCannotGrowMemory || function() { throw "abort growing memory"; }; @@ -45,10 +45,10 @@ env.tableBase = env.tableBase || 0; if (!imports.env.memory) { - imports.env.memory = new WebAssembly.Memory({ initial: 256 }); + imports.env.memory = new WebAssembly.Memory({ initial: 256, maximum: 256 }); } if (!imports.env.table) { - imports.env.table = new WebAssembly.Table({ initial: 0, element: 'anyfunc' }); + imports.env.table = new WebAssembly.Table({ initial: 0, maximum: 0, element: 'anyfunc' }); } return new WebAssembly.Instance(module, imports); }); diff --git a/samples/hello_world.c b/samples/hello_world.c new file mode 100644 index 0000000..7c99106 --- /dev/null +++ b/samples/hello_world.c @@ -0,0 +1,3 @@ +int call(int x) { + return 2 * x; +} \ No newline at end of file