[llvm] [mlir] [MLIR] [Bazel] Removed the stubgen plumbing added in #179211 (PR #185292)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 8 08:40:09 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Sergei Lebedev (superbobry)
<details>
<summary>Changes</summary>
The hope was that we would be able to reuse parts of this for Google-internal builds and for open-source jaxlib builds, but we ended up with custom plumbing in both cases, so I am now removing this effectively dead code.
---
Full diff: https://github.com/llvm/llvm-project/pull/185292.diff
4 Files Affected:
- (removed) mlir/lib/Bindings/Python/stubgen_runner.py (-54)
- (modified) utils/bazel/llvm-project-overlay/mlir/BUILD.bazel (-24)
- (modified) utils/bazel/llvm-project-overlay/mlir/build_defs.bzl (-21)
- (modified) utils/bazel/third_party_build/nanobind.BUILD (-2)
``````````diff
diff --git a/mlir/lib/Bindings/Python/stubgen_runner.py b/mlir/lib/Bindings/Python/stubgen_runner.py
deleted file mode 100644
index 9fb08425cbb1c..0000000000000
--- a/mlir/lib/Bindings/Python/stubgen_runner.py
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/usr/bin/env python3
-"""Generates .pyi stubs for nanobind extensions using nanobind's stubgen."""
-
-import argparse
-import ctypes
-import importlib.util
-import sys
-from pathlib import Path
-
-from python.runfiles import Runfiles
-
-
-def load_extension(path: Path):
- """Load an extension module from a .so file with RTLD_GLOBAL."""
- module_name = path.stem.removesuffix(".abi3")
-
- # Load with RTLD_GLOBAL so symbols are available to dependent extensions.
- ctypes.CDLL(str(path), mode=ctypes.RTLD_GLOBAL)
-
- spec = importlib.util.spec_from_file_location(module_name, path)
- if spec is None or spec.loader is None:
- sys.exit(f"Failed to load extension from {path}")
-
- module = importlib.util.module_from_spec(spec)
- sys.modules[module_name] = module
- spec.loader.exec_module(module)
- return module_name
-
-
-def main():
- parser = argparse.ArgumentParser()
- parser.add_argument(
- "--module", required=True, help="Module name to generate stubs for"
- )
- parser.add_argument(
- "--deps", required=True, help="Comma-separated .so files to load"
- )
- parser.add_argument("-o", "--output", required=True, help="Output directory")
- args = parser.parse_args()
-
- for dep_path in args.deps.split(","):
- load_extension(Path(dep_path).resolve())
-
- runfiles = Runfiles.Create()
- stubgen_path = runfiles.Rlocation("+llvm_repos_extension+nanobind/src/stubgen.py")
- spec = importlib.util.spec_from_file_location("stubgen", stubgen_path)
- stubgen = importlib.util.module_from_spec(spec)
- sys.modules["stubgen"] = stubgen
- spec.loader.exec_module(stubgen)
- stubgen.main(["-m", args.module, "-r", "-O", args.output])
-
-
-if __name__ == "__main__":
- main()
diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
index 901a6804d2ed4..0675bcd9ee0e0 100644
--- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
@@ -15,7 +15,6 @@ load(
"cc_headers_only",
"if_cuda_available",
"mlir_c_api_cc_library",
- "nanobind_pyi_genrule",
)
load(":linalggen.bzl", "genlinalg")
load(":tblgen.bzl", "gentbl_cc_library", "td_library")
@@ -1331,29 +1330,6 @@ cc_binary(
],
)
-##---------------------------------------------------------------------------##
-# Python stub generation for native extensions.
-##---------------------------------------------------------------------------##
-
-py_binary(
- name = "stubgen_runner",
- srcs = ["lib/Bindings/Python/stubgen_runner.py"],
- data = ["@nanobind//:src/stubgen.py"],
- deps = ["@rules_python//python/runfiles"],
-)
-
-nanobind_pyi_genrule(
- name = "_mlir_pyi",
- outs = [
- "_mlir/__init__.pyi",
- "_mlir/ir.pyi",
- "_mlir/passmanager.pyi",
- "_mlir/rewrite.pyi",
- ],
- module_name = "_mlir",
- deps = [":_mlir.so"],
-)
-
##---------------------------------------------------------------------------##
td_library(
diff --git a/utils/bazel/llvm-project-overlay/mlir/build_defs.bzl b/utils/bazel/llvm-project-overlay/mlir/build_defs.bzl
index 727ba2c923551..5a3a776258b06 100644
--- a/utils/bazel/llvm-project-overlay/mlir/build_defs.bzl
+++ b/utils/bazel/llvm-project-overlay/mlir/build_defs.bzl
@@ -72,24 +72,3 @@ def mlir_c_api_cc_library(
alwayslink = True,
**kwargs
)
-
-def nanobind_pyi_genrule(name, module_name, outs, deps, **kwargs):
- """Generates .pyi stub file(s) for a nanobind extension module.
-
- Args:
- name: Name of the generated target.
- module_name: Name of the module to generate stubs for (e.g., "_mlir").
- outs: List of expected output .pyi files.
- deps: All .so modules to load (including the target module).
- visibility: Visibility for the generated .pyi file(s).
- """
- deps_arg = ",".join(["$(location " + d + ")" for d in deps])
-
- native.genrule(
- name = name,
- srcs = deps,
- outs = outs,
- cmd = "$(location :stubgen_runner) --module " + module_name + " --deps " + deps_arg + " -o $(RULEDIR) > /dev/null",
- tools = [":stubgen_runner"],
- **kwargs
- )
diff --git a/utils/bazel/third_party_build/nanobind.BUILD b/utils/bazel/third_party_build/nanobind.BUILD
index c33fb71471aea..41296d9034fda 100644
--- a/utils/bazel/third_party_build/nanobind.BUILD
+++ b/utils/bazel/third_party_build/nanobind.BUILD
@@ -1,7 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
-exports_files(["src/stubgen.py"])
-
cc_library(
name = "nanobind",
srcs = glob(
``````````
</details>
https://github.com/llvm/llvm-project/pull/185292
More information about the llvm-commits
mailing list