Skip to content

Commit

Permalink
fix: do not try to use OpenSSL when building for Electron
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Jul 11, 2024
1 parent b010fa9 commit f53a88f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 16 additions & 2 deletions addon/openssl-crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
// This file provides native crypto hooks for OpenSSL 3 (the default since Node.js 18),
// allowing us to skip expensive round-trips between JS and C++.

#include "mongocrypt.h"

// Electron does not expose OpenSSL, so we cannot use OpenSSL
// functions directly if we're building against Electron:
// https://github.com/electron/electron/issues/13176
#if !defined(ELECTRON_ENSURE_CONFIG_GYPI) && !defined(MONGOCRYPT_AVOID_OPENSSL_CRYPTO)
#include <openssl/crypto.h>
#include <openssl/err.h>
#include <openssl/evp.h>
Expand All @@ -13,8 +19,6 @@

#include <stdexcept>

#include "mongocrypt.h"

#ifdef _WIN32
#include <windows.h>
#else
Expand Down Expand Up @@ -441,3 +445,13 @@ std::unique_ptr<CryptoHooks> createOpenSSLCryptoHooks() {

} // namespace opensslcrypto
} // namespace node_mongocrypt

#else // ELECTRON_ENSURE_CONFIG_GYPI
namespace node_mongocrypt {
namespace opensslcrypto {
std::unique_ptr<CryptoHooks> createOpenSSLCryptoHooks() {
return {};
}
}
}
#endif // ELECTRON_ENSURE_CONFIG_GYPI
2 changes: 2 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
'variables': {
'ARCH': '<(host_arch)',
'libmongocrypt_link_type%': 'static',
'mongocrypt_avoid_openssl_crypto%': 'false'
},
'sources': [
'addon/mongocrypt.cc',
Expand All @@ -25,6 +26,7 @@
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
},
'conditions': [
['mongocrypt_avoid_openssl_crypto=="true"', { 'defines': ['MONGOCRYPT_AVOID_OPENSSL_CRYPTO'] }],
['OS=="mac"', { 'cflags+': ['-fvisibility=hidden'] }],
['_type!="static_library" and ARCH=="arm64"', {
'xcode_settings': {
Expand Down

0 comments on commit f53a88f

Please sign in to comment.