m4heshd / better-sqlite3-multiple-ciphers

better-sqlite3 with multiple-cipher encryption support 🔒
MIT License
140 stars 27 forks source link

Building for NW.js #9

Closed NbrTDB closed 11 months ago

NbrTDB commented 2 years ago

By request, here is some details about how I'm building better-sqlite3 for NW.js 0.50.1 with nw-gyp v3.6.5 on Windows.

(Small disclaimer... mostly smashing this down from memory, haven't fiddled with the build environment in a while! Some of this process may be superfluous for better-sqlite3 and only necessary for other aspects of my project. I've stripped out the stuff I'm positive has nothing to do with better-sqlite3).

Firstly, the Node environment should be appropriate for the version of NW.js being used or you can end up with explosions. Firing up a blank NW.js project and running process.versions in devtools it shows Node is at 15.3.0 for this version of NW.js, so we want to aim for Node 15.x really.

Second requisite is windows-build-tools: npm install --global --production windows-build-tools

And of course, grab nw-gyp: npm install -g nw-gyp

Also need Python 2.7, if I recall. Python 3.x can be on the system too but ensure that 2.7 comes before it in the PATH environment variables.

Plonk better-sqlite3 in the project package.json file (I am finding builds for 7.5.0 do not currently work for Windows due to EPERM issues with symlinks, so I have specified "7.4.6"):

{
 "blah": "blah",
 "dependencies": {
    "better-sqlite3": "7.4.6"
  }
 "stuff": "etcetera"
}

After that I believe we're good to go with a little batch file we can run in the project directory:

@REM configure build environment
set PYTHON=C:\Python27\python.exe
set npm_config_target=0.50.1
set npm_config_arch=x64
set npm_config_runtime=node-webkit
set npm_config_build_from_source=true
set npm_config_node_gyp=%userprofile%\AppData\Roaming\npm\node_modules\nw-gyp\bin\nw-gyp.js

@REM try building
call npm install --msvs_version=2017

Then once it's finished just run nw with the project path as an argument and it should fire up.

If the above explodes during building it may be that you need Visual Studio 2017 build tools instead. If you have chocolatey you can just:

choco install -y visualstudio2017buildtools
m4heshd commented 2 years ago

Thank you so much for this. I've actually tried to build using pretty much similar configurations but it fails when prebuild is used. The problem is, since this build task need to be automated for all platforms, I'm stuck using prebuild. But there's a few things in your guide I need to try. Again, taking time to write this is much appreciated.

Would you also mind telling me what are the latest three versions of NW.js mostly popular among NW devs? I'm interested in providing prebuilds for at least three versions.

NbrTDB commented 2 years ago

You're welcome! I hope it proves useful. Yes npm prebuilds can get pretty explodey since the hooks don't line up with what NW.js requires, so it typically needs building from source.

I'm not really sure what versions would be most popular in general, to be honest. So don't take my word for it, but I'd say definitely the latest (which changes very regularly), and then there are certain versions like 0.51.2, 0.50.1, 0.45.3, which stand out as being pretty stable and without important things broken. Different devs are going to have different opinions on what is "vital" though, of course...!

m4heshd commented 2 years ago

0.51.2, 0.50.1, 0.45.3, which stand out as being pretty stable

That's exactly what I needed. Thank you.

Yes npm prebuilds can get pretty explodey since the hooks don't line up with what NW.js requires, so it typically needs building from source.

What I'm trying to accomplish is build the prebuild files so that NW.js users will never need to build from source. What prebuild module does is utilizing node-gyp or nw-gyp to do the linking and help the automation process in a massive way. What I've seen is nw-gyp doesn't couple very well with prebuild. As you can see on this workflow, I'm building prebuilds for all platforms except NW.js. Things doesn't work the same way as building locally when you automate your builds on CIs.

If the above explodes during building it may be that you need Visual Studio 2017 build tools instead.

Platform build tools are inherently available on CI runners. It fails on the linking process.