Skip to content

Commit ac0d205

Browse files
committed
WL#14815: Support OpenSSL 3.0
This worklog adds support for building MySQL Connector/Python with OpenSSL 3.0. Change-Id: I02db5feeccf7934c3b7361dd62fc8c0b6d03d202
1 parent b107f4e commit ac0d205

File tree

9 files changed

+168
-132
lines changed

9 files changed

+168
-132
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ v8.0.30
1515
- WL#15137: Fix linting issues
1616
- WL#15035: Enforce PEP 7 and PEP 8 coding style
1717
- WL#14822: Refactor the authentication plugin mechanism
18+
- WL#14815: Support OpenSSL 3.0
1819

1920
v8.0.29
2021
=======

cpydist/__init__.py

Lines changed: 65 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@
4747

4848
from setuptools.command.build_ext import build_ext
4949

50-
from .utils import ARCH, ARCH_64BIT, mysql_c_api_info, write_info_bin, write_info_src
50+
from .utils import (
51+
ARCH,
52+
ARCH_64BIT,
53+
get_openssl_libs,
54+
mysql_c_api_info,
55+
write_info_bin,
56+
write_info_src,
57+
)
5158

5259
# Load version information
5360
VERSION = [999, 0, 0, "a", 0]
@@ -166,30 +173,47 @@ def finalize_options(self):
166173
self.log.setLevel(logging.DEBUG)
167174
log.set_threshold(1) # Set Distutils logging level to DEBUG
168175

176+
if not self.with_mysql_capi:
177+
self.with_mysql_capi = os.environ.get("MYSQL_CAPI")
178+
if not self.with_openssl_include_dir:
179+
self.with_openssl_include_dir = os.environ.get("OPENSSL_INCLUDE_DIR")
180+
if not self.with_openssl_lib_dir:
181+
self.with_openssl_lib_dir = os.environ.get("OPENSSL_LIB_DIR")
182+
if not self.with_protobuf_include_dir:
183+
self.with_protobuf_include_dir = os.environ.get("PROTOBUF_INCLUDE_DIR")
184+
if not self.with_protobuf_lib_dir:
185+
self.with_protobuf_lib_dir = os.environ.get("PROTOBUF_LIB_DIR")
186+
if not self.with_protoc:
187+
self.with_protoc = os.environ.get("PROTOC")
188+
if not self.extra_compile_args:
189+
self.extra_compile_args = os.environ.get("EXTRA_COMPILE_ARGS")
190+
if not self.extra_link_args:
191+
self.extra_link_args = os.environ.get("EXTRA_LINK_ARGS")
192+
if not self.skip_vendor:
193+
self.skip_vendor = os.environ.get("SKIP_VENDOR")
194+
169195
cmd_build_ext = self.distribution.get_command_obj("build_ext")
170-
cmd_build_ext.with_mysql_capi = self.with_mysql_capi or os.environ.get(
171-
"MYSQL_CAPI"
172-
)
173-
cmd_build_ext.with_openssl_include_dir = (
174-
self.with_openssl_include_dir or os.environ.get("OPENSSL_INCLUDE_DIR")
175-
)
176-
cmd_build_ext.with_openssl_lib_dir = (
177-
self.with_openssl_lib_dir or os.environ.get("OPENSSL_LIB_DIR")
178-
)
179-
cmd_build_ext.with_protobuf_include_dir = (
180-
self.with_protobuf_include_dir or os.environ.get("PROTOBUF_INCLUDE_DIR")
181-
)
182-
cmd_build_ext.with_protobuf_lib_dir = (
183-
self.with_protobuf_lib_dir or os.environ.get("PROTOBUF_LIB_DIR")
184-
)
185-
cmd_build_ext.with_protoc = self.with_protoc or os.environ.get("PROTOC")
186-
cmd_build_ext.extra_compile_args = self.extra_compile_args or os.environ.get(
187-
"EXTRA_COMPILE_ARGS"
188-
)
189-
cmd_build_ext.extra_link_args = self.extra_link_args or os.environ.get(
190-
"EXTRA_LINK_ARGS"
191-
)
192-
cmd_build_ext.skip_vendor = self.skip_vendor or os.environ.get("SKIP_VENDOR")
196+
cmd_build_ext.with_mysql_capi = self.with_mysql_capi
197+
cmd_build_ext.with_openssl_include_dir = self.with_openssl_include_dir
198+
cmd_build_ext.with_openssl_lib_dir = self.with_openssl_lib_dir
199+
cmd_build_ext.with_protobuf_include_dir = self.with_protobuf_include_dir
200+
cmd_build_ext.with_protobuf_lib_dir = self.with_protobuf_lib_dir
201+
cmd_build_ext.with_protoc = self.with_protoc
202+
cmd_build_ext.extra_compile_args = self.extra_compile_args
203+
cmd_build_ext.extra_link_args = self.extra_link_args
204+
cmd_build_ext.skip_vendor = self.skip_vendor
205+
206+
install = self.distribution.get_command_obj("install")
207+
install.with_mysql_capi = self.with_mysql_capi
208+
install.with_openssl_include_dir = self.with_openssl_include_dir
209+
install.with_openssl_lib_dir = self.with_openssl_lib_dir
210+
install.with_protobuf_include_dir = self.with_protobuf_include_dir
211+
install.with_protobuf_lib_dir = self.with_protobuf_lib_dir
212+
install.with_protoc = self.with_protoc
213+
install.extra_compile_args = self.extra_compile_args
214+
install.extra_link_args = self.extra_link_args
215+
install.skip_vendor = self.skip_vendor
216+
193217
if not cmd_build_ext.skip_vendor:
194218
self._copy_vendor_libraries()
195219

@@ -202,35 +226,30 @@ def remove_temp(self):
202226
if os.path.exists(vendor_folder):
203227
remove_tree(vendor_folder)
204228
elif os.name == "nt":
205-
if ARCH == "64-bit":
206-
libraries = [
207-
"libmysql.dll",
208-
"libssl-1_1-x64.dll",
209-
"libcrypto-1_1-x64.dll",
210-
]
211-
else:
212-
libraries = [
213-
"libmysql.dll",
214-
"libssl-1_1.dll",
215-
"libcrypto-1_1.dll",
216-
]
229+
libssl, libcrypto = self._get_openssl_libs(ext="dll")
230+
libraries = ["libmysql.dll", libssl, libcrypto]
217231
for filename in libraries:
218232
dll_file = os.path.join(os.getcwd(), filename)
219233
if os.path.exists(dll_file):
220234
os.unlink(dll_file)
221235

222-
def _get_openssl_libs(self):
223-
libssl = glob(os.path.join(self.with_openssl_lib_dir, "libssl.*.*.*"))
224-
libcrypto = glob(os.path.join(self.with_openssl_lib_dir, "libcrypto.*.*.*"))
236+
def _get_openssl_libs(self, lib_dir=None, ext=None):
237+
if lib_dir is None:
238+
lib_dir = self.with_openssl_lib_dir
239+
libssl, libcrypto = get_openssl_libs(lib_dir, ext)
225240
if not libssl or not libcrypto:
226-
self.log.error(
227-
"Unable to find OpenSSL libraries in '%s'",
228-
self.with_openssl_lib_dir,
229-
)
241+
self.log.error("Unable to find OpenSSL libraries in '%s'", lib_dir)
230242
sys.exit(1)
231-
return (os.path.basename(libssl[0]), os.path.basename(libcrypto[0]))
243+
self.log.debug(
244+
"Found OpenSSL libraries '%s', '%s' in '%s'",
245+
libssl,
246+
libcrypto,
247+
lib_dir,
248+
)
249+
return (libssl, libcrypto)
232250

233251
def _copy_vendor_libraries(self):
252+
openssl_libs = []
234253
vendor_libs = []
235254

236255
if os.name == "posix":
@@ -284,14 +303,6 @@ def _copy_vendor_libraries(self):
284303
plugin_libs.append(lib_name)
285304
if plugin_libs:
286305
vendor_libs.append((libs_path, plugin_libs))
287-
288-
if ARCH_64BIT:
289-
openssl_libs = [
290-
"libssl-1_1-x64.dll",
291-
"libcrypto-1_1-x64.dll",
292-
]
293-
else:
294-
openssl_libs = ["libssl-1_1.dll", "libcrypto-1_1.dll"]
295306
if self.with_openssl_lib_dir:
296307
openssl_libs_path = os.path.abspath(self.with_openssl_lib_dir)
297308
if os.path.basename(openssl_libs_path) == "lib":
@@ -303,6 +314,8 @@ def _copy_vendor_libraries(self):
303314
self.log.info("# openssl_libs_path: %s", openssl_libs_path)
304315
else:
305316
openssl_libs_path = os.path.join(self.with_mysql_capi, "bin")
317+
libssl, libcrypto = self._get_openssl_libs(openssl_libs_path, "dll")
318+
openssl_libs = [libssl, libcrypto]
306319
vendor_libs.append((openssl_libs_path, openssl_libs))
307320

308321
if not vendor_libs:

cpydist/bdist_msi.py

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
ARCH_64BIT,
4848
add_arch_dep_elems,
4949
get_magic_tag,
50+
get_openssl_libs,
5051
write_info_bin,
5152
write_info_src,
5253
)
@@ -187,24 +188,25 @@ def _finalize_connector_c(self, connc_loc):
187188
copy_tree(os.path.join(connc_loc, "include"), self._connc_include)
188189

189190
self.log.info("# self.with_openssl_lib_dir: %s", self.with_openssl_lib_dir)
190-
if ARCH_64BIT:
191-
openssl_files = ["libssl-1_1-x64.dll", "libcrypto-1_1-x64.dll"]
191+
192+
if self.with_openssl_lib_dir:
193+
openssl_lib_dir = os.path.abspath(self.with_openssl_lib_dir)
194+
if os.path.basename(openssl_lib_dir) == "lib":
195+
openssl_dir, _ = os.path.split(openssl_lib_dir)
196+
if os.path.exists(os.path.join(openssl_dir, "bin")):
197+
openssl_lib_dir = os.path.join(openssl_dir, "bin")
192198
else:
193-
openssl_files = ["libssl-1_1.dll", "libcrypto-1_1.dll"]
194-
195-
for filename in openssl_files:
196-
if self.with_openssl_lib_dir:
197-
openssl_lib_dir = os.path.abspath(self.with_openssl_lib_dir)
198-
if os.path.basename(openssl_lib_dir) == "lib":
199-
openssl_lib_dir = os.path.split(openssl_lib_dir)[0]
200-
if os.path.exists(openssl_lib_dir) and os.path.exists(
201-
os.path.join(openssl_lib_dir, "bin")
202-
):
203-
openssl_lib_dir = os.path.join(openssl_lib_dir, "bin")
204-
self.log.info("# openssl_lib_dir: %s", openssl_lib_dir)
205-
src = os.path.join(openssl_lib_dir, filename)
206-
else:
207-
src = os.path.join(connc_loc, "bin", filename)
199+
openssl_lib_dir = os.path.join(connc_loc, "bin")
200+
201+
self.log.info("# openssl_lib_dir: %s", openssl_lib_dir)
202+
203+
libssl, libcrypto = get_openssl_libs(openssl_lib_dir, ext="dll")
204+
if not libssl or not libcrypto:
205+
self.log.error("Unable to find OpenSSL libraries in '%s'", openssl_lib_dir)
206+
sys.exit(1)
207+
208+
for filename in (libssl, libcrypto):
209+
src = os.path.join(openssl_lib_dir, filename)
208210
self.log.info("Using %s: located in %s", filename, src)
209211
dst = self._connc_lib
210212
self.log.info("copying {0} -> {1}".format(src, dst))
@@ -368,23 +370,16 @@ def _create_msi(self, dry_run=0):
368370
pyd_ext = ".pyd"
369371

370372
if self._connc_lib:
371-
if ARCH_64BIT:
372-
libcrypto_dll_path = os.path.join(
373-
os.path.abspath(self._connc_lib), "libcrypto-1_1-x64.dll"
374-
)
375-
libssl_dll_path = os.path.join(
376-
os.path.abspath(self._connc_lib), "libssl-1_1-x64.dll"
377-
)
378-
else:
379-
libcrypto_dll_path = os.path.join(
380-
os.path.abspath(self._connc_lib), "libcrypto-1_1.dll"
381-
)
382-
libssl_dll_path = os.path.join(
383-
os.path.abspath(self._connc_lib), "libssl-1_1.dll"
384-
)
373+
libssl, libcrypto = get_openssl_libs(self._connc_lib, ext="dll")
374+
libssl_dll_path = os.path.join(os.path.abspath(self._connc_lib), libssl)
375+
libcrypto_dll_path = os.path.join(
376+
os.path.abspath(self._connc_lib), libcrypto
377+
)
385378
else:
386-
libcrypto_dll_path = ""
387379
libssl_dll_path = ""
380+
libssl = ""
381+
libcrypto_dll_path = ""
382+
libcrypto = ""
388383

389384
# WiX preprocessor variables
390385
params = {
@@ -416,9 +411,12 @@ def _create_msi(self, dry_run=0):
416411
else "",
417412
"LIBcryptoDLL": libcrypto_dll_path,
418413
"LIBSSLDLL": libssl_dll_path,
414+
"LIBcrypto": libcrypto,
415+
"LIBSSL": libssl,
419416
"Win64": win64,
420417
"BitmapDir": os.path.join(os.getcwd(), "cpydist", "data", "msi"),
421418
}
419+
self.log.debug("Using WiX preprocessor variables: %s", repr(params))
422420
for py_ver in self._supported_versions:
423421
ver = py_ver.split(".")
424422
params["BDist{}{}".format(*ver)] = ""

cpydist/data/msi/PY310.wxs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333
<File Id="LibMySQLDLL310" Name="libmysql.dll"
3434
Source="$(var.LibMySQLDLL)" DiskId="1"/>
3535
<?if "$(var.Platform)"="x64" ?>
36-
<File Id="LIBcrypto310" Name="libcrypto-1_1-x64.dll"
36+
<File Id="LIBcrypto310" Name="$(var.LIBcrypto)"
3737
Source="$(var.LIBcryptoDLL)" DiskId="1"/>
38-
<File Id="LIBSSL310" Name="libssl-1_1-x64.dll"
38+
<File Id="LIBSSL310" Name="$(var.LIBSSL)"
3939
Source="$(var.LIBSSLDLL)" DiskId="1"/>
4040
<?else?>
41-
<File Id="LIBcrypto310" Name="libcrypto-1_1.dll"
41+
<File Id="LIBcrypto310" Name="$(var.LIBcrypto)"
4242
Source="$(var.LIBcryptoDLL)" DiskId="1"/>
43-
<File Id="LIBSSL310" Name="libssl-1_1.dll"
43+
<File Id="LIBSSL310" Name="$(var.LIBSSL)"
4444
Source="$(var.LIBSSLDLL)" DiskId="1"/>
4545
<?endif?>
4646
</Component>
@@ -138,15 +138,15 @@
138138
<?if $(var.HaveCExt310) = 1 ?>
139139
<Component Id="Vendor310" Guid="02156b38-6c13-44eb-bc59-53a5547cbad0" Win64="$(var.Win64)">
140140
<?if "$(var.Platform)"="x64" ?>
141-
<File Id="libcrypto_1_1310" Name="libcrypto-1_1-x64.dll"
142-
Source="$(var.BDist310)\mysql\vendor\libcrypto-1_1-x64.dll" DiskId="1"/>
143-
<File Id="libssl_1_1310" Name="libssl-1_1-x64.dll"
144-
Source="$(var.BDist310)\mysql\vendor\libssl-1_1-x64.dll" DiskId="1"/>
141+
<File Id="libcrypto_1_1310" Name="$(var.LIBcrypto)"
142+
Source="$(var.BDist310)\mysql\vendor\$(var.LIBcrypto)" DiskId="1"/>
143+
<File Id="libssl_1_1310" Name="$(var.LIBSSL)"
144+
Source="$(var.BDist310)\mysql\vendor\$(var.LIBSSL)" DiskId="1"/>
145145
<?else?>
146-
<File Id="libcrypto_1_1310" Name="libcrypto-1_1.dll"
147-
Source="$(var.BDist310)\mysql\vendor\libcrypto-1_1.dll" DiskId="1"/>
148-
<File Id="libssl_1_1310" Name="libssl-1_1.dll"
149-
Source="$(var.BDist310)\mysql\vendor\libssl-1_1.dll" DiskId="1"/>
146+
<File Id="libcrypto_1_1310" Name="$(var.LIBcrypto)"
147+
Source="$(var.BDist310)\mysql\vendor\$(var.LIBcrypto)" DiskId="1"/>
148+
<File Id="libssl_1_1310" Name="$(var.LIBSSL)"
149+
Source="$(var.BDist310)\mysql\vendor\$(var.LIBSSL)" DiskId="1"/>
150150
<?endif?>
151151
<?if $(var.HaveLdapLibs310) = 1 ?>
152152
<File Id="libsasl310" Name="libsasl.dll"

cpydist/data/msi/PY37.wxs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333
<File Id="LibMySQLDLL37" Name="libmysql.dll"
3434
Source="$(var.LibMySQLDLL)" DiskId="1"/>
3535
<?if "$(var.Platform)"="x64" ?>
36-
<File Id="LIBcrypto37" Name="libcrypto-1_1-x64.dll"
36+
<File Id="LIBcrypto37" Name="$(var.LIBcrypto)"
3737
Source="$(var.LIBcryptoDLL)" DiskId="1"/>
38-
<File Id="LIBSSL37" Name="libssl-1_1-x64.dll"
38+
<File Id="LIBSSL37" Name="$(var.LIBSSL)"
3939
Source="$(var.LIBSSLDLL)" DiskId="1"/>
4040
<?else?>
41-
<File Id="LIBcrypto37" Name="libcrypto-1_1.dll"
41+
<File Id="LIBcrypto37" Name="$(var.LIBcrypto)"
4242
Source="$(var.LIBcryptoDLL)" DiskId="1"/>
43-
<File Id="LIBSSL37" Name="libssl-1_1.dll"
43+
<File Id="LIBSSL37" Name="$(var.LIBSSL)"
4444
Source="$(var.LIBSSLDLL)" DiskId="1"/>
4545
<?endif?>
4646
</Component>
@@ -138,15 +138,15 @@
138138
<?if $(var.HaveCExt37) = 1 ?>
139139
<Component Id="Vendor37" Guid="103f2914-be39-11ea-98b1-04ea56793316" Win64="$(var.Win64)">
140140
<?if "$(var.Platform)"="x64" ?>
141-
<File Id="libcrypto_1_137" Name="libcrypto-1_1-x64.dll"
142-
Source="$(var.BDist37)\mysql\vendor\libcrypto-1_1-x64.dll" DiskId="1"/>
143-
<File Id="libssl_1_137" Name="libssl-1_1-x64.dll"
144-
Source="$(var.BDist37)\mysql\vendor\libssl-1_1-x64.dll" DiskId="1"/>
141+
<File Id="libcrypto_1_137" Name="$(var.LIBcrypto)"
142+
Source="$(var.BDist37)\mysql\vendor\$(var.LIBcrypto)" DiskId="1"/>
143+
<File Id="libssl_1_137" Name="$(var.LIBSSL)"
144+
Source="$(var.BDist37)\mysql\vendor\$(var.LIBSSL)" DiskId="1"/>
145145
<?else?>
146-
<File Id="libcrypto_1_137" Name="libcrypto-1_1.dll"
147-
Source="$(var.BDist37)\mysql\vendor\libcrypto-1_1.dll" DiskId="1"/>
148-
<File Id="libssl_1_137" Name="libssl-1_1.dll"
149-
Source="$(var.BDist37)\mysql\vendor\libssl-1_1.dll" DiskId="1"/>
146+
<File Id="libcrypto_1_137" Name="$(var.LIBcrypto)"
147+
Source="$(var.BDist37)\mysql\vendor\$(var.LIBcrypto)" DiskId="1"/>
148+
<File Id="libssl_1_137" Name="$(var.LIBSSL)"
149+
Source="$(var.BDist37)\mysql\vendor\$(var.LIBSSL)" DiskId="1"/>
150150
<?endif?>
151151
<?if $(var.HaveLdapLibs37) = 1 ?>
152152
<File Id="libsasl37" Name="libsasl.dll"

cpydist/data/msi/PY38.wxs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@
3333
<File Id="LibMySQLDLL38" Name="libmysql.dll"
3434
Source="$(var.LibMySQLDLL)" DiskId="1"/>
3535
<?if "$(var.Platform)"="x64" ?>
36-
<File Id="LIBcrypto38" Name="libcrypto-1_1-x64.dll"
36+
<File Id="LIBcrypto38" Name="$(var.LIBcrypto)"
3737
Source="$(var.LIBcryptoDLL)" DiskId="1"/>
38-
<File Id="LIBSSL38" Name="libssl-1_1-x64.dll"
38+
<File Id="LIBSSL38" Name="$(var.LIBSSL)"
3939
Source="$(var.LIBSSLDLL)" DiskId="1"/>
4040
<?else?>
41-
<File Id="LIBcrypto38" Name="libcrypto-1_1.dll"
41+
<File Id="LIBcrypto38" Name="$(var.LIBcrypto)"
4242
Source="$(var.LIBcryptoDLL)" DiskId="1"/>
43-
<File Id="LIBSSL38" Name="libssl-1_1.dll"
43+
<File Id="LIBSSL38" Name="$(var.LIBSSL)"
4444
Source="$(var.LIBSSLDLL)" DiskId="1"/>
4545
<?endif?>
4646
</Component>
@@ -138,15 +138,15 @@
138138
<?if $(var.HaveCExt38) = 1 ?>
139139
<Component Id="Vendor38" Guid="681a48cd-be38-11ea-84eb-04ea56793316" Win64="$(var.Win64)">
140140
<?if "$(var.Platform)"="x64" ?>
141-
<File Id="libcrypto_1_138" Name="libcrypto-1_1-x64.dll"
142-
Source="$(var.BDist38)\mysql\vendor\libcrypto-1_1-x64.dll" DiskId="1"/>
143-
<File Id="libssl_1_138" Name="libssl-1_1-x64.dll"
144-
Source="$(var.BDist38)\mysql\vendor\libssl-1_1-x64.dll" DiskId="1"/>
141+
<File Id="libcrypto_1_138" Name="$(var.LIBcrypto)"
142+
Source="$(var.BDist38)\mysql\vendor\$(var.LIBcrypto)" DiskId="1"/>
143+
<File Id="libssl_1_138" Name="$(var.LIBSSL)"
144+
Source="$(var.BDist38)\mysql\vendor\$(var.LIBSSL)" DiskId="1"/>
145145
<?else?>
146-
<File Id="libcrypto_1_138" Name="libcrypto-1_1.dll"
147-
Source="$(var.BDist38)\mysql\vendor\libcrypto-1_1.dll" DiskId="1"/>
148-
<File Id="libssl_1_138" Name="libssl-1_1.dll"
149-
Source="$(var.BDist38)\mysql\vendor\libssl-1_1.dll" DiskId="1"/>
146+
<File Id="libcrypto_1_138" Name="$(var.LIBcrypto)"
147+
Source="$(var.BDist38)\mysql\vendor\$(var.LIBcrypto)" DiskId="1"/>
148+
<File Id="libssl_1_138" Name="$(var.LIBSSL)"
149+
Source="$(var.BDist38)\mysql\vendor\$(var.LIBSSL)" DiskId="1"/>
150150
<?endif?>
151151
<?if $(var.HaveLdapLibs38) = 1 ?>
152152
<File Id="libsasl38" Name="libsasl.dll"

0 commit comments

Comments
 (0)