Skip to content

Commit 75a09cf

Browse files
Switch to static OpenSSL on Windows (#75)
* Switch to static OpenSSL on Windows Also includes include Windows ARM64 and updates @mapbox/node-pre-gyp. * Remove unnecessary ws2_32.lib and crypt32.lib * Remove copy_dll step * Revert "Remove unnecessary ws2_32.lib and crypt32.lib" This reverts commit 555d63a. * Add note about two libs needed for Windows Electron build * Update CircleCI to build ARM64 as well
1 parent 260019d commit 75a09cf

11 files changed

+256
-216
lines changed

.circleci/config.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ aliases:
2222
if [[ "${ELECTRON_VERSION}" ]]; then
2323
GYP_ARGS="--runtime=electron --target=${ELECTRON_VERSION} --dist-url=https://electronjs.org/headers"
2424
fi
25+
if [[ "${BUILD_ARM64}" == "true" ]]; then
26+
GYP_ARGS="${GYP_ARGS} --target_arch=arm64"
27+
fi
2528
./node_modules/.bin/node-pre-gyp rebuild package testpackage $GYP_ARGS
2629
2730
- &publish-command
@@ -46,6 +49,9 @@ aliases:
4649
if [[ "${ELECTRON_VERSION}" ]]; then
4750
GYP_ARGS="--runtime=electron --target=${ELECTRON_VERSION} --dist-url=https://electronjs.org/headers"
4851
fi
52+
if [[ "${BUILD_ARM64}" == "true" ]]; then
53+
GYP_ARGS="${GYP_ARGS} --target_arch=arm64"
54+
fi
4955
export PATH=/c/nodejs:$PATH
5056
COMMIT_MESSAGE=`git log --format=%s -n 1 $CIRCLE_SHA1`
5157
if [[ ${COMMIT_MESSAGE} =~ "[publish binary]" ]] && [[ "$PUBLISH" == "true" ]]; then
@@ -327,6 +333,7 @@ jobs:
327333
NODE_ARCH: x86
328334
PUBLISH: true
329335
ELECTRON_VERSION: "11.2.3"
336+
BUILD_ARM64: false
330337

331338
windows-14_x64:
332339
<<: *common-windows
@@ -335,6 +342,16 @@ jobs:
335342
NODE_ARCH: x64
336343
PUBLISH: true
337344
ELECTRON_VERSION: "11.2.3"
345+
BUILD_ARM64: false
346+
347+
windows-14_arm64:
348+
<<: *common-windows
349+
environment:
350+
NODE_VERSION: "14.11.0"
351+
NODE_ARCH: x64
352+
PUBLISH: true
353+
ELECTRON_VERSION: "11.2.3"
354+
BUILD_ARM64: true
338355

339356
workflows:
340357
version: 2

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ setup.sh
2828
bin
2929
/build-tmp-napi-v3
3030
/build-tmp-napi-v6
31+
deps/vcpkg
32+
deps/openssl-windows
33+
/sqlcipher-amalgamation-*

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Similarly, using electron directly should just work, but do check that a compati
9595

9696
SQLCipher depends on OpenSSL.
9797

98-
For Windows, we bundle OpenSSL 1.0.2n. Pre-built libraries are used from https://slproweb.com/products/Win32OpenSSL.html.
98+
For Windows, we bundle OpenSSL 1.1.1i. Binaries are generated using [vckpg](https://github.com/microsoft/vcpkg) (e.g., `.\vcpkg\vcpkg install openssl:x64-windows-static`).
9999

100100
On Mac we build against OpenSSL installed via brew, but statically link it so that end-users do not need to install it.
101101

SQLCipher.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,22 @@ The files are copied to: `sqlcipher-amalgamation-<version>`.
3333

3434
NodeJS typically includes OpenSSL. However, for Electron on Windows, we need to bundle a copy.
3535

36-
Download OpenSSL 1.0.x from https://slproweb.com/products/Win32OpenSSL.html, both 32-bit and 64-bit versions. Install locally, then copy these files:
36+
Run the following commands to generate the latest OpenSSL libs for Windows:
3737

3838
```
39-
lib/libeay32.lib
40-
lib/ssleay32.lib
41-
bin/libeay32.dll
42-
bin/msvcr120.dll
39+
cd deps
40+
.\openssl-windows.bat
4341
```
4442

45-
Place these files in `sqlcipher-amalgamation-<version>/OpenSSL-Win32` and `sqlcipher-amalgamation-<version>/OpenSSL-Win64`.
43+
... this will output the libs in `deps/openssl-windows` (OpenSSL-WinXX), including the header files in `deps/openssl-windows/openssl-include`. Every arch-specific folder includes these binaries:
4644

47-
Copy the header files (include folder) to `sqlcipher-amalgamation-<version>/openssl-include/openssl`.
45+
```
46+
libcrypto.lib
47+
libssl.lib
48+
ossl_static.pdb
49+
```
50+
51+
Copy all folders under `deps/openssl-windows` to `sqlcipher-amalgamation-<version>`.
4852

4953
## Step 3: Build the archive
5054

@@ -71,7 +75,7 @@ npm run test
7175

7276
# Notes
7377

74-
The OpenSSL files are specifically required for Electron, which doesn't bundle OpenSSL like NodeJS does. The header and .lib files are required at compile-time, and `libeay32.dll` and `mscvr120.dll` are required at runtime. We bundle it with the library, so the user does not need to manually install OpenSSL.
78+
The OpenSSL files are specifically required for Electron, which doesn't bundle OpenSSL like NodeJS does. The header and .lib files are required at compile-time. We bundle a statically-linked version of OpenSSL with the library, so the user does not need to manually install OpenSSL.
7579

7680
`deps/sqlite3.gyp` has been modified from the original node-sqlite3 one to:
7781
* Use the bundled OpenSSL on Windows.

binding.gyp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,6 @@
6060
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
6161
"destination": "<(module_path)"
6262
}
63-
],
64-
"conditions": [
65-
["OS == \"win\"", {
66-
"copies": [
67-
{
68-
"files": [
69-
"<(PRODUCT_DIR)/libeay32.dll",
70-
"<(PRODUCT_DIR)/msvcr120.dll"
71-
],
72-
"destination": "<(module_path)"
73-
}
74-
]
75-
}]
7663
]
7764
}
7865
]

deps/openssl-windows.bat

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
call git clone https://github.com/microsoft/vcpkg vcpkg
2+
call .\vcpkg\bootstrap-vcpkg.bat
3+
4+
.\vcpkg\vcpkg install openssl:x64-windows-static
5+
if %errorlevel% neq 0 exit /b %errorlevel%
6+
.\vcpkg\vcpkg install openssl:x86-windows-static
7+
if %errorlevel% neq 0 exit /b %errorlevel%
8+
.\vcpkg\vcpkg install openssl:arm64-windows-static
9+
if %errorlevel% neq 0 exit /b %errorlevel%
10+
11+
if not exist .\openssl-windows mkdir .\openssl-windows .\openssl-windows\OpenSSL-Win64 .\openssl-windows\OpenSSL-Win32 .\openssl-windows\OpenSSL-Win64-ARM .\openssl-windows\openssl-include\openssl
12+
13+
copy .\vcpkg\installed\x64-windows-static\lib\*.* .\openssl-windows\OpenSSL-Win64
14+
copy .\vcpkg\installed\x64-windows-static\include\openssl\*.* .\openssl-windows\openssl-include\openssl
15+
copy .\vcpkg\installed\x86-windows-static\lib\*.* .\openssl-windows\OpenSSL-Win32
16+
copy .\vcpkg\installed\arm64-windows-static\lib\*.* .\openssl-windows\OpenSSL-Win64-ARM
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:ff757fa6eb32081f9e628ef3c908f1ac3aabc7d63ce2b6e3f77fc23881486530
3-
size 5565172
2+
oid sha256:d9cae3671eebd756c1ae58541bb3f21a9de9e7a1b74c93feb233f3c718a801b1
3+
size 23153710

deps/sqlite3.gyp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
'variables': {
4444
'openssl_root%': 'OpenSSL-Win32',
4545
}
46+
}, 'target_arch == "arm64"', {
47+
'variables': {
48+
'openssl_root%': 'OpenSSL-Win64-ARM',
49+
}
4650
}, {
4751
'variables': {
4852
'openssl_root%': 'OpenSSL-Win64',
@@ -51,8 +55,11 @@
5155
],
5256
'link_settings': {
5357
'libraries': [
54-
'-llibeay32.lib',
55-
'-lssleay32.lib',
58+
'-llibcrypto.lib',
59+
'-llibssl.lib',
60+
# The two libs below are needed for the Electron build to succeed
61+
'-lws2_32.lib',
62+
'-lcrypt32.lib'
5663
],
5764
'library_dirs': [
5865
'<(SHARED_INTERMEDIATE_DIR)/sqlcipher-amalgamation-<@(sqlite_version)/<(openssl_root)'
@@ -103,24 +110,6 @@
103110
]
104111
},
105112
},
106-
{
107-
"target_name": "copy_dll",
108-
"type": "none",
109-
"dependencies": [ "action_before_build" ],
110-
"conditions": [
111-
["OS == \"win\"", {
112-
"copies": [
113-
{
114-
"files": [
115-
'<(SHARED_INTERMEDIATE_DIR)/sqlcipher-amalgamation-<@(sqlite_version)/>(openssl_root)/libeay32.dll',
116-
'<(SHARED_INTERMEDIATE_DIR)/sqlcipher-amalgamation-<@(sqlite_version)/>(openssl_root)/msvcr120.dll'
117-
],
118-
"destination": "<(PRODUCT_DIR)"
119-
}
120-
],
121-
}]
122-
]
123-
},
124113
{
125114
'target_name': 'sqlite3',
126115
'type': 'static_library',
@@ -145,8 +134,7 @@
145134
],
146135

147136
'dependencies': [
148-
'action_before_build',
149-
'copy_dll'
137+
'action_before_build'
150138
],
151139
'sources': [
152140
'<(SHARED_INTERMEDIATE_DIR)/sqlcipher-amalgamation-<@(sqlite_version)/sqlite3.c'

lib/sqlite3-binding.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var binary = require('node-pre-gyp');
1+
var binary = require('@mapbox/node-pre-gyp');
22
var path = require('path');
33
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
44
var binding = require(binding_path);

0 commit comments

Comments
 (0)