Skip to content

Commit d873e4a

Browse files
committed
experiment: no c++
1 parent eacdd06 commit d873e4a

10 files changed

Lines changed: 7754 additions & 1486 deletions

Makefile

Lines changed: 19 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -16,97 +16,37 @@ CURL_CONFIG ?= curl-config
1616
OS ?= $(shell uname -s | tr A-Z a-z)
1717
ARCH = $(shell uname -m)
1818

19-
# Collect all the C++ and C files to compile into MODULE_big.
20-
OBJS = $(subst .cpp,.o, $(wildcard src/*.cpp src/*/*.cpp)) \
21-
$(subst .c,.o, $(wildcard src/*.c src/*/*.c))
22-
23-
# Build static on Darwin by default.
24-
ifndef CH_BUILD
25-
# ifeq ($(OS),darwin)
26-
CH_BUILD = static
27-
# else
28-
# CH_BUILD = dynamic
29-
# endif
30-
endif
19+
# Collect all the C files to compile into MODULE_big.
20+
OBJS = $(subst .c,.o, $(wildcard src/*.c src/*/*.c))
3121

32-
# clickhouse-cpp source and build directories.
33-
CH_CPP_DIR = vendor/clickhouse-cpp
34-
CH_CPP_BUILD_DIR = vendor/_build/$(OS)-$(ARCH)-$(CH_BUILD)-$(shell git submodule status $(CH_CPP_DIR) | awk '{print substr($$1, 0, 7)}')
35-
36-
# List the clickhouse-cpp libraries we require.
37-
CH_CPP_LIB = $(CH_CPP_BUILD_DIR)/clickhouse/libclickhouse-cpp-lib$(DLSUFFIX)
38-
CH_CPP_FLAGS = -D CMAKE_BUILD_TYPE=Release -D WITH_OPENSSL=ON
39-
40-
# Are we statically compiling clickhouse-cpp into the extension or no?
41-
ifeq ($(CH_BUILD), static)
42-
# We'll need all the clickhouse-cpp static libraries.
43-
CH_CPP_LIB = $(CH_CPP_BUILD_DIR)/clickhouse/libclickhouse-cpp-lib.a
44-
SHLIB_LINK = $(CH_CPP_LIB) \
45-
$(CH_CPP_BUILD_DIR)/contrib/cityhash/cityhash/libcityhash.a \
46-
$(CH_CPP_BUILD_DIR)/contrib/absl/absl/libabsl_int128.a \
47-
$(CH_CPP_BUILD_DIR)/contrib/lz4/lz4/liblz4.a \
48-
$(CH_CPP_BUILD_DIR)/contrib/zstd/zstd/libzstdstatic.a
49-
else
50-
# Build and install the shared library.
51-
SHLIB_LINK = -L$(CH_CPP_BUILD_DIR)/clickhouse -lclickhouse-cpp-lib
52-
CH_CPP_FLAGS += -D BUILD_SHARED_LIBS=ON
53-
endif
22+
# clickhouse-c is a header-only single-header library. Override
23+
# CH_C_DIR to point elsewhere when developing against a local checkout.
24+
CH_C_DIR ?= vendor/clickhouse-c
5425

5526
# Add include directories.
56-
PG_CPPFLAGS = -I./src/include -I$(CH_CPP_DIR) -I$(CH_CPP_DIR)/contrib/absl
57-
58-
# Include other libraries compiled into clickhouse-cpp.
59-
PG_LDFLAGS = -lstdc++ -lssl -lcrypto $(shell $(CURL_CONFIG) --libs)
27+
PG_CPPFLAGS = -I./src/include -I$(CH_C_DIR)
6028

61-
# clickhouse-cpp requires C++ v17.
62-
PG_CXXFLAGS = -std=c++17
63-
64-
# Suppress annoying pre-c99 warning and include curl flags.
65-
PG_CFLAGS = -Wno-declaration-after-statement -Werror=type-limits $(shell $(CURL_CONFIG) --cflags)
29+
# Link OpenSSL (for TLS in the binary driver), curl (for the HTTP driver),
30+
# and libuuid (for http_streaming.c's query-id generator).
31+
PG_LDFLAGS = -lssl -lcrypto $(shell $(CURL_CONFIG) --libs)
6632

67-
# We'll need libuuid except on darwin, where it's included in the OS.
33+
# libuuid is provided by the OS on darwin; explicit link elsewhere.
6834
ifneq ($(OS),darwin)
6935
PG_LDFLAGS += -luuid
7036
endif
7137

72-
# Clean up the clickhouse-cpp build directory and generated files.
38+
# Suppress annoying pre-c99 warning and include curl flags.
39+
PG_CFLAGS = -Wno-declaration-after-statement -Werror=type-limits $(shell $(CURL_CONFIG) --cflags)
40+
41+
# Clean up generated files.
7342
EXTRA_CLEAN = sql/$(EXTENSION)--$(EXTVERSION).sql src/include/version.h compile_commands.json test/schedule $(EXTENSION)-$(DISTVERSION).zip
74-
ifndef NO_VENDOR_CLEAN
75-
EXTRA_CLEAN += $(CH_CPP_BUILD_DIR)
76-
endif
7743

7844
# Import PGXS.
7945
PGXS := $(shell $(PG_CONFIG) --pgxs)
8046
include $(PGXS)
8147

82-
# We'll need the clickhouse-cpp library and rpath so it can be found.
83-
SHLIB_LINK += -Wl,-rpath,$(pkglibdir)/
84-
85-
# PostgreSQL 15 and earlier violate a C++ v17 storage specifier error.
86-
ifeq ($(shell test $(MAJORVERSION) -lt 16; echo $$?),0)
87-
PG_CXXFLAGS += -Wno-register
88-
endif
89-
90-
# Add the flags to the bitcode compiler variables.
91-
COMPILE.cc.bc += $(PG_CPPFLAGS)
92-
COMPILE.cxx.bc += $(PG_CXXFLAGS)
93-
94-
# shlib is the final output product: clickhouse-cpp and all .o dependencies.
95-
$(shlib): $(CH_CPP_LIB) $(OBJS)
96-
97-
# Clone clickhouse-cpp submodule.
98-
$(CH_CPP_DIR)/CMakeLists.txt:
99-
git submodule update --init
100-
101-
# Require the vendored clickhouse-cpp and the version header.
102-
$(OBJS): $(CH_CPP_DIR)/CMakeLists.txt src/include/version.h
103-
104-
# Build clickhouse-cpp.
105-
$(CH_CPP_LIB): export CXXFLAGS=-fPIC
106-
$(CH_CPP_LIB): export CFLAGS=-fPIC
107-
$(CH_CPP_LIB): $(CH_CPP_DIR)/CMakeLists.txt # Sync with "Reset Vendor Timestamp" steps in workflows.
108-
cmake -B $(CH_CPP_BUILD_DIR) -S $(CH_CPP_DIR) $(CH_CPP_FLAGS) -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
109-
cmake --build $(CH_CPP_BUILD_DIR) --parallel $$(nproc) --target all
48+
# Require the version header.
49+
$(OBJS): src/include/version.h
11050

11151
# Require the versioned C source and SQL script.
11252
all: sql/$(EXTENSION)--$(EXTVERSION).sql
@@ -119,17 +59,6 @@ sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql
11959
src/include/version.h: src/include/version.h.in
12060
sed -e 's,__VERSION__,$(DISTVERSION),g' $< > $@
12161

122-
# Configure install/uninstall of the clickhouse-cpp library.
123-
ifneq ($(CH_BUILD), static)
124-
# Copy all dynamic files; use -a to preserve symlinks.
125-
install-ch-cpp: $(CH_CPP_LIB) $(shlib)
126-
cp -a $(CH_CPP_BUILD_DIR)/clickhouse/libclickhouse-cpp-lib*$(DLSUFFIX)* $(DESTDIR)$(pkglibdir)/
127-
uninstall-ch-cpp:
128-
rm -f $(DESTDIR)$(pkglibdir)/libclickhouse-cpp-lib*$(DLSUFFIX)*
129-
install: install-ch-cpp
130-
uninstall: uninstall-ch-cpp
131-
endif
132-
13362
# Build a PGXN distribution bundle.
13463
dist: $(EXTENSION)-$(DISTVERSION).zip
13564

@@ -191,7 +120,6 @@ bake-vars:
191120
# standard. Requires `pg_bsd_indent` to be in the path.
192121
indent: dev/indent.sh
193122
@$<
194-
clang-format --style=file:.clang-format -i src/binary.cpp
195123

196124
# Linting.
197125
.PHONY: lint # Lint the project
@@ -200,7 +128,7 @@ lint: .pre-commit-config.yaml
200128

201129
.PHONY: clang-tidy # Run clang-tidy static analysis (requires compile_commands.json)
202130
clang-tidy: compile_commands.json
203-
clang-tidy -p . $(wildcard src/*.c src/*.cpp)
131+
clang-tidy -p . $(wildcard src/*.c)
204132

205133
## .git/hooks/pre-commit: Install the pre-commit hook
206134
.git/hooks/pre-commit:
@@ -217,8 +145,8 @@ lsp: compile_commands.json
217145

218146
# Requires https://github.com/rizsotto/Bear.
219147
compile_commands.json:
220-
$(MAKE) clean -j $$(nproc) NO_VENDOR_CLEAN=$(NO_VENDOR_CLEAN)
221-
bear -- $(MAKE) all -j $$(nproc) NO_VENDOR_CLEAN=$(NO_VENDOR_CLEAN)
148+
$(MAKE) clean -j $$(nproc)
149+
bear -- $(MAKE) all -j $$(nproc)
222150

223151
# ClickHouse Docker Containers
224152
start-containers: dev/Makefile dev/docker-compose.yml

0 commit comments

Comments
 (0)