Skip to content

Commit fa397d9

Browse files
committed
try to force inclusion with msvc and gcc as well
1 parent c9d37ac commit fa397d9

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ elseif(UNIX AND NOT APPLE)
105105
target_link_options(
106106
_duckdb PRIVATE "LINKER:--export-dynamic-symbol=duckdb_adbc_init"
107107
"LINKER:--export-dynamic-symbol=PyInit__duckdb")
108+
elseif(WIN32)
109+
target_link_options(_duckdb PRIVATE "/EXPORT:duckdb_adbc_init"
110+
"/EXPORT:PyInit__duckdb")
108111
endif()
109112

110113
# ────────────────────────────────────────────

src/duckdb_py/duckdb_python.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "duckdb_python/pybind11/conversions/python_udf_type_enum.hpp"
2121
#include "duckdb_python/pybind11/conversions/python_csv_line_terminator_enum.hpp"
2222
#include "duckdb/common/enums/statement_type.hpp"
23+
#include "duckdb/common/adbc/adbc-init.hpp"
2324

2425
#include "duckdb.hpp"
2526

@@ -1007,14 +1008,34 @@ static void RegisterExpectedResultType(py::handle &m) {
10071008
expected_return_type.export_values();
10081009
}
10091010

1010-
/**
1011-
* Fwd declaration of duckdb_adbc_init (the entrypoint of our ADBC driver) that must be exported.
1012-
*/
1013-
extern "C" PYBIND11_EXPORT void duckdb_adbc_init(void);
1011+
// ######################################################################
1012+
// Symbol exports
1013+
//
1014+
// We want to limit the symbols we export to only the absolute minimum.
1015+
// This means we compile with -fvisibility=hidden to hide all symbols,
1016+
// and then explicitly export only the symbols we want.
1017+
//
1018+
// Right now we export two symbols only:
1019+
// - duckdb_adbc_init: the entrypoint for our ADBC driver
1020+
// - PyInit__duckdb: the entrypoint for the python extension
1021+
//
1022+
// All symbols that need exporting must be added to both the list below
1023+
// AND to CMakeLists.txt.
1024+
extern "C" {
1025+
PYBIND11_EXPORT void *_force_symbol_inclusion() {
1026+
static void *symbols[] = {
1027+
// Add functions to export here
1028+
(void *)&duckdb_adbc_init,
1029+
};
1030+
return symbols;
1031+
}
1032+
};
10141033

10151034
PYBIND11_MODULE(DUCKDB_PYTHON_LIB_NAME, m) { // NOLINT
1016-
// Take address to force duckdb_adbc_init symbol inclusion
1017-
(void)&duckdb_adbc_init;
1035+
// DO NOT REMOVE: the below forces that we include all symbols we want to export
1036+
volatile auto *keep_alive = _force_symbol_inclusion();
1037+
(void)keep_alive;
1038+
// END
10181039

10191040
py::enum_<duckdb::ExplainType>(m, "ExplainType")
10201041
.value("STANDARD", duckdb::ExplainType::EXPLAIN_STANDARD)

0 commit comments

Comments
 (0)