Skip to content

Commit 81d1130

Browse files
committed
windows: build tkinter in shared builds
Building the _tkinter extension module is much, much simpler in shared builds. This commit teaches the build to build this extension as well as install its resource files when performing a more traditional shared library build. As part of this, we needed to teach license mapping to map multiple downloads to incorporate licenses.
1 parent c086a9d commit 81d1130

File tree

1 file changed

+58
-20
lines changed

1 file changed

+58
-20
lines changed

cpython-windows/build.py

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"shared_depends_win32": ["libcrypto-1_1", "libssl-1_1"],
6767
"static_depends_no_project": ["libcrypto_static", "libssl_static"],
6868
},
69+
"_tkinter": {"ignore_static": True, "shared_depends": ["tcl86t", "tk86t"],},
6970
"_queue": {},
7071
"pyexpat": {},
7172
"select": {},
@@ -85,14 +86,15 @@
8586

8687
# Used to annotate licenses.
8788
EXTENSION_TO_LIBRARY_DOWNLOADS_ENTRY = {
88-
"_bz2": "bzip2",
89-
"_ctypes": "libffi",
90-
"_hashlib": "openssl",
91-
"_lzma": "xz",
92-
"_sqlite3": "sqlite",
93-
"_ssl": "openssl",
94-
"_uuid": "uuid",
95-
"zlib": "zlib",
89+
"_bz2": ["bzip2"],
90+
"_ctypes": ["libffi"],
91+
"_hashlib": ["openssl"],
92+
"_lzma": ["xz"],
93+
"_sqlite3": ["sqlite"],
94+
"_ssl": ["openssl"],
95+
"_tkinter": ["tcl", "tk", "tix"],
96+
"_uuid": ["uuid"],
97+
"zlib": ["zlib"],
9698
}
9799

98100

@@ -780,6 +782,10 @@ def hack_project_files(
780782

781783
if static:
782784
for extension, entry in sorted(CONVERT_TO_BUILTIN_EXTENSIONS.items()):
785+
if entry.get("ignore_static"):
786+
log("ignoring extension %s in static builds" % extension)
787+
continue
788+
783789
init_fn = entry.get("init", "PyInit_%s" % extension)
784790

785791
add_to_config_c(cpython_source_path, extension, init_fn)
@@ -1051,7 +1057,11 @@ def hack_source_files(source_path: pathlib.Path, static: bool):
10511057

10521058

10531059
def run_msbuild(
1054-
msbuild: pathlib.Path, pcbuild_path: pathlib.Path, configuration: str, platform: str
1060+
msbuild: pathlib.Path,
1061+
pcbuild_path: pathlib.Path,
1062+
configuration: str,
1063+
platform: str,
1064+
static: bool,
10551065
):
10561066
python_version = DOWNLOADS["cpython-3.7"]["version"]
10571067

@@ -1066,8 +1076,8 @@ def run_msbuild(
10661076
"/verbosity:normal",
10671077
"/property:IncludeExternals=true",
10681078
"/property:IncludeSSL=true",
1069-
# TODO support Tkinter
1070-
"/property:IncludeTkinter=false",
1079+
# TODO support tkinter in static builds.
1080+
"/property:IncludeTkinter=%s" % ("false" if static else "true"),
10711081
# TODO compile test extensions so we can get PGO benefits of tested code.
10721082
"/property:IncludeTests=false",
10731083
"/property:OverrideVersion=%s" % python_version,
@@ -1236,6 +1246,9 @@ def collect_python_build_artifacts(
12361246
extension_projects = set()
12371247

12381248
for extension, entry in CONVERT_TO_BUILTIN_EXTENSIONS.items():
1249+
if static and entry.get("ignore_static"):
1250+
continue
1251+
12391252
extension_projects.add(extension)
12401253
if static:
12411254
depends_projects |= set(entry.get("static_depends", []))
@@ -1388,14 +1401,23 @@ def find_additional_dependencies(project: pathlib.Path):
13881401
)
13891402

13901403
if ext in EXTENSION_TO_LIBRARY_DOWNLOADS_ENTRY:
1391-
download_entry = DOWNLOADS[EXTENSION_TO_LIBRARY_DOWNLOADS_ENTRY[ext]]
1404+
licenses = set()
1405+
license_paths = set()
1406+
license_public_domain = False
13921407

1393-
# This will raise if no license metadata defined. This is
1394-
# intentional because EXTENSION_TO_LIBRARY_DOWNLOADS_ENTRY is
1395-
# manually curated and we want to fail fast.
1396-
entry["licenses"] = download_entry["licenses"]
1397-
entry["license_paths"] = ["licenses/%s" % download_entry["license_file"]]
1398-
entry["license_public_domain"] = download_entry.get("license_public_domain")
1408+
for name in EXTENSION_TO_LIBRARY_DOWNLOADS_ENTRY[ext]:
1409+
download_entry = DOWNLOADS[name]
1410+
1411+
# This will raise if no license metadata defined. This is
1412+
# intentional because EXTENSION_TO_LIBRARY_DOWNLOADS_ENTRY is
1413+
# manually curated and we want to fail fast.
1414+
licenses |= set(download_entry["licenses"])
1415+
license_paths.add("licenses/%s" % download_entry["license_file"])
1416+
license_public_domain = download_entry.get("license_public_domain")
1417+
1418+
entry["licenses"] = list(sorted(licenses))
1419+
entry["license_paths"] = list(sorted(license_paths))
1420+
entry["license_public_domain"] = license_public_domain
13991421

14001422
res["extensions"][ext] = [entry]
14011423

@@ -1543,6 +1565,7 @@ def build_cpython(arch: str, pgo=False, build_mode="static"):
15431565
pcbuild_path,
15441566
configuration="PGInstrument",
15451567
platform=build_platform,
1568+
static=static,
15461569
)
15471570

15481571
# build-windows.py sets some environment variables which cause the
@@ -1600,13 +1623,21 @@ def build_cpython(arch: str, pgo=False, build_mode="static"):
16001623
)
16011624

16021625
run_msbuild(
1603-
msbuild, pcbuild_path, configuration="PGUpdate", platform=build_platform
1626+
msbuild,
1627+
pcbuild_path,
1628+
configuration="PGUpdate",
1629+
platform=build_platform,
1630+
static=static,
16041631
)
16051632
artifact_config = "PGUpdate"
16061633

16071634
else:
16081635
run_msbuild(
1609-
msbuild, pcbuild_path, configuration="Release", platform=build_platform
1636+
msbuild,
1637+
pcbuild_path,
1638+
configuration="Release",
1639+
platform=build_platform,
1640+
static=static,
16101641
)
16111642
artifact_config = "Release"
16121643

@@ -1639,6 +1670,10 @@ def build_cpython(arch: str, pgo=False, build_mode="static"):
16391670

16401671
if static:
16411672
args.append("--flat-dlls")
1673+
else:
1674+
args.extend(
1675+
["--include-idle", "--include-tcltk",]
1676+
)
16421677

16431678
exec_and_log(
16441679
args, pcbuild_path, os.environ,
@@ -1721,6 +1756,9 @@ def build_cpython(arch: str, pgo=False, build_mode="static"):
17211756
"license_path": "licenses/LICENSE.cpython.txt",
17221757
}
17231758

1759+
if not static:
1760+
python_info["tcl_library_path"] = "install/tcl"
1761+
17241762
with (out_dir / "python" / "PYTHON.json").open("w", encoding="utf8") as fh:
17251763
json.dump(python_info, fh, sort_keys=True, indent=4)
17261764

0 commit comments

Comments
 (0)