From b6e801ed88d87f0c4fa1de2cb735f61e4c9fadae Mon Sep 17 00:00:00 2001 From: Martin Dobias Date: Thu, 11 Jun 2026 22:59:22 +0200 Subject: [PATCH] Prevent clash with system GDAL On macOS, I have GDAL 3.13.0 from Homebrew and rasterio's setup.py was mistakenly using it instead of using GDAL from vcpkg port. The problem is that GDAL vcpkg port deletes gdal-config (for whatever reason) and so the gdal-config from PATH (Homebrew) gets picked and rasterio uses headers/libs from here. Then, when loaded against GDAL from vcpkg (3.12.x) I was getting a nasty ImportError due to ABI mismatch. The fix makes sure that rasterio ignores gdal-config, because there is no such executable from GDAL vcpkg port anyway. --- .../no-gdal-config-autodetect.patch | 27 +++++++++++++++++++ ports/py-rasterio/portfile.cmake | 4 +++ 2 files changed, 31 insertions(+) create mode 100644 ports/py-rasterio/no-gdal-config-autodetect.patch diff --git a/ports/py-rasterio/no-gdal-config-autodetect.patch b/ports/py-rasterio/no-gdal-config-autodetect.patch new file mode 100644 index 00000000..c1430f3b --- /dev/null +++ b/ports/py-rasterio/no-gdal-config-autodetect.patch @@ -0,0 +1,27 @@ +--- a/setup.py ++++ b/setup.py +@@ -233,24 +233,6 @@ + log.info("GDAL API version obtained from gdal-config: %s", gdalversion) + + if "clean" not in sys.argv: +- try: +- fill_gdal_build_options_using_gdal_config() +- except Exception as e: +- # Try to run gdalinfo and get information from that instead +- log.info( +- "Failed to use gdal-config, trying to run gdalinfo instead (gdal-config error of type %s: %s)", +- type(e).__name__, +- e, +- ) +- try: +- fill_gdal_build_options_using_executable(executable_name="gdalinfo") +- except Exception as e: +- log.warning( +- "Failed to get options via both gdal-config and gdalinfo. (gdalinfo error of type %s: %s)", +- type(e).__name__, +- e, +- ) +- + # Get GDAL API version from environment variable. + if 'GDAL_VERSION' in os.environ: + gdalversion = os.environ['GDAL_VERSION'] diff --git a/ports/py-rasterio/portfile.cmake b/ports/py-rasterio/portfile.cmake index de42567b..1e925e3a 100644 --- a/ports/py-rasterio/portfile.cmake +++ b/ports/py-rasterio/portfile.cmake @@ -34,6 +34,10 @@ library_dirs=${CURRENT_INSTALLED_DIR}/lib libraries=gdal ") +vcpkg_apply_patches(SOURCE_PATH "${SOURCE_PATH}" + PATCHES no-gdal-config-autodetect.patch +) + vcpkg_python_build_and_install_wheel(SOURCE_PATH "${SOURCE_PATH}") vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE.txt")