@@ -48,50 +48,84 @@ duckdb_add_library(duckdb_target)
4848
4949# Bundle in INTERFACE library
5050add_library (_duckdb_dependencies INTERFACE )
51- target_link_libraries (_duckdb_dependencies INTERFACE
52- pybind11::pybind11
53- duckdb_target
54- )
51+ target_link_libraries (_duckdb_dependencies INTERFACE pybind11::pybind11
52+ duckdb_target )
5553# Also add include directory
56- target_include_directories (_duckdb_dependencies INTERFACE
57- $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /src /duckdb_py /include >
54+ target_include_directories (
55+ _duckdb_dependencies
56+ INTERFACE $<BUILD_INTERFACE :${CMAKE_CURRENT_SOURCE_DIR} /src /duckdb_py /include >
5857)
5958
6059# ────────────────────────────────────────────
6160# Descend into the real DuckDB‑Python sources
6261# ────────────────────────────────────────────
6362add_subdirectory (src/duckdb_py )
6463
65- pybind11_add_module (_duckdb
66- $< TARGET_OBJECTS : python_src >
67- $<TARGET_OBJECTS :python_arrow >
68- $<TARGET_OBJECTS :python_common >
69- $<TARGET_OBJECTS :python_functional >
70- $<TARGET_OBJECTS :python_jupyter >
71- $<TARGET_OBJECTS :python_native >
72- $<TARGET_OBJECTS :python_numpy >
73- $<TARGET_OBJECTS :python_pandas >
74- $<TARGET_OBJECTS :python_pybind11 >
75- $<TARGET_OBJECTS :python_connection >
76- $<TARGET_OBJECTS :python_expression >
77- $<TARGET_OBJECTS :python_relation >
78- $<TARGET_OBJECTS :python_type >
79- )
64+ pybind11_add_module (
65+ _duckdb
66+ $<TARGET_OBJECTS :python_src >
67+ $<TARGET_OBJECTS :python_arrow >
68+ $<TARGET_OBJECTS :python_common >
69+ $<TARGET_OBJECTS :python_functional >
70+ $<TARGET_OBJECTS :python_jupyter >
71+ $<TARGET_OBJECTS :python_native >
72+ $<TARGET_OBJECTS :python_numpy >
73+ $<TARGET_OBJECTS :python_pandas >
74+ $<TARGET_OBJECTS :python_pybind11 >
75+ $<TARGET_OBJECTS :python_connection >
76+ $<TARGET_OBJECTS :python_expression >
77+ $<TARGET_OBJECTS :python_relation >
78+ $< TARGET_OBJECTS : python_type > )
8079# add _duckdb_dependencies
8180target_link_libraries (_duckdb PRIVATE _duckdb_dependencies )
8281
82+ # ────────────────────────────────────────────
83+ # Controlling symbol export
84+ #
85+ # We want to export exactly two symbols: - PyInit__duckdb: this allows CPython
86+ # to load the module - duckdb_adbc_init: the DuckDB ADBC driver
87+ #
88+ # The export of symbols on OSX and Linux is controlled by: - Visibility
89+ # annotations in the code (for this lib we use the PYBIND11_EXPORT macro) -
90+ # Telling the linker which symbols we want exported, which we do below
91+ #
92+ # For Windows, we rely on just the visbility annotations.
93+ # ────────────────────────────────────────────
94+ set_target_properties (
95+ _duckdb
96+ PROPERTIES CXX_VISIBILITY_PRESET hidden
97+ C_VISIBILITY_PRESET hidden
98+ VISIBILITY_INLINES_HIDDEN ON )
99+
100+ if (APPLE )
101+ target_link_options (
102+ _duckdb PRIVATE "LINKER:-exported_symbol,_duckdb_adbc_init"
103+ "LINKER:-exported_symbol,_PyInit__duckdb" )
104+ elseif (UNIX AND NOT APPLE )
105+ target_link_options (
106+ _duckdb PRIVATE "LINKER:--export-dynamic-symbol=duckdb_adbc_init"
107+ "LINKER:--export-dynamic-symbol=PyInit__duckdb" )
108+ elseif (WIN32 )
109+ target_link_options (_duckdb PRIVATE "/EXPORT:duckdb_adbc_init"
110+ "/EXPORT:PyInit__duckdb" )
111+ endif ()
112+
83113# ────────────────────────────────────────────
84114# Put the object file in the correct place
85115# ────────────────────────────────────────────
86116
87- # If we're not building through scikit-build-core then we have to set a different dest dir
117+ # If we're not building through scikit-build-core then we have to set a
118+ # different dest dir
88119include (GNUInstallDirs )
89120if (DEFINED SKBUILD_PLATLIB_DIR)
90121 set (_DUCKDB_PY_INSTALL_DIR "${SKBUILD_PLATLIB_DIR} " )
91122elseif (DEFINED Python_SITEARCH)
92123 set (_DUCKDB_PY_INSTALL_DIR "${Python_SITEARCH} " )
93124else ()
94- message (WARNING "Could not determine Python install dir. Falling back to CMAKE_INSTALL_LIBDIR." )
125+ message (
126+ WARNING
127+ "Could not determine Python install dir. Falling back to CMAKE_INSTALL_LIBDIR."
128+ )
95129 set (_DUCKDB_PY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR} " )
96130endif ()
97131
0 commit comments