Skip to content

Commit 92b7229

Browse files
committed
add duckdb extension
1 parent e9c2134 commit 92b7229

33 files changed

+1592
-497
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ duckdb_unittest_tempdir/
66
testext
77
test/python/__pycache__/
88
.Rhistory
9+
compile_commands.json
10+
11+
#proto gen folder
12+
gen/

.gitmodules

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
[submodule "duckdb"]
2-
path = duckdb
3-
url = https://github.com/duckdb/duckdb
4-
branch = main
51
[submodule "extension-ci-tools"]
62
path = extension-ci-tools
73
url = https://github.com/duckdb/extension-ci-tools
4+
branch = main
5+
[submodule "vortex"]
6+
path = vortex
7+
url = https://github.com/spiraldb/vortex
88
branch = main

CMakeLists.txt

Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,93 @@
1-
cmake_minimum_required(VERSION 3.5)
1+
cmake_minimum_required(VERSION 3.22)
22

3-
# Set extension name here
4-
set(TARGET_NAME quack)
3+
set(TARGET_NAME vortex)
4+
project(${TARGET_NAME}_project)
55

6-
# DuckDB's extension distribution supports vcpkg. As such, dependencies can be added in ./vcpkg.json and then
7-
# used in cmake with find_package. Feel free to remove or replace with other dependencies.
8-
# Note that it should also be removed from vcpkg.json to prevent needlessly installing it..
9-
find_package(OpenSSL REQUIRED)
6+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
7+
set(CMAKE_CXX_STANDARD 20)
8+
9+
include(FetchContent)
10+
FetchContent_Declare(
11+
Corrosion
12+
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
13+
GIT_TAG v0.5.1
14+
)
15+
FetchContent_Declare(
16+
vcpkg
17+
GIT_REPOSITORY https://github.com/microsoft/vcpkg.git
18+
GIT_TAG 2025.03.19
19+
)
20+
FetchContent_MakeAvailable(Corrosion)
21+
FetchContent_MakeAvailable(vcpkg)
22+
23+
# Install vcpkg dependencies.
24+
execute_process(
25+
COMMAND bash ./bootstrap-vcpkg.sh -disableMetrics
26+
WORKING_DIRECTORY "${vcpkg_SOURCE_DIR}"
27+
RESULT_VARIABLE VCPKG_BOOTSTRAP_RESULT
28+
)
29+
set(VCPKG_INSTALL_DIR "${CMAKE_BINARY_DIR}/vcpkg_installed")
30+
file(MAKE_DIRECTORY "${VCPKG_INSTALL_DIR}")
31+
execute_process(
32+
COMMAND "${vcpkg_SOURCE_DIR}/vcpkg" install --no-print-usage --x-manifest-root=${CMAKE_CURRENT_SOURCE_DIR}/vcpkg --x-install-root=${VCPKG_INSTALL_DIR}
33+
WORKING_DIRECTORY "${vcpkg_SOURCE_DIR}"
34+
)
35+
36+
if (APPLE AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
37+
set(CMAKE_PREFIX_PATH ${VCPKG_INSTALL_DIR}/arm64-osx)
38+
elseif (APPLE)
39+
set(CMAKE_PREFIX_PATH ${VCPKG_INSTALL_DIR}/x64-osx)
40+
elseif (UNIX AND NOT APPLE)
41+
set(CMAKE_PREFIX_PATH ${VCPKG_INSTALL_DIR}/x64-linux)
42+
endif ()
43+
44+
find_package(Catch2 CONFIG REQUIRED)
45+
find_package(Protobuf CONFIG REQUIRED)
46+
if (APPLE)
47+
find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation)
48+
find_library(SECURITY_FRAMEWORK Security)
49+
endif ()
50+
51+
corrosion_import_crate(MANIFEST_PATH vortex/Cargo.toml
52+
# CORROSION_TOOLS_RUST_TOOLCHAIN "nightly-2025-02-24"
53+
CRATES vortex-ffi
54+
FEATURES duckdb
55+
IMPORTED_CRATES vortex_ffi
56+
)
1057

1158
set(EXTENSION_NAME ${TARGET_NAME}_extension)
59+
set(EXTENSION_SOURCES src/vortex_extension.cpp src/expr/expr.cpp src/vortex_write.cpp src/vortex_scan.cpp)
1260
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
1361

14-
project(${TARGET_NAME})
15-
include_directories(src/include)
62+
# Generate C++ code from .proto files.
63+
file(GLOB PROTO_FILES "vortex/vortex-proto/proto/*.proto")
64+
set(PROTO_GEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/gen)
65+
file(MAKE_DIRECTORY ${PROTO_GEN_DIR})
66+
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_FILES} PROTOC_OUT_DIR ${PROTO_GEN_DIR})
67+
68+
include_directories(src/include ${PROTO_GEN_DIR} vortex/vortex-ffi/cinclude)
1669

17-
set(EXTENSION_SOURCES src/quack_extension.cpp)
70+
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES} ${PROTO_SRCS})
71+
build_loadable_extension(${TARGET_NAME} ${EXTENSION_SOURCES} ${PROTO_SRCS})
1872

19-
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
20-
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
73+
target_link_libraries(${EXTENSION_NAME}
74+
vortex_ffi-static
75+
protobuf::libprotobuf
76+
${CORE_FOUNDATION_FRAMEWORK}
77+
${SECURITY_FRAMEWORK}
78+
)
79+
target_link_libraries(${LOADABLE_EXTENSION_NAME}
80+
vortex_ffi-shared
81+
protobuf::libprotobuf
82+
${CORE_FOUNDATION_FRAMEWORK}
83+
${SECURITY_FRAMEWORK}
84+
)
2185

22-
# Link OpenSSL in both the static library as the loadable extension
23-
target_link_libraries(${EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto)
24-
target_link_libraries(${LOADABLE_EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto)
86+
add_subdirectory(test)
2587

2688
install(
27-
TARGETS ${EXTENSION_NAME}
28-
EXPORT "${DUCKDB_EXPORT_SET}"
29-
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
30-
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}")
89+
TARGETS ${EXTENSION_NAME}
90+
EXPORT "${DUCKDB_EXPORT_SET}"
91+
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
92+
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
93+
)

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
PROJ_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
22

33
# Configuration of extension
4-
EXT_NAME=quack
4+
EXT_NAME=vortex_duckdb
55
EXT_CONFIG=${PROJ_DIR}extension_config.cmake
6+
EXT_FLAGS=-DDISABLE_VPTR_SANITIZER=ON -DOVERRIDE_GIT_DESCRIBE=v1.2.2
7+
EXT_FLAGS += -DCMAKE_OSX_DEPLOYMENT_TARGET=13.0
8+
9+
export MACOSX_DEPLOYMENT_TARGET=13.0
10+
export VCPKG_OSX_DEPLOYMENT_TARGET=13.0
11+
export VCPKG_FEATURE_FLAGS=-binarycaching
612

713
# Include the Makefile from extension-ci-tools
8-
include extension-ci-tools/makefiles/duckdb_extension.Makefile
14+
include extension-ci-tools/makefiles/duckdb_extension.Makefile
Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,124 @@
1-
# Quack
1+
# VortexDuckdb
22

3-
This repository is based on https://github.com/duckdb/extension-template, check it out if you want to build and ship your own DuckDB extension.
3+
This repository is based on https://github.com/duckdb/extension-template, check it out if you want to build and ship
4+
your own DuckDB extension.
45

56
---
67

7-
This extension, Quack, allow you to ... <extension_goal>.
8-
8+
This extension, VortexDuckdb, allow you to ... <extension_goal>.
99

1010
## Building
11+
12+
### Install required system dependencies
13+
14+
#### MacOS
15+
16+
```shell
17+
brew install pkg-config
18+
```
19+
1120
### Managing dependencies
12-
DuckDB extensions uses VCPKG for dependency management. Enabling VCPKG is very simple: follow the [installation instructions](https://vcpkg.io/en/getting-started) or just run the following:
21+
22+
DuckDB extensions uses VCPKG for dependency management. Enabling VCPKG is very simple: follow
23+
the [installation instructions](https://vcpkg.io/en/getting-started) or just run the following:
24+
1325
```shell
1426
git clone https://github.com/Microsoft/vcpkg.git
1527
./vcpkg/bootstrap-vcpkg.sh
1628
export VCPKG_TOOLCHAIN_PATH=`pwd`/vcpkg/scripts/buildsystems/vcpkg.cmake
1729
```
18-
Note: VCPKG is only required for extensions that want to rely on it for dependency management. If you want to develop an extension without dependencies, or want to do your own dependency management, just skip this step. Note that the example extension uses VCPKG to build with a dependency for instructive purposes, so when skipping this step the build may not work without removing the dependency.
30+
31+
Note: VCPKG is only required for extensions that want to rely on it for dependency management. If you want to develop an
32+
extension without dependencies, or want to do your own dependency management, just skip this step. Note that the example
33+
extension uses VCPKG to build with a dependency for instructive purposes, so when skipping this step the build may not
34+
work without removing the dependency.
1935

2036
### Build steps
37+
2138
Now to build the extension, run:
39+
2240
```sh
2341
make
2442
```
43+
2544
The main binaries that will be built are:
45+
2646
```sh
2747
./build/release/duckdb
2848
./build/release/test/unittest
29-
./build/release/extension/quack/quack.duckdb_extension
49+
./build/release/extension/vortex_duckdb/vortex_duckdb.duckdb_extension
3050
```
51+
3152
- `duckdb` is the binary for the duckdb shell with the extension code automatically loaded.
3253
- `unittest` is the test runner of duckdb. Again, the extension is already linked into the binary.
33-
- `quack.duckdb_extension` is the loadable binary as it would be distributed.
54+
- `vortex_duckdb.duckdb_extension` is the loadable binary as it would be distributed.
3455

3556
## Running the extension
57+
3658
To run the extension code, simply start the shell with `./build/release/duckdb`.
3759

38-
Now we can use the features from the extension directly in DuckDB. The template contains a single scalar function `quack()` that takes a string arguments and returns a string:
60+
Now we can use the features from the extension directly in DuckDB. The template contains a single scalar function
61+
`vortex_duckdb()` that takes a string arguments and returns a string:
62+
3963
```
40-
D select quack('Jane') as result;
64+
D select vortex_duckdb('Jane') as result;
4165
┌───────────────┐
4266
│ result │
4367
│ varchar │
4468
├───────────────┤
45-
Quack Jane 🐥 │
69+
VortexDuckdb Jane 🐥 │
4670
└───────────────┘
4771
```
4872

4973
## Running the tests
50-
Different tests can be created for DuckDB extensions. The primary way of testing DuckDB extensions should be the SQL tests in `./test/sql`. These SQL tests can be run using:
74+
75+
Different tests can be created for DuckDB extensions. The primary way of testing DuckDB extensions should be the SQL
76+
tests in `./test/sql`. These SQL tests can be run using:
77+
5178
```sh
5279
make test
5380
```
5481

5582
### Installing the deployed binaries
83+
5684
To install your extension binaries from S3, you will need to do two things. Firstly, DuckDB should be launched with the
5785
`allow_unsigned_extensions` option set to true. How to set this will depend on the client you're using. Some examples:
5886

5987
CLI:
88+
6089
```shell
6190
duckdb -unsigned
6291
```
6392

6493
Python:
94+
6595
```python
66-
con = duckdb.connect(':memory:', config={'allow_unsigned_extensions' : 'true'})
96+
con = duckdb.connect(':memory:', config={'allow_unsigned_extensions': 'true'})
6797
```
6898

6999
NodeJS:
100+
70101
```js
71102
db = new duckdb.Database(':memory:', {"allow_unsigned_extensions": "true"});
72103
```
73104

74-
Secondly, you will need to set the repository endpoint in DuckDB to the HTTP url of your bucket + version of the extension
105+
Secondly, you will need to set the repository endpoint in DuckDB to the HTTP url of your bucket + version of the
106+
extension
75107
you want to install. To do this run the following SQL query in DuckDB:
108+
76109
```sql
77-
SET custom_extension_repository='bucket.s3.eu-west-1.amazonaws.com/<your_extension_name>/latest';
110+
SET
111+
custom_extension_repository='bucket.s3.eu-west-1.amazonaws.com/<your_extension_name>/latest';
78112
```
79-
Note that the `/latest` path will allow you to install the latest extension version available for your current version of
113+
114+
Note that the `/latest` path will allow you to install the latest extension version available for your current version
115+
of
80116
DuckDB. To specify a specific version, you can pass the version instead.
81117

82118
After running these steps, you can install and load your extension using the regular INSTALL/LOAD commands in DuckDB:
119+
83120
```sql
84-
INSTALL quack
85-
LOAD quack
121+
INSTALL
122+
vortex_duckdb
123+
LOAD vortex_duckdb
86124
```

0 commit comments

Comments
 (0)