Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,6 @@ if(BUDDY_MLIR_ENABLE_RISCV_GNU_TOOLCHAIN)
)
endif()

#-------------------------------------------------------------------------------
# Initialize Python packages
#-------------------------------------------------------------------------------
if(BUDDY_MLIR_ENABLE_PYTHON_PACKAGES)
# Find the Python interpreter and development components,
# requiring a minimum version of 3.10
find_package(Python3 3.10 REQUIRED COMPONENTS Interpreter Development)
# Create directories for the BUDDY-MLIR Python packages
file(MAKE_DIRECTORY ${BUDDY_MLIR_PYTHON_PACKAGES_DIR}/buddy)
file(MAKE_DIRECTORY ${BUDDY_MLIR_PYTHON_PACKAGES_DIR}/buddy/compiler)
# Create empty __init__.py files to make these directories Python packages
file(WRITE ${BUDDY_MLIR_PYTHON_PACKAGES_DIR}/buddy/__init__.py "")
file(WRITE ${BUDDY_MLIR_PYTHON_PACKAGES_DIR}/buddy/compiler/__init__.py "")

install(DIRECTORY ${BUDDY_MLIR_PYTHON_PACKAGES_DIR}/buddy DESTINATION python_packages)
endif()

#-------------------------------------------------------------------------------
# Directory setup
#-------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ set(BUDDY_EXAMPLES_DEPENDS
mlir-runner
)

if(BUDDY_MLIR_ENABLE_PYTHON_PACKAGES)
list(APPEND BUDDY_TEST_DEPENDS BuddyMLIRPythonModules)
if(BUDDY_MLIR_ENABLE_PYTHON_PACKAGES AND MLIR_ENABLE_BINDINGS_PYTHON)
list(APPEND BUDDY_TEST_DEPENDS python-package-buddy-mlir)
endif()

add_lit_testsuite(check-examples "Checking the buddy-mlir examples..."
Expand Down
40 changes: 34 additions & 6 deletions frontend/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
# Find the Python interpreter and module development components,
# requiring a minimum version of 3.10
find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED COMPONENTS Interpreter Development.Module)

set(BUDDY_MLIR_PYTHON_PACKAGES_DIR ${CMAKE_BINARY_DIR}/python_packages)

# Create directories for the BUDDY-MLIR Python packages
file(MAKE_DIRECTORY ${BUDDY_MLIR_PYTHON_PACKAGES_DIR}/buddy)
file(MAKE_DIRECTORY ${BUDDY_MLIR_PYTHON_PACKAGES_DIR}/buddy/compiler)
# Create empty __init__.py files to make these directories Python packages
file(WRITE ${BUDDY_MLIR_PYTHON_PACKAGES_DIR}/buddy/__init__.py "")
file(WRITE ${BUDDY_MLIR_PYTHON_PACKAGES_DIR}/buddy/compiler/__init__.py "")

# Recursively retrieve all python files from the current directory.
file(GLOB_RECURSE ALL_PY_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.py")

set(PYTHON_OUTPUT_FILES "")
foreach(FILE ${ALL_PY_FILES})
# Get the directory of the current file.
get_filename_component(DIR "${FILE}" DIRECTORY)
# Set the destination directory for the target file.
set(DEST "${BUDDY_MLIR_PYTHON_PACKAGES_DIR}/buddy/compiler/${DIR}")
# Copy the file into the destination directory.
file(COPY ${FILE} DESTINATION ${DEST})
get_filename_component(REL_DIR "${FILE}" DIRECTORY)
set(SRC "${CMAKE_CURRENT_SOURCE_DIR}/${FILE}")
set(DEST_DIR "${BUDDY_MLIR_PYTHON_PACKAGES_DIR}/buddy/compiler/${REL_DIR}")
set(DEST_FILE "${BUDDY_MLIR_PYTHON_PACKAGES_DIR}/buddy/compiler/${FILE}")

add_custom_command(
OUTPUT "${DEST_FILE}"
COMMAND ${CMAKE_COMMAND} -E make_directory "${DEST_DIR}"
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SRC}" "${DEST_FILE}"
DEPENDS "${SRC}"
COMMENT "Syncing ${FILE}"
VERBATIM
)

list(APPEND PYTHON_OUTPUT_FILES "${DEST_FILE}")
endforeach()

add_custom_target(python-package-buddy
ALL DEPENDS ${PYTHON_OUTPUT_FILES}
COMMENT "Syncing python package files"
)
2 changes: 2 additions & 0 deletions midend/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ add_mlir_python_modules(BuddyMLIRPythonModules
BuddyMLIRPythonCAPI
MLIRPythonCAPI
)

add_custom_target(python-package-buddy-mlir DEPENDS BuddyMLIRPythonModules)
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if(BUDDY_MLIR_ENABLE_DIP_LIB)
endif()

if(BUDDY_MLIR_ENABLE_PYTHON_PACKAGES)
list(APPEND BUDDY_TEST_DEPENDS BuddyMLIRPythonModules)
list(APPEND BUDDY_TEST_DEPENDS python-package-buddy-mlir)
endif()

add_lit_testsuite(check-tests "Running the buddy regression tests..."
Expand Down Expand Up @@ -59,6 +59,7 @@ if(BUDDY_ENABLE_E2E_TESTS)
buddy-translate
mlir-runner
buddy-lenet-run-test-cpu
python-package-buddy
)

add_lit_testsuite(check-e2e "Running E2E tests for Models directory..."
Expand Down
Loading