From f53a88f58db99bf65a92259995ff5d5d0ada028c Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 11 Jul 2024 13:06:22 +0200 Subject: [PATCH] fix: do not try to use OpenSSL when building for Electron --- addon/openssl-crypto.cc | 18 ++++++++++++++++-- binding.gyp | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/addon/openssl-crypto.cc b/addon/openssl-crypto.cc index 8d8d976..618a57d 100644 --- a/addon/openssl-crypto.cc +++ b/addon/openssl-crypto.cc @@ -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 #include #include @@ -13,8 +19,6 @@ #include -#include "mongocrypt.h" - #ifdef _WIN32 #include #else @@ -441,3 +445,13 @@ std::unique_ptr createOpenSSLCryptoHooks() { } // namespace opensslcrypto } // namespace node_mongocrypt + +#else // ELECTRON_ENSURE_CONFIG_GYPI +namespace node_mongocrypt { +namespace opensslcrypto { +std::unique_ptr createOpenSSLCryptoHooks() { + return {}; +} +} +} +#endif // ELECTRON_ENSURE_CONFIG_GYPI diff --git a/binding.gyp b/binding.gyp index ec2f22b..79a5985 100644 --- a/binding.gyp +++ b/binding.gyp @@ -8,6 +8,7 @@ 'variables': { 'ARCH': '<(host_arch)', 'libmongocrypt_link_type%': 'static', + 'mongocrypt_avoid_openssl_crypto%': 'false' }, 'sources': [ 'addon/mongocrypt.cc', @@ -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': {