prebuild / prebuildify

Create and package prebuilds for native modules
MIT License
200 stars 37 forks source link

Why does prebuildify have its own headers and node.lib cache? #64

Open CMCDragonkai opened 2 years ago

CMCDragonkai commented 2 years ago

I've been trying out prebuildify on Windows, and I noticed it has its own node headers and node.lib cache.

For example:

C:\Users\Roger Qiu\AppData\Local\node-gyp\Cache\16.14.2

Is the node-gyp cache. While

C:\Users\Roger Qiu\AppData\Local\Temp\prebuildify\node\16.14.2

Is prebuildify's node cache.

Considering that many packages are using node-gyp-install as their install script, their cache is likely populated by node-gyp automatically, why is prebuildify then creating its own cache?

I also noticed that node-gyp will automatically fill the target with the current node version. But prebuildify doesn't. Even when node-gyp was using 16.14.2, prebuildify defaulted to 18.0.0, I had to explicitly set the --target=16.14.2 when using prebuildify to ensure it was using the same.

Furthermore on Linux, once I have nodedir set, prebuildify doesn't put anything in /tmp/prebuildify, it only does it on Windows.

vweevers commented 2 years ago

https://github.com/prebuild/prebuildify/blob/c6e4368f02b1c1965aec3b1f5564a8e15c239ba5/index.js#L183-L187

CMCDragonkai commented 2 years ago

I see, what about the need to explicitly set the --target in prebuildify that seems inconsistent with how node-gyp automatically knows the right version.

vweevers commented 2 years ago

I see, what about the need to explicitly set the --target in prebuildify that seems inconsistent with how node-gyp automatically knows the right version.

prebuildify is geared towards Node-API, so the version of the executing node process is not necessarily the right version. It defaults to compiling against the latest node version (relying on backwards compatibility of Node-API, assuming that NAPI_VERSION is defined appropriately). You can also choose to compile against the minimum node version (relying on forwards compatibility, and not necessarily having to define NAPI_VERSION).

I don't know if there's a practical difference between these options though (because Node-API has delivered on their promise of compatibility, and defining NAPI_VERSION is a best practice in any case). It might just be that there is no good default for prebuildify, or better said, from a "glass half full" perspective, that any of these options would work as a default for the majority of users.

Furthermore on Linux, once I have nodedir set, prebuildify doesn't put anything in /tmp/prebuildify, it only does it on Windows.

The Linux behavior is as expected because setting nodedir tells node-gyp to use your own node source code instead of downloading headers from an official node version. How/where are you setting nodedir on Windows?

CMCDragonkai commented 2 years ago

I wasn't setting nodedir on windows. Maybe that's the reason?

Windows nodejs installation by default doesn't come with headers.

So it seems it requires headers and also this thing called node.lib. Not sure what that is.

vweevers commented 2 years ago

I wasn't setting nodedir on windows. Maybe that's the reason?

Yeah, that's it.

It shouldn't be necessary to set nodedir unless you want to build against a fork of node (or a specific commit of node).