Skip to content

Commit 766fca9

Browse files
committed
windows: statically link CRT in static builds
By simply switch from /MD to /MT, we can statically link the MS CRT and avoid the run-time requirement on vcruntimeXXX.dll. Closes #37.
1 parent 102fb0d commit 766fca9

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

cpython-windows/build.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,19 @@ def hack_project_files(
889889
pcbuild_proj, b'<Projects2 Include="_freeze_importlib.vcxproj" />', b""
890890
)
891891

892+
# Switch to the static version of the run-time library.
893+
if static:
894+
static_replace_in_file(
895+
pcbuild_path / "pyproject.props",
896+
b"<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>",
897+
b"<RuntimeLibrary>MultiThreaded</RuntimeLibrary>",
898+
)
899+
static_replace_in_file(
900+
pcbuild_path / "pyproject.props",
901+
b"<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>",
902+
b"<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>",
903+
)
904+
892905

893906
PYPORT_EXPORT_SEARCH_NEW = b"""
894907
#if defined(__CYGWIN__)
@@ -1225,6 +1238,9 @@ def build_openssl_for_arch(
12251238
{**env, "CFLAGS": env.get("CFLAGS", "") + " /FS",},
12261239
)
12271240

1241+
if "static" in profile:
1242+
static_replace_in_file(source_root / "Makefile", b"/MD", b"/MT")
1243+
12281244
# exec_and_log(["nmake"], source_root, env)
12291245
exec_and_log(
12301246
[str(jom_path / "jom"), "/J", str(multiprocessing.cpu_count())],
@@ -1965,8 +1981,10 @@ def build_cpython(
19651981
# __declspec(dllexport), even for static distributions.
19661982
python_symbol_visibility = "dllexport"
19671983

1968-
# We currently always link vcruntime140.dll.
1969-
crt_features = ["vcruntime:140"]
1984+
if static:
1985+
crt_features = ["static"]
1986+
else:
1987+
crt_features = ["vcruntime:140"]
19701988

19711989
if "pgo" in profile:
19721990
optimizations = "pgo"

0 commit comments

Comments
 (0)