[Mlir-commits] [mlir] [mlir][python] fix symbol resolution on MacOS with multiple packages (PR #174057)

Maksim Levental llvmlistbot at llvm.org
Fri Jan 2 10:43:51 PST 2026


https://github.com/makslevental updated https://github.com/llvm/llvm-project/pull/174057

>From 9ba8371d08800ee328bc58afee34e4e54048260f Mon Sep 17 00:00:00 2001
From: makslevental <maksim.levental at gmail.com>
Date: Tue, 30 Dec 2025 22:09:33 -0800
Subject: [PATCH 1/5] [mlir][python] fix flatnamespace

---
 mlir/cmake/modules/AddMLIRPython.cmake        |  6 +++
 mlir/examples/standalone/CMakeLists.txt       |  4 +-
 mlir/examples/standalone/test/lit.cfg.py      | 12 ++---
 .../standalone/test/python/smoketest.py       | 53 ++++++++++++++++---
 mlir/test/Examples/standalone/test.toy        |  2 +
 mlir/test/Examples/standalone/test.wheel.toy  | 14 ++++-
 6 files changed, 74 insertions(+), 17 deletions(-)

diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index ca90151e76268..8c301faf0941a 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -766,6 +766,12 @@ function(add_mlir_python_extension libname extname)
     FREE_THREADED
     ${ARG_SOURCES}
   )
+  if(APPLE)
+    # In llvm/cmake/modules/HandleLLVMOptions.cmake:268 we set -Wl,-flat_namespace which breaks
+    # the default name spacing on MacOS and causes "cross-wired" symbol resolution when multiple
+    # bindings packages are loaded.
+    target_link_options(${libname} PRIVATE "LINKER:-twolevel_namespace")
+  endif()
 
   if (NOT MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES
       AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
diff --git a/mlir/examples/standalone/CMakeLists.txt b/mlir/examples/standalone/CMakeLists.txt
index c6c49fde12d2e..955c9ec7a7b4c 100644
--- a/mlir/examples/standalone/CMakeLists.txt
+++ b/mlir/examples/standalone/CMakeLists.txt
@@ -71,7 +71,9 @@ if(MLIR_ENABLE_BINDINGS_PYTHON)
   endif()
   add_subdirectory(python)
 endif()
-add_subdirectory(test)
+if(MLIR_INCLUDE_TESTS)
+  add_subdirectory(test)
+endif()
 add_subdirectory(standalone-opt)
 if(NOT WIN32)
   add_subdirectory(standalone-plugin)
diff --git a/mlir/examples/standalone/test/lit.cfg.py b/mlir/examples/standalone/test/lit.cfg.py
index e27dddd7fb0b9..89cdd6889a1f2 100644
--- a/mlir/examples/standalone/test/lit.cfg.py
+++ b/mlir/examples/standalone/test/lit.cfg.py
@@ -61,10 +61,8 @@
 
 llvm_config.add_tool_substitutions(tools, tool_dirs)
 
-llvm_config.with_environment(
-    "PYTHONPATH",
-    [
-        os.path.join(config.mlir_obj_dir, "python_packages", "standalone"),
-    ],
-    append_path=True,
-)
+python_path = [os.path.join(config.mlir_obj_dir, "python_packages", "standalone")]
+if "PYTHONPATH" in os.environ:
+    python_path += [os.environ["PYTHONPATH"]]
+
+llvm_config.with_environment("PYTHONPATH", python_path, append_path=True)
diff --git a/mlir/examples/standalone/test/python/smoketest.py b/mlir/examples/standalone/test/python/smoketest.py
index f8819841fac45..addd767f53592 100644
--- a/mlir/examples/standalone/test/python/smoketest.py
+++ b/mlir/examples/standalone/test/python/smoketest.py
@@ -1,16 +1,55 @@
-# RUN: %python %s nanobind | FileCheck %s
+# RUN: %python %s 2>&1 | FileCheck %s
+import sys
 
-from mlir_standalone.ir import *
+# CHECK: Testing mlir_standalone package
+print("Testing mlir_standalone package", file=sys.stderr)
+
+import mlir_standalone.ir
 from mlir_standalone.dialects import standalone_nanobind as standalone_d
 
-with Context():
+with mlir_standalone.ir.Context():
     standalone_d.register_dialects()
-    module = Module.parse(
+    standalone_module = mlir_standalone.ir.Module.parse(
         """
     %0 = arith.constant 2 : i32
     %1 = standalone.foo %0 : i32
     """
     )
-    # CHECK: %[[C:.*]] = arith.constant 2 : i32
-    # CHECK: standalone.foo %[[C]] : i32
-    print(str(module))
+    # CHECK: %[[C2:.*]] = arith.constant 2 : i32
+    # CHECK: standalone.foo %[[C2]] : i32
+    print(str(standalone_module), file=sys.stderr)
+
+
+# CHECK: Testing mlir package
+print("Testing mlir package", file=sys.stderr)
+
+import mlir.ir
+from mlir.dialects import (
+    amdgpu,
+    gpu,
+    irdl,
+    llvm,
+    nvgpu,
+    pdl,
+    quant,
+    smt,
+    sparse_tensor,
+    transform,
+    # Note: uncommenting linalg below will cause
+    # LLVM ERROR: Attempting to attach an interface to an unregistered operation builtin.unrealized_conversion_cast.
+    # unless you have built both mlir and mlir_standalone with
+    # -DCMAKE_C_VISIBILITY_PRESET=hidden -DCMAKE_CXX_VISIBILITY_PRESET=hidden -DCMAKE_VISIBILITY_INLINES_HIDDEN=ON
+    # which is highly recommended.
+    # linalg,
+)
+
+# CHECK-NOT: RuntimeWarning: nanobind: type '{{.*}}' was already registered!
+
+with mlir.ir.Context():
+    mlir_module = mlir.ir.Module.parse(
+        """
+    %0 = arith.constant 3 : i32
+    """
+    )
+    # CHECK: %[[C3:.*]] = arith.constant 3 : i32
+    print(str(mlir_module), file=sys.stderr)
diff --git a/mlir/test/Examples/standalone/test.toy b/mlir/test/Examples/standalone/test.toy
index a88c115ebf197..dc3c17f3da3d9 100644
--- a/mlir/test/Examples/standalone/test.toy
+++ b/mlir/test/Examples/standalone/test.toy
@@ -4,8 +4,10 @@
 # RUN: -DLLVM_ENABLE_LIBCXX=%enable_libcxx -DMLIR_DIR=%mlir_cmake_dir \
 # RUN: -DLLVM_USE_LINKER=%llvm_use_linker \
 # RUN: -DMLIR_PYTHON_PACKAGE_PREFIX=mlir_standalone \
+# RUN: -DMLIR_INCLUDE_TESTS=ON \
 # RUN: -DPython3_EXECUTABLE=%python \
 # RUN: -DPython_EXECUTABLE=%python
+# RUN: export PYTHONPATH="%mlir_obj_root/python_packages/mlir_core"
 # RUN: "%cmake_exe" --build . --target check-standalone | tee %t
 # RUN: FileCheck --input-file=%t %s
 
diff --git a/mlir/test/Examples/standalone/test.wheel.toy b/mlir/test/Examples/standalone/test.wheel.toy
index c8d188a3cacd0..e9232e3f16098 100644
--- a/mlir/test/Examples/standalone/test.wheel.toy
+++ b/mlir/test/Examples/standalone/test.wheel.toy
@@ -14,21 +14,31 @@
 # RUN: export CMAKE_GENERATOR=%cmake_generator
 # RUN: export LLVM_USE_LINKER=%llvm_use_linker
 # RUN: export MLIR_DIR="%mlir_cmake_dir"
+# RUN: export MLIR_INCLUDE_TESTS=ON
 
 # RUN: %python -m pip wheel "%mlir_src_root/examples/standalone" -w "%mlir_obj_root/wheelhouse" -v | tee %t
 
 # RUN: rm -rf "%mlir_obj_root/standalone-python-bindings-install"
 # RUN: %python -m pip install standalone_python_bindings -f "%mlir_obj_root/wheelhouse" --target "%mlir_obj_root/standalone-python-bindings-install" -v | tee -a %t
 
-# RUN: export PYTHONPATH="%mlir_obj_root/standalone-python-bindings-install"
-# RUN: %python "%mlir_src_root/examples/standalone/test/python/smoketest.py" nanobind | tee -a %t
+# RUN: export PYTHONPATH="%mlir_obj_root/standalone-python-bindings-install:%mlir_obj_root/python_packages/mlir_core"
+# RUN: %python "%mlir_src_root/examples/standalone/test/python/smoketest.py" 2>&1 | tee -a %t
 
 # RUN: FileCheck --input-file=%t %s
 
 # CHECK: Successfully built standalone-python-bindings
 
+# CHECK: Testing mlir_standalone package
+
 # CHECK: module {
 # CHECK:   %[[C2:.*]] = arith.constant 2 : i32
 # CHECK:   %[[V0:.*]] = standalone.foo %[[C2]] : i32
 # CHECK: }
 
+# CHECK: Testing mlir package
+
+# CHECK-NOT: RuntimeWarning: nanobind: type '{{.*}}' was already registered!
+
+# CHECK: module {
+# CHECK:   %[[C3:.*]] = arith.constant 3 : i32
+# CHECK: }

>From f7fcd17b870226126253ffe0d79b34920dffb1bb Mon Sep 17 00:00:00 2001
From: makslevental <maksim.levental at gmail.com>
Date: Wed, 31 Dec 2025 00:28:32 -0800
Subject: [PATCH 2/5] add doc

---
 mlir/docs/Bindings/Python.md                    | 12 ++++++++++++
 .../standalone/test/python/smoketest.py         | 17 ++++-------------
 mlir/test/Examples/standalone/test.wheel.toy    |  4 ----
 3 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/mlir/docs/Bindings/Python.md b/mlir/docs/Bindings/Python.md
index 877ae5170d68c..4f4f531f7723c 100644
--- a/mlir/docs/Bindings/Python.md
+++ b/mlir/docs/Bindings/Python.md
@@ -25,6 +25,18 @@
     multiple Python implementations, setting this explicitly to the preferred
     `python3` executable is strongly recommended.
 
+*   **`CMAKE_C_VISIBILITY_PRESET`**: `STRING`
+*   **`CMAKE_CXX_VISIBILITY_PRESET`**: `STRING`
+*   **`CMAKE_VISIBILITY_INLINES_HIDDEN`**: `BOOL`
+
+    It is **highly** recommended these are set to `hidden`, `hidden`, and `ON` (respectively) if the final built package
+    is intended to be used in a context/use-case where multiple bindings packages will be used simultaneously
+    (i.e., multiple bindings packages loaded in the same Python interpreter session). Failing to do so can lead
+    to incorrect/ambiguous symbol resolution; the symptom of this is an `LLVM ERROR` like:
+    ```
+    LLVM ERROR: ... unregistered/uninitialized dialect/type/pass ...`
+    ```
+
 ### Recommended development practices
 
 It is recommended to use a Python virtual environment. Many ways exist for this,
diff --git a/mlir/examples/standalone/test/python/smoketest.py b/mlir/examples/standalone/test/python/smoketest.py
index addd767f53592..319251b063773 100644
--- a/mlir/examples/standalone/test/python/smoketest.py
+++ b/mlir/examples/standalone/test/python/smoketest.py
@@ -4,12 +4,12 @@
 # CHECK: Testing mlir_standalone package
 print("Testing mlir_standalone package", file=sys.stderr)
 
-import mlir_standalone.ir
+from mlir_standalone.ir import *
 from mlir_standalone.dialects import standalone_nanobind as standalone_d
 
-with mlir_standalone.ir.Context():
+with Context():
     standalone_d.register_dialects()
-    standalone_module = mlir_standalone.ir.Module.parse(
+    module = Module.parse(
         """
     %0 = arith.constant 2 : i32
     %1 = standalone.foo %0 : i32
@@ -17,7 +17,7 @@
     )
     # CHECK: %[[C2:.*]] = arith.constant 2 : i32
     # CHECK: standalone.foo %[[C2]] : i32
-    print(str(standalone_module), file=sys.stderr)
+    print(str(module), file=sys.stderr)
 
 
 # CHECK: Testing mlir package
@@ -44,12 +44,3 @@
 )
 
 # CHECK-NOT: RuntimeWarning: nanobind: type '{{.*}}' was already registered!
-
-with mlir.ir.Context():
-    mlir_module = mlir.ir.Module.parse(
-        """
-    %0 = arith.constant 3 : i32
-    """
-    )
-    # CHECK: %[[C3:.*]] = arith.constant 3 : i32
-    print(str(mlir_module), file=sys.stderr)
diff --git a/mlir/test/Examples/standalone/test.wheel.toy b/mlir/test/Examples/standalone/test.wheel.toy
index e9232e3f16098..ebf26b26b4cba 100644
--- a/mlir/test/Examples/standalone/test.wheel.toy
+++ b/mlir/test/Examples/standalone/test.wheel.toy
@@ -38,7 +38,3 @@
 # CHECK: Testing mlir package
 
 # CHECK-NOT: RuntimeWarning: nanobind: type '{{.*}}' was already registered!
-
-# CHECK: module {
-# CHECK:   %[[C3:.*]] = arith.constant 3 : i32
-# CHECK: }

>From 190e8847cc91b2cc751a8903f2204cb98375e06c Mon Sep 17 00:00:00 2001
From: makslevental <maksim.levental at gmail.com>
Date: Wed, 31 Dec 2025 02:26:04 -0800
Subject: [PATCH 3/5] fixup

---
 mlir/cmake/modules/AddMLIR.cmake              |  9 +++++
 mlir/examples/standalone/CMakeLists.txt       |  3 ++
 mlir/examples/standalone/pyproject.toml       |  7 +++-
 .../standalone/test/python/smoketest.py       | 35 +++++++------------
 mlir/test/Examples/standalone/test.toy        |  1 +
 mlir/test/Examples/standalone/test.wheel.toy  |  6 ++++
 6 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake
index 6589458ab7894..92d558d86c754 100644
--- a/mlir/cmake/modules/AddMLIR.cmake
+++ b/mlir/cmake/modules/AddMLIR.cmake
@@ -445,6 +445,15 @@ function(add_mlir_library name)
       MLIR_AGGREGATE_DEP_LIBS_IMPORTED "${CURRENT_LINK_LIBRARIES}"
     )
 
+    # On MacOS, all template instantiations become weak symbols - this causes incorrect symbol
+    # resolution in cases where multiple aggregates are loaded in the same process (such as when multiple Python
+    # bindings packages are loaded, each with their own C API aggregate).
+    if(APPLE AND TARGET "obj.${name}" AND (NOT BUILD_SHARED_LIBS))
+      set_target_properties("obj.${name}" PROPERTIES
+        C_VISIBILITY_PRESET hidden
+        CXX_VISIBILITY_PRESET hidden
+        VISIBILITY_INLINES_HIDDEN YES)
+    endif()
     # In order for out-of-tree projects to build aggregates of this library,
     # we need to install the OBJECT library.
     if(TARGET "obj.${name}" AND MLIR_INSTALL_AGGREGATE_OBJECTS AND NOT ARG_DISABLE_INSTALL)
diff --git a/mlir/examples/standalone/CMakeLists.txt b/mlir/examples/standalone/CMakeLists.txt
index 955c9ec7a7b4c..17d712f6a1064 100644
--- a/mlir/examples/standalone/CMakeLists.txt
+++ b/mlir/examples/standalone/CMakeLists.txt
@@ -66,6 +66,9 @@ if(MLIR_ENABLE_BINDINGS_PYTHON)
   if(NOT MLIR_PYTHON_PACKAGE_PREFIX)
     set(MLIR_PYTHON_PACKAGE_PREFIX "mlir_standalone" CACHE STRING "" FORCE)
   endif()
+  if(NOT MLIR_BINDINGS_PYTHON_NB_DOMAIN)
+    set(MLIR_BINDINGS_PYTHON_NB_DOMAIN "mlir_standalone" CACHE STRING "" FORCE)
+  endif()
   if(NOT MLIR_BINDINGS_PYTHON_INSTALL_PREFIX)
     set(MLIR_BINDINGS_PYTHON_INSTALL_PREFIX "python_packages/standalone/${MLIR_PYTHON_PACKAGE_PREFIX}" CACHE STRING "" FORCE)
   endif()
diff --git a/mlir/examples/standalone/pyproject.toml b/mlir/examples/standalone/pyproject.toml
index c4194153743ef..8fc8d7d8266c3 100644
--- a/mlir/examples/standalone/pyproject.toml
+++ b/mlir/examples/standalone/pyproject.toml
@@ -6,7 +6,7 @@
 [project]
 name = "standalone-python-bindings"
 dynamic = ["version"]
-requires-python = ">=3.8,<=3.14"
+requires-python = ">=3.8"
 dependencies = [
     "numpy>=1.19.5, <=2.1.2",
     "PyYAML>=5.4.0, <=6.0.1",
@@ -56,9 +56,14 @@ MLIR_DIR = { env = "MLIR_DIR", default = "" }
 # Non-optional
 CMAKE_BUILD_TYPE = { env = "CMAKE_BUILD_TYPE", default = "Release" }
 MLIR_ENABLE_BINDINGS_PYTHON = "ON"
+
 # Effectively non-optional (any downstream project should specify this).
+MLIR_BINDINGS_PYTHON_NB_DOMAIN = "mlir_standalone"
 MLIR_PYTHON_PACKAGE_PREFIX = "mlir_standalone"
+
 # This specifies the directory in the install directory (i.e., /tmp/pip-wheel/platlib) where _mlir_libs, dialects, etc.
 # are installed. Thus, this will be the package location (and the name of the package) that pip assumes is
 # the root package.
 MLIR_BINDINGS_PYTHON_INSTALL_PREFIX = "mlir_standalone"
+# Optional
+MLIR_INCLUDE_TESTS = { env = "MLIR_INCLUDE_TESTS", default = "ON" }
diff --git a/mlir/examples/standalone/test/python/smoketest.py b/mlir/examples/standalone/test/python/smoketest.py
index 319251b063773..3ec0e7a33f233 100644
--- a/mlir/examples/standalone/test/python/smoketest.py
+++ b/mlir/examples/standalone/test/python/smoketest.py
@@ -4,12 +4,12 @@
 # CHECK: Testing mlir_standalone package
 print("Testing mlir_standalone package", file=sys.stderr)
 
-from mlir_standalone.ir import *
+import mlir_standalone.ir
 from mlir_standalone.dialects import standalone_nanobind as standalone_d
 
-with Context():
+with mlir_standalone.ir.Context():
     standalone_d.register_dialects()
-    module = Module.parse(
+    standalone_module = mlir_standalone.ir.Module.parse(
         """
     %0 = arith.constant 2 : i32
     %1 = standalone.foo %0 : i32
@@ -17,30 +17,21 @@
     )
     # CHECK: %[[C2:.*]] = arith.constant 2 : i32
     # CHECK: standalone.foo %[[C2]] : i32
-    print(str(module), file=sys.stderr)
+    print(str(standalone_module), file=sys.stderr)
 
 
 # CHECK: Testing mlir package
 print("Testing mlir package", file=sys.stderr)
 
 import mlir.ir
-from mlir.dialects import (
-    amdgpu,
-    gpu,
-    irdl,
-    llvm,
-    nvgpu,
-    pdl,
-    quant,
-    smt,
-    sparse_tensor,
-    transform,
-    # Note: uncommenting linalg below will cause
-    # LLVM ERROR: Attempting to attach an interface to an unregistered operation builtin.unrealized_conversion_cast.
-    # unless you have built both mlir and mlir_standalone with
-    # -DCMAKE_C_VISIBILITY_PRESET=hidden -DCMAKE_CXX_VISIBILITY_PRESET=hidden -DCMAKE_VISIBILITY_INLINES_HIDDEN=ON
-    # which is highly recommended.
-    # linalg,
-)
 
 # CHECK-NOT: RuntimeWarning: nanobind: type '{{.*}}' was already registered!
+
+with mlir.ir.Context():
+    mlir_module = mlir.ir.Module.parse(
+        """
+    %0 = arith.constant 3 : i32
+    """
+    )
+    # CHECK: %[[C3:.*]] = arith.constant 3 : i32
+    print(str(mlir_module), file=sys.stderr)
diff --git a/mlir/test/Examples/standalone/test.toy b/mlir/test/Examples/standalone/test.toy
index dc3c17f3da3d9..8836adde72ed8 100644
--- a/mlir/test/Examples/standalone/test.toy
+++ b/mlir/test/Examples/standalone/test.toy
@@ -4,6 +4,7 @@
 # RUN: -DLLVM_ENABLE_LIBCXX=%enable_libcxx -DMLIR_DIR=%mlir_cmake_dir \
 # RUN: -DLLVM_USE_LINKER=%llvm_use_linker \
 # RUN: -DMLIR_PYTHON_PACKAGE_PREFIX=mlir_standalone \
+# RUN: -DMLIR_BINDINGS_PYTHON_NB_DOMAIN=mlir_standalone \
 # RUN: -DMLIR_INCLUDE_TESTS=ON \
 # RUN: -DPython3_EXECUTABLE=%python \
 # RUN: -DPython_EXECUTABLE=%python
diff --git a/mlir/test/Examples/standalone/test.wheel.toy b/mlir/test/Examples/standalone/test.wheel.toy
index ebf26b26b4cba..68ad479de8395 100644
--- a/mlir/test/Examples/standalone/test.wheel.toy
+++ b/mlir/test/Examples/standalone/test.wheel.toy
@@ -15,6 +15,8 @@
 # RUN: export LLVM_USE_LINKER=%llvm_use_linker
 # RUN: export MLIR_DIR="%mlir_cmake_dir"
 # RUN: export MLIR_INCLUDE_TESTS=ON
+# RUN: export MLIR_PYTHON_PACKAGE_PREFIX=mlir_standalone
+# RUN: export MLIR_BINDINGS_PYTHON_NB_DOMAIN=mlir_standalone
 
 # RUN: %python -m pip wheel "%mlir_src_root/examples/standalone" -w "%mlir_obj_root/wheelhouse" -v | tee %t
 
@@ -38,3 +40,7 @@
 # CHECK: Testing mlir package
 
 # CHECK-NOT: RuntimeWarning: nanobind: type '{{.*}}' was already registered!
+
+# CHECK: module {
+# CHECK:   %[[C3:.*]] = arith.constant 3 : i32
+# CHECK: }

>From 10edd430f57e73620a7c9a13df44cef6e11877d5 Mon Sep 17 00:00:00 2001
From: makslevental <maksim.levental at gmail.com>
Date: Wed, 31 Dec 2025 12:01:16 -0800
Subject: [PATCH 4/5] dont create module

---
 mlir/examples/standalone/test/python/smoketest.py | 11 +----------
 mlir/test/Examples/standalone/test.wheel.toy      |  3 ---
 2 files changed, 1 insertion(+), 13 deletions(-)

diff --git a/mlir/examples/standalone/test/python/smoketest.py b/mlir/examples/standalone/test/python/smoketest.py
index 3ec0e7a33f233..09040eb2f45dc 100644
--- a/mlir/examples/standalone/test/python/smoketest.py
+++ b/mlir/examples/standalone/test/python/smoketest.py
@@ -23,15 +23,6 @@
 # CHECK: Testing mlir package
 print("Testing mlir package", file=sys.stderr)
 
-import mlir.ir
+from mlir.ir import *
 
 # CHECK-NOT: RuntimeWarning: nanobind: type '{{.*}}' was already registered!
-
-with mlir.ir.Context():
-    mlir_module = mlir.ir.Module.parse(
-        """
-    %0 = arith.constant 3 : i32
-    """
-    )
-    # CHECK: %[[C3:.*]] = arith.constant 3 : i32
-    print(str(mlir_module), file=sys.stderr)
diff --git a/mlir/test/Examples/standalone/test.wheel.toy b/mlir/test/Examples/standalone/test.wheel.toy
index 68ad479de8395..b60347ba687d0 100644
--- a/mlir/test/Examples/standalone/test.wheel.toy
+++ b/mlir/test/Examples/standalone/test.wheel.toy
@@ -41,6 +41,3 @@
 
 # CHECK-NOT: RuntimeWarning: nanobind: type '{{.*}}' was already registered!
 
-# CHECK: module {
-# CHECK:   %[[C3:.*]] = arith.constant 3 : i32
-# CHECK: }

>From dd3157636915626ce788c9ebeaaf018d2013fe94 Mon Sep 17 00:00:00 2001
From: makslevental <maksim.levental at gmail.com>
Date: Fri, 2 Jan 2026 10:36:15 -0800
Subject: [PATCH 5/5] remove vis attributes

---
 mlir/cmake/modules/AddMLIR.cmake        | 9 ---------
 mlir/examples/standalone/pyproject.toml | 6 +++---
 2 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake
index 92d558d86c754..6589458ab7894 100644
--- a/mlir/cmake/modules/AddMLIR.cmake
+++ b/mlir/cmake/modules/AddMLIR.cmake
@@ -445,15 +445,6 @@ function(add_mlir_library name)
       MLIR_AGGREGATE_DEP_LIBS_IMPORTED "${CURRENT_LINK_LIBRARIES}"
     )
 
-    # On MacOS, all template instantiations become weak symbols - this causes incorrect symbol
-    # resolution in cases where multiple aggregates are loaded in the same process (such as when multiple Python
-    # bindings packages are loaded, each with their own C API aggregate).
-    if(APPLE AND TARGET "obj.${name}" AND (NOT BUILD_SHARED_LIBS))
-      set_target_properties("obj.${name}" PROPERTIES
-        C_VISIBILITY_PRESET hidden
-        CXX_VISIBILITY_PRESET hidden
-        VISIBILITY_INLINES_HIDDEN YES)
-    endif()
     # In order for out-of-tree projects to build aggregates of this library,
     # we need to install the OBJECT library.
     if(TARGET "obj.${name}" AND MLIR_INSTALL_AGGREGATE_OBJECTS AND NOT ARG_DISABLE_INSTALL)
diff --git a/mlir/examples/standalone/pyproject.toml b/mlir/examples/standalone/pyproject.toml
index 8fc8d7d8266c3..4b9627a3ca582 100644
--- a/mlir/examples/standalone/pyproject.toml
+++ b/mlir/examples/standalone/pyproject.toml
@@ -58,12 +58,12 @@ CMAKE_BUILD_TYPE = { env = "CMAKE_BUILD_TYPE", default = "Release" }
 MLIR_ENABLE_BINDINGS_PYTHON = "ON"
 
 # Effectively non-optional (any downstream project should specify this).
-MLIR_BINDINGS_PYTHON_NB_DOMAIN = "mlir_standalone"
-MLIR_PYTHON_PACKAGE_PREFIX = "mlir_standalone"
+MLIR_BINDINGS_PYTHON_NB_DOMAIN = { env = "MLIR_BINDINGS_PYTHON_NB_DOMAIN", default = "mlir_standalone" }
+MLIR_PYTHON_PACKAGE_PREFIX = { env = "MLIR_PYTHON_PACKAGE_PREFIX", default = "mlir_standalone" }
 
 # This specifies the directory in the install directory (i.e., /tmp/pip-wheel/platlib) where _mlir_libs, dialects, etc.
 # are installed. Thus, this will be the package location (and the name of the package) that pip assumes is
 # the root package.
-MLIR_BINDINGS_PYTHON_INSTALL_PREFIX = "mlir_standalone"
+MLIR_BINDINGS_PYTHON_INSTALL_PREFIX = { env = "MLIR_BINDINGS_PYTHON_INSTALL_PREFIX", default = "mlir_standalone" }
 # Optional
 MLIR_INCLUDE_TESTS = { env = "MLIR_INCLUDE_TESTS", default = "ON" }



More information about the Mlir-commits mailing list