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

ncc and prebuildify #1183

Closed
sroussey opened this issue Apr 12, 2024 · 3 comments
Closed

ncc and prebuildify #1183

sroussey opened this issue Apr 12, 2024 · 3 comments
Labels
question Further information is requested

Comments

@sroussey
Copy link

I help maintain a few npm packages. I use prebuildify and prebuild all the versions of the binary .node files. All are included in the npm package itself so no install scripts need run (and the binary files are small anyway). Also, newer things like bun don't support lifecycle scripts out of the box, and you have to declare that your trust each one in order to run them.

People using ncc don't get the binary .node files however in this scenario.

How can I best alter the various npm packages such that ncc will recognize them, or will it never work because the npm package has binaries for multiple architectures?

@styfle
Copy link
Member

styfle commented Apr 15, 2024

require('./hello.node') will be statically analyzed properly

There's an integration test here https://github.com/vercel/ncc/blob/main/test/integration/binary-require.js

If you're running into a problem, its likely because you're doing dynamic require which can't be statically analyzed easily, something like function dynamic(str) { return require(str) }

The partially dynamic case should also work, something like function prebuildPath(str) { return path.join(__dirname, 'prebuild', str) } since the prefix is statically analyzable so the entire directory can be included.

@sroussey
Copy link
Author

Yes, stuff is dynamic. I was able to get around it by adding this:

// dummy code for ncc to include the native module
if (process.uptime() < 0) {
  require(__dirname + "/../../../prebuilds/darwin-arm64+x64/usearch.node");
  require(__dirname + "/../../../prebuilds/linux-arm64/usearch.node");
  require(__dirname + "/../../../prebuilds/linux-x64/usearch.node");
  require(__dirname + "/../../../prebuilds/win32-ia32/usearch.node");
  require(__dirname + "/../../../prebuilds/win32-x64/usearch.node");
  require(__dirname + "/../../../build/Release/usearch.node");
}

@styfle styfle added the question Further information is requested label Apr 15, 2024
@styfle
Copy link
Member

styfle commented Apr 15, 2024

Great, I'll close this issue since its working 👍

@styfle styfle closed this as completed Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants