llvm-project
9f27e016 - [mlir][python] Avoid versioned Python DLL with stable ABI on Windows (#225794)

Commit
9 days ago
[mlir][python] Avoid versioned Python DLL with stable ABI on Windows (#225794) ## Summary On Windows, `add_mlir_python_extension` links every MLIR Python extension and shared support library against `Python3_LIBRARY_RELEASE`, even with `MLIR_ENABLE_PYTHON_STABLE_ABI=ON`. That adds a dependency on the versioned Python DLL and prevents loading the abi3 modules with another Python version. nanobind's shared `-abi3` runtime already provides `Python::SABIModule` as a public link dependency. Skip MLIR's extra versioned-library link for stable ABI builds. Preserve it for non-stable and free-threaded builds. ## Testing Configured current upstream `main` (9120c137) with Python 3.12.11, nanobind 2.9.2, clang-cl, Ninja, `MLIR_ENABLE_BINDINGS_PYTHON=ON`, and `MLIR_ENABLE_PYTHON_STABLE_ABI=ON`, then built `_mlir.pyd`. Before the change, `llvm-readobj --coff-imports` showed `python312.dll` in both `_mlir.pyd` and `MLIRPythonSupport-mlir.dll`. Python 3.12 could import and parse `module {}`, while Python 3.14 failed to load `_mlir`. After the change, both binaries import only `python3.dll`. The same build imports and parses `module {}` with Python 3.12 and 3.14. `git diff --check` passes. ## AI assistance OpenAI Codex assisted with the investigation, patch, testing, and drafting this PR description.
Author
Parents
Loading