Skip to content
Draft
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
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.25)

project(ClickHouse LANGUAGES C CXX ASM)

# chDB: set visibility to hidden for smaller chDB package
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)

# If turned off: e.g. when ENABLE_FOO is ON, but FOO tool was not found, the CMake will continue.
option(FAIL_ON_UNSUPPORTED_OPTIONS_COMBINATION
"Stop/Fail CMake configuration if some ENABLE_XXX option is defined (either ON or OFF)
Expand Down
41 changes: 9 additions & 32 deletions chdb/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ if [ "$(uname)" == "Darwin" ]; then
GLIBC_COMPATIBILITY="-DGLIBC_COMPATIBILITY=0"
UNWIND="-DUSE_UNWIND=0"
JEMALLOC="-DENABLE_JEMALLOC=0"
PYINIT_ENTRY="-Wl,-exported_symbol,_PyInit_${CHDB_PY_MOD}"
HDFS="-DENABLE_HDFS=0 -DENABLE_GSASL_LIBRARY=0 -DENABLE_KRB5=0"
MYSQL="-DENABLE_MYSQL=0"
ICU="-DENABLE_ICU=0"
Expand Down Expand Up @@ -54,7 +53,6 @@ elif [ "$(uname)" == "Linux" ]; then
GLIBC_COMPATIBILITY="-DGLIBC_COMPATIBILITY=1"
UNWIND="-DUSE_UNWIND=1"
JEMALLOC="-DENABLE_JEMALLOC=1"
PYINIT_ENTRY="-Wl,-ePyInit_${CHDB_PY_MOD}"
ICU="-DENABLE_ICU=1"
SED_INPLACE="sed -i"
# only x86_64, enable AVX, enable embedded compiler
Expand Down Expand Up @@ -153,16 +151,13 @@ if [ ! "${USING_RESPONSE_FILE}" == "" ]; then
${SED_INPLACE} 's/ '${CHDB_PY_MODULE}'/ '${LIBCHDB_SO}'/g' CMakeFiles/libchdb.rsp
fi

if [ "$(uname)" == "Linux" ]; then
LIBCHDB_CMD=$(echo ${LIBCHDB_CMD} | sed 's/ '${PYINIT_ENTRY}'/ /g')
if [ ! "${USING_RESPONSE_FILE}" == "" ]; then
${SED_INPLACE} 's/ '${PYINIT_ENTRY}'/ /g' CMakeFiles/libchdb.rsp
fi
fi

# Control exported symbols for libchdb.so
if [ "$(uname)" == "Darwin" ]; then
LIBCHDB_CMD=$(echo ${LIBCHDB_CMD} | sed 's/ '${PYINIT_ENTRY}'/ -Wl,-exported_symbol,_query_stable -Wl,-exported_symbol,_free_result -Wl,-exported_symbol,_query_stable_v2 -Wl,-exported_symbol,_free_result_v2/g')
# ${SED_INPLACE} 's/ '${PYINIT_ENTRY}'/ -Wl,-exported_symbol,_query_stable -Wl,-exported_symbol,_free_result -Wl,-exported_symbol,_query_stable_v2 -Wl,-exported_symbol,_free_result_v2/g' CMakeFiles/libchdb.rsp
# macOS: use exported_symbols_list file
LIBCHDB_CMD="${LIBCHDB_CMD} -Wl,-exported_symbols_list,${CHDB_DIR}/libchdb_export_macos.txt"
else
# Linux: use version script
LIBCHDB_CMD="${LIBCHDB_CMD} -Wl,--version-script=${CHDB_DIR}/libchdb_export.map"
fi

LIBCHDB_CMD=$(echo ${LIBCHDB_CMD} | sed 's/@CMakeFiles\/clickhouse.rsp/@CMakeFiles\/libchdb.rsp/g')
Expand Down Expand Up @@ -212,20 +207,13 @@ fi

# extract the command to generate CHDB_PY_MODULE
PYCHDB_CMD=$(grep -m 1 'clang++.*-o programs/clickhouse .*' build.log \
| sed "s/-o programs\/clickhouse/-fPIC -Wl,-undefined,dynamic_lookup -shared ${PYINIT_ENTRY} -o ${CHDB_PY_MODULE}/" \
| sed "s/-o programs\/clickhouse/-fPIC -Wl,-undefined,dynamic_lookup -shared -o ${CHDB_PY_MODULE}/" \
| sed 's/^[^&]*&& //' | sed 's/&&.*//' \
| sed 's/ -Wl,-undefined,error/ -Wl,-undefined,dynamic_lookup/g' \
| sed 's/ -Xlinker --no-undefined//g' \
| sed 's/@CMakeFiles\/clickhouse.rsp/@CMakeFiles\/pychdb.rsp/g' \
)


# # inplace modify the CMakeFiles/pychdb.rsp
# ${SED_INPLACE} 's/-o programs\/clickhouse/-fPIC -Wl,-undefined,dynamic_lookup -shared ${PYINIT_ENTRY} -o ${CHDB_PY_MODULE}/' CMakeFiles/pychdb.rsp
# ${SED_INPLACE} 's/ -Wl,-undefined,error/ -Wl,-undefined,dynamic_lookup/g' CMakeFiles/pychdb.rsp
# ${SED_INPLACE} 's/ -Xlinker --no-undefined//g' CMakeFiles/pychdb.rsp


if [ "$(uname)" == "Linux" ]; then
# remove src/CMakeFiles/clickhouse_malloc.dir/Common/stubFree.c.o
PYCHDB_CMD=$(echo ${PYCHDB_CMD} | sed 's/ src\/CMakeFiles\/clickhouse_malloc.dir\/Common\/stubFree.c.o//g')
Expand All @@ -239,8 +227,10 @@ fi

if [ "$(uname)" == "Darwin" ]; then
PYCHDB_CMD=$(echo ${PYCHDB_CMD} | sed 's|-Wl,-rpath,/[^[:space:]]*/pybind11-cmake|-Wl,-rpath,@loader_path|g')
PYCHDB_CMD="${PYCHDB_CMD} -Wl,-exported_symbols_list,${CHDB_DIR}/pychdb_export_macos.txt"
else
PYCHDB_CMD=$(echo ${PYCHDB_CMD} | sed 's|-Wl,-rpath,/[^[:space:]]*/pybind11-cmake|-Wl,-rpath,\$ORIGIN|g')
PYCHDB_CMD="${PYCHDB_CMD} -Wl,--undefined=PyInit__chdb -Wl,--version-script=${CHDB_DIR}/pychdb_export.map"
fi

# save the command to a file for debug
Expand Down Expand Up @@ -294,20 +284,7 @@ ${NM} ${LIBCHDB} | grep query_stable || true

echo -e "\nAfter copy:"
cd ${PROJ_DIR} && pwd
# ls -lh ${PROJ_DIR}

# strip the binary (no debug info at all)
# strip ${CHDB_DIR}/${CHDB_PY_MODULE} || true

# echo -e "\nAfter strip:"
# echo -e "\nLIBCHDB: ${PYCHDB}"
# ls -lh ${CHDB_DIR}
# echo -e "\nfile info of ${PYCHDB}"
# file ${CHDB_DIR}/${CHDB_PY_MODULE}

ccache -s || true

# bash ${DIR}/build_bind.sh
# bash ${DIR}/test_smoke.sh

CMAKE_ARGS="${CMAKE_ARGS}" bash ${DIR}/build_pybind11.sh --all
46 changes: 46 additions & 0 deletions chdb/libchdb_export.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
global:
/* Deprecated API */
query_stable;
free_result;
query_stable_v2;
free_result_v2;
connect_chdb;
close_conn;
query_conn;
query_conn_n;
query_conn_streaming;
query_conn_streaming_n;
chdb_streaming_result_error;
chdb_streaming_fetch_result;
chdb_streaming_cancel_query;
chdb_destroy_result;

/* New API */
chdb_connect;
chdb_close_conn;
chdb_query;
chdb_query_n;
chdb_query_cmdline;
chdb_stream_query;
chdb_stream_query_n;
chdb_stream_fetch_result;
chdb_stream_cancel_query;
chdb_destroy_query_result;
chdb_result_buffer;
chdb_result_length;
chdb_result_elapsed;
chdb_result_rows_read;
chdb_result_bytes_read;
chdb_result_storage_rows_read;
chdb_result_storage_bytes_read;
chdb_result_error;

/* Arrow Integration */
chdb_arrow_scan;
chdb_arrow_array_scan;
chdb_arrow_unregister_table;

local:
*;
};
40 changes: 40 additions & 0 deletions chdb/libchdb_export_macos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Deprecated API
_query_stable
_free_result
_query_stable_v2
_free_result_v2
_connect_chdb
_close_conn
_query_conn
_query_conn_n
_query_conn_streaming
_query_conn_streaming_n
_chdb_streaming_result_error
_chdb_streaming_fetch_result
_chdb_streaming_cancel_query
_chdb_destroy_result

# New API
_chdb_connect
_chdb_close_conn
_chdb_query
_chdb_query_n
_chdb_query_cmdline
_chdb_stream_query
_chdb_stream_query_n
_chdb_stream_fetch_result
_chdb_stream_cancel_query
_chdb_destroy_query_result
_chdb_result_buffer
_chdb_result_length
_chdb_result_elapsed
_chdb_result_rows_read
_chdb_result_bytes_read
_chdb_result_storage_rows_read
_chdb_result_storage_bytes_read
_chdb_result_error

# Arrow Integration
_chdb_arrow_scan
_chdb_arrow_array_scan
_chdb_arrow_unregister_table
21 changes: 21 additions & 0 deletions chdb/pychdb_export.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
global:
PyInit__chdb;

/* C++ operator new/delete (mangled names) */
_Znwm; /* operator new(size_t) */
_Znam; /* operator new[](size_t) */
_ZdlPv; /* operator delete(void*) */
_ZdaPv; /* operator delete[](void*) */
_ZdlPvm; /* operator delete(void*, size_t) */
_ZdaPvm; /* operator delete[](void*, size_t) */
_ZnwmSt11align_val_t; /* operator new(size_t, align_val_t) */
_ZnamSt11align_val_t; /* operator new[](size_t, align_val_t) */
_ZdlPvSt11align_val_t; /* operator delete(void*, align_val_t) */
_ZdaPvSt11align_val_t; /* operator delete[](void*, align_val_t) */
_ZdlPvmSt11align_val_t; /* operator delete(void*, size_t, align_val_t) */
_ZdaPvmSt11align_val_t; /* operator delete[](void*, size_t, align_val_t) */

local:
*;
};
1 change: 1 addition & 0 deletions chdb/pychdb_export_macos.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_PyInit__chdb
Loading