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

A problem with npm and some questions #36

Closed
RussCoder opened this issue Feb 28, 2018 · 9 comments
Closed

A problem with npm and some questions #36

RussCoder opened this issue Feb 28, 2018 · 9 comments

Comments

@RussCoder
Copy link

Hey there!

I have tried to create a simple program following the guide

https://github.com/AssemblyScript/assemblyscript/wiki/Hello-World

but for me the installation via npm doesn't work, when I do npm run build, I get the following:

$ npm run build

> asc@1.0.0 build D:\study\asc_test
> npm run build:untouched && npm run build:optimized


> asc@1.0.0 build:untouched D:\study\asc_test
> asc assembly/module.ts -t module.untouched.wat -b module.untouched.wasm --validate --sourceMap --measure

Error: Cannot find module './assemblyscript'
    at Function.Module._resolveFilename (module.js:527:15)
    at Function.Module._load (module.js:476:23)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (D:\study\asc_test\node_modules\assemblyscript\bin\asc.js:23:22)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! asc@1.0.0 build:untouched: `asc assembly/module.ts -t module.untouched.wat -b module.untouched.wasm --validate --sourceMap --measure`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the asc@1.0.0 build:untouched script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

However, I have tried tried out the alternative way to install the tool

$> git clone https://github.com/AssemblyScript/assemblyscript.git
$> cd assemblyscript
$> npm install
$> npm link

And it compiled successfully.

However, it will be nice, if you fix the installation via npm.

Also, some questions.

  • Is there a way to import Memory in a script? That is to say, how can I get something like (import "js" "mem" (memory 1)) in the .wasm module?

  • Is there any program API besides the CLI API? As here https://www.npmjs.com/package/assemblyscript#api

  • Why do you switch from the Prototype to the NEXT version? Is the NEXT version something completely new? Will be I right, if I say that it's recommended to use the NEXT version, rather than this module
    https://www.npmjs.com/package/assemblyscript
    ?

  • Also, I wonder, do you plan to implement a support for (data ...) expressions? It's a rather useful thing in case when one needs to define a constant array, for example.

  • And Table (of functions) hasn't been supported yet, hasn't it?

@dcodeIO
Copy link
Member

dcodeIO commented Feb 28, 2018

but for me the installation via npm doesn't work

Seems this is failing here. Just tried and it is failing for me as well, going to take a look.

Is there a way to import Memory in a script?

Not yet, but it should be rather trivial to add as a command line option like --importMemory. Going to take a look later.

Is there any program API besides the CLI API?

Somewhat. There is a low-level API exported from index.ts, which is meant to work the same regardless of if the compiler has been compiled to JS or WASM (eventually). All the other things can also be used from TypeScript, of course, but there is no API documentation except the comments in the sources yet and the portable polyfill (d.ts) must be included in the application using it.

Why do you switch from the Prototype to the NEXT version?

The prototype was based on TypeScript's compiler API, while NEXT is a complete reimplementation with the goal to compile the compiler itself to WebAssembly eventually.

Will be I right, if I say that it's recommended to use the NEXT version

Yes, there is no development taking place on the prototype anymore.

Also, I wonder, do you plan to implement a support for (data ...) expressions

There is some support already, but it's currently limited to static strings. Static arrays are planned as well. This is somewhat connected with having a working runtime, i.e. a memory manager and GC.

And Table (of functions) hasn't been supported yet, hasn't it?

Just recently I started to implement function expressions, which use tables, so it shouldn't be long.

dcodeIO added a commit that referenced this issue Feb 28, 2018
@dcodeIO
Copy link
Member

dcodeIO commented Feb 28, 2018

but for me the installation via npm doesn't work

Appears I somehow moved the Binaryen dependency to devDependencies. Should work now with the fix above applied.

dcodeIO added a commit that referenced this issue Feb 28, 2018
@dcodeIO
Copy link
Member

dcodeIO commented Feb 28, 2018

It's now also possible to import the memory instance (here: env.memory), like so:

Usage: asc myModule.ts --importMemory

@RussCoder
Copy link
Author

Thanks, now the npm installation works well.

As for the program API, I found out that I can use it this way:

const asc = require('assemblyscript/bin/asc');

asc.main([
    'assembly/module.ts',
    '-t', 'module.optimized.wat',
    '-b', 'module.optimized.wasm',
    '--validate', '--sourceMap', '--measure', '--optimize'
]);

However, I added the --importMemory option, and now I get the following error:

$ npm run build

> asc@1.0.0 build D:\study\asc_test
> npm run build:untouched && npm run build:optimized


> asc@1.0.0 build:untouched D:\study\asc_test
> asc assembly/module.ts -t module.untouched.wat -b module.untouched.wasm --validate --sourceMap --measure --importMemory

[wasm-validator error in module] unexpected false: Memory import record exists but memory is not marked as imported, on
$memory
Error: Validate error
    at stats.validateTime.measure (D:\study\asc_test\node_modules\assemblyscript\bin\asc.js:304:25)
    at measure (D:\study\asc_test\node_modules\assemblyscript\bin\asc.js:626:3)
    at Object.main (D:\study\asc_test\node_modules\assemblyscript\bin\asc.js:301:27)
    at Object.<anonymous> (D:\study\asc_test\node_modules\assemblyscript\bin\asc:4:26)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)

D:\study\asc_test\node_modules\binaryen\index.js:6
if(m){var da,ea;a.read=function(b,d){var c=p(b);c||(da||(da=require("fs")),ea||(ea=require("path")),b=ea.normalize(b),c=da.readFileSync(b));return d?c:c.toString()};a.readBinary=function(b){b=a.read(b,!0);b.buffer||(b=new Uint8Array(b));assert(b.buffer);return b};1<process.argv.length&&(a.thisProgram=process.argv[1].replace(/\\/g,"/"));a.arguments=process.argv.slice(2);process.on("uncaughtException",function(b){if(!(b instanceof fa))throw b;});process.on("unhandledRejection",function(){process.exit(1)});


                                                                                                                         ^
abort(). Build with -s ASSERTIONS=1 for more info.
npm ERR! code ELIFECYCLE
npm ERR! errno 7
npm ERR! asc@1.0.0 build:untouched: `asc assembly/module.ts -t module.untouched.wat -b module.untouched.wasm --validate --sourceMap --measure --importMemory` npm ERR! Exit status 7
npm ERR!
npm ERR! Failed at the asc@1.0.0 build:untouched script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Perhaps, it's required to add something to the script itself, but I don't know what I should add.
I have tried something like declare const memory: Memory but it doesn't work.

The script itself:

export function add(a: i32, b: i32): i32 {
    return a + b;
}

There is some support already, but it's currently limited to static strings.

Where can I see an example?

@dcodeIO
Copy link
Member

dcodeIO commented Mar 1, 2018

[wasm-validator error in module] unexpected false: Memory import record exists but memory is not marked as imported

Looks like an issue with Binaryen, going to take a look.

Perhaps, it's required to add something to the script itself

That's not how it works, memory is a configuration thing :)

Where can I see an example?

It's still in its early days, but this compiler test (output) shows what's possible already. Basically, whenever a string literal is used, it becomes a data segment in the form 4bytes length + length * 16bit charcodes.

dcodeIO added a commit that referenced this issue Mar 2, 2018
@dcodeIO
Copy link
Member

dcodeIO commented Mar 2, 2018

Memory imports should validate now. Let me know if you see any other issues :)

@RussCoder
Copy link
Author

Hello!

Thank you for the memory imports fix, now it works correctly as expected.

But the bug with npm installation has arose again for me:

$ npm run build

> asc@1.0.0 build D:\study\asc_test
> npm run build:untouched && npm run build:optimized


> asc@1.0.0 build:untouched D:\study\asc_test
> asc assembly/module.ts -t module.untouched.wat -b module.untouched.wasm --validate --sourceMap --measure

Error: Cannot find module './assemblyscript'
    at Function.Module._resolveFilename (module.js:527:15)
    at Function.Module._load (module.js:476:23)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (D:\study\asc_test\node_modules\assemblyscript\bin\asc.js:23:22)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! asc@1.0.0 build:untouched: `asc assembly/module.ts -t module.untouched.wat -b module.untouched.wasm --validate --sourceMap --measure`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the asc@1.0.0 build:untouched script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

As in the previous time, the installation via git clone works well, namely this way I have checked the memory import feature.

Take a look, please.

@dcodeIO
Copy link
Member

dcodeIO commented Mar 3, 2018

Does it work now? I think the switch to webpack 4 broke it again.

@RussCoder
Copy link
Author

Yes, it works. Thanks.

radu-matei pushed a commit to radu-matei/assemblyscript that referenced this issue Oct 13, 2020
Bumps [assemblyscript](https://github.com/AssemblyScript/assemblyscript) from 0.10.1 to 0.12.0.
- [Release notes](https://github.com/AssemblyScript/assemblyscript/releases)
- [Commits](AssemblyScript/assemblyscript@v0.10.1...v0.12.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants