diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 06ed811..eb2c615 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,7 +19,7 @@ jobs: with: python-version: "3.14" - - uses: astral-sh/setup-uv@v10.3.0 + - uses: astral-sh/setup-uv@v10.4.2 - run: uvx --with tox-uv tox -e py,style,ty,pyrefly,pyright,mypy,zuban - run: uv build - name: Publish to PyPI diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b53fce0..e800572 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -26,7 +26,7 @@ jobs: with: python-version: ${{ matrix.python-version }} - - uses: astral-sh/setup-uv@v10.3.0 + - uses: astral-sh/setup-uv@v10.4.2 - run: uvx --with tox-uv tox -e py - uses: coverallsapp/github-action@v2 @@ -55,5 +55,5 @@ jobs: with: python-version: "3.14" - - uses: astral-sh/setup-uv@v10.3.0 + - uses: astral-sh/setup-uv@v10.4.2 - run: uvx --with tox-uv tox -e style,ty,pyrefly,pyright,mypy,zuban diff --git a/CHANGELOG.md b/CHANGELOG.md index dfa1694..d3f8f3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,31 @@ # Changelog +## v2.2.0 + +### Fixed + +- `sysconfig` refers to the C++ compiler by name (`CXX`, `LDCXXSHARED`), as it does for the C compiler, instead of by the build host path where `./configure` found it. Since python 3.14.6, that path could be a build-host-only wrapper such as `/usr/lib/ccache/g++`, making C++ extension builds fail on hosts without it. A compiler wrapper (`ccache`, `sccache`, `distcc`) explicitly configured into `sysconfig` is reported with a warning. + +### Bundled components + +| Component | Version | Why | +|-----------|---------|-----| +| OpenSSL | 3.5.9 → 3.5.10 | Security patch release, staying on the 3.5 LTS line | +| libffi | 3.8.0 → 3.8.2 | Patch releases with security fixes | +| xz | 5.8.4 → 5.8.5 | Security fixes | +| SQLite | 3.53.4 → 3.54.1 | New line, now past its `.0` | +| zlib | 1.3.2 → 1.4 | Several CVE fixes, breaking changes affect CMake/MSVC/Cygwin builds only | +| zstd | 1.5.7 → 1.6.0 | CVE fix release, "highly recommended" upstream | + +These match [python-build-standalone](https://github.com/astral-sh/python-build-standalone)'s current choices, including the move to the zlib 1.4 and zstd 1.6.0 lines, except xz (5.8.5 is a security release newer than theirs). +Every other component was re-checked against upstream: already current, or deliberately held back (see the `version` property comments). + +### Changed + +- Library use: `ModuleBuilder.version` is now always a `Version` (external modules used to report a `str`) + +_Also: refreshed the dependency lock, bumped `astral-sh/setup-uv` in CI._ + ## v2.1.0 - portable-python's code is now checked by multiple type checkers on every change diff --git a/docs/architecture/cpython.md b/docs/architecture/cpython.md index 6d642bd..b0a8610 100644 --- a/docs/architecture/cpython.md +++ b/docs/architecture/cpython.md @@ -3,7 +3,7 @@ type: Class title: Cpython description: The concrete PythonBuilder that compiles CPython — configure/make/install, optimization flags, and the finalize step that makes the install relocatable. tags: [class, cpython, build, finalize] -timestamp: 2026-06-23T00:00:00Z +timestamp: 2026-12-03T00:00:00Z --- # Cpython @@ -14,6 +14,11 @@ The concrete [`PythonBuilder`](/architecture/python-builder.md) that compiles CP CPython is configured purely through flags — never source patches (the [no-patches principle](/overview.md)). Defaults come from `cpython-configure` in [config](/configuration/portable-python-yml.md) (optimizations, LTO, ensurepip), plus computed flags that point the build at the statically-compiled [deps](/concepts/static-linking.md). +Right after `./configure`, the compiler commands it recorded in the generated `Makefile` (which become `sysconfig`'s `CC`, `CXX`, `LDSHARED`, `LDCXXSHARED`, used to build extensions on the user's machine) are groomed: + +- `./configure` looks up the C++ compiler on `PATH`, so a missing one is noticed at configure time, and records it by the absolute path where it found it. That path is specific to the build host: for example `/usr/lib/ccache/g++` when a compiler cache masquerade folder is first on `PATH`. A portable python builds extensions on other hosts, so `CXX` refers to the compiler by name instead (as `CC` does), to be found on that host's `PATH`. The build is unchanged: on the build host, that name resolves to the same path, ccache included. A `CXX` set by the user is left alone. +- A compiler wrapper (`ccache`, `sccache`, `distcc`) that still ends up in `sysconfig`, for example via an explicit `CC="ccache gcc"`, is reported with a warning. + ## Finalize — making it relocatable After `make install`, a portable build's interpreter still thinks it lives at the placeholder [`/ppp-marker/{version}`](/concepts/ppp-marker.md). Finalizing turns it into a [portable](/concepts/portability.md) install: diff --git a/docs/log.md b/docs/log.md index c76aaa1..86e5a7e 100644 --- a/docs/log.md +++ b/docs/log.md @@ -1,5 +1,9 @@ # Knowledge Bundle Update Log +## 2026-12-03 + +* **Update**: [Cpython](/architecture/cpython.md): `sysconfig` refers to the C++ compiler by name rather than by its build host path, and compiler wrappers recorded in `sysconfig` are reported with a warning. + ## 2026-10-09 * **Update**: [Configuration](/configuration/portable-python-yml.md): `{module}-configure` substitutes `$lib_dir` and `$lib64_dir` (not `$deps_lib`), and its value is split into separate args. diff --git a/requirements.txt b/requirements.txt index a5abbb0..f4997d8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,22 +1,24 @@ # This file was autogenerated by uv via the following command: # uv pip compile pyproject.toml --universal -o requirements.txt --python-version 3.10 --group dev -certifi==2026.10.19 +certifi==2026.11.20 # via requests -charset-normalizer==3.5.2 +charset-normalizer==3.5.3 # via requests -click==8.5.0 +click==8.5.1 # via portable-python (pyproject.toml) colorama==0.4.6 ; sys_platform == 'win32' # via pytest -coverage==7.16.2 +coverage==7.16.2 ; python_full_version < '3.11' # via pytest-cov -exceptiongroup==1.3.1 ; python_full_version < '3.11' +coverage==7.18.0 ; python_full_version >= '3.11' + # via pytest-cov +exceptiongroup==1.3.2 ; python_full_version < '3.11' # via pytest idna==3.20 # via requests iniconfig==2.3.1 # via pytest -packaging==26.3 +packaging==26.4 # via pytest pluggy==1.7.0 # via @@ -24,17 +26,17 @@ pluggy==1.7.0 # pytest-cov pygments==2.21.0 # via pytest -pytest==9.1.1 +pytest==9.2.0 # via pytest-cov pytest-cov==7.1.0 # via portable-python (pyproject.toml:dev) -pyyaml==6.0.3 +pyyaml==6.0.4 # via portable-python (pyproject.toml) requests==2.34.2 # via portable-python (pyproject.toml) -runez==5.11.1 +runez==5.11.3 # via portable-python (pyproject.toml) -tomli==2.5.0 ; python_full_version <= '3.11' +tomli==2.5.0 ; python_full_version < '3.11' # via # coverage # pytest diff --git a/src/portable_python/__init__.py b/src/portable_python/__init__.py index 7d328ec..ef8ee3c 100644 --- a/src/portable_python/__init__.py +++ b/src/portable_python/__init__.py @@ -21,7 +21,7 @@ import runez from runez.http import RestClient -from runez.pyenv import PythonSpec +from runez.pyenv import PythonSpec, Version from runez.render import Header, PrettyTable from portable_python.versions import PPG @@ -506,8 +506,9 @@ def is_usable_module(self, name): """Is module with name either selected or usable as a shared lib, as determined via its telltale""" return self.modules.is_usable_module(name) - def cfg_version(self, default): - return PPG.config.get_value("%s-version" % self.m_name) or default + def cfg_version(self, default: str) -> Version: + # str(): a version in yaml config may have been parsed as a float (eg: `gdbm-version: 1.26`) + return Version(str(PPG.config.get_value("%s-version" % self.m_name) or default)) def cfg_http_headers(self): if config_http_headers := PPG.config.get_value("%s-http-headers" % self.m_name): @@ -554,9 +555,12 @@ def src_suffix(self): return self.cfg_src_suffix() @property - def version(self): - """Version to use""" - return self.parent_module and self.parent_module.version + def version(self) -> Version: + """Version to use, sub-modules (such as tcl/tk/tix) share the version of their parent module by default""" + if self.parent_module is None: + return self.setup.python_spec.version # Top of the module tree: the python being built + + return self.parent_module.version @property def deps(self): @@ -822,10 +826,6 @@ def bin_python(self) -> pathlib.Path: return self._bin_python - @property - def version(self): - return self.setup.python_spec.version - def xenv_LDFLAGS(self): """Python builder does not reuse the common setting""" yield from () diff --git a/src/portable_python/cpython.py b/src/portable_python/cpython.py index 3bfad4d..4d0d00c 100644 --- a/src/portable_python/cpython.py +++ b/src/portable_python/cpython.py @@ -2,10 +2,10 @@ import datetime import os import re +import shutil import runez import yaml -from runez.pyenv import Version from portable_python import LOG, patch_file, patch_folder, PPG, PythonBuilder from portable_python.external.xcpython import Bdb, Bzip2, Gdbm, LibFFI, Mpdec, Openssl, Readline, Sqlite, Uuid, Xz, Zlib, Zstd @@ -20,6 +20,11 @@ test_struct test_threading test_time test_traceback test_unicode """ +# Compiler commands that ./configure records in the Makefile end up in sysconfig, and are used to build C/C++ extensions +RX_MAKEFILE_COMPILER = re.compile(r"^(CC|CXX|LDSHARED|LDCXXSHARED)=[ \t]*(.*?)[ \t]*$", flags=re.MULTILINE) +# Compiler wrappers that may exist on the build host only, recording them in sysconfig is worth a warning +RX_COMPILER_WRAPPER = re.compile(r"\b(ccache|sccache|distcc)\b") + def represented_yaml(key_value_pairs): """ @@ -164,7 +169,7 @@ def c_configure_args(self): tkinter = self.active_module(TkInter) if tkinter: # TODO: this doesn't seem to be enough, on macos cpython's ./configure still picks up the shared macos tcl/tk libs - version = Version(tkinter.version) + version = tkinter.version yield f"--with-tcltk-includes=-I{self.deps}/include" lib_dir_flags = " ".join(f"-L{lib_dir}" for lib_dir in self.deps_lib_dirs) @@ -246,6 +251,7 @@ def _prepare(self): def _do_linux_compile(self): self.run_configure("./configure", self.c_configure_args(), prefix=self.c_configure_prefix) + self.groom_makefile_compilers() make_args = [] if self.version < "3.8": pgo_tests = runez.joined(runez.flattened(PGO_TESTS, split=True)) @@ -255,6 +261,48 @@ def _do_linux_compile(self): # Don't parallelize `make install`, see https://github.com/python/cpython/issues/109796 self.run_make("install", f"DESTDIR={self.destdir}") + def groom_makefile_compilers(self): + """ + Keep the compiler commands that end up in sysconfig usable on hosts other than the build host. + + ./configure looks up the C++ compiler on PATH (so that a missing one is noticed at configure time), + and records it by the absolute path where it found it, a path that is specific to the build host. + For example `/usr/lib/ccache/g++`, when a compiler cache masquerade folder is first on PATH. + A portable python builds extensions on other hosts: refer to the compiler by name (as for the C compiler), + to be found on that host's PATH. The build is unchanged: on the build host, that name resolves to the same path. + A `CXX` explicitly provided by the user is left alone. + """ + makefile = "Makefile" + if not os.path.exists(makefile): + return # Not configured (dryrun mode) + + with open(makefile) as fh: + compilers = dict(RX_MAKEFILE_COMPILER.findall(fh.read())) + + cxx = compilers.get("CXX") + if cxx and not self._is_cxx_preset(): + program, _, flags = cxx.partition(" ") + bare_name = os.path.basename(program) + if program != bare_name and shutil.which(bare_name) == program: + # Makefile.pre first: Makefile is generated from it, and must not end up older than it + for path in ("Makefile.pre", makefile): + patch_file(path, rf"^(CXX=[ \t]*){re.escape(program)}(?=[ \t]|$)", rf"\g<1>{bare_name}") + + compilers["CXX"] = runez.joined(bare_name, flags) + + for name, command in sorted(compilers.items()): + if RX_COMPILER_WRAPPER.search(command): + LOG.warning( + "sysconfig will record compiler wrapper '%s=%s', extensions won't build on hosts without it" + " (a wrapper masquerade folder on PATH applies to the build only)", + name, + command, + ) + + def _is_cxx_preset(self): + """Did the user explicitly provide which C++ compiler to use? (via env var, or `CXX=` in `cpython-configure`)""" + return bool(os.environ.get("CXX")) or any(x.startswith("CXX=") for x in self.c_configure_args_from_config) + def _finalize(self): is_shared = self.setup.prefix or self.has_configure_opt("--enable-shared", "yes") if is_shared: diff --git a/src/portable_python/external/xcpython.py b/src/portable_python/external/xcpython.py index 56f9182..41941e0 100644 --- a/src/portable_python/external/xcpython.py +++ b/src/portable_python/external/xcpython.py @@ -136,8 +136,9 @@ def url(self): @property def version(self): # python-build-standalone moved from 3.4.8 straight to 3.8.0 in Oct 2026 (their PR #1302), follow their lead + # 3.8.x patch releases carry security fixes (3.8.2: GHSA advisories), keep current within the line # Check https://github.com/libffi/libffi/releases - return self.cfg_version("3.8.0") + return self.cfg_version("3.8.2") def c_configure_args(self): if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir): @@ -170,9 +171,9 @@ def auto_select_reason(self): @property def url(self): - if self.version and self.version.startswith("1.1.1"): + if self.version.text.startswith("1.1.1"): # Not sure why URL suddenly changed for this on github... - vfolder = self.version.replace(".", "_") + vfolder = self.version.text.replace(".", "_") return ( self.cfg_url(self.version) or f"https://github.com/openssl/openssl/releases/download/OpenSSL_{vfolder}/openssl-{self.version}.tar.gz" @@ -186,7 +187,7 @@ def version(self): # Stay on the 3.5 LTS line: 3.6.x and 4.0.x have shipped but are not verified for cpython builds # (python-build-standalone pins 3.5.x as well) # Check https://github.com/openssl/openssl/releases and https://endoflife.date/openssl - return self.cfg_version("3.5.9") + return self.cfg_version("3.5.10") def c_configure_args(self): if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir): @@ -320,9 +321,10 @@ def url(self): @property def version(self): - # 3.53.x gets frequent fix-only releases, keep current within the line + # Fix-only releases are frequent within a line, keep current; move to a new line once its .1 is out + # (3.54.1, also used by python-build-standalone) # Check https://sqlite.org/changes.html (avoid withdrawn releases like 3.52.0) - return self.cfg_version("3.53.4") + return self.cfg_version("3.54.1") def c_configure_args(self): if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir): @@ -389,8 +391,9 @@ def url(self): @property def version(self): + # 5.8.x patch releases carry security fixes (5.8.5), keep current within the line # Check https://github.com/tukaani-project/xz/releases - return self.cfg_version("5.8.4") + return self.cfg_version("5.8.5") def c_configure_args(self): if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir): @@ -433,8 +436,10 @@ def url(self): @property def version(self): + # 1.4 fixes several CVEs, its breaking changes are CMake/MSVC/Cygwin only (we use ./configure) + # python-build-standalone moved to 1.4 as well # Check https://zlib.net/ and https://github.com/madler/zlib/releases - return self.cfg_version("1.3.2") + return self.cfg_version("1.4") def c_configure_args(self): if config_args := self.cfg_configure(self.deps_lib_dir, self.deps_lib64_dir): @@ -474,8 +479,10 @@ def url(self): @property def version(self): + # 1.6.0 was released early as a CVE fix (CVE-2026-124851), upstream "highly recommends" it + # python-build-standalone moved to 1.6.0 as well # Check https://github.com/facebook/zstd/releases - return self.cfg_version("1.5.7") + return self.cfg_version("1.6.0") def _do_linux_compile(self): # Notably, this does not build when given a relative path. diff --git a/tests/test_build.py b/tests/test_build.py index f0aa0b4..6ec1678 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -1,7 +1,10 @@ +import os from unittest.mock import patch import runez +from portable_python import BuildSetup, required_python_spec +from portable_python.cpython import Cpython from portable_python.versions import PPG @@ -24,7 +27,7 @@ def test_build_free_threaded(cli): cli.run("-n", "-tmacos-arm64", "build", "3.14.4t", "-mreadline,tkinter") assert cli.succeeded assert " --enable-aqua=yes" in cli.logged # tk on macos - assert "zstd 1.5.7 static* [auto-selected] Required for 3.14 and up" in cli.logged + assert "zstd 1.6.0 static* [auto-selected] Required for 3.14 and up" in cli.logged assert " --disable-gil" in cli.logged assert "env LIBMPDEC_LIBS=build/deps/lib/libmpdec.a" in cli.logged assert "env LIBREADLINE_LIBS=-Lbuild/deps/lib -lreadline -lncursesw" in cli.logged @@ -134,3 +137,48 @@ def test_finalization(cli, monkeypatch): assert f"PEP 668: Cleaned 2 build artifacts (0 B): pip pip{f.mm}" in cli.logged # bin/ exes remain unchanged with --prefix assert list(runez.readlines(f.destdir / "opt/foo/bin/some-exe")) == ["#!.../bin/python3", "hello"] + + +SAMPLE_MAKEFILE = """ +CC=\t\tgcc -pthread +CXX=\t\t{cxx} +LDSHARED=\t$(CC) -shared +LDCXXSHARED=\t$(CXX) -shared +""" + + +def testgroom_makefile_compilers(temp_folder, logged, monkeypatch): + PPG.grab_config(target="linux-x86_64") + python_builder = BuildSetup(required_python_spec("3.14.6")).python_builder + assert isinstance(python_builder, Cpython) + python_builder.groom_makefile_compilers() # No Makefile yet (dryrun mode): no-op + assert not logged + + # Since 3.14.6, ./configure records the absolute path of the C++ compiler found on PATH (here: a ccache masquerade folder) + wrapper = os.path.abspath("ccache/g++") + runez.write(wrapper, "#!/bin/sh\n", logger=None) + os.chmod(wrapper, 0o755) + monkeypatch.setenv("PATH", os.path.dirname(wrapper)) + monkeypatch.delenv("CXX", raising=False) + for path in ("Makefile.pre", "Makefile"): + runez.write(path, SAMPLE_MAKEFILE.format(cxx=f"{wrapper} -pthread"), logger=None) + + python_builder.groom_makefile_compilers() + for path in ("Makefile.pre", "Makefile"): + assert list(runez.readlines(path))[2] == "CXX=\t\tg++ -pthread" # Bare name, compilation still uses the same g++ via PATH + + logged.pop() + python_builder.groom_makefile_compilers() # Already bare: no-op + assert not logged + + # A CXX that is not the one found on PATH is left as-is (as is a CXX explicitly provided by the user) + runez.write("Makefile", SAMPLE_MAKEFILE.format(cxx="/usr/bin/g++"), logger=None) + python_builder.groom_makefile_compilers() + assert list(runez.readlines("Makefile"))[2] == "CXX=\t\t/usr/bin/g++" + + # A compiler wrapper explicitly provided by the user ends up in sysconfig, with a warning + monkeypatch.setenv("CXX", wrapper) + runez.write("Makefile", SAMPLE_MAKEFILE.format(cxx=wrapper), logger=None) + python_builder.groom_makefile_compilers() + assert f"sysconfig will record compiler wrapper 'CXX={wrapper}'" in logged.pop() + assert list(runez.readlines("Makefile"))[2] == f"CXX=\t\t{wrapper}" # User provided CXX is not modified diff --git a/tests/test_failed.py b/tests/test_failed.py index 424303b..cd0d802 100644 --- a/tests/test_failed.py +++ b/tests/test_failed.py @@ -7,7 +7,7 @@ def test_build_bogus_platform(cli): def test_failed_build(cli): cli.run("-tmacos-arm64", "build", "3.12.0") assert cli.failed - assert "Error while compiling xz:5.8.4: ForbiddenHttpError" in cli.logged + assert "Error while compiling xz:5.8.5: ForbiddenHttpError" in cli.logged assert "Overall compilation failed:" in cli.logged diff --git a/tests/test_report.py b/tests/test_report.py index 90a2bb4..dbc3f03 100644 --- a/tests/test_report.py +++ b/tests/test_report.py @@ -15,7 +15,7 @@ def test_scan(cli): with patch.object(PPG, "find_telltale", return_value=None): # Simulate a host without any system headers cli.run("-tlinux-x86_64", "build-report", "3.14.0") - assert "zstd 1.5.7 static* broken, can't compile without libzstd-dev" in cli.logged # Auto-selected ('*') + assert "zstd 1.6.0 static* broken, can't compile without libzstd-dev" in cli.logged # Auto-selected ('*') assert "mpdec 4.0.1 static* broken, can't compile without libmpdec-dev" in cli.logged cli.run("-tmacos-arm64", "build-report", "3.14.0") diff --git a/tests/test_setup.py b/tests/test_setup.py index 2005189..0e9372c 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -87,7 +87,7 @@ def test_edge_cases(temp_folder, monkeypatch, logged): mb = ModuleBuilder(setup) assert not mb.url - assert not mb.version + assert mb.version == "3.9.6" # Top-level module: version of the python being built mb.resolved_telltale = "foo.h" mb.m_debian = "-foo" outcome, reason = mb.linker_outcome(is_selected=True)