Skip to content

Commit 83f8f57

Browse files
committed
fix static binding
1 parent 7d3ed62 commit 83f8f57

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

CMakeLists.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,34 @@ build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
4444

4545
# Create list of libraries in correct order for static linking
4646
set(STATIC_LIBS
47+
-Wl,--whole-archive
4748
${WVLET_STATIC_PATH}
49+
-Wl,--no-whole-archive
50+
# Runtime dependencies
51+
${CMAKE_DL_LIBS}
52+
-pthread
4853
OpenSSL::Crypto
4954
OpenSSL::SSL
5055
)
5156

5257
# For static extension, use static library with correct link order
5358
target_link_libraries(${EXTENSION_NAME}
54-
${WVLET_DYNAMIC_PATH}
59+
# ${WVLET_DYNAMIC_PATH}
5560
${STATIC_LIBS}
5661
)
5762

5863
# For loadable extension, use dynamic library
59-
target_link_libraries(${LOADABLE_EXTENSION_NAME}
60-
OpenSSL::SSL
61-
OpenSSL::Crypto
64+
target_link_libraries(${LOADABLE_EXTENSION_NAME}
65+
OpenSSL::SSL
66+
OpenSSL::Crypto
6267
${WVLET_DYNAMIC_PATH}
6368
)
6469

6570
# Set link flags to ensure proper symbol resolution
6671
set_target_properties(${EXTENSION_NAME} PROPERTIES
67-
LINK_FLAGS "-Wl,--no-as-needed"
72+
LINK_FLAGS "-Wl,--no-as-needed -Wl,-z,now -Wl,--export-dynamic"
73+
ENABLE_EXPORTS ON
74+
POSITION_INDEPENDENT_CODE ON
6875
)
6976

7077
install(

src/wvlet_extension.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,42 @@
1010
#include <sstream>
1111
#include <stdexcept>
1212

13+
#ifdef __cplusplus
1314
extern "C" {
14-
int wvlet_compile_main(const char*);
15-
const char* wvlet_compile_compile(const char*);
15+
#endif
16+
extern int ScalaNativeInit(void);
17+
18+
extern int wvlet_compile_main(const char*);
19+
extern const char* wvlet_compile_compile(const char*);
20+
21+
#ifdef __cplusplus
1622
}
23+
#endif
1724

1825
namespace duckdb {
1926

27+
// EXPERIMENT INIT
28+
bool InitializeWvletRuntime() {
29+
try {
30+
// Set heap sizes via environment variables
31+
setenv("GC_INITIAL_HEAP_SIZE", "2097152", 1); // 64MB
32+
setenv("GC_MAXIMUM_HEAP_SIZE", "8388608", 1); // 256MB
33+
34+
// fprintf(stderr, "Initializing Scala Native Runtime...\n");
35+
int init_result = ScalaNativeInit();
36+
if (init_result != 0) {
37+
fprintf(stderr, "Failed to initialize Scala Native Runtime: %d\n", init_result);
38+
return false;
39+
}
40+
41+
// fprintf(stderr, "Scala Native Runtime initialized successfully!\n");
42+
return true;
43+
} catch (...) {
44+
fprintf(stderr, "Scala Runtime Initialization failed with exception!\n");
45+
return false;
46+
}
47+
}
48+
2049
void WvletScriptFunction::ParseWvletScript(DataChunk &args, ExpressionState &state, Vector &result) {
2150
auto &input_vector = args.data[0];
2251
auto input = FlatVector::GetData<string_t>(input_vector);
@@ -130,6 +159,10 @@ static void LoadInternal(DatabaseInstance &instance) {
130159

131160
void WvletExtension::Load(DuckDB &db) {
132161
LoadInternal(*db.instance);
162+
// EXPERIMENT
163+
if (!InitializeWvletRuntime()) {
164+
throw std::runtime_error("Failed to initialize Wvlet runtime");
165+
}
133166
}
134167

135168
std::string WvletExtension::Name() {

0 commit comments

Comments
 (0)