Skip to content

Commit 0a16d1a

Browse files
authored
[MLIR][Python] fix standalone example/test (#156197)
Fix some things in `standalone` in order to unblock #155741.
1 parent 1956941 commit 0a16d1a

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

mlir/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ configure_file(
191191

192192
set(MLIR_BINDINGS_PYTHON_NB_DOMAIN "mlir"
193193
CACHE STRING "nanobind domain for MLIR python bindings.")
194+
set(MLIR_PYTHON_PACKAGE_PREFIX "mlir"
195+
CACHE STRING "Specifies that all MLIR packages are co-located under the
196+
`MLIR_PYTHON_PACKAGE_PREFIX` top level package (the API has been
197+
embedded in a relocatable way).")
194198
set(MLIR_ENABLE_BINDINGS_PYTHON 0 CACHE BOOL
195199
"Enables building of Python bindings.")
196200
set(MLIR_BINDINGS_PYTHON_INSTALL_PREFIX "python_packages/mlir_core/mlir" CACHE STRING

mlir/examples/standalone/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ add_subdirectory(include)
5252
add_subdirectory(lib)
5353
if(MLIR_ENABLE_BINDINGS_PYTHON)
5454
message(STATUS "Enabling Python API")
55+
include(MLIRDetectPythonEnv)
56+
mlir_configure_python_dev_packages()
57+
set(MLIR_PYTHON_PACKAGE_PREFIX "mlir_standalone" CACHE STRING "" FORCE)
58+
set(MLIR_BINDINGS_PYTHON_INSTALL_PREFIX "python_packages/standalone/mlir_standalone" CACHE STRING "" FORCE)
5559
add_subdirectory(python)
5660
endif()
5761
add_subdirectory(test)

mlir/examples/standalone/python/CMakeLists.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ include(AddMLIRPython)
22

33
# Specifies that all MLIR packages are co-located under the `mlir_standalone`
44
# top level package (the API has been embedded in a relocatable way).
5-
# TODO: Add an upstream cmake param for this vs having a global here.
6-
add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=mlir_standalone.")
5+
add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=${MLIR_PYTHON_PACKAGE_PREFIX}.")
76

87

98
################################################################################
@@ -49,30 +48,32 @@ declare_mlir_python_extension(StandalonePythonSources.NanobindExtension
4948

5049
add_mlir_python_common_capi_library(StandalonePythonCAPI
5150
INSTALL_COMPONENT StandalonePythonModules
52-
INSTALL_DESTINATION python_packages/standalone/mlir_standalone/_mlir_libs
53-
OUTPUT_DIRECTORY "${MLIR_BINARY_DIR}/python_packages/standalone/mlir_standalone/_mlir_libs"
51+
INSTALL_DESTINATION "${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}/_mlir_libs"
52+
OUTPUT_DIRECTORY "${MLIR_BINARY_DIR}/${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}/_mlir_libs"
5453
RELATIVE_INSTALL_ROOT "../../../.."
5554
DECLARED_SOURCES
5655
StandalonePythonSources
5756
# TODO: Remove this in favor of showing fine grained registration once
5857
# available.
5958
MLIRPythonExtension.RegisterEverything
6059
MLIRPythonSources.Core
60+
MLIRPythonSources.Dialects.builtin
6161
)
6262

6363
################################################################################
6464
# Instantiation of all Python modules
6565
################################################################################
6666

6767
add_mlir_python_modules(StandalonePythonModules
68-
ROOT_PREFIX "${MLIR_BINARY_DIR}/python_packages/standalone/mlir_standalone"
69-
INSTALL_PREFIX "python_packages/standalone/mlir_standalone"
68+
ROOT_PREFIX "${MLIR_BINARY_DIR}/${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}"
69+
INSTALL_PREFIX "${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}"
7070
DECLARED_SOURCES
7171
StandalonePythonSources
7272
# TODO: Remove this in favor of showing fine grained registration once
7373
# available.
7474
MLIRPythonExtension.RegisterEverything
75-
MLIRPythonSources
75+
MLIRPythonSources.Core
76+
MLIRPythonSources.Dialects.builtin
7677
COMMON_CAPI_LINK_LIBS
7778
StandalonePythonCAPI
7879
)

mlir/test/Examples/standalone/test.toy

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
# RUN: -DCMAKE_CXX_COMPILER=%host_cxx -DCMAKE_C_COMPILER=%host_cc \
33
# RUN: -DLLVM_ENABLE_LIBCXX=%enable_libcxx -DMLIR_DIR=%mlir_cmake_dir \
44
# RUN: -DLLVM_USE_LINKER=%llvm_use_linker \
5-
# RUN: -DPython3_EXECUTABLE=%python
6-
# RUN: "%cmake_exe" --build . --target check-standalone | tee %t | FileCheck %s
5+
# RUN: -DPython3_EXECUTABLE=%python \
6+
# RUN: -DPython_EXECUTABLE=%python
7+
# RUN: "%cmake_exe" --build . --target check-standalone | tee %t
8+
# RUN: FileCheck --input-file=%t %s
79

810
# Note: The number of checked tests is not important. The command will fail
911
# if any fail.
1012
# CHECK: Passed
13+
# CHECK-NOT: Failed
1114
# UNSUPPORTED: target={{.*(windows|android).*}}

0 commit comments

Comments
 (0)