Skip to content

Commit

Permalink
Move pyarrow detection to get_arrow.cmake so that it also affects C++…
Browse files Browse the repository at this point in the history
… builds
  • Loading branch information
vyasr committed Dec 5, 2023
1 parent d29aecc commit ff42ca3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
3 changes: 0 additions & 3 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ option(
)
mark_as_advanced(CUDF_BUILD_STREAMS_TEST_UTIL)

option(USE_LIBARROW_FROM_PYARROW "Use the libarrow contained within pyarrow." OFF)
mark_as_advanced(USE_LIBARROW_FROM_PYARROW)

message(VERBOSE "CUDF: Build with NVTX support: ${USE_NVTX}")
message(VERBOSE "CUDF: Configure CMake to build tests: ${BUILD_TESTS}")
message(VERBOSE "CUDF: Configure CMake to build (google & nvbench) benchmarks: ${BUILD_BENCHMARKS}")
Expand Down
36 changes: 32 additions & 4 deletions cpp/cmake/thirdparty/get_arrow.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function(find_libarrow_in_python_wheel PYARROW_VERSION)
# `${MINOR_VERSION}${PATCH_VERSION}` is almost always equivalent to "00"),
# the soname is not generated by concatenating the major, minor, and patch versions into a single
# version number soname, just `${MAJOR_VERSION}00`
set(PYARROW_LIB "libarrow.so.${PYARROW_SO_VER}00")
set(PYARROW_LIB "libarrow.${CMAKE_SHARED_LIBRARY_SUFFIX}.${PYARROW_SO_VER}00")

execute_process(
COMMAND "${Python_EXECUTABLE}" -c "import pyarrow; print(pyarrow.get_library_dirs()[0])"
Expand Down Expand Up @@ -90,10 +90,10 @@ endfunction()

# This function finds arrow and sets any additional necessary environment variables.
function(find_and_configure_arrow VERSION BUILD_STATIC ENABLE_S3 ENABLE_ORC ENABLE_PYTHON
ENABLE_PARQUET
ENABLE_PARQUET PYARROW_LIBARROW
)

if(USE_LIBARROW_FROM_PYARROW)
if(PYARROW_LIBARROW)
# Generate a FindArrow.cmake to find pyarrow's libarrow.so
find_libarrow_in_python_wheel(${VERSION})
set(ARROW_FOUND
Expand Down Expand Up @@ -431,7 +431,35 @@ if(NOT DEFINED CUDF_VERSION_Arrow)
)
endif()

# If the pyarrow package contains libarrow we want to link against it directly instead of searching
# for a separate libarrow. Even if libcudf was built against a different libarrow, that library
# would have to be ABI-compatible with the one in pyarrow for the packages to work together, and for
# wheels we must use the library in the pyarrow wheel, so it's best to simply be consistent.
find_package(Python 3.9 COMPONENTS Interpreter)

if (${Python_FOUND})
execute_process(
COMMAND "${Python_EXECUTABLE}" -c "import importlib; print(importlib.util.find_spec('pyarrow') is not None)"
OUTPUT_VARIABLE _pyarrow_installed
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (${_pyarrow_installed} STREQUAL "True")
execute_process(
COMMAND "${Python_EXECUTABLE}" -c "import pyarrow; print(pyarrow.get_library_dirs()[0])"
OUTPUT_VARIABLE _pyarrow_lib_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
)
file(GLOB _pyarrow_libs "${_pyarrow_lib_dir}/libarrow.${CMAKE_SHARED_LIBRARY_SUFFIX}*")
list(LENGTH _pyarrow_libs _pyarrow_libs_len)
if(_pyarrow_libs_len GREATER 0)
set(USE_LIBARROW_FROM_PYARROW ON)
else()
set(USE_LIBARROW_FROM_PYARROW OFF)
endif()
endif()
endif()

find_and_configure_arrow(
${CUDF_VERSION_Arrow} ${CUDF_USE_ARROW_STATIC} ${CUDF_ENABLE_ARROW_S3} ${CUDF_ENABLE_ARROW_ORC}
${CUDF_ENABLE_ARROW_PYTHON} ${CUDF_ENABLE_ARROW_PARQUET}
${CUDF_ENABLE_ARROW_PYTHON} ${CUDF_ENABLE_ARROW_PARQUET} ${USE_LIBARROW_FROM_PYARROW}
)
18 changes: 1 addition & 17 deletions python/cudf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,9 @@ option(FIND_CUDF_CPP "Search for existing CUDF C++ installations before defaulti
OFF
)

# If the pyarrow package contains libarrow we want to link against it directly instead of searching
# for a separate libarrow. Even if libcudf was built against a different libarrow, that library
# would have to be ABI-compatible with the one in pyarrow for the packages to work together, and for
# wheels we must use the library in the pyarrow wheel.
# Find Python early so that later commands can use it
find_package(Python 3.9 REQUIRED COMPONENTS Interpreter)

execute_process(
COMMAND "${Python_EXECUTABLE}" -c "import pyarrow; print(pyarrow.get_library_dirs()[0])"
OUTPUT_VARIABLE _pyarrow_lib_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
)
file(GLOB _pyarrow_libs "${_pyarrow_lib_dir}/libarrow.${CMAKE_SHARED_LIBRARY_SUFFIX}*")
list(LENGTH _pyarrow_libs _pyarrow_libs_len)
if(_pyarrow_libs_len GREATER 0)
set(USE_LIBARROW_FROM_PYARROW ON)
else()
set(USE_LIBARROW_FROM_PYARROW OFF)
endif()

# If the user requested it we attempt to find CUDF.
if(FIND_CUDF_CPP)
# We need to find arrow before libcudf since libcudf requires it but doesn't bundle arrow
Expand Down

0 comments on commit ff42ca3

Please sign in to comment.