Skip to content

todbot/napi-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

napi-demo

Demonstration NAPI and prebuildify

Demo taken from https://github.com/nodejs/node-addon-examples/

The helloworld.c is not part of this demo, but added to show simple Universal (fat) binary compilation and linking.

Multi- arch test setup

# our current arch, M1 Mac
$ arch
arm64

# install arm version of node, using 17.1.0
$ nvm install 17.1.0

# install x86_64 version of node, using 17.0.1
$ arch -x86_64 /bin/bash -c "source $HOME/.nvm/nvm.sh; nvm install 17.0.1"

# Change back to arm64 node
$ nvm use 17.1.0

# Install our project, verify it works
$ npm install
$ npm run test

# Make prebuilds and remove temp build dir
$ npm run prebuild-darwin
$ rm -rf build

# Try out arm64 prebuild
$ npm use 17.1.0
$ npm run test

# Try out x86_64 node
nvm use 17.0.1
npm run test


# prebuild dir has universal binary (from 'build' dir)
$  file prebuilds/darwin-x64+arm64/node.napi.node
prebuilds/darwin-x64+arm64/node.napi.node: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit bundle x86_64] [arm64:Mach-O 64-bit bundle arm64]
prebuilds/darwin-x64+arm64/node.napi.node (for architecture x86_64):	Mach-O 64-bit bundle x86_64
prebuilds/darwin-x64+arm64/node.napi.node (for architecture arm64):	Mach-O 64-bit bundle arm64

About

Demonstration NAPI and prebuildify

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published