Skip to content

Commit 3886c37

Browse files
committed
fix: do not try to use OpenSSL when building for Electron
1 parent b010fa9 commit 3886c37

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Diff for: addon/openssl-crypto.cc

+16-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
// This file provides native crypto hooks for OpenSSL 3 (the default since Node.js 18),
66
// allowing us to skip expensive round-trips between JS and C++.
77

8+
#include "mongocrypt.h"
9+
10+
// Electron does not expose OpenSSL, so we cannot use OpenSSL
11+
// functions directly if we're building against Electron:
12+
// https://github.com/electron/electron/issues/13176
13+
#ifndef MONGOCRYPT_AVOID_OPENSSL_CRYPTO
814
#include <openssl/crypto.h>
915
#include <openssl/err.h>
1016
#include <openssl/evp.h>
@@ -13,8 +19,6 @@
1319

1420
#include <stdexcept>
1521

16-
#include "mongocrypt.h"
17-
1822
#ifdef _WIN32
1923
#include <windows.h>
2024
#else
@@ -441,3 +445,13 @@ std::unique_ptr<CryptoHooks> createOpenSSLCryptoHooks() {
441445

442446
} // namespace opensslcrypto
443447
} // namespace node_mongocrypt
448+
449+
#else // MONGOCRYPT_AVOID_OPENSSL_CRYPTO
450+
namespace node_mongocrypt {
451+
namespace opensslcrypto {
452+
std::unique_ptr<CryptoHooks> createOpenSSLCryptoHooks() {
453+
return {};
454+
}
455+
}
456+
}
457+
#endif // MONGOCRYPT_AVOID_OPENSSL_CRYPTO

Diff for: binding.gyp

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
'variables': {
99
'ARCH': '<(host_arch)',
1010
'libmongocrypt_link_type%': 'static',
11+
'mongocrypt_avoid_openssl_crypto%': 'false',
12+
'built_with_electron%': 0
1113
},
1214
'sources': [
1315
'addon/mongocrypt.cc',
@@ -25,6 +27,7 @@
2527
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
2628
},
2729
'conditions': [
30+
['mongocrypt_avoid_openssl_crypto=="true" or built_with_electron==1', { 'defines': ['MONGOCRYPT_AVOID_OPENSSL_CRYPTO'] }],
2831
['OS=="mac"', { 'cflags+': ['-fvisibility=hidden'] }],
2932
['_type!="static_library" and ARCH=="arm64"', {
3033
'xcode_settings': {

0 commit comments

Comments
 (0)