Skip to content

Commit

Permalink
fix static binding
Browse files Browse the repository at this point in the history
  • Loading branch information
lmangani committed Nov 24, 2024
1 parent 7d3ed62 commit 83f8f57
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
17 changes: 12 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,34 @@ build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})

# Create list of libraries in correct order for static linking
set(STATIC_LIBS
-Wl,--whole-archive
${WVLET_STATIC_PATH}
-Wl,--no-whole-archive
# Runtime dependencies
${CMAKE_DL_LIBS}
-pthread
OpenSSL::Crypto
OpenSSL::SSL
)

# For static extension, use static library with correct link order
target_link_libraries(${EXTENSION_NAME}
${WVLET_DYNAMIC_PATH}
# ${WVLET_DYNAMIC_PATH}
${STATIC_LIBS}
)

# For loadable extension, use dynamic library
target_link_libraries(${LOADABLE_EXTENSION_NAME}
OpenSSL::SSL
OpenSSL::Crypto
target_link_libraries(${LOADABLE_EXTENSION_NAME}
OpenSSL::SSL
OpenSSL::Crypto
${WVLET_DYNAMIC_PATH}
)

# Set link flags to ensure proper symbol resolution
set_target_properties(${EXTENSION_NAME} PROPERTIES
LINK_FLAGS "-Wl,--no-as-needed"
LINK_FLAGS "-Wl,--no-as-needed -Wl,-z,now -Wl,--export-dynamic"
ENABLE_EXPORTS ON
POSITION_INDEPENDENT_CODE ON
)

install(
Expand Down
37 changes: 35 additions & 2 deletions src/wvlet_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,42 @@
#include <sstream>
#include <stdexcept>

#ifdef __cplusplus
extern "C" {
int wvlet_compile_main(const char*);
const char* wvlet_compile_compile(const char*);
#endif
extern int ScalaNativeInit(void);

extern int wvlet_compile_main(const char*);
extern const char* wvlet_compile_compile(const char*);

#ifdef __cplusplus
}
#endif

namespace duckdb {

// EXPERIMENT INIT
bool InitializeWvletRuntime() {
try {
// Set heap sizes via environment variables
setenv("GC_INITIAL_HEAP_SIZE", "2097152", 1); // 64MB
setenv("GC_MAXIMUM_HEAP_SIZE", "8388608", 1); // 256MB

// fprintf(stderr, "Initializing Scala Native Runtime...\n");
int init_result = ScalaNativeInit();
if (init_result != 0) {
fprintf(stderr, "Failed to initialize Scala Native Runtime: %d\n", init_result);
return false;
}

// fprintf(stderr, "Scala Native Runtime initialized successfully!\n");
return true;
} catch (...) {
fprintf(stderr, "Scala Runtime Initialization failed with exception!\n");
return false;
}
}

void WvletScriptFunction::ParseWvletScript(DataChunk &args, ExpressionState &state, Vector &result) {
auto &input_vector = args.data[0];
auto input = FlatVector::GetData<string_t>(input_vector);
Expand Down Expand Up @@ -130,6 +159,10 @@ static void LoadInternal(DatabaseInstance &instance) {

void WvletExtension::Load(DuckDB &db) {
LoadInternal(*db.instance);
// EXPERIMENT
if (!InitializeWvletRuntime()) {
throw std::runtime_error("Failed to initialize Wvlet runtime");
}
}

std::string WvletExtension::Name() {
Expand Down

0 comments on commit 83f8f57

Please sign in to comment.