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

gyp / node-gyp / napi / node-addon-api #67

Open
magicdawn opened this issue Mar 10, 2016 · 5 comments
Open

gyp / node-gyp / napi / node-addon-api #67

magicdawn opened this issue Mar 10, 2016 · 5 comments

Comments

@magicdawn
Copy link
Owner

gyp & node-gyp

@magicdawn
Copy link
Owner Author

gyp

一个 gyp 使用例子 https://github.com/coordcn/LuaIO

@magicdawn
Copy link
Owner Author

node-gyp

  1. 生成 hello.node, from Release/obj.target/hello/hello.o

@magicdawn
Copy link
Owner Author

静态库

"libraries": ["<(module_root_dir)/node_modules/mozjpeg-src/.libs/libjpeg.a"],

@magicdawn magicdawn changed the title gyp / node-gyp gyp / node-gyp / napi / node-addon-api Jun 15, 2020
@magicdawn
Copy link
Owner Author

magicdawn commented Jun 15, 2020

napi

版本 & 兼容性

使用

#define NAPI_VERSION 3
#include <node_api.h>

version matrix
https://nodejs.org/api/n-api.html#n_api_n_api_version_matrix

Version 4 is an extension to version 3 in that it has all of the APIs from version 3 with some additions. This means that it is not necessary to recompile for new versions of Node.js which are listed as supporting a later version.

版本4有版本3的全部功能, 并添加了一些功能. 这意味着使用 NAPI_VERSION=3 编译的 addon, 没有必要为支持 NAPI_VERSION = 4/5/6 的 Node.js 版本重新编译.

例子

sharp

写死的 NAPI_VERSION=3, 目前正常版本都可以使用
https://github.com/lovell/sharp/blob/v0.25.1/binding.gyp#L51

ffi-napi

https://github.com/node-ffi-napi/node-ffi-napi/blob/v3.0.1/src/ffi.cc#L1-L2

#define NAPI_VERSION 6
#define NAPI_EXPERIMENTAL /* Until Node.js v12.17.0 is released */

只支持比较新的 node.js 版本., 只支持这两个版本
image

prebuild

https://github.com/prebuild/prebuild

需要指定支持的 napi-version, 比如 sharp 写只支持 3, 无论当前 NAPI_VERSION 是多少, prebuild-install 都会去下载 napi-3 的版本.

@magicdawn
Copy link
Owner Author

node-addon-api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant