Skip to content

Commit

Permalink
Support build for electron v20 (#870)
Browse files Browse the repository at this point in the history
* 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 <matthew@photostructure.com>
  • Loading branch information
neoxpert and mceachen committed Nov 21, 2022
1 parent 54e6cba commit ba9fcec
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 50 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/build.yml
Expand Up @@ -22,8 +22,6 @@ jobs:
- macos-latest
- windows-2019
node:
- 10
- 12
- 14
- 16
- 18
Expand Down Expand Up @@ -69,10 +67,10 @@ jobs:
with:
node-version: 16
- run: npm install --ignore-scripts
- 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 }}
- 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 }}
- 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 }}
- 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 }}
- if: matrix.os == 'windows-2019'
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 }}
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 }}

prebuild-alpine:
name: Prebuild on alpine
Expand All @@ -83,7 +81,7 @@ jobs:
- uses: actions/checkout@v2
- run: apk add build-base git python3 --update-cache
- run: npm install --ignore-scripts
- 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 }}
- 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 }}

prebuild-alpine-arm:
strategy:
Expand All @@ -102,7 +100,7 @@ jobs:
apk add build-base git python3 --update-cache && \
cd /tmp/project && \
npm install --ignore-scripts && \
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 }}"
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 }}"
prebuild-linux-arm:
strategy:
Expand All @@ -120,4 +118,4 @@ jobs:
docker run --rm -v $(pwd):/tmp/project --entrypoint /bin/sh --platform linux/${{ matrix.arch }} node:16 -c "\
cd /tmp/project && \
npm install --ignore-scripts && \
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 }}"
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 }}"
11 changes: 9 additions & 2 deletions binding.gyp
Expand Up @@ -9,9 +9,16 @@
'target_name': 'better_sqlite3',
'dependencies': ['deps/sqlite3.gyp:sqlite3'],
'sources': ['src/better_sqlite3.cpp'],
'cflags': ['-std=c++14'],
'cflags_cc': ['-std=c++17'],
'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS': ['-std=c++14', '-stdlib=libc++'],
'OTHER_CPLUSPLUSFLAGS': ['-std=c++17', '-stdlib=libc++'],
},
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': [
'/std:c++17'
]
}
},
'conditions': [
['OS=="linux"', {
Expand Down
6 changes: 6 additions & 0 deletions package.json
Expand Up @@ -24,11 +24,17 @@
"cli-color": "^2.0.2",
"fs-extra": "^10.1.0",
"mocha": "^8.3.2",
"node-gyp": "8.4.1",
"nodemark": "^0.3.0",
"prebuild": "^11.0.4",
"sqlite": "^4.1.1",
"sqlite3": "^5.0.8"
},
"overrides": {
"prebuild": {
"node-gyp": "$node-gyp"
}
},
"scripts": {
"install": "prebuild-install || node-gyp rebuild --release",
"build-release": "node-gyp rebuild --release",
Expand Down
53 changes: 28 additions & 25 deletions src/better_sqlite3.cpp
Expand Up @@ -2,6 +2,21 @@
//

#include "better_sqlite3.hpp"
#line 39 "./src/util/binder.lzz"
static bool IsPlainObject(v8::Isolate* isolate, v8::Local<v8::Object> obj) {
v8::Local<v8::Value> proto = obj->GetPrototype();

#if defined NODE_MODULE_VERSION && NODE_MODULE_VERSION < 93
v8::Local<v8::Context> ctx = obj->CreationContext();
#else
v8::Local<v8::Context> ctx = obj->GetCreationContext().ToLocalChecked();
#endif

ctx->Enter();
v8::Local<v8::Value> baseProto = v8::Object::New(isolate)->GetPrototype();
ctx->Exit();
return proto->StrictEquals(baseProto) || proto->StrictEquals(v8::Null(isolate));
}
#line 67 "./src/better_sqlite3.lzz"
NODE_MODULE_INIT(/* exports, context */) {
v8::Isolate* isolate = context->GetIsolate();
Expand Down Expand Up @@ -104,8 +119,7 @@ void SetPrototypeGetter (v8::Isolate * isolate, v8::Local <v8::External> data, v
0,
data,
v8::AccessControl::DEFAULT,
v8::PropertyAttribute::None,
v8::AccessorSignature::New(isolate, recv)
v8::PropertyAttribute::None
);
}
#line 4 "./src/util/constants.lzz"
Expand Down Expand Up @@ -1951,37 +1965,26 @@ bool Binder::Bind (v8::FunctionCallbackInfo <v8 :: Value> const & info, int argc
}
return success;
}
#line 35 "./src/util/binder.lzz"
bool Binder::IsPlainObject (v8::Isolate * isolate, v8::Local <v8::Object> obj)
#line 35 "./src/util/binder.lzz"
{
v8::Local<v8::Value> proto = obj->GetPrototype();
v8::Local<v8::Context> ctx = obj->CreationContext();
ctx->Enter();
v8::Local<v8::Value> baseProto = v8::Object::New(isolate)->GetPrototype();
ctx->Exit();
return proto->StrictEquals(baseProto) || proto->StrictEquals(v8::Null(isolate));
}
#line 44 "./src/util/binder.lzz"
#line 54 "./src/util/binder.lzz"
void Binder::Fail (void (* Throw) (char const *), char const * message)
#line 44 "./src/util/binder.lzz"
#line 54 "./src/util/binder.lzz"
{
assert(success == true);
assert((Throw == NULL) == (message == NULL));
assert(Throw == ThrowError || Throw == ThrowTypeError || Throw == ThrowRangeError || Throw == NULL);
if (Throw) Throw(message);
success = false;
}
#line 52 "./src/util/binder.lzz"
#line 62 "./src/util/binder.lzz"
int Binder::NextAnonIndex ()
#line 52 "./src/util/binder.lzz"
#line 62 "./src/util/binder.lzz"
{
while (sqlite3_bind_parameter_name(handle, ++anon_index) != NULL) {}
return anon_index;
}
#line 58 "./src/util/binder.lzz"
#line 68 "./src/util/binder.lzz"
void Binder::BindValue (v8::Isolate * isolate, v8::Local <v8::Value> value, int index)
#line 58 "./src/util/binder.lzz"
#line 68 "./src/util/binder.lzz"
{
int status = Data::BindValueFromJS(isolate, handle, index, value);
if (status != SQLITE_OK) {
Expand All @@ -2000,9 +2003,9 @@ void Binder::BindValue (v8::Isolate * isolate, v8::Local <v8::Value> value, int
assert(false);
}
}
#line 79 "./src/util/binder.lzz"
#line 89 "./src/util/binder.lzz"
int Binder::BindArray (v8::Isolate * isolate, v8::Local <v8::Array> arr)
#line 79 "./src/util/binder.lzz"
#line 89 "./src/util/binder.lzz"
{
v8 :: Local < v8 :: Context > ctx = isolate -> GetCurrentContext ( ) ;
uint32_t length = arr->Length();
Expand All @@ -2024,9 +2027,9 @@ int Binder::BindArray (v8::Isolate * isolate, v8::Local <v8::Array> arr)
}
return len;
}
#line 105 "./src/util/binder.lzz"
#line 115 "./src/util/binder.lzz"
int Binder::BindObject (v8::Isolate * isolate, v8::Local <v8::Object> obj, Statement * stmt)
#line 105 "./src/util/binder.lzz"
#line 115 "./src/util/binder.lzz"
{
v8 :: Local < v8 :: Context > ctx = isolate -> GetCurrentContext ( ) ;
BindMap* bind_map = stmt->GetBindMap(isolate);
Expand Down Expand Up @@ -2063,9 +2066,9 @@ int Binder::BindObject (v8::Isolate * isolate, v8::Local <v8::Object> obj, State

return len;
}
#line 149 "./src/util/binder.lzz"
#line 159 "./src/util/binder.lzz"
Binder::Result Binder::BindArgs (v8::FunctionCallbackInfo <v8 :: Value> const & info, int argc, Statement * stmt)
#line 149 "./src/util/binder.lzz"
#line 159 "./src/util/binder.lzz"
{
v8 :: Isolate * isolate = info . GetIsolate ( ) ;
int count = 0;
Expand Down
24 changes: 12 additions & 12 deletions src/better_sqlite3.hpp
Expand Up @@ -18,6 +18,8 @@
#include <node_buffer.h>
#line 31 "./src/util/macros.lzz"
template <class T> using CopyablePersistent = v8::Persistent<T, v8::CopyablePersistentTraits<T>>;
#line 36 "./src/util/binder.lzz"
static bool IsPlainObject(v8::Isolate* isolate, v8::Local<v8::Object> obj);
#define LZZ_INLINE inline
#line 16 "./src/util/macros.lzz"
v8::Local <v8::String> StringFromUtf8 (v8::Isolate * isolate, char const * data, int length);
Expand Down Expand Up @@ -752,27 +754,25 @@ class Binder
#line 32 "./src/util/binder.lzz"
bool bound_object;
};
#line 35 "./src/util/binder.lzz"
static bool IsPlainObject (v8::Isolate * isolate, v8::Local <v8::Object> obj);
#line 44 "./src/util/binder.lzz"
#line 54 "./src/util/binder.lzz"
void Fail (void (* Throw) (char const *), char const * message);
#line 52 "./src/util/binder.lzz"
#line 62 "./src/util/binder.lzz"
int NextAnonIndex ();
#line 58 "./src/util/binder.lzz"
#line 68 "./src/util/binder.lzz"
void BindValue (v8::Isolate * isolate, v8::Local <v8::Value> value, int index);
#line 79 "./src/util/binder.lzz"
#line 89 "./src/util/binder.lzz"
int BindArray (v8::Isolate * isolate, v8::Local <v8::Array> arr);
#line 105 "./src/util/binder.lzz"
#line 115 "./src/util/binder.lzz"
int BindObject (v8::Isolate * isolate, v8::Local <v8::Object> obj, Statement * stmt);
#line 149 "./src/util/binder.lzz"
#line 159 "./src/util/binder.lzz"
Result BindArgs (v8::FunctionCallbackInfo <v8 :: Value> const & info, int argc, Statement * stmt);
#line 189 "./src/util/binder.lzz"
#line 199 "./src/util/binder.lzz"
sqlite3_stmt * handle;
#line 190 "./src/util/binder.lzz"
#line 200 "./src/util/binder.lzz"
int param_count;
#line 191 "./src/util/binder.lzz"
#line 201 "./src/util/binder.lzz"
int anon_index;
#line 192 "./src/util/binder.lzz"
#line 202 "./src/util/binder.lzz"
bool success;
};
#line 34 "./src/better_sqlite3.lzz"
Expand Down
12 changes: 11 additions & 1 deletion src/util/binder.lzz
Expand Up @@ -32,15 +32,25 @@ private:
bool bound_object;
};

#hdr
static bool IsPlainObject(v8::Isolate* isolate, v8::Local<v8::Object> obj);
#end
#src
static bool IsPlainObject(v8::Isolate* isolate, v8::Local<v8::Object> obj) {
v8::Local<v8::Value> proto = obj->GetPrototype();

#if defined NODE_MODULE_VERSION && NODE_MODULE_VERSION < 93
v8::Local<v8::Context> ctx = obj->CreationContext();
#else
v8::Local<v8::Context> ctx = obj->GetCreationContext().ToLocalChecked();
#endif

ctx->Enter();
v8::Local<v8::Value> baseProto = v8::Object::New(isolate)->GetPrototype();
ctx->Exit();
return proto->StrictEquals(baseProto) || proto->StrictEquals(v8::Null(isolate));
}

#end
void Fail(void (*Throw)(const char* _), const char* message) {
assert(success == true);
assert((Throw == NULL) == (message == NULL));
Expand Down
3 changes: 1 addition & 2 deletions src/util/macros.lzz
Expand Up @@ -153,7 +153,6 @@ void SetPrototypeGetter(
0,
data,
v8::AccessControl::DEFAULT,
v8::PropertyAttribute::None,
v8::AccessorSignature::New(isolate, recv)
v8::PropertyAttribute::None
);
}

0 comments on commit ba9fcec

Please sign in to comment.