Skip to content

Commit 0c1e828

Browse files
committed
windows: patch OpenSSL uplink.c in shared builds
The CPython build system does this. This is needed to ensure things still work in shared builds.
1 parent a06e509 commit 0c1e828

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

cpython-windows/build.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,12 @@ def run_msbuild(
10981098

10991099

11001100
def build_openssl_for_arch(
1101-
perl_path, arch: str, openssl_archive, nasm_archive, build_root: pathlib.Path
1101+
perl_path,
1102+
arch: str,
1103+
openssl_archive,
1104+
nasm_archive,
1105+
build_root: pathlib.Path,
1106+
profile: str,
11021107
):
11031108
openssl_version = DOWNLOADS["openssl"]["version"]
11041109
nasm_version = DOWNLOADS["nasm-windows-bin"]["version"]
@@ -1116,6 +1121,16 @@ def build_openssl_for_arch(
11161121

11171122
source_root = build_root / ("openssl-%s" % openssl_version)
11181123

1124+
# uplink.c tries to find the OPENSSL_Applink function exported from the current
1125+
# executable. However, it is exported from _ssl[_d].pyd in shared builds. So
1126+
# update its sounce to look for it from there.
1127+
if "shared" in profile:
1128+
static_replace_in_file(
1129+
source_root / "ms" / "uplink.c",
1130+
b"((h = GetModuleHandle(NULL)) == NULL)",
1131+
b'((h = GetModuleHandleA("_ssl.pyd")) == NULL) if ((h = GetModuleHandleA("_ssl_d.pyd")) == NULL) if ((h = GetModuleHandle(NULL)) == NULL)',
1132+
)
1133+
11191134
if arch == "x86":
11201135
configure = "VC-WIN32"
11211136
prefix = "32"
@@ -1164,7 +1179,7 @@ def build_openssl_for_arch(
11641179
shutil.copyfile(source, dest)
11651180

11661181

1167-
def build_openssl(perl_path: pathlib.Path, arch: str):
1182+
def build_openssl(perl_path: pathlib.Path, arch: str, profile: str):
11681183
"""Build OpenSSL from sources using the Perl executable specified."""
11691184

11701185
# First ensure the dependencies are in place.
@@ -1180,12 +1195,12 @@ def build_openssl(perl_path: pathlib.Path, arch: str):
11801195
if arch == "x86":
11811196
root_32.mkdir()
11821197
build_openssl_for_arch(
1183-
perl_path, "x86", openssl_archive, nasm_archive, root_32
1198+
perl_path, "x86", openssl_archive, nasm_archive, root_32, profile
11841199
)
11851200
elif arch == "amd64":
11861201
root_64.mkdir()
11871202
build_openssl_for_arch(
1188-
perl_path, "amd64", openssl_archive, nasm_archive, root_64
1203+
perl_path, "amd64", openssl_archive, nasm_archive, root_64, profile
11891204
)
11901205
else:
11911206
raise ValueError("unhandled arch: %s" % arch)
@@ -1197,7 +1212,7 @@ def build_openssl(perl_path: pathlib.Path, arch: str):
11971212
else:
11981213
shutil.copytree(root_64 / "install" / "64", install / "openssl" / "amd64")
11991214

1200-
dest_archive = BUILD / ("openssl-windows-%s.tar" % arch)
1215+
dest_archive = BUILD / ("openssl-windows-%s-%s.tar" % (arch, profile))
12011216
with dest_archive.open("wb") as fh:
12021217
create_tar_from_directory(fh, install)
12031218

@@ -1596,9 +1611,7 @@ def build_cpython(arch: str, profile):
15961611
for test in sorted(tests):
15971612
# test_regrtest hangs for some reason. It is the test for the
15981613
# test harness itself and isn't exercising useful code. Skip it.
1599-
#
1600-
# test_ssl also seems to hang.
1601-
if test in ("test_regrtest", "test_ssl"):
1614+
if test == "test_regrtest":
16021615
continue
16031616

16041617
exec_and_log(
@@ -1804,11 +1817,11 @@ def main():
18041817
arch = "x86" if os.environ.get("Platform") == "x86" else "amd64"
18051818

18061819
# TODO need better dependency checking.
1807-
openssl_out = BUILD / ("openssl-windows-%s.tar" % arch)
1820+
openssl_out = BUILD / ("openssl-windows-%s-%s.tar" % (arch, args.profile))
18081821
if not openssl_out.exists():
18091822
perl_path = fetch_strawberry_perl() / "perl" / "bin" / "perl.exe"
18101823
LOG_PREFIX[0] = "openssl"
1811-
build_openssl(perl_path, arch)
1824+
build_openssl(perl_path, arch, profile=args.profile)
18121825

18131826
LOG_PREFIX[0] = "cpython"
18141827
tar_path = build_cpython(arch, profile=args.profile)

0 commit comments

Comments
 (0)