dcodeio / webassembly Goto Github PK
View Code? Open in Web Editor NEWA minimal toolkit and runtime to produce and run WebAssembly modules.
License: Other
A minimal toolkit and runtime to produce and run WebAssembly modules.
License: Other
wa compile
throws 4 errors when trying to compile a c++ file that imports the webassembly header.
You can reproduce it by copying the example code in the readme into a file named program.cpp
and trying to run wa compile -o program.wasm program.cpp
.
Output:
Compiling on darwin-x64 ...
clang program.cpp
-c
--target=wasm32-unknown-unknown
-emit-llvm
-nostdinc
-nostdlib
-D WEBASSEMBLY
-isystem /Users/emurray/.nvm/versions/node/v7.7.3/lib/node_modules/webassembly/include
-o /var/folders/ts/rnwyskln05vg3cbkgl5d4s5xb72qlv/T/wa1_1788ixvKyawdM9VX.tmp
In file included from program.cpp:1:
In file included from /Users/emurray/.nvm/versions/node/v7.7.3/lib/node_modules/webassembly/include/webassembly.h:16:
/Users/emurray/.nvm/versions/node/v7.7.3/lib/node_modules/webassembly/include/uchar.h:17:35: error: C++ requires a type specifier for all declarations
size_t c16rtomb(char *__restrict, char16_t, mbstate_t *__restrict);
^
/Users/emurray/.nvm/versions/node/v7.7.3/lib/node_modules/webassembly/include/uchar.h:18:17: error: unknown type name 'char16_t'
size_t mbrtoc16(char16_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict);
^
/Users/emurray/.nvm/versions/node/v7.7.3/lib/node_modules/webassembly/include/uchar.h:20:35: error: C++ requires a type specifier for all declarations
size_t c32rtomb(char *__restrict, char32_t, mbstate_t *__restrict);
^
/Users/emurray/.nvm/versions/node/v7.7.3/lib/node_modules/webassembly/include/uchar.h:21:17: error: unknown type name 'char32_t'
size_t mbrtoc32(char32_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict);
^
4 errors generated.
I've also tried extern "C"
the header with the same result (and it looks like you've externed all the header files anyway.)
I should also note that I'm very new to c, cpp and learning just to play with wasm so it's very likely that I've made a silly error.
Considering submitting a PR adding an examples folder with proper npm scripts/build process in place for users to easily npm install && npm start
to get up and running.
Thoughts? Would this be likely to get accepted?
Edit: I've missed this PR ca9b195, it would be a more in depth version of this I guess
What can I do if I need to force a standard to compile the c code to webassembly?
I'm trying to compile it with the C90 Ansi standard, and I have no clues about the one used by the compiler of this module
Will this tool help me build a VS17 project? I don't really understand much of the documentation here. I am looking everywhere for a simple explanation of how to build a VS17 project with emscripten for webAssembly.
I tried to install webassembly on my wsl, but got the following errors
⚡ root > npm install -g webassembly
npm WARN deprecated [email protected]: ⚠️ WARNING ⚠️ tar.gz module has been deprecated and your application is vulnerable. Please use tar module instead: https://npmjs.com/tar
/usr/local/bin/wa -> /usr/local/lib/node_modules/webassembly/bin/wa
/usr/local/bin/wa-compile -> /usr/local/lib/node_modules/webassembly/bin/wa-compile
/usr/local/bin/wa-assemble -> /usr/local/lib/node_modules/webassembly/bin/wa-assemble
/usr/local/bin/wa-disassemble -> /usr/local/lib/node_modules/webassembly/bin/wa-disassemble
> [email protected] postinstall /usr/local/lib/node_modules/webassembly
> node scripts/setup
sh: 1: node: Permission denied
npm ERR! Linux 4.4.0-43-Microsoft
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "webassembly"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! [email protected] postinstall: `node scripts/setup`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] postinstall script 'node scripts/setup'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the webassembly package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node scripts/setup
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs webassembly
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls webassembly
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /root/npm-debug.log
log is here: npm-debug.log
What is more interesting is that there's no webassembly
folder under nodes_modules
folder after install:
⚡ root > ls -al /usr/local/lib/node_modules
total 0
drwxr-xr-x 0 root root 512 Oct 23 14:36 .
drwxr-xr-x 0 root root 512 Oct 23 11:45 ..
drwxrwxrwx 0 root root 512 Oct 23 14:27 tar
drwxrwxrwx 0 nobody root 512 Oct 23 14:31 wargo
But still, /usr/local/bin/wa
is present.
Downloading binaries for darwin-x64 ...
/private/tmp/w/node_modules/webassembly/scripts/setup.js:64
throw err;
^
Error: no prebuilt binaries available for darwin-x64 (code 404)
at RedirectableRequest.https.get.res (/private/tmp/w/node_modules/webassembly/scripts/setup.js:21:22)
Hi, I can install packages with npm most of the time, but when I run npm install -g webassembly
in a Docker container from library/debian:buster, then I get an error at the end of the installation:
# npm install -g webassembly
npm WARN npm npm does not support Node.js v10.15.1
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.
npm WARN npm You can find the latest version at https://nodejs.org/
npm WARN deprecated [email protected]: ⚠️ WARNING ⚠️ tar.gz module has been deprecated and your application is vulnerable. Please use tar module instead: https://npmjs.com/tar
/usr/local/bin/wa -> /usr/local/lib/node_modules/webassembly/bin/wa
/usr/local/bin/wa-compile -> /usr/local/lib/node_modules/webassembly/bin/wa-compile
/usr/local/bin/wa-assemble -> /usr/local/lib/node_modules/webassembly/bin/wa-assemble
/usr/local/bin/wa-disassemble -> /usr/local/lib/node_modules/webassembly/bin/wa-disassemble
> [email protected] postinstall /usr/local/lib/node_modules/webassembly
> node scripts/setup
fs.js:115
throw err;
^
Error: EACCES: permission denied, open '/usr/local/lib/node_modules/webassembly/wa-tools-3287gDj9vAX5jff0.tmp'
at Object.openSync (fs.js:439:3)
at Object._createTmpFileSync [as fileSync] (/usr/local/lib/node_modules/webassembly/node_modules/tmp/lib/tmp.js:266:15)
at Object.<anonymous> (/usr/local/lib/node_modules/webassembly/scripts/setup.js:18:16)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `node scripts/setup`
npm ERR! Exit status 1
Any tips for resolution?
My system has libtinfo.so.6 so binaries don't work, how should I compile this? I haven't found instructions for that anywhere. Thanks
When passing -O
to cli/compiler
I'm getting in the compiled module:
LinkError: WebAssembly Instantiation: Import #3 module="env" function="memset" error: function import requires a callable at <anonymous>
I'm using malloc in my code, the compiler arguments look like this:
let args = [
"-O",
"-q",
"-o", "./wasm_tmp.wasm",
"src/main.c"
];
Hi all,
I am trying to compile a simple Hello World Script.
#include <stdio.h>
char * c_hello() {
return "Hello World";
}
I can compile it fine using mbebenita.github.io/WasmExplorer but when I try to compile it using the following command
./node_modules/.bin/wa compile -o HelloWorld.wasm HelloWorld.c
I get the following error
$> ./node_modules/.bin/wa compile -o HelloWorld.wasm HelloWorld.c
Compiling on darwin-x64 ...
clang HelloWorld.c
-c
--target=wasm32-unknown-unknown
-emit-llvm
-nostdinc
-nostdlib
-D WEBASSEMBLY
-isystem /Users/anthonybudd/Development/WebAssembly_HelloWorld/node_modules/webassembly/include
-o /var/folders/vl/3fkjykn52zdb88cv3flv75zr0000gn/T/wa1_7474HSLCSC30dn9g.tmp
HelloWorld.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
FAILED Error: code 1
at ChildProcess.<anonymous> (/Users/anthonybudd/Development/WebAssembly_HelloWorld/node_modules/webassembly/cli/util.js:38:24)
at ChildProcess.emit (events.js:200:13)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
FYI I know absolutely nothing about C. So apologies if this is a stupid question.
Hi,
Awesome minimalist tool, all is working fine expect when I try to grow memory or use malloc.
Do I have to grow memory at a specific time ?
I'm not a C expert maybe i'm doing something wrong. I working on mac and using npm lib using webpack to compile the final app.
Otherwise all's fine I did some test on matrix operation using a custom C port of gl-matrix I have a x10 execution speed with optimisation enabled. Performance is much less significant when I use math function (sin,cos) on matrix rotation), I have x1.3 exec speed.
Cheers,
I know that this project is inspired by emcsripten.
In emscripten, you can compile a c code that uses malloc, and you don't need to import it.
The malloc is defined in the .wasm, and you can export it.
Why can't I do something similar with this tool ?
I don't know how I'm suppose to export the malloc function !
Any chance to add support for ARM?
I'm working on a Raspberry PI and this would really simplify my workflow.
As the description, the module provider runtime for WebAssembly modules.
I used AssemblyScript
to compile the typescript file to wasm.
export function add(x: u64, y: u64): u64 {
return x + y;
}
Then, using the webassembly
to run the module,
require("webassembly")
.load("main.wasm")
.then(module => {
console.log("1 + 2 = " + module.exports.add(1, 2));
});
I got the error below
(node:92224) UnhandledPromiseRejectionWarning: TypeError: wasm function signature contains illegal type
at require.load.then.module (/Users/Peng/Downloads/wasm-project-yolspucnghl/out/program.js:7:45)
(node:92224) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:92224) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Is there a gap between the AssemblyScript
and webassembly
?
And is there a node.js module to run the webassembly modules that AseemblyScript
compiled.
I have a simple C file:
#include <webassembly.h>
export int contract_function(int bid) {
return bid;
}
compiled with:
wa-compile --bare -o example.wasm example.c
Which generates:
(module
(type $0 (func (param i32) (result i32)))
(import "env" "memory" (memory $0 1))
(table 0 anyfunc)
(export "contract_function" (func $0))
(func $0 (type $0) (param $var$0 i32) (result i32)
(block $label$0 i32
(i32.store offset=12
(i32.sub
(i32.load offset=4
(i32.const 0)
)
(i32.const 16)
)
(get_local $var$0)
)
(get_local $var$0)
)
)
)
This generates a memory RuntimeError: memory access out of bounds
when I try to load it.
However, when I compile using wasmfiddle I get:
(module
(table 0 anyfunc)
(memory $0 1)
(export "memory" (memory $0))
(export "contract_function" (func $contract_function))
(func $contract_function (; 0 ;) (param $0 i32) (result i32)
(get_local $0)
)
)
Any ideas?
wa compile -Oo output/dir/target.wasm source.c
$ npm run wasm # wa compile -Oo priv/static/dist/fib.wasm fib.c
> [email protected] wasm /Users/yumatsuzawa/Workspace/yubot
> wa compile -Oo priv/static/dist/fib.wasm wasm/src/fib.c
Compiling on darwin-x64 ...
clang wasm/src/fib.c
-O
-c
--target=wasm32-unknown-unknown
-emit-llvm
-nostdinc
-nostdlib
-D WEBASSEMBLY
-isystem /Users/yumatsuzawa/Workspace/yubot/node_modules/webassembly/include
-o /var/folders/f0/03jcty091k3684vmw5qr8yf00000gp/T/wa1_92739CYGeomA1qYDj.tmp
llvm-link /var/folders/f0/03jcty091k3684vmw5qr8yf00000gp/T/wa1_92739CYGeomA1qYDj.tmp /Users/yumatsuzawa/Workspace/yubot/node_modules/webassembly/lib/webassembly.bc
-only-needed
-o /var/folders/f0/03jcty091k3684vmw5qr8yf00000gp/T/wa2_92739T8s4xIqm7bBx.tmp
llc /var/folders/f0/03jcty091k3684vmw5qr8yf00000gp/T/wa2_92739T8s4xIqm7bBx.tmp
-march=wasm32
-filetype=asm
-asm-verbose=false
-thread-model=single
-data-sections
-function-sections
-o /var/folders/f0/03jcty091k3684vmw5qr8yf00000gp/T/wa1_92739CYGeomA1qYDj.tmp
s2wasm /var/folders/f0/03jcty091k3684vmw5qr8yf00000gp/T/wa1_92739CYGeomA1qYDj.tmp
--import-memory
--allocate-stack 10000
-o /var/folders/f0/03jcty091k3684vmw5qr8yf00000gp/T/wa2_92739T8s4xIqm7bBx.tmp
wasm-opt /var/folders/f0/03jcty091k3684vmw5qr8yf00000gp/T/wa2_92739T8s4xIqm7bBx.tmp
-O3
--coalesce-locals-learning
--dce
--duplicate-function-elimination
--inlining
--local-cse
--merge-blocks
--optimize-instructions
--reorder-functions
--reorder-locals
--vacuum
-o priv/static/dist/fib.wasm
Failed opening 'priv/static/dist/fib.wasm'
FAILED Error: code 1
at ChildProcess.<anonymous> (/Users/yumatsuzawa/Workspace/yubot/node_modules/webassembly/cli/util.js:38:24)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at maybeClose (internal/child_process.js:925:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
$ echo $status
0
In this case, priv/static/dist
directory does not exist yet, so wasm-opt
failing on file opening.
It exited with error code 1, though wa compile
command itself is exiting with exit status 0 as shown above (I'm using fish-shell so echo $status
equals to echo $?
in bash).
After following your instructions in the README I get the following issue in Chrome 59:
src:211 Uncaught (in promise) LinkError: Import #0 module="env" function="DYNAMICTOP_PTR" error: global import must be a number at then.then.buffer (http://127.0.0.1:8080/node_modules/webassembly/dist/webassembly.js:212:37) at <anonymous>
However it works correctly in Firefox Nightly.
Had to comment out the -static-libgcc
flags for it to compile. Test passing, haven't tried anything else yet.
I tried to use npm install webassembly
and wa compile
failed to compile. I then forked and cloned this repo and tried it and it takes the same way. After investigating I determined the pre-compiled tools isn't untaring properly and in linux-x64 only clang is there and it's not executable.
I then tired untaring manually and that worked but when I tried to execute clang it failed because of missing shared libraries. In the end I used a local version of wasm clang, binaryen, want tools that I'd created previously. And symlinked tools/bin/linux-x64 to my build, and that worked.
It seems that this module causes a global variable leak 'WebAssembly'.
Perhaps this is required or intentional, but it breaks leak detection for all dependent packages (chalk, for example).
If it's possible, it'd be best to stop 'WebAssembly' leaking, if this isn't possible then feel free to close this issue.
When I follow the steps for running the example here, I run into an error regarding access rights. Is there some more set up that isn't mentioned here that I could be missing?
I'm running node v6.11.1
I get the same error if I use sudo
as well.
❯ wa compile -o program.wasm program.c
Compiling on darwin-x64 ...
clang program.c
-c
--target=wasm32-unknown-unknown
-emit-llvm
-nostdinc
-nostdlib
-D WEBASSEMBLY
-isystem /Users/nick/.nvm/versions/node/v5.12.0/lib/node_modules/webassembly/include
-o /var/folders/4f/gjs6r6bj2xqcx4dmh91_njl00000gn/T/wa1_216779hYBi2Zw1d18.tmp
FAILED Error: spawn EACCES
at exports._errnoException (util.js:893:11)
at ChildProcess.spawn (internal/child_process.js:302:11)
at Object.exports.spawn (child_process.js:367:9)
at /Users/nick/.nvm/versions/node/v5.12.0/lib/node_modules/webassembly/cli/util.js:33:34
at Object.run (/Users/nick/.nvm/versions/node/v5.12.0/lib/node_modules/webassembly/cli/util.js:32:12)
at Object.exports.main.defines.forEach.headers.forEach.include.forEach [as main] (/Users/nick/.nvm/versions/node/v5.12.0/lib/node_
modules/webassembly/cli/compiler.js:108:10)
at Object.<anonymous> (/Users/nick/.nvm/versions/node/v5.12.0/lib/node_modules/webassembly/bin/wa-compile:2:38)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.