[Mlir-commits] [mlir] [mlir][python] add pyproject.toml (PR #124878)

Maksim Levental llvmlistbot at llvm.org
Tue Jan 28 21:04:52 PST 2025


https://github.com/makslevental created https://github.com/llvm/llvm-project/pull/124878

It [frequently](https://discourse.llvm.org/t/mlir-python-bindings-pyi-imports/83350/5?u=makslevental) comes up that we don't describe/document how to distribute the python bindings (as a wheel or otherwise). There are [lots](https://github.com/iree-org/stablehlo/blob/691c6765186c6a8507c5132e080de568bfa32a90/stablehlo/integrations/python/setup.py) [of](https://github.com/triton-lang/triton/blob/main/python/setup.py) [downstream](https://github.com/iree-org/iree/blob/main/runtime/setup.py) [examples](https://github.com/iree-org/iree/blob/main/compiler/setup.py) but these are probably unknown/obscure to novices. 

This PR introduces a relatively simple (and differing from the aforementioned examples) way to build and package the bindings as a wheel. It uses [`scikit-build-core`](https://scikit-build-core.readthedocs.io/en/latest/index.html) to (effectively) drive `cmake`. It can be combined with [`cibuildwheel`](https://github.com/llvm/eudsl/blob/main/projects/eudsl-py/pyproject.toml#L44-L95) to produce `manylinux` wheels. 

In principle it maybe belongs under `mlir/examples/standalone/python` because it's not comprehensive (and maybe I'll move there after strong protest) but that would make it specifically an example of how to build standalone bindings rather than upstream bindings. 

Anyway the point of putting this up is so we can iterate so that we have _something_ to point people at.

>From fc9e28ee5240b5e533e7a27a2b520e8565d9c5e0 Mon Sep 17 00:00:00 2001
From: max <maksim.levental at gmail.com>
Date: Tue, 28 Jan 2025 23:52:11 -0500
Subject: [PATCH] [mlir][python] add pyproject.toml

---
 mlir/python/pyproject.toml | 40 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 mlir/python/pyproject.toml

diff --git a/mlir/python/pyproject.toml b/mlir/python/pyproject.toml
new file mode 100644
index 00000000000000..04ba2a6548e847
--- /dev/null
+++ b/mlir/python/pyproject.toml
@@ -0,0 +1,40 @@
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+# Copyright (c) 2025.
+
+[project]
+name = "mlir"
+version = "0.0.1"
+requires-python = ">=3.8,<=3.13"
+[project.urls]
+Homepage = "https://github.com/llvm/llvm-project"
+
+[build-system]
+requires = [
+    "scikit-build-core==0.10.7",
+    "typing_extensions==4.12.2",
+    "nanobind>=2.4, <3.0",
+    "numpy>=1.19.5, <=2.1.2",
+    "pybind11>=2.10.0, <=2.13.6",
+    "PyYAML>=5.4.0, <=6.0.1",
+    'ml_dtypes>=0.1.0, <=0.6.0; python_version<"3.13"',
+    'ml_dtypes>=0.5.0, <=0.6.0; python_version>="3.13"'
+]
+build-backend = "scikit_build_core.build"
+
+[tool.scikit-build]
+minimum-version = "0.4"
+build-dir = "../../build"
+cmake.source-dir = "../../llvm"
+wheel.packages = ["tools/mlir/python_packages/mlir_core"]
+
+[tool.scikit-build.cmake.define]
+CMAKE_C_COMPILER_LAUNCHER = { env = "CMAKE_C_COMPILER_LAUNCHER", default = "" }
+CMAKE_CXX_COMPILER_LAUNCHER = { env = "CMAKE_CXX_COMPILER_LAUNCHER", default = "" }
+CMAKE_CXX_VISIBILITY_PRESET = "hidden"
+CMAKE_C_VISIBILITY_PRESET = "hidden"
+CMAKE_VISIBILITY_INLINES_HIDDEN = "ON"
+CMAKE_VERBOSE_MAKEFILE = "ON"
+LLVM_ENABLE_PROJECTS = "mlir"
+MLIR_ENABLE_BINDINGS_PYTHON = "ON"



More information about the Mlir-commits mailing list