Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile a wasm file compiled by assemblyscript #51

Closed
zs33 opened this issue Jan 2, 2020 · 17 comments
Closed

compile a wasm file compiled by assemblyscript #51

zs33 opened this issue Jan 2, 2020 · 17 comments
Milestone

Comments

@zs33
Copy link

zs33 commented Jan 2, 2020

Hi, Can I compile a wasm file compiled by assemblyscript not from c++, when i executed innative xx.wasm, it said ERR_FATAL_INVALID_MODULE, why? thanks

@Xe
Copy link

Xe commented Jan 2, 2020

Can you upload the assembly script source and the resulting wasm file?

@ErikMcClure
Copy link
Contributor

Be aware that proper assemblyscript support is currently being worked on. We need to support both #26 and potentially #20, which may be the issue you are running into, if the module does not specify a standard start function.

@zs33
Copy link
Author

zs33 commented Jan 2, 2020

Can you upload the assembly script source and the resulting wasm file?
This is the wasm file
https://github.com/jtiscione/webassembly-wave/tree/master/as/build

@ErikMcClure
Copy link
Contributor

ErikMcClure commented Jan 2, 2020

(export "init" (func $assembly/index/init))

This is the problem. Assemblyscript is apparently creating it's own "init" function that does not adhere to any actual webassembly standard. inNative cannot support arbitrary start functions - this particular one takes a completely custom set of arguments that do not make sense outside of assemblyscript. This would require, at minimum, an assemblyscript environment that itself knows how to pass the correct arguments to this function - whatever they are.

Alternatively, you can compile a DLL instead of an EXE and call this function yourself. Simply use -f library.

Note that the current assemblyscript environment is available here, which will allow it to link but won't actually do anything: https://github.com/innative-sdk/innative/blob/master/innative-assemblyscript/assemblyscript.c

@zs33
Copy link
Author

zs33 commented Jan 2, 2020

how can i compile DLL, is there any guide? And i'm also confuse how to use the assemblyscript.c you given? thanks

@ErikMcClure
Copy link
Contributor

Please read the Wiki for detailed instructions. The assemblyscript library would be used like this:

err = (*exports.AddEmbedding)(env, 0, (void*)"innative-assemblyscript.lib", 0);

Check the Quick Start Guide for a quick overview of how to compile and load a DLL.

@MaxGraey
Copy link

MaxGraey commented Jan 2, 2020

Assemblyscript is apparently creating it's own "init" function that does not adhere to any actual webassembly standard

Assemblyscript uses Binaryen for wasm codegen (same as emscripten btw). And all follow by wasm spec. init function just typical exported function by user same as step. If start function is empty binaryen just optimize it away

That wasm module is highly depend on web host and just expose (exported) two functions. So you really need compile it as dynamic library

@ErikMcClure
Copy link
Contributor

The assemblyscript is assuming there is an entry function with arguments, but because you can't set that as the "start" function in the webassembly module, it's set to "empty" and you must manually invoke whatever init function in order to run the program. "init" may be a common entry point, but it is not a standard one, and thus a runtime like inNative cannot possibly know it exists, which means it cannot compile an EXE.

Whether or not this is "Standard" is up for debate, but this is a problem that keeps coming up over and over again - people try to build a program with a standard main function, then complain because it is impossible for a runtime like this to actually run the program.

@MaxGraey
Copy link

MaxGraey commented Jan 2, 2020

"init" may be a common entry point

No, it's just some exported function by user which manually called on host specifically for this module

@ErikMcClure
Copy link
Contributor

At this point it might be worth making a library the default behavior if nothing actually compiles things that are executables.

@MaxGraey
Copy link

MaxGraey commented Jan 2, 2020

What if follow this rules?

  • If WebAssembly module has start section name or exported _start (this standard main used by WASI) - produce executable or dynamic library on the choice

  • if WebAssembly module hast't start section name or _start - produce dynamic or static library + header file

@ErikMcClure
Copy link
Contributor

ErikMcClure commented Jan 2, 2020

I will likely have to do this, yes. I was trying to make everything explicit, but if this is a common situation I have no choice but to simply default to a library if no start function is found. This change will go in the next release. _start will have to wait until WASI support is actually added #12

@zs33
Copy link
Author

zs33 commented Jan 3, 2020

Please read the Wiki for detailed instructions. The assemblyscript library would be used like this:

err = (*exports.AddEmbedding)(env, 0, (void*)"innative-assemblyscript.lib", 0);

Check the Quick Start Guide for a quick overview of how to compile and load a DLL.

Thanks for you reply, i have read (https://github.com/innative-sdk/innative/wiki/Quick-Start-Guide), but i still not very clear how to build the dll, it said "Simply place this library files somewhere in your project" But my wasm file just use Assemblyscript to obtain? where these libs to put? how to compile lib i needed? is it mean i should compile assemblyscript.c file you provided to a lib file using gcc. And then where the command "err = (exports.AddEmbedding)(env, 0, (void)"innative-assemblyscript.lib", 0);" should i add? The instruction also said a lot commands about set up the environment, but i also don't know where these commands to add?

In addition, i tried to run wast file in spec\test\core to know more about how innative works, it also has error: no start start function . how can i to run tests you provided ? is there any standalone webassembly files can be compiled by innative, thanks a lot!

@ErikMcClure
Copy link
Contributor

I do not know how to set up a project using only assemblyscript. The provided instructions are for a C program that loads the DLL. If you need to load the DLL using assemblyscript, I cannot provide instructions. You can try to ask in the discord chat, but I don't know of anyone who has actually gotten this to work.

You cannot create standalone assemblyscript binaries from webassembly right now. It is not possible. It might be possible after WASI support is added, but it hasn't been added yet.

The tests are not standalone. There are operating system specific example scripts located in /scripts/ - you can attempt to run either test-posix.wat or test-win64.wat.

@zs33
Copy link
Author

zs33 commented Jan 3, 2020

Thanks for your reply. Is it mean Innative only can be used for wasm file compiled from c program?

I have cloned this project, If i want to run innative-sdk/innative/innative-test/ in this project, what should i do? just make in this directory?

@ErikMcClure
Copy link
Contributor

ErikMcClure commented Jan 3, 2020

For all practical purposes, inNative currently can only be embedded from inside a C program. It provides a C interface that will allow languages with FFI to call it as well, but no such bindings have been written yet.

Follow the instructions for building from source, and innative-test will be in the bin directory.

@ErikMcClure
Copy link
Contributor

This can't be fully addressed because there's no way to build an EXE out of something that takes an arbitrary init function. Custom start functions were added with b69b45a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants