Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Testing latest pari + WASM + node.js... and it works?! Wow.

Path: pari / notes.md
Views: 1470
License: GPL3
Image: ubuntu2004

second try (july 1, 2021)

Using pari-2.14.0.alpha again

time emconfigure ./Configure --host=wasm-emscripten --graphic=none cd Oemscripten-wasm; time emmake make "CC_FLAVOR=-s ERROR_ON_UNDEFINED_SYMBOLS=0 -s ALLOW_MEMORY_GROWTH=1 -s PRECISE_I64_MATH=1 -s EXPORTED_FUNCTIONS=[\'_main\',\'_gp_embedded\',\'_gp_embedded_init\',\'_pari_emscripten_plot_init\'] -s EXPORTED_RUNTIME_METHODS=[\'ccall\',\'cwrap\'] -s INITIAL_MEMORY=2146435072 -s MODULARIZE=1"

This builds but starting fails as before with getpwuid missing. So... this is because of code in es.c that looks a bit funny. In any case, let's directly edit Oemscripten-wasm/paricfg.h and delete the #define UNIX line, which is set by paricfg.h.SH.

The option MODULARIZE=1 solves the noInitialRun problem, but as follows:

(async ()=> { gp = await require('./gp-sta')({noInitialRun:true}) global.pari = (s) => { return gp.ccall("gp_embedded","string",["string"],[s]); } })()

first try

Got pari from

https://pari.math.u-bordeaux.fr/pub/pari/snapshots/

Built as explained here

https://pari.math.u-bordeaux.fr/archives/pari-dev-1610/msg00015.html

but with changes figured out by googling randomly e.g., this

Also we're missing ccall and cwrap: https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html?highlight=ccall#interacting-with-code-ccall-cwrap

RUNTEST=node CC=emcc ./Configure --host=javascript-emscripten --graphic=none --time=gettimeofday make -C Oemscripten-javascript "CC_FLAVOR=-s ERROR_ON_UNDEFINED_SYMBOLS=0 -s ALLOW_MEMORY_GROWTH=1 -s PRECISE_I64_MATH=1 -s EXPORTED_FUNCTIONS=[\'_main\',\'_gp_embedded\',\'_gp_embedded_init\',\'_pari_emscripten_plot_init\'] -s EXPORTED_RUNTIME_METHODS=[\'ccall\',\'cwrap\'] "

Now hitting this https://github.com/emscripten-core/emscripten/issues/13219

I just manually edited gp-sta.js and changed the getpwuid function to return 0 instead of error. Then doing this in a console:

myinit()

gives an error, which I ignore. Then

myevalm('print(2+8)')

prints out "not enough memory"... but the answer DOES APPEAR!

I manually edited some code so that noInitialRun is true in the js file, then directly imported it in node. Then I did this:

~/pari/test$ node Welcome to Node.js v14.15.5. Type ".help" for more information. > ... gp = require('./gp-sta'); gp.ccall("gp_embedded_init",null,["number","number"],[100000000,100000000]); function pari(s) { return gp.ccall("gp_embedded","string",["string"],[s]); }

I bet the memory fix is to add -s INITIAL_MEMORY=2146435072