generated from duckdb/extension-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 69c3418
Showing
22 changed files
with
837 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
duckdb/.editorconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
# | ||
# NOTE: this workflow is for testing the extension template itself, | ||
# this workflow will be removed when scripts/bootstrap-template.py is run | ||
# | ||
name: Extension Template | ||
on: [push, pull_request,repository_dispatch] | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || '' }}-${{ github.base_ref || '' }}-${{ github.ref != 'refs/heads/main' || github.sha }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
linux: | ||
name: Linux | ||
if: ${{ vars.RUN_RENAME_TEST == 'true' || github.repository == 'duckdb/extension-template' }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
# Add commits/tags to build against other DuckDB versions | ||
duckdb_version: [ '<submodule_version>' ] | ||
env: | ||
VCPKG_TOOLCHAIN_PATH: ${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake | ||
VCPKG_TARGET_TRIPLET: 'x64-linux' | ||
GEN: ninja | ||
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true | ||
defaults: | ||
run: | ||
shell: bash | ||
|
||
steps: | ||
- name: Install Ninja | ||
shell: bash | ||
run: sudo apt-get update -y -qq && sudo apt-get install -y -qq ninja-build | ||
|
||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
submodules: 'true' | ||
|
||
- name: Checkout DuckDB to version | ||
if: ${{ matrix.duckdb_version != '<submodule_version>'}} | ||
run: | | ||
cd duckdb | ||
git checkout ${{ matrix.duckdb_version }} | ||
- name: Setup vcpkg | ||
uses: lukka/[email protected] | ||
with: | ||
vcpkgGitCommitId: a1a1cbc975abf909a6c8985a6a2b8fe20bbd9bd6 | ||
|
||
- name: Rename extension | ||
run: | | ||
python3 scripts/bootstrap-template.py ext_1_a_123b_b11 | ||
- name: Build | ||
run: | | ||
make | ||
- name: Test | ||
run: | | ||
make test | ||
macos: | ||
name: MacOS | ||
if: ${{ vars.RUN_RENAME_TEST == 'true' || github.repository == 'duckdb/extension-template' }} | ||
runs-on: macos-latest | ||
strategy: | ||
matrix: | ||
# Add commits/tags to build against other DuckDB versions | ||
duckdb_version: [ '<submodule_version>'] | ||
env: | ||
VCPKG_TOOLCHAIN_PATH: ${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake | ||
VCPKG_TARGET_TRIPLET: 'x64-osx' | ||
OSX_BUILD_ARCH: 'x86_64' | ||
GEN: ninja | ||
defaults: | ||
run: | ||
shell: bash | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
submodules: 'true' | ||
|
||
- name: Install Ninja | ||
run: brew install ninja | ||
|
||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Checkout DuckDB to version | ||
if: ${{ matrix.duckdb_version != '<submodule_version>'}} | ||
run: | | ||
cd duckdb | ||
git checkout ${{ matrix.duckdb_version }} | ||
- name: Setup vcpkg | ||
uses: lukka/[email protected] | ||
with: | ||
vcpkgGitCommitId: a1a1cbc975abf909a6c8985a6a2b8fe20bbd9bd6 | ||
|
||
- name: Rename extension | ||
run: | | ||
python scripts/bootstrap-template.py ext_1_a_123b_b11 | ||
- name: Build | ||
run: | | ||
make | ||
- name: Test | ||
run: | | ||
make test | ||
windows: | ||
name: Windows | ||
if: ${{ vars.RUN_RENAME_TEST == 'true' || github.repository == 'duckdb/extension-template' }} | ||
runs-on: windows-latest | ||
strategy: | ||
matrix: | ||
# Add commits/tags to build against other DuckDB versions | ||
duckdb_version: [ '<submodule_version>' ] | ||
env: | ||
VCPKG_TOOLCHAIN_PATH: ${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake | ||
VCPKG_TARGET_TRIPLET: 'x64-windows-static-md' | ||
defaults: | ||
run: | ||
shell: bash | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
submodules: 'true' | ||
|
||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: Checkout DuckDB to version | ||
# Add commits/tags to build against other DuckDB versions | ||
if: ${{ matrix.duckdb_version != '<submodule_version>'}} | ||
run: | | ||
cd duckdb | ||
git checkout ${{ matrix.duckdb_version }} | ||
- name: Setup vcpkg | ||
uses: lukka/[email protected] | ||
with: | ||
vcpkgGitCommitId: a1a1cbc975abf909a6c8985a6a2b8fe20bbd9bd6 | ||
|
||
- name: Rename extension | ||
run: | | ||
python scripts/bootstrap-template.py ext_1_a_123b_b11 | ||
- name: Build | ||
run: | | ||
make | ||
- name: Test extension | ||
run: | | ||
build/release/test/Release/unittest.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# | ||
# This workflow calls the main distribution pipeline from DuckDB to build, test and (optionally) release the extension | ||
# | ||
name: Main Extension Distribution Pipeline | ||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref || '' }}-${{ github.base_ref || '' }}-${{ github.ref != 'refs/heads/main' || github.sha }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
duckdb-next-build: | ||
name: Build extension binaries | ||
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main | ||
with: | ||
duckdb_version: main | ||
ci_tools_version: main | ||
extension_name: quack | ||
|
||
duckdb-stable-build: | ||
name: Build extension binaries | ||
uses: duckdb/extension-ci-tools/.github/workflows/[email protected] | ||
with: | ||
duckdb_version: v1.1.3 | ||
ci_tools_version: v1.1.3 | ||
extension_name: quack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
build | ||
.idea | ||
cmake-build-debug | ||
duckdb_unittest_tempdir/ | ||
.DS_Store | ||
testext | ||
test/python/__pycache__/ | ||
.Rhistory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[submodule "duckdb"] | ||
path = duckdb | ||
url = https://github.com/duckdb/duckdb | ||
branch = main | ||
[submodule "extension-ci-tools"] | ||
path = extension-ci-tools | ||
url = https://github.com/duckdb/extension-ci-tools | ||
branch = main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
# Set extension name here | ||
set(TARGET_NAME quack) | ||
|
||
# DuckDB's extension distribution supports vcpkg. As such, dependencies can be added in ./vcpkg.json and then | ||
# used in cmake with find_package. Feel free to remove or replace with other dependencies. | ||
# Note that it should also be removed from vcpkg.json to prevent needlessly installing it.. | ||
find_package(OpenSSL REQUIRED) | ||
|
||
set(EXTENSION_NAME ${TARGET_NAME}_extension) | ||
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension) | ||
|
||
project(${TARGET_NAME}) | ||
include_directories(src/include) | ||
|
||
set(EXTENSION_SOURCES src/quack_extension.cpp) | ||
|
||
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES}) | ||
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES}) | ||
|
||
# Link OpenSSL in both the static library as the loadable extension | ||
target_link_libraries(${EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto) | ||
target_link_libraries(${LOADABLE_EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto) | ||
|
||
install( | ||
TARGETS ${EXTENSION_NAME} | ||
EXPORT "${DUCKDB_EXPORT_SET}" | ||
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" | ||
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2018-2024 Stichting DuckDB Foundation | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
PROJ_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
|
||
# Configuration of extension | ||
EXT_NAME=quack | ||
EXT_CONFIG=${PROJ_DIR}extension_config.cmake | ||
|
||
# Include the Makefile from extension-ci-tools | ||
include extension-ci-tools/makefiles/duckdb_extension.Makefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Quack | ||
|
||
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. | ||
|
||
--- | ||
|
||
This extension, Quack, allow you to ... <extension_goal>. | ||
|
||
|
||
## Building | ||
### Managing dependencies | ||
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: | ||
```shell | ||
git clone https://github.com/Microsoft/vcpkg.git | ||
./vcpkg/bootstrap-vcpkg.sh | ||
export VCPKG_TOOLCHAIN_PATH=`pwd`/vcpkg/scripts/buildsystems/vcpkg.cmake | ||
``` | ||
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. | ||
|
||
### Build steps | ||
Now to build the extension, run: | ||
```sh | ||
make | ||
``` | ||
The main binaries that will be built are: | ||
```sh | ||
./build/release/duckdb | ||
./build/release/test/unittest | ||
./build/release/extension/quack/quack.duckdb_extension | ||
``` | ||
- `duckdb` is the binary for the duckdb shell with the extension code automatically loaded. | ||
- `unittest` is the test runner of duckdb. Again, the extension is already linked into the binary. | ||
- `quack.duckdb_extension` is the loadable binary as it would be distributed. | ||
|
||
## Running the extension | ||
To run the extension code, simply start the shell with `./build/release/duckdb`. | ||
|
||
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: | ||
``` | ||
D select quack('Jane') as result; | ||
┌───────────────┐ | ||
│ result │ | ||
│ varchar │ | ||
├───────────────┤ | ||
│ Quack Jane 🐥 │ | ||
└───────────────┘ | ||
``` | ||
|
||
## Running the tests | ||
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: | ||
```sh | ||
make test | ||
``` | ||
|
||
### Installing the deployed binaries | ||
To install your extension binaries from S3, you will need to do two things. Firstly, DuckDB should be launched with the | ||
`allow_unsigned_extensions` option set to true. How to set this will depend on the client you're using. Some examples: | ||
|
||
CLI: | ||
```shell | ||
duckdb -unsigned | ||
``` | ||
|
||
Python: | ||
```python | ||
con = duckdb.connect(':memory:', config={'allow_unsigned_extensions' : 'true'}) | ||
``` | ||
|
||
NodeJS: | ||
```js | ||
db = new duckdb.Database(':memory:', {"allow_unsigned_extensions": "true"}); | ||
``` | ||
|
||
Secondly, you will need to set the repository endpoint in DuckDB to the HTTP url of your bucket + version of the extension | ||
you want to install. To do this run the following SQL query in DuckDB: | ||
```sql | ||
SET custom_extension_repository='bucket.s3.eu-west-1.amazonaws.com/<your_extension_name>/latest'; | ||
``` | ||
Note that the `/latest` path will allow you to install the latest extension version available for your current version of | ||
DuckDB. To specify a specific version, you can pass the version instead. | ||
|
||
After running these steps, you can install and load your extension using the regular INSTALL/LOAD commands in DuckDB: | ||
```sql | ||
INSTALL quack | ||
LOAD quack | ||
``` |
Oops, something went wrong.