Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to link libduckdb statically #618

Merged
merged 4 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,16 @@ jobs:
- name: Build pg_duckdb extension
id: build
working-directory: duckdb
run: ERROR_ON_WARNING=1 make -j8 install
# For PG17 we build DuckDB as a static library. There's nothing special
# about the static library, nor PG17. This is only done so that we have
# CI coverage for our logic to build a static library version.
run: |
if [ '${{ matrix.version }}' = REL_17_STABLE ]; then
ERROR_ON_WARNING=1 make -j8 install DUCKDB_BUILD=Static
Comment on lines +118 to +119
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems error-prone to only build one version that way no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too worried about the static library build of DuckDB working for one PG version, but not for another. I mainly added this CI coverage to make sure we don't accidentally break the static build logic in our makefile completely. So I think running it for just one version is fine. I'll add a code comment explaining that though.

else
ERROR_ON_WARNING=1 make -j8 install
fi


- name: Run make installcheck
id: installcheck
Expand Down
26 changes: 22 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,27 @@ DUCKDB_BUILD_TYPE=
ifeq ($(DUCKDB_BUILD), Debug)
DUCKDB_BUILD_CXX_FLAGS = -g -O0 -D_GLIBCXX_ASSERTIONS
DUCKDB_BUILD_TYPE = debug
DUCKDB_MAKE_TARGET = debug
else ifeq ($(DUCKDB_BUILD), ReleaseStatic)
DUCKDB_BUILD_CXX_FLAGS =
DUCKDB_BUILD_TYPE = release
DUCKDB_MAKE_TARGET = bundle-library
else
DUCKDB_BUILD_CXX_FLAGS =
DUCKDB_BUILD_TYPE = release
DUCKDB_MAKE_TARGET = release
endif

DUCKDB_LIB = libduckdb$(DLSUFFIX)
FULL_DUCKDB_LIB = third_party/duckdb/build/$(DUCKDB_BUILD_TYPE)/src/$(DUCKDB_LIB)
PG_DUCKDB_LINK_FLAGS = -Wl,-rpath,$(PG_LIB)/ -lpq -Lthird_party/duckdb/build/$(DUCKDB_BUILD_TYPE)/src -L$(PG_LIB) -lstdc++ -llz4
DUCKDB_BUILD_DIR = third_party/duckdb/build/$(DUCKDB_BUILD_TYPE)

ifeq ($(DUCKDB_BUILD), ReleaseStatic)
PG_DUCKDB_LINK_FLAGS += third_party/duckdb/build/release/libduckdb_bundle.a
FULL_DUCKDB_LIB = $(DUCKDB_BUILD_DIR)/$(DUCKDB_LIB)
else
PG_DUCKDB_LINK_FLAGS += -lduckdb
FULL_DUCKDB_LIB = $(DUCKDB_BUILD_DIR)/src/$(DUCKDB_LIB)/libduckdb$(DLSUFFIX)
endif

ERROR_ON_WARNING ?=
ifeq ($(ERROR_ON_WARNING), 1)
Expand All @@ -54,7 +68,7 @@ override PG_CXXFLAGS += -std=c++17 ${DUCKDB_BUILD_CXX_FLAGS} ${COMPILER_FLAGS} -
# changes to the vendored code in one place.
override PG_CFLAGS += -Wno-declaration-after-statement

SHLIB_LINK += -Wl,-rpath,$(PG_LIB)/ -lpq -Lthird_party/duckdb/build/$(DUCKDB_BUILD_TYPE)/src -L$(PG_LIB) -lduckdb -lstdc++ -llz4
SHLIB_LINK += $(PG_DUCKDB_LINK_FLAGS)

include Makefile.global

Expand Down Expand Up @@ -102,10 +116,14 @@ $(FULL_DUCKDB_LIB): .git/modules/third_party/duckdb/HEAD
DISABLE_ASSERTIONS=$(DUCKDB_DISABLE_ASSERTIONS) \
EXTENSION_CONFIGS="../pg_duckdb_extensions.cmake" \
$(MAKE) -C third_party/duckdb \
$(DUCKDB_BUILD_TYPE)
$(DUCKDB_MAKE_TARGET)

ifeq ($(DUCKDB_BUILD), ReleaseStatic)
install-duckdb: $(FULL_DUCKDB_LIB) $(shlib)
else
install-duckdb: $(FULL_DUCKDB_LIB) $(shlib)
$(install_bin) -m 755 $(FULL_DUCKDB_LIB) $(DESTDIR)$(PG_LIB)
endif

clean-duckdb:
rm -rf third_party/duckdb/build
Expand Down
2 changes: 2 additions & 0 deletions docs/compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ To build and install, run:
make install
```

If you want to link `libduckdb` statically, set `DUCKDB_BUILD=ReleaseStatic` when interacting with `make(1)`.

Add `pg_duckdb` to the `shared_preload_libraries` in your `postgresql.conf` file:

```ini
Expand Down