Skip to content

Commit ba9fcec

Browse files
neoxpertmceachen
andauthored
Support build for electron v20 (WiseLibs#870)
* support prebuild for electron v20 * Remove unsupported versions of Node and Electron (see https://www.electronjs.org/docs/latest/tutorial/electron-timelines and https://github.com/nodejs/Release/#end-of-life-releases) * enforce the use of node-gyp 8.4.1 builds for electron 20 fail with prebuild 11.0.4 internal node-gyp version 6.1.0 * conditional compile with CreationContext for NodeJs < 16 * use c++17 to fix Mac M1 and Linux x64 builds * add c++17 flag for MSVC Co-authored-by: Matthew McEachen <[email protected]>
1 parent 54e6cba commit ba9fcec

File tree

7 files changed

+73
-50
lines changed

7 files changed

+73
-50
lines changed

.github/workflows/build.yml

+6-8
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ jobs:
2222
- macos-latest
2323
- windows-2019
2424
node:
25-
- 10
26-
- 12
2725
- 14
2826
- 16
2927
- 18
@@ -69,10 +67,10 @@ jobs:
6967
with:
7068
node-version: 16
7169
- run: npm install --ignore-scripts
72-
- run: npx --no-install prebuild -r node -t 10.20.0 -t 12.0.0 -t 14.0.0 -t 16.0.0 -t 18.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}
73-
- run: npx --no-install prebuild -r electron -t 10.0.0 -t 11.0.0 -t 12.0.0 -t 13.0.0 -t 14.0.0 -t 15.0.0 -t 16.0.0 -t 17.0.0 -t 18.0.0 -t 19.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}
70+
- run: npx --no-install prebuild -r node -t 14.0.0 -t 16.0.0 -t 18.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}
71+
- run: npx --no-install prebuild -r electron -t 16.0.0 -t 17.0.0 -t 18.0.0 -t 19.0.0 -t 20.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}
7472
- if: matrix.os == 'windows-2019'
75-
run: npx --no-install prebuild -r electron -t 10.0.0 -t 11.0.0 -t 12.0.0 -t 13.0.0 -t 14.0.0 -t 15.0.0 -t 16.0.0 -t 17.0.0 -t 18.0.0 -t 19.0.0 --include-regex 'better_sqlite3.node$' --arch ia32 -u ${{ secrets.GITHUB_TOKEN }}
73+
run: npx --no-install prebuild -r electron -t 16.0.0 -t 17.0.0 -t 18.0.0 -t 19.0.0 -t 20.0.0 --include-regex 'better_sqlite3.node$' --arch ia32 -u ${{ secrets.GITHUB_TOKEN }}
7674

7775
prebuild-alpine:
7876
name: Prebuild on alpine
@@ -83,7 +81,7 @@ jobs:
8381
- uses: actions/checkout@v2
8482
- run: apk add build-base git python3 --update-cache
8583
- run: npm install --ignore-scripts
86-
- run: npx --no-install prebuild -r node -t 10.20.0 -t 12.0.0 -t 14.0.0 -t 16.0.0 -t 18.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}
84+
- run: npx --no-install prebuild -r node -t 14.0.0 -t 16.0.0 -t 18.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}
8785

8886
prebuild-alpine-arm:
8987
strategy:
@@ -102,7 +100,7 @@ jobs:
102100
apk add build-base git python3 --update-cache && \
103101
cd /tmp/project && \
104102
npm install --ignore-scripts && \
105-
npx --no-install prebuild -r node -t 10.20.0 -t 12.0.0 -t 14.0.0 -t 16.0.0 -t 18.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}"
103+
npx --no-install prebuild -r node -t 14.0.0 -t 16.0.0 -t 18.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}"
106104
107105
prebuild-linux-arm:
108106
strategy:
@@ -120,4 +118,4 @@ jobs:
120118
docker run --rm -v $(pwd):/tmp/project --entrypoint /bin/sh --platform linux/${{ matrix.arch }} node:16 -c "\
121119
cd /tmp/project && \
122120
npm install --ignore-scripts && \
123-
npx --no-install prebuild -r node -t 10.20.0 -t 12.0.0 -t 14.0.0 -t 16.0.0 -t 18.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}"
121+
npx --no-install prebuild -r node -t 14.0.0 -t 16.0.0 -t 18.0.0 --include-regex 'better_sqlite3.node$' -u ${{ secrets.GITHUB_TOKEN }}"

binding.gyp

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@
99
'target_name': 'better_sqlite3',
1010
'dependencies': ['deps/sqlite3.gyp:sqlite3'],
1111
'sources': ['src/better_sqlite3.cpp'],
12-
'cflags': ['-std=c++14'],
12+
'cflags_cc': ['-std=c++17'],
1313
'xcode_settings': {
14-
'OTHER_CPLUSPLUSFLAGS': ['-std=c++14', '-stdlib=libc++'],
14+
'OTHER_CPLUSPLUSFLAGS': ['-std=c++17', '-stdlib=libc++'],
15+
},
16+
'msvs_settings': {
17+
'VCCLCompilerTool': {
18+
'AdditionalOptions': [
19+
'/std:c++17'
20+
]
21+
}
1522
},
1623
'conditions': [
1724
['OS=="linux"', {

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@
2424
"cli-color": "^2.0.2",
2525
"fs-extra": "^10.1.0",
2626
"mocha": "^8.3.2",
27+
"node-gyp": "8.4.1",
2728
"nodemark": "^0.3.0",
2829
"prebuild": "^11.0.4",
2930
"sqlite": "^4.1.1",
3031
"sqlite3": "^5.0.8"
3132
},
33+
"overrides": {
34+
"prebuild": {
35+
"node-gyp": "$node-gyp"
36+
}
37+
},
3238
"scripts": {
3339
"install": "prebuild-install || node-gyp rebuild --release",
3440
"build-release": "node-gyp rebuild --release",

src/better_sqlite3.cpp

+28-25
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
//
33

44
#include "better_sqlite3.hpp"
5+
#line 39 "./src/util/binder.lzz"
6+
static bool IsPlainObject(v8::Isolate* isolate, v8::Local<v8::Object> obj) {
7+
v8::Local<v8::Value> proto = obj->GetPrototype();
8+
9+
#if defined NODE_MODULE_VERSION && NODE_MODULE_VERSION < 93
10+
v8::Local<v8::Context> ctx = obj->CreationContext();
11+
#else
12+
v8::Local<v8::Context> ctx = obj->GetCreationContext().ToLocalChecked();
13+
#endif
14+
15+
ctx->Enter();
16+
v8::Local<v8::Value> baseProto = v8::Object::New(isolate)->GetPrototype();
17+
ctx->Exit();
18+
return proto->StrictEquals(baseProto) || proto->StrictEquals(v8::Null(isolate));
19+
}
520
#line 67 "./src/better_sqlite3.lzz"
621
NODE_MODULE_INIT(/* exports, context */) {
722
v8::Isolate* isolate = context->GetIsolate();
@@ -104,8 +119,7 @@ void SetPrototypeGetter (v8::Isolate * isolate, v8::Local <v8::External> data, v
104119
0,
105120
data,
106121
v8::AccessControl::DEFAULT,
107-
v8::PropertyAttribute::None,
108-
v8::AccessorSignature::New(isolate, recv)
122+
v8::PropertyAttribute::None
109123
);
110124
}
111125
#line 4 "./src/util/constants.lzz"
@@ -1951,37 +1965,26 @@ bool Binder::Bind (v8::FunctionCallbackInfo <v8 :: Value> const & info, int argc
19511965
}
19521966
return success;
19531967
}
1954-
#line 35 "./src/util/binder.lzz"
1955-
bool Binder::IsPlainObject (v8::Isolate * isolate, v8::Local <v8::Object> obj)
1956-
#line 35 "./src/util/binder.lzz"
1957-
{
1958-
v8::Local<v8::Value> proto = obj->GetPrototype();
1959-
v8::Local<v8::Context> ctx = obj->CreationContext();
1960-
ctx->Enter();
1961-
v8::Local<v8::Value> baseProto = v8::Object::New(isolate)->GetPrototype();
1962-
ctx->Exit();
1963-
return proto->StrictEquals(baseProto) || proto->StrictEquals(v8::Null(isolate));
1964-
}
1965-
#line 44 "./src/util/binder.lzz"
1968+
#line 54 "./src/util/binder.lzz"
19661969
void Binder::Fail (void (* Throw) (char const *), char const * message)
1967-
#line 44 "./src/util/binder.lzz"
1970+
#line 54 "./src/util/binder.lzz"
19681971
{
19691972
assert(success == true);
19701973
assert((Throw == NULL) == (message == NULL));
19711974
assert(Throw == ThrowError || Throw == ThrowTypeError || Throw == ThrowRangeError || Throw == NULL);
19721975
if (Throw) Throw(message);
19731976
success = false;
19741977
}
1975-
#line 52 "./src/util/binder.lzz"
1978+
#line 62 "./src/util/binder.lzz"
19761979
int Binder::NextAnonIndex ()
1977-
#line 52 "./src/util/binder.lzz"
1980+
#line 62 "./src/util/binder.lzz"
19781981
{
19791982
while (sqlite3_bind_parameter_name(handle, ++anon_index) != NULL) {}
19801983
return anon_index;
19811984
}
1982-
#line 58 "./src/util/binder.lzz"
1985+
#line 68 "./src/util/binder.lzz"
19831986
void Binder::BindValue (v8::Isolate * isolate, v8::Local <v8::Value> value, int index)
1984-
#line 58 "./src/util/binder.lzz"
1987+
#line 68 "./src/util/binder.lzz"
19851988
{
19861989
int status = Data::BindValueFromJS(isolate, handle, index, value);
19871990
if (status != SQLITE_OK) {
@@ -2000,9 +2003,9 @@ void Binder::BindValue (v8::Isolate * isolate, v8::Local <v8::Value> value, int
20002003
assert(false);
20012004
}
20022005
}
2003-
#line 79 "./src/util/binder.lzz"
2006+
#line 89 "./src/util/binder.lzz"
20042007
int Binder::BindArray (v8::Isolate * isolate, v8::Local <v8::Array> arr)
2005-
#line 79 "./src/util/binder.lzz"
2008+
#line 89 "./src/util/binder.lzz"
20062009
{
20072010
v8 :: Local < v8 :: Context > ctx = isolate -> GetCurrentContext ( ) ;
20082011
uint32_t length = arr->Length();
@@ -2024,9 +2027,9 @@ int Binder::BindArray (v8::Isolate * isolate, v8::Local <v8::Array> arr)
20242027
}
20252028
return len;
20262029
}
2027-
#line 105 "./src/util/binder.lzz"
2030+
#line 115 "./src/util/binder.lzz"
20282031
int Binder::BindObject (v8::Isolate * isolate, v8::Local <v8::Object> obj, Statement * stmt)
2029-
#line 105 "./src/util/binder.lzz"
2032+
#line 115 "./src/util/binder.lzz"
20302033
{
20312034
v8 :: Local < v8 :: Context > ctx = isolate -> GetCurrentContext ( ) ;
20322035
BindMap* bind_map = stmt->GetBindMap(isolate);
@@ -2063,9 +2066,9 @@ int Binder::BindObject (v8::Isolate * isolate, v8::Local <v8::Object> obj, State
20632066

20642067
return len;
20652068
}
2066-
#line 149 "./src/util/binder.lzz"
2069+
#line 159 "./src/util/binder.lzz"
20672070
Binder::Result Binder::BindArgs (v8::FunctionCallbackInfo <v8 :: Value> const & info, int argc, Statement * stmt)
2068-
#line 149 "./src/util/binder.lzz"
2071+
#line 159 "./src/util/binder.lzz"
20692072
{
20702073
v8 :: Isolate * isolate = info . GetIsolate ( ) ;
20712074
int count = 0;

src/better_sqlite3.hpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <node_buffer.h>
1919
#line 31 "./src/util/macros.lzz"
2020
template <class T> using CopyablePersistent = v8::Persistent<T, v8::CopyablePersistentTraits<T>>;
21+
#line 36 "./src/util/binder.lzz"
22+
static bool IsPlainObject(v8::Isolate* isolate, v8::Local<v8::Object> obj);
2123
#define LZZ_INLINE inline
2224
#line 16 "./src/util/macros.lzz"
2325
v8::Local <v8::String> StringFromUtf8 (v8::Isolate * isolate, char const * data, int length);
@@ -752,27 +754,25 @@ class Binder
752754
#line 32 "./src/util/binder.lzz"
753755
bool bound_object;
754756
};
755-
#line 35 "./src/util/binder.lzz"
756-
static bool IsPlainObject (v8::Isolate * isolate, v8::Local <v8::Object> obj);
757-
#line 44 "./src/util/binder.lzz"
757+
#line 54 "./src/util/binder.lzz"
758758
void Fail (void (* Throw) (char const *), char const * message);
759-
#line 52 "./src/util/binder.lzz"
759+
#line 62 "./src/util/binder.lzz"
760760
int NextAnonIndex ();
761-
#line 58 "./src/util/binder.lzz"
761+
#line 68 "./src/util/binder.lzz"
762762
void BindValue (v8::Isolate * isolate, v8::Local <v8::Value> value, int index);
763-
#line 79 "./src/util/binder.lzz"
763+
#line 89 "./src/util/binder.lzz"
764764
int BindArray (v8::Isolate * isolate, v8::Local <v8::Array> arr);
765-
#line 105 "./src/util/binder.lzz"
765+
#line 115 "./src/util/binder.lzz"
766766
int BindObject (v8::Isolate * isolate, v8::Local <v8::Object> obj, Statement * stmt);
767-
#line 149 "./src/util/binder.lzz"
767+
#line 159 "./src/util/binder.lzz"
768768
Result BindArgs (v8::FunctionCallbackInfo <v8 :: Value> const & info, int argc, Statement * stmt);
769-
#line 189 "./src/util/binder.lzz"
769+
#line 199 "./src/util/binder.lzz"
770770
sqlite3_stmt * handle;
771-
#line 190 "./src/util/binder.lzz"
771+
#line 200 "./src/util/binder.lzz"
772772
int param_count;
773-
#line 191 "./src/util/binder.lzz"
773+
#line 201 "./src/util/binder.lzz"
774774
int anon_index;
775-
#line 192 "./src/util/binder.lzz"
775+
#line 202 "./src/util/binder.lzz"
776776
bool success;
777777
};
778778
#line 34 "./src/better_sqlite3.lzz"

src/util/binder.lzz

+11-1
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,25 @@ private:
3232
bool bound_object;
3333
};
3434

35+
#hdr
36+
static bool IsPlainObject(v8::Isolate* isolate, v8::Local<v8::Object> obj);
37+
#end
38+
#src
3539
static bool IsPlainObject(v8::Isolate* isolate, v8::Local<v8::Object> obj) {
3640
v8::Local<v8::Value> proto = obj->GetPrototype();
41+
42+
#if defined NODE_MODULE_VERSION && NODE_MODULE_VERSION < 93
3743
v8::Local<v8::Context> ctx = obj->CreationContext();
44+
#else
45+
v8::Local<v8::Context> ctx = obj->GetCreationContext().ToLocalChecked();
46+
#endif
47+
3848
ctx->Enter();
3949
v8::Local<v8::Value> baseProto = v8::Object::New(isolate)->GetPrototype();
4050
ctx->Exit();
4151
return proto->StrictEquals(baseProto) || proto->StrictEquals(v8::Null(isolate));
4252
}
43-
53+
#end
4454
void Fail(void (*Throw)(const char* _), const char* message) {
4555
assert(success == true);
4656
assert((Throw == NULL) == (message == NULL));

src/util/macros.lzz

+1-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ void SetPrototypeGetter(
153153
0,
154154
data,
155155
v8::AccessControl::DEFAULT,
156-
v8::PropertyAttribute::None,
157-
v8::AccessorSignature::New(isolate, recv)
156+
v8::PropertyAttribute::None
158157
);
159158
}

0 commit comments

Comments
 (0)