diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake --- a/mlir/cmake/modules/AddMLIRPython.cmake +++ b/mlir/cmake/modules/AddMLIRPython.cmake @@ -229,12 +229,20 @@ get_filename_component(_install_path "${ARG_INSTALL_PREFIX}/${_dest_relative_path}" DIRECTORY) file(MAKE_DIRECTORY "${_dest_dir}") + + # On Windows create_symlink requires special permissions. Use copy_if_different instead. + if(CMAKE_HOST_WIN32) + set(_link_or_copy copy_if_different) + else() + set(_link_or_copy create_symlink) + endif() + add_custom_command( TARGET ${modules_target} PRE_BUILD COMMENT "Copying python source ${_src_path} -> ${_dest_path}" DEPENDS "${_src_path}" BYPRODUCTS "${_dest_path}" - COMMAND "${CMAKE_COMMAND}" -E create_symlink + COMMAND "${CMAKE_COMMAND}" -E ${_link_or_copy} "${_src_path}" "${_dest_path}" ) install( @@ -285,7 +293,7 @@ endforeach() # Create an install target. - if (NOT LLVM_ENABLE_IDE) + if(NOT LLVM_ENABLE_IDE) add_llvm_install_targets( install-${name} DEPENDS ${name} @@ -483,10 +491,10 @@ "INSTALL_COMPONENT;INSTALL_DIR;OUTPUT_DIRECTORY" "SOURCES;LINK_LIBS" ${ARGN}) - if (ARG_UNPARSED_ARGUMENTS) + if(ARG_UNPARSED_ARGUMENTS) message(FATAL_ERROR " Unhandled arguments to add_mlir_python_extension(${libname}, ... : ${ARG_UNPARSED_ARGUMENTS}") endif() - if ("${ARG_SOURCES}" STREQUAL "") + if("${ARG_SOURCES}" STREQUAL "") message(FATAL_ERROR " Missing SOURCES argument to add_mlir_python_extension(${libname}, ...") endif() @@ -527,12 +535,9 @@ ) endif() - # Python extensions depends *only* on the public API and LLVMSupport unless - # if further dependencies are added explicitly. target_link_libraries(${libname} PRIVATE ${ARG_LINK_LIBS} - ${PYEXT_LIBADD} ) target_link_options(${libname} @@ -545,7 +550,7 @@ ################################################################################ # Install ################################################################################ - if (ARG_INSTALL_DIR) + if(ARG_INSTALL_DIR) install(TARGETS ${libname} COMPONENT ${ARG_INSTALL_COMPONENT} LIBRARY DESTINATION ${ARG_INSTALL_DIR} diff --git a/mlir/test/lit.cfg.py b/mlir/test/lit.cfg.py --- a/mlir/test/lit.cfg.py +++ b/mlir/test/lit.cfg.py @@ -94,6 +94,10 @@ # TODO: detect Darwin/Windows situation (or mark these tests as unsupported on these platforms). if "asan" in config.available_features and "Linux" in config.host_os: python_executable = f"LD_PRELOAD=$({config.host_cxx} -print-file-name=libclang_rt.asan-{config.host_arch}.so) {config.python_executable}" +# On Windows the path to python could contains spaces in which case it needs to be provided in quotes. +# This is the equivalent of how %python is setup in llvm/utils/lit/lit/llvm/config.py. +elif "Windows" in config.host_os: + python_executable = '"%s"' % (python_executable) tools.extend([ ToolSubst('%PYTHON', python_executable, unresolved='ignore'), ]) diff --git a/mlir/test/python/dialects/shape.py b/mlir/test/python/dialects/shape.py --- a/mlir/test/python/dialects/shape.py +++ b/mlir/test/python/dialects/shape.py @@ -23,7 +23,7 @@ RankedTensorType.get((12, -1), f32)) def const_shape_tensor(arg): return shape.ConstShapeOp( - DenseElementsAttr.get(np.array([10, 20]), type=IndexType.get())) + DenseElementsAttr.get(np.array([10, 20], dtype=np.int64), type=IndexType.get())) # CHECK-LABEL: func @const_shape_tensor(%arg0: tensor<12x?xf32>) # CHECK: shape.const_shape [10, 20] : tensor<2xindex> diff --git a/mlir/test/python/execution_engine.py b/mlir/test/python/execution_engine.py --- a/mlir/test/python/execution_engine.py +++ b/mlir/test/python/execution_engine.py @@ -345,13 +345,21 @@ arg0_memref_ptr = ctypes.pointer( ctypes.pointer(get_ranked_memref_descriptor(arg0))) + if sys.platform == 'win32': + shared_libs = [ + "../../../../bin/mlir_runner_utils.dll", + "../../../../bin/mlir_c_runner_utils.dll" + ] + else: + shared_libs = [ + "../../../../lib/libmlir_runner_utils.so", + "../../../../lib/libmlir_c_runner_utils.so" + ] + execution_engine = ExecutionEngine( lowerToLLVM(module), opt_level=3, - shared_libs=[ - "../../../../lib/libmlir_runner_utils.so", - "../../../../lib/libmlir_c_runner_utils.so" - ]) + shared_libs=shared_libs) execution_engine.invoke("main", arg0_memref_ptr) # CHECK: Unranked Memref # CHECK-NEXT: [42] @@ -379,13 +387,21 @@ func.func private @printMemrefI64(memref<*xi64>) attributes { llvm.emit_c_interface } }""") + if sys.platform == 'win32': + shared_libs = [ + "../../../../bin/mlir_runner_utils.dll", + "../../../../bin/mlir_c_runner_utils.dll" + ] + else: + shared_libs = [ + "../../../../lib/libmlir_runner_utils.so", + "../../../../lib/libmlir_c_runner_utils.so" + ] + execution_engine = ExecutionEngine( lowerToLLVM(module), opt_level=3, - shared_libs=[ - "../../../../lib/libmlir_runner_utils.so", - "../../../../lib/libmlir_c_runner_utils.so" - ]) + shared_libs=shared_libs) execution_engine.invoke("main") # CHECK: Unranked Memref # CHECK: [{{.*}}]