From ba9fcecb870ee0dd325930d7f642ca6a45ebc00e Mon Sep 17 00:00:00 2001 From: neoxpert <18628980+neoxpert@users.noreply.github.com> Date: Tue, 22 Nov 2022 00:31:03 +0100 Subject: [PATCH] Support build for electron v20 (#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 --- .github/workflows/build.yml | 14 +++++----- binding.gyp | 11 ++++++-- package.json | 6 +++++ src/better_sqlite3.cpp | 53 ++++++++++++++++++++----------------- src/better_sqlite3.hpp | 24 ++++++++--------- src/util/binder.lzz | 12 ++++++++- src/util/macros.lzz | 3 +-- 7 files changed, 73 insertions(+), 50 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7e2fd25b1..1f24ea99d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,8 +22,6 @@ jobs: - macos-latest - windows-2019 node: - - 10 - - 12 - 14 - 16 - 18 @@ -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 @@ -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: @@ -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: @@ -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 }}" diff --git a/binding.gyp b/binding.gyp index 59fa0a81f..13f437433 100644 --- a/binding.gyp +++ b/binding.gyp @@ -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"', { diff --git a/package.json b/package.json index 591d6e59d..5ce5b9ad1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/better_sqlite3.cpp b/src/better_sqlite3.cpp index ae4573daa..fd36d3e24 100644 --- a/src/better_sqlite3.cpp +++ b/src/better_sqlite3.cpp @@ -2,6 +2,21 @@ // #include "better_sqlite3.hpp" +#line 39 "./src/util/binder.lzz" + static bool IsPlainObject(v8::Isolate* isolate, v8::Local obj) { + v8::Local proto = obj->GetPrototype(); + + #if defined NODE_MODULE_VERSION && NODE_MODULE_VERSION < 93 + v8::Local ctx = obj->CreationContext(); + #else + v8::Local ctx = obj->GetCreationContext().ToLocalChecked(); + #endif + + ctx->Enter(); + v8::Local 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(); @@ -104,8 +119,7 @@ void SetPrototypeGetter (v8::Isolate * isolate, v8::Local data, v 0, data, v8::AccessControl::DEFAULT, - v8::PropertyAttribute::None, - v8::AccessorSignature::New(isolate, recv) + v8::PropertyAttribute::None ); } #line 4 "./src/util/constants.lzz" @@ -1951,20 +1965,9 @@ bool Binder::Bind (v8::FunctionCallbackInfo const & info, int argc } return success; } -#line 35 "./src/util/binder.lzz" -bool Binder::IsPlainObject (v8::Isolate * isolate, v8::Local obj) -#line 35 "./src/util/binder.lzz" - { - v8::Local proto = obj->GetPrototype(); - v8::Local ctx = obj->CreationContext(); - ctx->Enter(); - v8::Local 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)); @@ -1972,16 +1975,16 @@ void Binder::Fail (void (* Throw) (char const *), char const * message) 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 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) { @@ -2000,9 +2003,9 @@ void Binder::BindValue (v8::Isolate * isolate, v8::Local value, int assert(false); } } -#line 79 "./src/util/binder.lzz" +#line 89 "./src/util/binder.lzz" int Binder::BindArray (v8::Isolate * isolate, v8::Local 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(); @@ -2024,9 +2027,9 @@ int Binder::BindArray (v8::Isolate * isolate, v8::Local arr) } return len; } -#line 105 "./src/util/binder.lzz" +#line 115 "./src/util/binder.lzz" int Binder::BindObject (v8::Isolate * isolate, v8::Local 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); @@ -2063,9 +2066,9 @@ int Binder::BindObject (v8::Isolate * isolate, v8::Local obj, State return len; } -#line 149 "./src/util/binder.lzz" +#line 159 "./src/util/binder.lzz" Binder::Result Binder::BindArgs (v8::FunctionCallbackInfo 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; diff --git a/src/better_sqlite3.hpp b/src/better_sqlite3.hpp index 1fcc01a2d..c73a1e873 100644 --- a/src/better_sqlite3.hpp +++ b/src/better_sqlite3.hpp @@ -18,6 +18,8 @@ #include #line 31 "./src/util/macros.lzz" template using CopyablePersistent = v8::Persistent>; +#line 36 "./src/util/binder.lzz" + static bool IsPlainObject(v8::Isolate* isolate, v8::Local obj); #define LZZ_INLINE inline #line 16 "./src/util/macros.lzz" v8::Local StringFromUtf8 (v8::Isolate * isolate, char const * data, int length); @@ -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 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 value, int index); -#line 79 "./src/util/binder.lzz" +#line 89 "./src/util/binder.lzz" int BindArray (v8::Isolate * isolate, v8::Local arr); -#line 105 "./src/util/binder.lzz" +#line 115 "./src/util/binder.lzz" int BindObject (v8::Isolate * isolate, v8::Local obj, Statement * stmt); -#line 149 "./src/util/binder.lzz" +#line 159 "./src/util/binder.lzz" Result BindArgs (v8::FunctionCallbackInfo 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" diff --git a/src/util/binder.lzz b/src/util/binder.lzz index 364a0d8dd..479bbf8f1 100644 --- a/src/util/binder.lzz +++ b/src/util/binder.lzz @@ -32,15 +32,25 @@ private: bool bound_object; }; +#hdr + static bool IsPlainObject(v8::Isolate* isolate, v8::Local obj); +#end +#src static bool IsPlainObject(v8::Isolate* isolate, v8::Local obj) { v8::Local proto = obj->GetPrototype(); + + #if defined NODE_MODULE_VERSION && NODE_MODULE_VERSION < 93 v8::Local ctx = obj->CreationContext(); + #else + v8::Local ctx = obj->GetCreationContext().ToLocalChecked(); + #endif + ctx->Enter(); v8::Local 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)); diff --git a/src/util/macros.lzz b/src/util/macros.lzz index f8f6ce4a7..666488cc5 100644 --- a/src/util/macros.lzz +++ b/src/util/macros.lzz @@ -153,7 +153,6 @@ void SetPrototypeGetter( 0, data, v8::AccessControl::DEFAULT, - v8::PropertyAttribute::None, - v8::AccessorSignature::New(isolate, recv) + v8::PropertyAttribute::None ); }