Skip to content

Commit f53a88f

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

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

addon/openssl-crypto.cc

Lines changed: 16 additions & 2 deletions
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+
#if !defined(ELECTRON_ENSURE_CONFIG_GYPI) && !defined(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 // ELECTRON_ENSURE_CONFIG_GYPI
450+
namespace node_mongocrypt {
451+
namespace opensslcrypto {
452+
std::unique_ptr<CryptoHooks> createOpenSSLCryptoHooks() {
453+
return {};
454+
}
455+
}
456+
}
457+
#endif // ELECTRON_ENSURE_CONFIG_GYPI

binding.gyp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
'variables': {
99
'ARCH': '<(host_arch)',
1010
'libmongocrypt_link_type%': 'static',
11+
'mongocrypt_avoid_openssl_crypto%': 'false'
1112
},
1213
'sources': [
1314
'addon/mongocrypt.cc',
@@ -25,6 +26,7 @@
2526
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
2627
},
2728
'conditions': [
29+
['mongocrypt_avoid_openssl_crypto=="true"', { 'defines': ['MONGOCRYPT_AVOID_OPENSSL_CRYPTO'] }],
2830
['OS=="mac"', { 'cflags+': ['-fvisibility=hidden'] }],
2931
['_type!="static_library" and ARCH=="arm64"', {
3032
'xcode_settings': {

0 commit comments

Comments
 (0)