From 10031f19da92e60e79e608cc04c35663c8ef28ac Mon Sep 17 00:00:00 2001 From: Geoffrey Thomas Date: Thu, 18 Sep 2025 10:48:21 -0400 Subject: [PATCH] windows: Sync SQLite build flags from the UNIX build Notably this adds * SQLITE_ENABLE_FTS3_PARENTHESIS (syntax change, see #550) * SQLITE_ENABLE_DBSTAT_VTAB (#309) * SQLITE_ENABLE_GEOPOLY (historically present on UNIX, maybe see #694) --- cpython-unix/build-sqlite.sh | 1 + cpython-windows/build.py | 30 ++++++++++++++++++++++++++++++ src/verify_distribution.py | 11 ++--------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/cpython-unix/build-sqlite.sh b/cpython-unix/build-sqlite.sh index 596ceae9..780e8270 100755 --- a/cpython-unix/build-sqlite.sh +++ b/cpython-unix/build-sqlite.sh @@ -28,6 +28,7 @@ fi unset CXX CC_FOR_BUILD="${HOST_CC}" \ +# Please try to keep these in sync with cpython-windows/build.py CFLAGS="${EXTRA_TARGET_CFLAGS} \ -DSQLITE_ENABLE_DBSTAT_VTAB \ -DSQLITE_ENABLE_FTS3 \ diff --git a/cpython-windows/build.py b/cpython-windows/build.py index 26023247..f8902132 100644 --- a/cpython-windows/build.py +++ b/cpython-windows/build.py @@ -568,6 +568,36 @@ def hack_project_files( rb"%s" % sqlite3_version_parts[3], ) + # Please try keep these in sync with cpython-unix/build-sqlite.sh + sqlite_build_flags = { + b"SQLITE_ENABLE_DBSTAT_VTAB", + b"SQLITE_ENABLE_FTS3", + b"SQLITE_ENABLE_FTS3_PARENTHESIS", + b"SQLITE_ENABLE_FTS4", + b"SQLITE_ENABLE_FTS5", + b"SQLITE_ENABLE_GEOPOLY", + b"SQLITE_ENABLE_RTREE", + } + with sqlite3_path.open("rb") as fh: + data = fh.read() + sqlite_preprocessor_regex = ( + rb"(SQLITE_ENABLE.*)" + ) + m = re.search(sqlite_preprocessor_regex, data) + if m is None: + raise NoSearchStringError( + "search string (%s) not in %s" % (sqlite_preprocessor_regex, sqlite3_path) + ) + current_flags = set(m.group(1).split(b";")) + data = ( + data[: m.start(1)] + + b";".join(sqlite_build_flags - current_flags) + + b";" + + data[m.start(1) :] + ) + with sqlite3_path.open("wb") as fh: + fh.write(data) + # Our version of the xz sources is newer than what's in cpython-source-deps # and the xz sources changed the path to config.h. Hack the project file # accordingly. diff --git a/src/verify_distribution.py b/src/verify_distribution.py index 16901883..9968606f 100644 --- a/src/verify_distribution.py +++ b/src/verify_distribution.py @@ -123,15 +123,8 @@ def test_sqlite(self): self.assertTrue(hasattr(conn, "enable_load_extension")) # Backup feature requires modern SQLite, which we always have. self.assertTrue(hasattr(conn, "backup")) - # Ensure that various extensions are present. These will raise if they are not. Note that - # CPython upstream carries configuration flags for the Windows build, so geopoly is missing - # on all versions and rtree is missing in 3.9. On non-Windows platforms, we configure - # SQLite ourselves. We might want to patch the build to enable these on Windows, see #666. - extensions = ["fts3", "fts4", "fts5"] - if os.name != "nt": - extensions.append("geopoly") - if os.name != "nt" or sys.version_info[0:2] > (3, 9): - extensions.append("rtree") + # Ensure that various extensions are present. These will raise if they are not. + extensions = ["fts3", "fts4", "fts5", "geopoly", "rtree"] cursor = conn.cursor() for extension in extensions: with self.subTest(extension=extension):