[llvm] [llvm-ir2vec] setting up pyproject.toml file for user-side wheel builds (PR #187929)

via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 22 06:53:35 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlgo

Author: Nishant Sachdeva  (nishant-sachdeva)

<details>
<summary>Changes</summary>

@<!-- -->svkeerthy , @<!-- -->mtrofin , @<!-- -->boomanaiden154 

- This patch adds Python packaging metadata for the IR2Vec Python bindings. 
- Rather than introducing a full wheel-building pipeline at this stage, I want to start with the bare minimum pyproject.toml.
- I've added an adjacent README.md to provide build instructions for users who want to produce wheels locally. 
- As context, per my understanding, LIT is currently the only Python package published directly from the LLVM monorepo.
- Several other packages such as clang/libclang, MLIR, etc have their packaging metadata in-tree, with publishing handled downstream. 
- This patch follows that same approach for ir2vec. Adding @<!-- -->boomanaiden154  here for feedback, particularly for whether there's a pathway to eventually integrate with release-tasks.yml in the same way lit does, or follow a separate downstream publishing model like the usual way.

---
Full diff: https://github.com/llvm/llvm-project/pull/187929.diff


3 Files Affected:

- (added) llvm/tools/llvm-ir2vec/Bindings/package/.gitignore (+11) 
- (added) llvm/tools/llvm-ir2vec/Bindings/package/README.md (+86) 
- (added) llvm/tools/llvm-ir2vec/Bindings/package/pyproject.toml (+32) 


``````````diff
diff --git a/llvm/tools/llvm-ir2vec/Bindings/package/.gitignore b/llvm/tools/llvm-ir2vec/Bindings/package/.gitignore
new file mode 100644
index 0000000000000..019c4a4104145
--- /dev/null
+++ b/llvm/tools/llvm-ir2vec/Bindings/package/.gitignore
@@ -0,0 +1,11 @@
+__pycache__/
+*.py[cod]
+*$py.class
+build/
+dist/
+*.egg-info/
+_skbuild/
+.env
+.venv
+env/
+venv/
\ No newline at end of file
diff --git a/llvm/tools/llvm-ir2vec/Bindings/package/README.md b/llvm/tools/llvm-ir2vec/Bindings/package/README.md
new file mode 100644
index 0000000000000..1b5d8517f3443
--- /dev/null
+++ b/llvm/tools/llvm-ir2vec/Bindings/package/README.md
@@ -0,0 +1,86 @@
+<!--
+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
+-->
+
+# ir2vec
+
+Python bindings for [IR2Vec](https://llvm.org/docs/MLGO.html#ir2vec), an LLVM IR
+embedding framework that generates vector representations of LLVM IR for use
+in machine learning-based compiler optimization.
+
+## Requirements
+
+- Python >= 3.10
+- NumPy
+- An IR2Vec vocabulary file (see the IR2Vec documentation)
+
+## Building a Wheel
+
+These bindings require a pre-built shared library. The following steps build a wheel by packaging the compiled shared library produced during the LLVM build.
+
+**Step 1: Build LLVM with Python bindings enabled**
+
+Configure and build LLVM with the `-DLLVM_IR2VEC_ENABLE_PYTHON_BINDINGS=ON`
+flag:
+```bash
+cmake -G Ninja -S llvm-project/llvm -B build-llvm \
+  -DCMAKE_BUILD_TYPE=Release \
+  -DLLVM_TARGETS_TO_BUILD=host \
+  -DLLVM_IR2VEC_ENABLE_PYTHON_BINDINGS=ON \
+  -DPython_EXECUTABLE=$(which python3) \
+  -DPython3_EXECUTABLE=$(which python3) \
+  ...
+
+ninja -C build-llvm
+```
+
+**Step 2: Locate the built shared library**
+```bash
+find build-llvm/ -name "ir2vec*.so"
+```
+
+**Step 3: Stage and build the wheel**
+
+Copy the shared library, `pyproject.toml`, and `README.md` to a staging
+directory and build the wheel from there:
+```bash
+mkdir /tmp/ir2vec-wheel
+cp build-llvm/lib/ir2vec*.so /tmp/ir2vec-wheel/
+cp llvm-project/llvm/tools/llvm-ir2vec/Bindings/package/pyproject.toml /tmp/ir2vec-wheel/
+cp llvm-project/llvm/tools/llvm-ir2vec/Bindings/package/README.md /tmp/ir2vec-wheel/
+
+cd /tmp/ir2vec-wheel
+pip install build
+python -m build --wheel --no-isolation
+```
+
+The wheel will be written to `/tmp/ir2vec-wheel/dist/`.
+
+**Step 4: Install**
+```bash
+pip install /tmp/ir2vec-wheel/dist/ir2vec-*.whl
+```
+
+## Usage
+```python
+import ir2vec
+
+tool = ir2vec.initEmbedding(
+    filename="module.ll",
+    mode="sym",
+    vocabPath="/path/to/vocab.json"
+)
+embeddings = tool.getFuncEmbMap()
+```
+
+## Source
+
+This package is part of the LLVM Project:
+https://github.com/llvm/llvm-project/tree/main/llvm/tools/llvm-ir2vec
+
+## License
+
+Apache License v2.0 with LLVM Exceptions.
+See https://llvm.org/LICENSE.txt for details.
diff --git a/llvm/tools/llvm-ir2vec/Bindings/package/pyproject.toml b/llvm/tools/llvm-ir2vec/Bindings/package/pyproject.toml
new file mode 100644
index 0000000000000..0b29abc7d2613
--- /dev/null
+++ b/llvm/tools/llvm-ir2vec/Bindings/package/pyproject.toml
@@ -0,0 +1,32 @@
+# 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
+
+[build-system]
+requires = ["setuptools>=68"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "ir2vec"
+version = "0.1.0"
+description = "Python bindings for IR2Vec, an LLVM IR embedding framework"
+readme = {file = "README.md", content-type = "text/markdown"}
+license = "Apache-2.0 WITH LLVM-exception"
+authors = [
+    { name = "LLVM" }
+]
+keywords = ["llvm", "ir2vec", "compilers", "embeddings", "machine learning"]
+classifiers = [
+    "Intended Audience :: Developers",
+    "Development Status :: 3 - Alpha",
+    "Topic :: Software Development :: Compilers",
+    "Programming Language :: Python :: 3",
+]
+requires-python = ">=3.10"
+dependencies = ["numpy"]
+
+[project.urls]
+Homepage = "https://llvm.org/"
+Discussions = "https://discourse.llvm.org/"
+"Issue Tracker" = "https://github.com/llvm/llvm-project/issues"
+"Source Code" = "https://github.com/llvm/llvm-project/tree/main/llvm/tools/llvm-ir2vec"

``````````

</details>


https://github.com/llvm/llvm-project/pull/187929


More information about the llvm-commits mailing list