Skip to content

Commit

Permalink
Explicit exports (#2118)
Browse files Browse the repository at this point in the history
* Integrate C and C++ examples into the main build so that they link properly

* Explicitly export symbols from the public API
  • Loading branch information
benjaminwinger committed Sep 30, 2023
1 parent 23e43b3 commit 9d99a95
Show file tree
Hide file tree
Showing 20 changed files with 160 additions and 155 deletions.
20 changes: 6 additions & 14 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,9 @@ jobs:
file: cover.info
functionalities: 'search'

- name: C Example
working-directory: examples/c
- name: C and C++ Examples
run: |
mkdir build -p
cd build
CC=gcc CXX=g++ cmake ..
cmake --build .
- name: C++ Example
working-directory: examples/cpp
run: |
mkdir build -p
cd build
CC=gcc CXX=g++ cmake ..
cmake --build .
CC=gcc CXX=g++ make example NUM_THREADS=32
rust-build-test:
name: rust build & test
Expand Down Expand Up @@ -195,6 +183,10 @@ jobs:
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
make javatest NUM_THREADS=18
- name: C and C++ Examples
run: |
make example NUM_THREADS=32
header-include-guard-check:
name: header include guard check
runs-on: kuzu-self-hosted-testing
Expand Down
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
cmake_minimum_required(VERSION 3.11)

project(Kuzu VERSION 0.0.8.12 LANGUAGES CXX)
project(Kuzu VERSION 0.0.8.12 LANGUAGES CXX C)

find_package(Threads REQUIRED)

set(CMAKE_FIND_PACKAGE_RESOLVE_SYMLINKS TRUE)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if (MSVC)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
endif()

# Detect OS and architecture, copied from DuckDB
set(OS_NAME "unknown")
Expand Down Expand Up @@ -124,6 +128,7 @@ option(BUILD_PYTHON_API "Build Python API." TRUE)
option(BUILD_SHELL "Build Interactive Shell" TRUE)
option(BUILD_TESTS "Build C++ and Python tests." FALSE)
option(BUILD_BENCHMARK "Build benchmarks." FALSE)
option(BUILD_EXAMPLES "Build examples." FALSE)

option(BUILD_LCOV "Build coverage report." FALSE)
if(${BUILD_LCOV})
Expand Down Expand Up @@ -233,3 +238,8 @@ elseif (${BUILD_BENCHMARK})
add_subdirectory(test/test_helper)
endif()
add_subdirectory(tools)

if (${BUILD_EXAMPLES})
add_subdirectory(examples/c)
add_subdirectory(examples/cpp)
endif()
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ debug:

all:
$(call mkdirp,build/release) && cd build/release && \
cmake $(GENERATOR) $(FORCE_COLOR) $(SANITIZER_FLAG) -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=TRUE -DBUILD_BENCHMARK=TRUE -DBUILD_NODEJS=TRUE ../.. && \
cmake $(GENERATOR) $(FORCE_COLOR) $(SANITIZER_FLAG) -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=TRUE -DBUILD_BENCHMARK=TRUE -DBUILD_NODEJS=TRUE -DBUILD_EXAMPLES=TRUE ../.. && \
cmake --build . --config Release

example:
$(call mkdirp,build/release) && cd build/release && \
cmake $(GENERATOR) $(FORCE_COLOR) $(SANITIZER_FLAG) -DCMAKE_BUILD_TYPE=Release -DBUILD_EXAMPLES=TRUE ../.. && \
cmake --build . --config Release

alldebug:
Expand Down
8 changes: 1 addition & 7 deletions examples/c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
cmake_minimum_required(VERSION 3.11)
project(example-c)

include_directories(../../src/include)
link_directories(../../build/release/src)

add_executable(example-c main.c)
target_link_libraries(example-c kuzu)
target_link_libraries(example-c kuzu_shared)
10 changes: 1 addition & 9 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
cmake_minimum_required(VERSION 3.11)
project(example-cpp)

set(CMAKE_CXX_STANDARD 20)

include_directories(../../src/include)
link_directories(../../build/release/src)

add_executable(example-cpp main.cpp)
target_link_libraries(example-cpp kuzu)
target_link_libraries(example-cpp kuzu_shared)
16 changes: 13 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
include_directories(${CMAKE_CURRENT_BINARY_DIR})
# Avoid the import annotation when building on windows
# Really this should be set per target,
# but the targets are split among many files and only the object files are linked against here
add_compile_definitions(kuzu_shared_EXPORTS)

add_subdirectory(binder)
add_subdirectory(c_api)
add_subdirectory(catalog)
Expand All @@ -18,12 +24,16 @@ target_link_libraries(kuzu
target_include_directories(kuzu
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
add_library(kuzu_shared SHARED ${ALL_OBJECT_FILES})
if(WIN32)
set_target_properties(kuzu_shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
else()
if(NOT WIN32)
set_target_properties(kuzu_shared PROPERTIES OUTPUT_NAME kuzu)
endif()
target_link_libraries(kuzu_shared
PUBLIC antlr4_cypher antlr4_runtime fast_float utf8proc re2 serd ${PARQUET_LIB} ${ARROW_LIB} Threads::Threads fastpfor miniparquet)
target_include_directories(kuzu_shared
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

include(GenerateExportHeader)
generate_export_header(kuzu_shared BASE_NAME kuzu EXPORT_MACRO_NAME KUZU_API STATIC_DEFINE KUZU_STATIC_DEFINE)
target_include_directories(kuzu PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(kuzu_shared PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
target_compile_definitions(kuzu PUBLIC KUZU_STATIC_DEFINE)
6 changes: 4 additions & 2 deletions src/include/c_api/kuzu.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <stdlib.h>
#include <string.h>

#include "common/api.h"

// The Arrow C data interface.
// https://arrow.apache.org/docs/format/CDataInterface.html

Expand Down Expand Up @@ -60,9 +62,9 @@ struct ArrowArray {
#endif

#ifdef __cplusplus
#define KUZU_C_API extern "C"
#define KUZU_C_API extern "C" KUZU_API
#else
#define KUZU_C_API
#define KUZU_C_API KUZU_API
#endif

/**
Expand Down
5 changes: 2 additions & 3 deletions src/include/common/api.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once

#ifndef KUZU_API
#define KUZU_API
#endif
// Generated by cmake
#include "kuzu_export.h"
2 changes: 1 addition & 1 deletion src/include/common/types/date_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace common {
struct timestamp_t;

// System representation of dates as the number of days since 1970-01-01.
KUZU_API struct date_t {
struct KUZU_API date_t {
int32_t days;

date_t();
Expand Down
2 changes: 1 addition & 1 deletion src/include/common/types/dtime_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace kuzu {
namespace common {

// Type used to represent time (microseconds)
KUZU_API struct dtime_t {
struct KUZU_API dtime_t {
int64_t micros;

dtime_t();
Expand Down
2 changes: 1 addition & 1 deletion src/include/common/types/internal_id_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ constexpr table_id_t INVALID_TABLE_ID = UINT64_MAX;
constexpr offset_t INVALID_OFFSET = UINT64_MAX;

// System representation for internalID.
KUZU_API struct internalID_t {
struct KUZU_API internalID_t {
offset_t offset;
table_id_t tableID;

Expand Down
4 changes: 2 additions & 2 deletions src/include/common/types/interval_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace common {
struct timestamp_t;
struct date_t;

KUZU_API enum class DatePartSpecifier : uint8_t {
enum class KUZU_API DatePartSpecifier : uint8_t {
YEAR,
MONTH,
DAY,
Expand All @@ -26,7 +26,7 @@ KUZU_API enum class DatePartSpecifier : uint8_t {
HOUR,
};

KUZU_API struct interval_t {
struct KUZU_API interval_t {
int32_t months = 0;
int32_t days = 0;
int64_t micros = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/include/common/types/timestamp_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace kuzu {
namespace common {

// Type used to represent timestamps (value is in microseconds since 1970-01-01)
KUZU_API struct timestamp_t {
struct KUZU_API timestamp_t {
int64_t value = 0;

timestamp_t();
Expand Down
2 changes: 1 addition & 1 deletion src/include/common/types/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct struct_entry_t {

using union_entry_t = struct_entry_t;

KUZU_API enum class LogicalTypeID : uint8_t {
enum class KUZU_API LogicalTypeID : uint8_t {
ANY = 0,
NODE = 10,
REL = 11,
Expand Down
Loading

0 comments on commit 9d99a95

Please sign in to comment.