Unverified Commit d933d65b authored by Lei Wang's avatar Lei Wang Committed by GitHub
Browse files

[Bugfix][Build] Update CMake configuration to remove project root injection for sys.path (#1385)

* [Build] Update CMake configuration for tilelang_cython_wrapper installation

- Adjusted output directories for the tilelang_cython_wrapper to ensure that development builds place the extension in build/lib.
- Updated installation paths to place the extension in tilelang/lib within the wheel, improving organization and avoiding potential conflicts with other modules.
- Modified the internal library path exposure in env.py to prevent shadowing of common module names, enhancing compatibility and usability in user projects.

* [Build] Standardize output directories for tilelang libraries

- Set output directories for both tilelang and tilelang_module libraries to "${CMAKE_BINARY_DIR}/lib" for consistency in development builds.
- This change enhances organization and ensures that all build artifacts are located in a unified directory structure.
parent 305c854b
...@@ -238,6 +238,18 @@ add_library(tilelang SHARED $<TARGET_OBJECTS:tilelang_objs>) ...@@ -238,6 +238,18 @@ add_library(tilelang SHARED $<TARGET_OBJECTS:tilelang_objs>)
add_library(tilelang_module SHARED $<TARGET_OBJECTS:tilelang_objs>) add_library(tilelang_module SHARED $<TARGET_OBJECTS:tilelang_objs>)
target_link_libraries(tilelang PUBLIC tvm_runtime tvm) target_link_libraries(tilelang PUBLIC tvm_runtime tvm)
target_link_libraries(tilelang_module PUBLIC tvm) target_link_libraries(tilelang_module PUBLIC tvm)
# Place dev build outputs under build/lib for consistency
set_target_properties(tilelang PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
)
set_target_properties(tilelang_module PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
)
# Build cython extension # Build cython extension
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_COMPONENT}) find_package(Python REQUIRED COMPONENTS Interpreter Development.Module ${SKBUILD_SABI_COMPONENT})
...@@ -257,11 +269,19 @@ if(NOT "${SKBUILD_SABI_VERSION}" STREQUAL "") ...@@ -257,11 +269,19 @@ if(NOT "${SKBUILD_SABI_VERSION}" STREQUAL "")
endif() endif()
python_add_library(tilelang_cython_wrapper MODULE "${CMAKE_BINARY_DIR}/tilelang_cython_wrapper.cpp" ${USE_SABI} WITH_SOABI) python_add_library(tilelang_cython_wrapper MODULE "${CMAKE_BINARY_DIR}/tilelang_cython_wrapper.cpp" ${USE_SABI} WITH_SOABI)
# Install extension into the tilelang package directory
# Ensure dev builds drop the extension into build/lib alongside other shared libs
set_target_properties(tilelang_cython_wrapper PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
)
# Install the extension into tilelang/lib inside the wheel
install(TARGETS tilelang_cython_wrapper install(TARGETS tilelang_cython_wrapper
LIBRARY DESTINATION tilelang LIBRARY DESTINATION tilelang/lib
RUNTIME DESTINATION tilelang RUNTIME DESTINATION tilelang/lib
ARCHIVE DESTINATION tilelang) ARCHIVE DESTINATION tilelang/lib)
# let libtilelang to search tvm/tvm_runtime in same dir # let libtilelang to search tvm/tvm_runtime in same dir
if(APPLE) if(APPLE)
......
...@@ -20,7 +20,9 @@ TL_TEMPLATE_NOT_FOUND_MESSAGE = ("TileLang is not installed or found in the expe ...@@ -20,7 +20,9 @@ TL_TEMPLATE_NOT_FOUND_MESSAGE = ("TileLang is not installed or found in the expe
TVM_LIBRARY_NOT_FOUND_MESSAGE = ("TVM is not installed or found in the expected path") TVM_LIBRARY_NOT_FOUND_MESSAGE = ("TVM is not installed or found in the expected path")
TL_ROOT = os.path.dirname(os.path.abspath(__file__)) TL_ROOT = os.path.dirname(os.path.abspath(__file__))
TL_LIBS = [TL_ROOT, os.path.join(TL_ROOT, 'lib')] # Only expose the internal lib directory to sys.path to avoid shadowing
# common top-level module names (e.g., utils, analysis) from user projects.
TL_LIBS = [os.path.join(TL_ROOT, 'lib')]
TL_LIBS = [i for i in TL_LIBS if os.path.exists(i)] TL_LIBS = [i for i in TL_LIBS if os.path.exists(i)]
DEV = False DEV = False
...@@ -30,7 +32,9 @@ if not os.path.exists(THIRD_PARTY_ROOT): ...@@ -30,7 +32,9 @@ if not os.path.exists(THIRD_PARTY_ROOT):
tl_dev_root = os.path.dirname(TL_ROOT) tl_dev_root = os.path.dirname(TL_ROOT)
dev_lib_root = os.path.join(tl_dev_root, 'build') dev_lib_root = os.path.join(tl_dev_root, 'build')
TL_LIBS = [dev_lib_root, os.path.join(dev_lib_root, 'tvm')] # In dev builds, place artifacts under build/lib and point search path there
# to avoid adding the entire build root to sys.path.
TL_LIBS = [os.path.join(dev_lib_root, 'lib'), os.path.join(dev_lib_root, 'tvm')]
THIRD_PARTY_ROOT = os.path.join(tl_dev_root, '3rdparty') THIRD_PARTY_ROOT = os.path.join(tl_dev_root, '3rdparty')
logger.warning(f'Loading tilelang libs from dev root: {dev_lib_root}') logger.warning(f'Loading tilelang libs from dev root: {dev_lib_root}')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment