Skip to content

Commit

Permalink
Compile Node.js addon using CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperisager committed May 21, 2024
1 parent b0cc255 commit f1ca5fc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 42 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/prebuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: lts/*
- run: npm install -g bare-runtime bare-dev prebuildify node-gyp
- run: npm install -g bare-runtime bare-dev
- run: npm install --ignore-scripts
- run: bare-dev install --platform ${{ matrix.platform }} --arch ${{ matrix.arch }}
- run: prebuildify --platform ${{ matrix.platform }} --arch ${{ matrix.arch }}
- run: bare-dev install --bare --node --platform ${{ matrix.platform }} --arch ${{ matrix.arch }}
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform }}-${{ matrix.arch }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ jobs:
node-version: lts/*
- run: npm install -g bare-runtime bare-dev
- run: npm install --ignore-scripts
- run: bare-dev install --platform ${{ matrix.platform }} --arch ${{ matrix.arch }} --debug
- run: bare-dev install --bare --node --platform ${{ matrix.platform }} --arch ${{ matrix.arch }} --debug
- run: npm test
29 changes: 26 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,42 @@ cmake_minimum_required(VERSION 3.25)
project(rocksdb_native C CXX)

include(bare)
include(napi)

add_subdirectory(vendor/librocksdb EXCLUDE_FROM_ALL)

add_bare_module(rocksdb_native)
add_bare_module(rocksdb_native_bare)

target_sources(
${rocksdb_native}
${rocksdb_native_bare}
PRIVATE
binding.c
)

target_link_libraries(
${rocksdb_native}
${rocksdb_native_bare}
PUBLIC
rocksdb_static
)

add_napi_module(rocksdb_native_node)

bare_include_directories(compat NAPI)

target_include_directories(
${rocksdb_native_node}
PRIVATE
${compat}
)

target_sources(
${rocksdb_native_node}
PRIVATE
binding.c
)

target_link_libraries(
${rocksdb_native_node}
PUBLIC
rocksdb_static
)
30 changes: 0 additions & 30 deletions binding.gyp

This file was deleted.

2 changes: 1 addition & 1 deletion binding.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('node-gyp-build')(__dirname)
module.exports = require('load-addon')(__dirname)
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"files": [
"index.js",
"binding.c",
"binding.gyp",
"binding.js",
"CMakeLists.txt",
"lib",
Expand All @@ -15,8 +14,7 @@
],
"addon": true,
"scripts": {
"test": "standard && bare test.js",
"install": "node-gyp-build"
"test": "standard && bare test.js && node test.js"
},
"repository": {
"type": "git",
Expand All @@ -30,7 +28,7 @@
"homepage": "https://github.com/holepunchto/rocksdb-native",
"dependencies": {
"b4a": "^1.6.6",
"node-gyp-build": "^4.6.1",
"load-addon": "^1.0.0",
"ready-resource": "^1.0.0",
"streamx": "^2.16.1"
},
Expand Down

0 comments on commit f1ca5fc

Please sign in to comment.