Skip to content

Commit 31d71b4

Browse files
committed
windows: fixed native build for windows
* Added `scripts/prebuild.js` which is set as the `prebuild` script in `package.json` * The `scripts/prebuild.js` supports `npm_config_devdir`, `npm_config_nodedir` and `npm_config_arch` as environment variables * Environment variables are necessary to pass configuration when using `npm run build` because the prebuild script doesn't receive commmand line parameters * Added `engines` which specifies the node runtime and msvs version, used by `scripts/prebuild.js` * Renamed `src/rocksdb` to `src/native` to avoid name conflict with `deps/rocksdb`, this affects windows builds * All `package.json` scripts must be prefixed with the actual program to be executable on Windows * The `execFile` functions do not read `PATHEXT` requiring the usage of `shell: true` option on windows * Node headers and static libraries are installed into `npm_config_devdir` but only for window and macos, nix still uses `npm_config_nodedir` * The `scripts/prebuild.js` supports incremental compilation, just need to cache the `./build` directory * No more `prebuildify`, completely replaced by `scripts/prebuild.js`, replicates expected `./prebuilds` file and directory structure
1 parent 5b43d96 commit 31d71b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+210
-382
lines changed

.gitlab-ci.yml

+10-7
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ build:merge:
123123
build:linux:
124124
stage: build
125125
needs: []
126+
variables:
127+
# Only x64 architecture is needed
128+
npm_config_arch: "x64"
126129
script:
127130
- >
128131
nix-shell --run '
@@ -154,21 +157,18 @@ build:windows:
154157
tags:
155158
- windows
156159
variables:
157-
# Target node version must match nixpkgs `pkgs.nodejs.version`
158-
npm_config_target: '16.14.2'
159160
# Location node-gyp installed headers and static libraries
160161
npm_config_devdir: "${CI_PROJECT_DIR}/tmp/node-gyp"
161-
npm_config_nodedir: "${CI_PROJECT_DIR}/tmp/node-gyp/$npm_config_target"
162+
# Only x64 architecture is needed
163+
npm_config_arch: "x64"
162164
before_script:
163165
- mkdir -Force "$CI_PROJECT_DIR/tmp"
164-
- choco install nodejs --version="$npm_config_target" -y
166+
- choco install nodejs --version="16.15.1" -y
165167
- choco install python --version=3.9.12 -y
166168
- refreshenv
167169
script:
168-
- npm config set msvs_version 2019 --location project
169170
- npm install --ignore-scripts
170171
- $env:Path = "$(npm bin);" + $env:Path
171-
- node-gyp install --ensure
172172
- npm run build --verbose
173173
- npm test -- --ci
174174
artifacts:
@@ -193,6 +193,10 @@ build:macos:
193193
variables:
194194
HOMEBREW_NO_INSTALL_UPGRADE: "true"
195195
HOMEBREW_NO_INSTALL_CLEANUP: "true"
196+
# Location node-gyp installed headers and static libraries
197+
npm_config_devdir: "${CI_PROJECT_DIR}/tmp/node-gyp"
198+
# Produce universal binary
199+
npm_config_arch: 'x64+arm64'
196200
before_script:
197201
- eval "$(brew shellenv)"
198202
- brew install node@16
@@ -203,7 +207,6 @@ build:macos:
203207
script:
204208
- npm install --ignore-scripts
205209
- export PATH="$(npm bin):$PATH"
206-
- export PREBUILD_ARCH=x64+arm64
207210
- npm run build --verbose
208211
- npm test -- --ci
209212
artifacts:

.npmrc

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
# Enables npm link
22
prefix=~/.npm
3-
# Use all cores during node-gyp compilation
4-
jobs=max

binding.gyp

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
{
22
'targets': [{
3-
'target_name': 'rocksdb',
3+
'target_name': 'native',
44
'include_dirs': [
55
"<!(node -e \"require('napi-macros')\")"
66
],
77
'dependencies': [
88
'<(module_root_dir)/deps/rocksdb/rocksdb.gyp:rocksdb'
99
],
1010
'sources': [
11-
'./src/rocksdb/napi/batch.cpp',
12-
'./src/rocksdb/napi/database.cpp',
13-
'./src/rocksdb/napi/debug.cpp',
14-
'./src/rocksdb/napi/index.cpp',
15-
'./src/rocksdb/napi/iterator.cpp',
16-
'./src/rocksdb/napi/snapshot.cpp',
17-
'./src/rocksdb/napi/transaction.cpp',
18-
'./src/rocksdb/napi/utils.cpp',
19-
'./src/rocksdb/napi/worker.cpp',
20-
'./src/rocksdb/napi/workers/batch_workers.cpp',
21-
'./src/rocksdb/napi/workers/database_workers.cpp',
22-
'./src/rocksdb/napi/workers/iterator_workers.cpp',
23-
'./src/rocksdb/napi/workers/transaction_workers.cpp',
24-
'./src/rocksdb/napi/workers/snapshot_workers.cpp'
11+
'./src/native/napi/batch.cpp',
12+
'./src/native/napi/database.cpp',
13+
'./src/native/napi/debug.cpp',
14+
'./src/native/napi/index.cpp',
15+
'./src/native/napi/iterator.cpp',
16+
'./src/native/napi/snapshot.cpp',
17+
'./src/native/napi/transaction.cpp',
18+
'./src/native/napi/utils.cpp',
19+
'./src/native/napi/worker.cpp',
20+
'./src/native/napi/workers/batch_workers.cpp',
21+
'./src/native/napi/workers/database_workers.cpp',
22+
'./src/native/napi/workers/iterator_workers.cpp',
23+
'./src/native/napi/workers/transaction_workers.cpp',
24+
'./src/native/napi/workers/snapshot_workers.cpp'
2525
],
2626
'conditions': [
2727
['OS=="linux"', {

0 commit comments

Comments
 (0)