[Bazel] Add Bazel rules for Python bindings#4609
Open
kalvdans wants to merge 1 commit into
Open
Conversation
Adds Bazel support for building the torch-mlir Python bindings, which previously had no Bazel coverage: - BUILD.bazel: add `mlir_c_api_cc_library` rules for the `CAPITorch` and `CAPITorchRegisterEverything` C API targets, and export `include/torch-mlir-c/Registration.h`. - python/fileutils.bzl: add a `copy_into_directory` rule that symlinks generated files into the package subdirectory layout CMake produces. - python/BUILD.bazel: generate the Torch op bindings, build the `_torchMlir.so` (pybind11) and `_mlirRegisterEverything.so` (nanobind) extension modules, and assemble everything into a `torch-mlir` py_library.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Bazel build support for the torch-mlir Python bindings. Until now the
Bazel build (
utils/bazel/) only coveredtorch-mlir-optand the C++libraries; the Python package could only be built via CMake. This brings the
Bazel build closer to parity with CMake for projects that consume torch-mlir
through Bazel.
What's included
torch-mlir-overlay/BUILD.bazel:CAPITorchandCAPITorchRegisterEverything(viamlir_c_api_cc_library), plus anexports_filesforinclude/torch-mlir-c/Registration.h.python/BUILD.bazel(new):_torch_ops_gen.py) withgentbl_filegroup;_torchMlir.so(pybind11) and_mlirRegisterEverything.so(nanobind) extension modules;
torch-mlirpy_library, mirroring thepackage tree CMake produces (
torch_mlir/,torch_mlir/dialects,torch_mlir/_mlir_libs).python/fileutils.bzl(new): a smallcopy_into_directoryrule thatsymlinks generated files into that package layout.
Notes
this is peripheral-tier and opt-in. The default Bazel CI target
(
@torch-mlir//:torch-mlir-opt) is unaffected.the consuming project to provide
nanobindand a Python toolchain(
@rules_python//python/cclibs) through its module graph; torch-mlir'sstandalone Bazel build does not register these.
buildifieras requested by thecontributing guidelines.
Testing
bazel query @torch-mlir//python:torch-mlir + @torch-mlir//:CAPITorch + @torch-mlir//:CAPITorchRegisterEverythingresolves.bazel build --nobuild) of@torch-mlir//python:torch-mlirconfigures the full dependency graph against the pinned LLVM revision.
py_librarydependency in a downstreamBazel (bzlmod) project that provides the nanobind/Python-toolchain deps.