Skip to content

Commit

Permalink
Use the latest tcl/tk for 3.14
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Jan 14, 2025
1 parent d4eddc7 commit 5b3edf8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
27 changes: 23 additions & 4 deletions cpython-windows/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ def hack_props(
td: pathlib.Path,
pcbuild_path: pathlib.Path,
arch: str,
python_version: str,
):
# TODO can we pass props into msbuild.exe?

Expand All @@ -355,9 +356,14 @@ def hack_props(
sqlite_version = DOWNLOADS["sqlite"]["version"]
xz_version = DOWNLOADS["xz"]["version"]
zlib_version = DOWNLOADS["zlib"]["version"]
tcltk_commit = DOWNLOADS["tk-windows-bin-8612"]["git_commit"]

mpdecimal_version = DOWNLOADS["mpdecimal"]["version"]

if meets_python_minimum_version(python_version, "3.14"):
tcltk_commit = DOWNLOADS["tk-windows-bin"]["git_commit"]
else:
tcltk_commit = DOWNLOADS["tk-windows-bin-8612"]["git_commit"]

sqlite_path = td / ("sqlite-autoconf-%s" % sqlite_version)
bzip2_path = td / ("bzip2-%s" % bzip2_version)
libffi_path = td / "libffi"
Expand Down Expand Up @@ -487,6 +493,7 @@ def hack_project_files(
td,
pcbuild_path,
build_directory,
python_version,
)

# Our SQLite directory is named weirdly. This throws off version detection
Expand Down Expand Up @@ -1128,6 +1135,10 @@ def find_additional_dependencies(project: pathlib.Path):
if name == "openssl":
name = openssl_entry

# On 3.14+, we use the latest tcl/tk version
if ext == "_tkinter" and python_majmin == "314":
name = name.replace("-8612", "")

download_entry = DOWNLOADS[name]

# This will raise if no license metadata defined. This is
Expand Down Expand Up @@ -1197,9 +1208,6 @@ def build_cpython(

bzip2_archive = download_entry("bzip2", BUILD)
sqlite_archive = download_entry("sqlite", BUILD)
tk_bin_archive = download_entry(
"tk-windows-bin-8612", BUILD, local_name="tk-windows-bin.tar.gz"
)
xz_archive = download_entry("xz", BUILD)
zlib_archive = download_entry("zlib", BUILD)

Expand All @@ -1211,6 +1219,17 @@ def build_cpython(
setuptools_wheel = download_entry("setuptools", BUILD)
pip_wheel = download_entry("pip", BUILD)

# On CPython 3.14+, we use the latest tcl/tk version which has additional runtime
# dependencies, so we are conservative and use the old version elsewhere.
if meets_python_minimum_version(python_version, "3.14"):
tk_bin_archive = download_entry(
"tk-windows-bin", BUILD, local_name="tk-windows-bin.tar.gz"
)
else:
tk_bin_archive = download_entry(
"tk-windows-bin-8612", BUILD, local_name="tk-windows-bin.tar.gz"
)

# CPython 3.13+ no longer uses a bundled `mpdecimal` version so we build it
if meets_python_minimum_version(python_version, "3.13"):
mpdecimal_archive = download_entry("mpdecimal", BUILD)
Expand Down
20 changes: 18 additions & 2 deletions src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ const PE_ALLOWED_LIBRARIES: &[&str] = &[
"tk86t.dll",
];

// CPython 3.14 uses tcl/tk 8.6.14+ which includes a bundled zlib and dynamically links to msvcrt.
const PE_ALLOWED_LIBRARIES_314: &[&str] = &["msvcrt.dll", "zlib1.dll"];

static GLIBC_MAX_VERSION_BY_TRIPLE: Lazy<HashMap<&'static str, version_compare::Version<'static>>> =
Lazy::new(|| {
let mut versions = HashMap::new();
Expand Down Expand Up @@ -1331,6 +1334,7 @@ fn validate_macho<Mach: MachHeader<Endian = Endianness>>(

fn validate_pe<'data, Pe: ImageNtHeaders>(
context: &mut ValidationContext,
python_major_minor: &str,
path: &Path,
pe: &PeFile<'data, Pe, &'data [u8]>,
) -> Result<()> {
Expand All @@ -1346,6 +1350,18 @@ fn validate_pe<'data, Pe: ImageNtHeaders>(
let lib = import_table.name(descriptor.name.get(object::LittleEndian))?;
let lib = String::from_utf8(lib.to_vec())?;

match python_major_minor {
"3.9" | "3.10" | "3.11" | "3.12" | "3.13" => {}
"3.14" => {
if PE_ALLOWED_LIBRARIES_314.contains(&lib.as_str()) {
continue;
}
}
_ => {
panic!("unhandled Python version: {}", python_major_minor);
}
}

if !PE_ALLOWED_LIBRARIES.contains(&lib.as_str()) {
context
.errors
Expand Down Expand Up @@ -1451,11 +1467,11 @@ fn validate_possible_object_file(
}
FileKind::Pe32 => {
let file = PeFile32::parse(data)?;
validate_pe(&mut context, path, &file)?;
validate_pe(&mut context, python_major_minor, path, &file)?;
}
FileKind::Pe64 => {
let file = PeFile64::parse(data)?;
validate_pe(&mut context, path, &file)?;
validate_pe(&mut context, python_major_minor, path, &file)?;
}
_ => {}
}
Expand Down

0 comments on commit 5b3edf8

Please sign in to comment.