Skip to content

Commit 98fc78d

Browse files
authored
Initial commit
0 parents  commit 98fc78d

22 files changed

+846
-0
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
duckdb/.editorconfig
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#
2+
# NOTE: this workflow is for testing the extension template itself,
3+
# this workflow will be removed when scripts/bootstrap-template.py is run
4+
#
5+
name: Extension Template
6+
on: [push, pull_request,repository_dispatch]
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || '' }}-${{ github.base_ref || '' }}-${{ github.ref != 'refs/heads/main' || github.sha }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
linux:
13+
name: Linux
14+
if: ${{ vars.RUN_RENAME_TEST == 'true' || github.repository == 'duckdb/extension-template' }}
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
# Add commits/tags to build against other DuckDB versions
19+
duckdb_version: [ '<submodule_version>' ]
20+
env:
21+
VCPKG_TOOLCHAIN_PATH: ${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake
22+
VCPKG_TARGET_TRIPLET: 'x64-linux'
23+
GEN: ninja
24+
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
25+
defaults:
26+
run:
27+
shell: bash
28+
29+
steps:
30+
- name: Install Ninja
31+
shell: bash
32+
run: sudo apt-get update -y -qq && sudo apt-get install -y -qq ninja-build
33+
34+
- uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
submodules: 'true'
38+
39+
- name: Checkout DuckDB to version
40+
if: ${{ matrix.duckdb_version != '<submodule_version>'}}
41+
run: |
42+
cd duckdb
43+
git checkout ${{ matrix.duckdb_version }}
44+
45+
- name: Setup vcpkg
46+
uses: lukka/[email protected]
47+
with:
48+
vcpkgGitCommitId: a1a1cbc975abf909a6c8985a6a2b8fe20bbd9bd6
49+
50+
- name: Rename extension
51+
run: |
52+
python3 scripts/bootstrap-template.py ext_1_a_123b_b11
53+
54+
- name: Build
55+
run: |
56+
make
57+
58+
- name: Test
59+
run: |
60+
make test
61+
62+
macos:
63+
name: MacOS
64+
if: ${{ vars.RUN_RENAME_TEST == 'true' || github.repository == 'duckdb/extension-template' }}
65+
runs-on: macos-latest
66+
strategy:
67+
matrix:
68+
# Add commits/tags to build against other DuckDB versions
69+
duckdb_version: [ '<submodule_version>']
70+
env:
71+
VCPKG_TOOLCHAIN_PATH: ${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake
72+
VCPKG_TARGET_TRIPLET: 'x64-osx'
73+
OSX_BUILD_ARCH: 'x86_64'
74+
GEN: ninja
75+
defaults:
76+
run:
77+
shell: bash
78+
79+
steps:
80+
- uses: actions/checkout@v4
81+
with:
82+
fetch-depth: 0
83+
submodules: 'true'
84+
85+
- name: Install Ninja
86+
run: brew install ninja
87+
88+
- uses: actions/setup-python@v2
89+
with:
90+
python-version: '3.11'
91+
92+
- name: Checkout DuckDB to version
93+
if: ${{ matrix.duckdb_version != '<submodule_version>'}}
94+
run: |
95+
cd duckdb
96+
git checkout ${{ matrix.duckdb_version }}
97+
98+
- name: Setup vcpkg
99+
uses: lukka/[email protected]
100+
with:
101+
vcpkgGitCommitId: a1a1cbc975abf909a6c8985a6a2b8fe20bbd9bd6
102+
103+
- name: Rename extension
104+
run: |
105+
python scripts/bootstrap-template.py ext_1_a_123b_b11
106+
107+
- name: Build
108+
run: |
109+
make
110+
111+
- name: Test
112+
run: |
113+
make test
114+
115+
windows:
116+
name: Windows
117+
if: ${{ vars.RUN_RENAME_TEST == 'true' || github.repository == 'duckdb/extension-template' }}
118+
runs-on: windows-latest
119+
strategy:
120+
matrix:
121+
# Add commits/tags to build against other DuckDB versions
122+
duckdb_version: [ '<submodule_version>' ]
123+
env:
124+
VCPKG_TOOLCHAIN_PATH: ${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake
125+
VCPKG_TARGET_TRIPLET: 'x64-windows-static-md'
126+
defaults:
127+
run:
128+
shell: bash
129+
130+
steps:
131+
- uses: actions/checkout@v4
132+
with:
133+
fetch-depth: 0
134+
submodules: 'true'
135+
136+
- uses: actions/setup-python@v2
137+
with:
138+
python-version: '3.11'
139+
140+
- name: Checkout DuckDB to version
141+
# Add commits/tags to build against other DuckDB versions
142+
if: ${{ matrix.duckdb_version != '<submodule_version>'}}
143+
run: |
144+
cd duckdb
145+
git checkout ${{ matrix.duckdb_version }}
146+
147+
- name: Setup vcpkg
148+
uses: lukka/[email protected]
149+
with:
150+
vcpkgGitCommitId: a1a1cbc975abf909a6c8985a6a2b8fe20bbd9bd6
151+
152+
- name: Rename extension
153+
run: |
154+
python scripts/bootstrap-template.py ext_1_a_123b_b11
155+
156+
- name: Build
157+
run: |
158+
make
159+
160+
- name: Test extension
161+
run: |
162+
build/release/test/Release/unittest.exe
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#
2+
# This workflow calls the main distribution pipeline from DuckDB to build, test and (optionally) release the extension
3+
#
4+
name: Main Extension Distribution Pipeline
5+
on:
6+
push:
7+
pull_request:
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || '' }}-${{ github.base_ref || '' }}-${{ github.ref != 'refs/heads/main' || github.sha }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
duckdb-next-build:
16+
name: Build extension binaries
17+
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main
18+
with:
19+
duckdb_version: main
20+
ci_tools_version: main
21+
extension_name: quack
22+
23+
duckdb-stable-build:
24+
name: Build extension binaries
25+
uses: duckdb/extension-ci-tools/.github/workflows/[email protected]
26+
with:
27+
duckdb_version: v1.1.3
28+
ci_tools_version: v1.1.3
29+
extension_name: quack

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build
2+
.idea
3+
cmake-build-debug
4+
duckdb_unittest_tempdir/
5+
.DS_Store
6+
testext
7+
test/python/__pycache__/
8+
.Rhistory

.gitmodules

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

CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
# Set extension name here
4+
set(TARGET_NAME quack)
5+
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)
10+
11+
set(EXTENSION_NAME ${TARGET_NAME}_extension)
12+
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
13+
14+
project(${TARGET_NAME})
15+
include_directories(src/include)
16+
17+
set(EXTENSION_SOURCES src/quack_extension.cpp)
18+
19+
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
20+
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
21+
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)
25+
26+
install(
27+
TARGETS ${EXTENSION_NAME}
28+
EXPORT "${DUCKDB_EXPORT_SET}"
29+
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
30+
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}")

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2018-2025 Stichting DuckDB Foundation
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
PROJ_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
2+
3+
# Configuration of extension
4+
EXT_NAME=quack
5+
EXT_CONFIG=${PROJ_DIR}extension_config.cmake
6+
7+
# Include the Makefile from extension-ci-tools
8+
include extension-ci-tools/makefiles/duckdb_extension.Makefile

docs/NEXT_README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Quack
2+
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.
4+
5+
---
6+
7+
This extension, Quack, allow you to ... <extension_goal>.
8+
9+
10+
## Building
11+
### 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:
13+
```shell
14+
git clone https://github.com/Microsoft/vcpkg.git
15+
./vcpkg/bootstrap-vcpkg.sh
16+
export VCPKG_TOOLCHAIN_PATH=`pwd`/vcpkg/scripts/buildsystems/vcpkg.cmake
17+
```
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.
19+
20+
### Build steps
21+
Now to build the extension, run:
22+
```sh
23+
make
24+
```
25+
The main binaries that will be built are:
26+
```sh
27+
./build/release/duckdb
28+
./build/release/test/unittest
29+
./build/release/extension/quack/quack.duckdb_extension
30+
```
31+
- `duckdb` is the binary for the duckdb shell with the extension code automatically loaded.
32+
- `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.
34+
35+
## Running the extension
36+
To run the extension code, simply start the shell with `./build/release/duckdb`.
37+
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:
39+
```
40+
D select quack('Jane') as result;
41+
┌───────────────┐
42+
│ result │
43+
│ varchar │
44+
├───────────────┤
45+
│ Quack Jane 🐥 │
46+
└───────────────┘
47+
```
48+
49+
## 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:
51+
```sh
52+
make test
53+
```
54+
55+
### Installing the deployed binaries
56+
To install your extension binaries from S3, you will need to do two things. Firstly, DuckDB should be launched with the
57+
`allow_unsigned_extensions` option set to true. How to set this will depend on the client you're using. Some examples:
58+
59+
CLI:
60+
```shell
61+
duckdb -unsigned
62+
```
63+
64+
Python:
65+
```python
66+
con = duckdb.connect(':memory:', config={'allow_unsigned_extensions' : 'true'})
67+
```
68+
69+
NodeJS:
70+
```js
71+
db = new duckdb.Database(':memory:', {"allow_unsigned_extensions": "true"});
72+
```
73+
74+
Secondly, you will need to set the repository endpoint in DuckDB to the HTTP url of your bucket + version of the extension
75+
you want to install. To do this run the following SQL query in DuckDB:
76+
```sql
77+
SET custom_extension_repository='bucket.s3.eu-west-1.amazonaws.com/<your_extension_name>/latest';
78+
```
79+
Note that the `/latest` path will allow you to install the latest extension version available for your current version of
80+
DuckDB. To specify a specific version, you can pass the version instead.
81+
82+
After running these steps, you can install and load your extension using the regular INSTALL/LOAD commands in DuckDB:
83+
```sql
84+
INSTALL quack
85+
LOAD quack
86+
```

0 commit comments

Comments
 (0)