Skip to content

Commit 80ffbf1

Browse files
authored
[GLUTEN-8627][VL] Fix cpp build and build script on MacOS (#8628)
Fix the cpp compilation error and make builddeps-veloxbe.sh work on MacOS. Manually tested with ./dev/builddeps-veloxbe.sh --run_setup_script=ON --build_arrow=ON --build_type=Debug --build_tests=ON --build_examples=ON and also tested with switching OFF the build options and Release build type. Note --build_benchmarks=ON still fails because the function to set CPU affinity on macOS is not supported. I will fix that in a separate patch.
1 parent cd7c790 commit 80ffbf1

File tree

5 files changed

+67
-18
lines changed

5 files changed

+67
-18
lines changed

cpp/core/CMakeLists.txt

+19
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ endif(CCACHE_FOUND)
5252
macro(find_protobuf)
5353
set(CMAKE_FIND_LIBRARY_SUFFIXES_BCK ${CMAKE_FIND_LIBRARY_SUFFIXES})
5454
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
55+
56+
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
57+
# brew --prefix protobuf will not return the correct path. Update `brew
58+
# --prefix protobuf@21` if protobuf version is changed.
59+
execute_process(
60+
COMMAND brew --prefix protobuf@21
61+
RESULT_VARIABLE BREW_PROTOBUF
62+
OUTPUT_VARIABLE BREW_PROTOBUF_PREFIX
63+
OUTPUT_STRIP_TRAILING_WHITESPACE)
64+
if(BREW_PROTOBUF EQUAL 0 AND EXISTS "${BREW_PROTOBUF_PREFIX}")
65+
message(
66+
STATUS "Found protobuf installed by Homebrew at ${BREW_PROTOBUF_PREFIX}"
67+
)
68+
list(APPEND CMAKE_PREFIX_PATH "${BREW_PROTOBUF_PREFIX}")
69+
else()
70+
message(WARNING "Homebrew protobuf not found.")
71+
endif()
72+
endif()
73+
5574
find_package(Protobuf)
5675
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_BCK})
5776
if("${Protobuf_LIBRARY}" STREQUAL "Protobuf_LIBRARY-NOTFOUND")

cpp/velox/CMakeLists.txt

+20-11
Original file line numberDiff line numberDiff line change
@@ -282,18 +282,27 @@ endif()
282282

283283
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_BCK})
284284

285-
set(icu_components i18n uc data)
286-
foreach(component ${icu_components})
287-
find_library(ICU_${component}_LIB NAMES icu${component})
288-
if(NOT ICU_${component}_LIB)
289-
message(FATAL_ERROR "icu${component} library not found")
285+
# Adopted from Velox's CMakeLists.txt.
286+
# https://github.com/facebookincubator/velox/pull/11410
287+
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
288+
execute_process(
289+
COMMAND brew --prefix icu4c
290+
RESULT_VARIABLE BREW_ICU4C
291+
OUTPUT_VARIABLE BREW_ICU4C_PREFIX
292+
OUTPUT_STRIP_TRAILING_WHITESPACE)
293+
if(BREW_ICU4C EQUAL 0 AND EXISTS "${BREW_ICU4C_PREFIX}")
294+
message(STATUS "Found icu4c installed by Homebrew at ${BREW_ICU4C_PREFIX}")
295+
list(APPEND CMAKE_PREFIX_PATH "${BREW_ICU4C_PREFIX}")
296+
else()
297+
list(APPEND CMAKE_PREFIX_PATH "/usr/local/opt/icu4c")
290298
endif()
291-
message(STATUS "Found ICU::${component}: ${ICU_${component}_LIB}")
292-
add_library(ICU::${component} UNKNOWN IMPORTED)
293-
set_target_properties(ICU::${component} PROPERTIES IMPORTED_LOCATION
294-
${ICU_${component}_LIB})
295-
target_link_libraries(velox PUBLIC ICU::${component})
296-
endforeach()
299+
endif()
300+
301+
find_package(
302+
ICU
303+
COMPONENTS i18n uc data
304+
REQUIRED)
305+
target_link_libraries(velox PUBLIC ICU::i18n ICU::uc ICU::data)
297306

298307
if(BUILD_TESTS)
299308
add_subdirectory(tests)

cpp/velox/tests/FunctionTest.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ TEST_F(FunctionTest, getIdxFromNodeName) {
7373

7474
TEST_F(FunctionTest, getNameBeforeDelimiter) {
7575
std::string functionSpec = "lte:fp64_fp64";
76-
std::string_view funcName = SubstraitParser::getNameBeforeDelimiter(functionSpec);
76+
auto funcName = SubstraitParser::getNameBeforeDelimiter(functionSpec);
7777
ASSERT_EQ(funcName, "lte");
7878

7979
functionSpec = "lte:";

cpp/velox/tests/VeloxRowToColumnarTest.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class VeloxRowToColumnarTest : public ::testing::Test, public test::VectorTestBa
4343
uint8_t* address = columnarToRowConverter->getBufferAddress();
4444
auto lengthVec = columnarToRowConverter->getLengths();
4545

46-
long lengthArr[lengthVec.size()];
46+
int64_t lengthArr[lengthVec.size()];
4747
for (int i = 0; i < lengthVec.size(); i++) {
4848
lengthArr[i] = lengthVec[i];
4949
}

dev/builddeps-veloxbe.sh

+26-5
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,32 @@ function build_gluten_cpp {
198198
rm -rf build
199199
mkdir build
200200
cd build
201-
cmake -DBUILD_VELOX_BACKEND=ON -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
202-
-DVELOX_HOME=${VELOX_HOME} \
203-
-DBUILD_TESTS=$BUILD_TESTS -DBUILD_EXAMPLES=$BUILD_EXAMPLES -DBUILD_BENCHMARKS=$BUILD_BENCHMARKS -DENABLE_JEMALLOC_STATS=$ENABLE_JEMALLOC_STATS \
204-
-DENABLE_HBM=$ENABLE_HBM -DENABLE_QAT=$ENABLE_QAT -DENABLE_IAA=$ENABLE_IAA -DENABLE_GCS=$ENABLE_GCS \
205-
-DENABLE_S3=$ENABLE_S3 -DENABLE_HDFS=$ENABLE_HDFS -DENABLE_ABFS=$ENABLE_ABFS ..
201+
202+
GLUTEN_CMAKE_OPTIONS="-DBUILD_VELOX_BACKEND=ON \
203+
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
204+
-DVELOX_HOME=$VELOX_HOME \
205+
-DBUILD_TESTS=$BUILD_TESTS \
206+
-DBUILD_EXAMPLES=$BUILD_EXAMPLES \
207+
-DBUILD_BENCHMARKS=$BUILD_BENCHMARKS \
208+
-DENABLE_JEMALLOC_STATS=$ENABLE_JEMALLOC_STATS \
209+
-DENABLE_HBM=$ENABLE_HBM \
210+
-DENABLE_QAT=$ENABLE_QAT \
211+
-DENABLE_IAA=$ENABLE_IAA \
212+
-DENABLE_GCS=$ENABLE_GCS \
213+
-DENABLE_S3=$ENABLE_S3 \
214+
-DENABLE_HDFS=$ENABLE_HDFS \
215+
-DENABLE_ABFS=$ENABLE_ABFS"
216+
217+
if [ $OS == 'Darwin' ]; then
218+
if [ -n "$INSTALL_PREFIX" ]; then
219+
DEPS_INSTALL_DIR=$INSTALL_PREFIX
220+
else
221+
DEPS_INSTALL_DIR=$VELOX_HOME/deps-install
222+
fi
223+
GLUTEN_CMAKE_OPTIONS+=" -DCMAKE_PREFIX_PATH=$DEPS_INSTALL_DIR"
224+
fi
225+
226+
cmake $GLUTEN_CMAKE_OPTIONS ..
206227
make -j $NUM_THREADS
207228
}
208229

0 commit comments

Comments
 (0)