better-sqlite3 icon indicating copy to clipboard operation
better-sqlite3 copied to clipboard

Support build for electron v20

Open neoxpert opened this issue 1 year ago • 7 comments

This PR contains changes in order to support builds against electron 20.

Note: Used MSVC 2022, NodeJS 16.17.0 LTS. Tested builds for electron v16 to v20.

fixes #858 fixes #867

neoxpert avatar Aug 26 '22 22:08 neoxpert

@mceachen do you have the necessary permissions to trigger the workflow? I want to see if it succeeds everywhere so that we can move on from there or make changes if necessary. I have a feeling this might fail on older Node.js.

Prinzhorn avatar Sep 09 '22 14:09 Prinzhorn

Ugh, node 12:

./src/util/binder.lzz:37:51: error: ‘class v8::Object’ has no member named ‘GetCreationContext’; did you mean ‘CreationContext’?

@JoshuaWise we should drop unsupported versions of Node: v12 EOL was 2022-04-30.

mceachen avatar Sep 09 '22 15:09 mceachen

So unfortunately GetCreationContext was introduced after Node v14, so we may have to #ifdef around this issue. :disappointed:

mceachen avatar Sep 09 '22 16:09 mceachen

Ugh, node 12:

./src/util/binder.lzz:37:51: error: ‘class v8::Object’ has no member named ‘GetCreationContext’; did you mean ‘CreationContext’?

No, the use of GetCreationContext is intentional, as CreationContext is no longer available for v8::Object in the electron 20 header files.

v8-object.h for electron 19.0.0 line 495 and following:

/**
 * Returns the context in which the object was created.
 */
V8_DEPRECATED("Use MaybeLocal<Context> GetCreationContext()")
Local<Context> CreationContext();
MaybeLocal<Context> GetCreationContext();

v8-object.h for electron 20.0.0 line 495 and following:

 /**
  * Returns the context in which the object was created.
  */
  MaybeLocal<Context> GetCreationContext();

Unfortunately this breaks backwards compatibility as the first version to support GetCreationContext was electron 13, at least it's the first version to have it in the header files.

neoxpert avatar Sep 09 '22 16:09 neoxpert

Thank you for the PR. It looks like we also need to use C++ 17 instead of C++ 14 for this to work (ref, Signal's fork: https://github.com/signalapp/better-sqlite3/blob/better-sqlcipher/binding.gyp#L12)

The change failed to compile on my Mac M1 but after switching to C++ 17, it works.

quanglam2807 avatar Sep 09 '22 21:09 quanglam2807

-      '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++'],
       },

quanglam2807 avatar Sep 09 '22 21:09 quanglam2807

Kudos, @neoxpert , thanks for your work here, and for the assist, @quanglam2807 !

I’ll try this branch locally with PhotoStructure’s test suite, but if anyone else can verify it works that’d be better.

@JoshuaWise do you want to review this before it gets merged?

mceachen avatar Sep 10 '22 23:09 mceachen

As the changes of this merge request are also required to build for the todays release of Electron v21, would we handle this within this merge request / branch or wait until this one is merged and create a new one after that?

neoxpert avatar Sep 27 '22 19:09 neoxpert

@neoxpert could you fork this PR and create a new one with 21 added for the CI? I can't speak for the maintainers, but I just want to make sure that it works (new memory cage should not affects us) so that we're prepared for 21 already. In general I don't see a problem with adding the 21 to this PR, but maybe leave it for now.

Prinzhorn avatar Sep 29 '22 15:09 Prinzhorn

Hi, just wondering when will we merge this PR?

zhoukq avatar Oct 12 '22 14:10 zhoukq

I don't have an M1 mac, but maybe we should incorporate @quanglam2807's feedback before merging?

JoshuaWise avatar Oct 12 '22 15:10 JoshuaWise

I don't have an M1 mac, but maybe we should incorporate @quanglam2807's feedback before merging?

Yes, please. It's not just M1, but also x64 Linux - the commit in the Signal fork that adds this fix is titled: "Fix Linux builds", I can also confirm that I had to apply it before I could build it successfully (on Linux).

mckravchyk avatar Oct 13 '22 08:10 mckravchyk

I added the changes mentioned by @quanglam2807.

neoxpert avatar Oct 19 '22 12:10 neoxpert

On windows, there are also build issues. This comment saved my day: https://github.com/nodejs/node-gyp/issues/1662#issuecomment-1270232265

maximilize avatar Oct 20 '22 20:10 maximilize

@maximilize Just out of curiosity, which MSVC version are you using? So far I did not encounter any issues with MS Build 2017, 2019 and 2022.

neoxpert avatar Oct 20 '22 21:10 neoxpert

people who can merge, please take another look?

segmentedcontrol avatar Oct 25 '22 11:10 segmentedcontrol

@segmentedcontrol My fork (@anonrig/better-sqlite3) has both arm64 prebuilds and electron 20 & 21 support: http://github.com/anonrig/better-sqlite3

anonrig avatar Oct 25 '22 14:10 anonrig

For anyone else waiting on the merge, you should be able to install with:

npm install WiseLibs/better-sqlite3#pull/870/head

Has saved me some time for now 🙌🏽

megancooper avatar Oct 26 '22 04:10 megancooper

Any plans of merging this in near future? 👀

ddramone avatar Nov 11 '22 16:11 ddramone

With yarn, the syntax that worked for me for installing this PR directly is slightly different:

yarn add node-gyp
yarn add better-sqlite3@neoxpert/better-sqlite3#fix_electron20_build

Juanc1to avatar Nov 15 '22 22:11 Juanc1to

So I also added the /std:c++17 flag for the MSVC settings. But I think it is worth to mention that, as of now, builds against the electron 20 / 21 API only work with MSVC 2019 or 2022. While 2017 should work (whyever it did before I cleaned my MSVC setups...), there seem to be known issues regarding that (https://github.com/electron/electron/issues/36033) leading to build errors (shortened output):

..\v8-callbacks.h(335): error C2062: "int"-Typ unerwartet
..\v8-isolate.h(292): error C3646: "legacy_oom_error_callback": Unbekannter Überschreibungsspezifizierer
..\v8-isolate.h(292): error C4430: Fehlender Typspezifizierer - int wird angenommen. Hinweis: "default-int" wird von C++ nicht unterstützt.
..\v8-isolate.h(1482): error C2061: Syntaxfehler: Bezeichner "LegacyOOMErrorCallback"
..\v8-isolate.h(1545): error C2061: Syntaxfehler: Bezeichner "WasmDynamicTieringEnabledCallback"
..\v8-initialization.h(290): error C2061: Syntaxfehler: Bezeichner "LegacyOOMErrorCallback

neoxpert avatar Nov 16 '22 09:11 neoxpert

Thanks for all the work on this @neoxpert and everybody 👍

JoshuaWise avatar Nov 21 '22 23:11 JoshuaWise