eigen-js icon indicating copy to clipboard operation
eigen-js copied to clipboard

Yarn build without OSQP broken

Open Archer6621 opened this issue 1 year ago • 0 comments

Hey there, I tried forking this repo and building without OSQP as instructed in the readme using the latest version of emscripten:

emcc -D NO_OSQP -I lib/eigen -Isrc -s DISABLE_EXCEPTION_CATCHING=0 -s ASSERTIONS=0 -O3 -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 --bind -o build/eigen_gen.js src/cpp/embind.cc

Then I indeed did a yarn build, pushed the new index.js that got generated, and tried to install the fork.

Upon trying to use it, I get greeted by the following error:

index.js:1  Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'prototype')
    at D.initClass (index.js:1:935979)
    at index.js:1:936495
    at Set.forEach (<anonymous>)
    at index.js:1:936476
initClass @ index.js:1
(anonymous) @ index.js:1
(anonymous) @ index.js:1
Promise.then (async)
(anonymous) @ HSWFC.js:36

I suspected that it was because of the following piece of code at the end of eigen.mjs that adds the GC to the classes, since it still has the QuadProgSolver in there:

eig.ready = Module.then(module => {
  const classes = new Set([
    "Vector",
    "Vector2d",
    "Complex",
    "Matrix",
    "SparseMatrix",
    "TripletVector",
    "ComplexDenseMatrix",
    "Solvers",
    "Decompositions",
    "QuadProgSolver",
    "Random",
  ]);
  classes.forEach(className => {
    eig[className] = GC.initClass(classes, module[className])
  })
  addHelpers(eig);
})

After removing "QuadProgSolver" it indeed started working. I'm not savvy enough in web build tools to come up with a nicer solution for this, but maybe it is good to put a disclaimer/warning in the readme for now about it, so people can still perform a functioning yarn build without OSQP in there.

Archer6621 avatar May 05 '23 10:05 Archer6621