RobLoach / node-raylib

Node.js bindings for Raylib
https://robloach.github.io/node-raylib/
Other
245 stars 20 forks source link

DRM build is not working on some platforms #181

Open konsumer opened 8 months ago

konsumer commented 8 months ago

I am on Mac M1, in docker (just doing some build-testing) so it's technically ARM64 linux.

If I run a project that uses node-raylib, it seems to be trying to load the plain .node file, but it downloaded the drm file:

node:internal/modules/cjs/loader:1144
  const err = new Error(message);
              ^

Error: Cannot find module '../../build/Release/node-raylib.node'
Require stack:
- /test/node_modules/raylib/src/generated/node-raylib.js
- /test/node_modules/raylib/index.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)
    at Module._load (node:internal/modules/cjs/loader:985:27)
    at Module.require (node:internal/modules/cjs/loader:1235:19)
    at require (node:internal/modules/helpers:176:18)
    at Object.<anonymous> (/test/node_modules/raylib/src/generated/node-raylib.js:10:11)
    at Module._compile (node:internal/modules/cjs/loader:1376:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at Module.require (node:internal/modules/cjs/loader:1235:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/test/node_modules/raylib/src/generated/node-raylib.js',
    '/test/node_modules/raylib/index.js'
  ]
}

Node.js v21.1.0

On an ARM64 host, this will repro:

docker run -it --rm node bash
cd root
npm i raylib
node -e 'require("raylib")'

This is shape of node_modules:

node_modules/raylib/build
`-- Release
    `-- node-raylib-drm.node

I think @twuky and I talked about this before, but I think the DRM-stuff needs a little work. A possible solution, in my mind, is to just make a totally seperate npm lib that is only for drm. Essentially, a pi, for example, can run the regular .node file fine, with X, like any other linux, but gets more performance (and works without X) with the DRM-version, so if they were separate npm packages, the user could choose to specifically require that, if they want to. I think we could build/publish both npm packages in CI, so it's not really much of a code-change, other than our build-scripts.

Another option might be an env-var that chooses which native lib to load, but I feel like that could get a bit flakey (it would need to be set at all the different stages, like setup/download/build/runtime.)

An aspect of this issue, also, is that DRM-build is useful, even to non-arm64 (x86_64 can use it too) so targeting only arm64 is maybe not enough, anyway. Originally, we did this because it makes a huge difference on pi0-2 and other low-end ARM64 devices (like Anbernic handhelds) but I think giving everyone the option of DRM or X would be better.

I think this is all related to an overhaul of our build/download steps. It could definitely be simplified and improved.

I'd like to see this, as a total solution, and if it seems ok, I will work on it:

I figured out some CI tricks for doing better matrix-builds and copying assets into releases and stuff (see #182) so I think I can improve the whole setup.

twuky commented 8 months ago

i remember another solution being that ARM platforms would download both, and then its up to the user to require raylib or raylib/drm. would something like that help here?

konsumer commented 8 months ago

I really like that, as a solution. essentially leave it up to the user, so they can include either one, since the default import will work fine (in X.)