Skip to content

Commit 5af6a7f

Browse files
committed
introduce single CMake script build all packages
This introduces single CMake script to build all packages and non-package build with same result, including shared library SONAME and versioning. Complicated shellscripting to build package build are no longer required, everything can be build with "cmake -S . -B build && cmake --build build".
1 parent 0aea23a commit 5af6a7f

17 files changed

+474
-425
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Setup environment
2424
run: |
2525
sudo apt-get update
26-
sudo apt-get install libssl1.1 libuv1-dev libkrb5-dev libc6-dbg
26+
sudo apt-get install libssl-dev libuv1-dev libkrb5-dev pkg-config openssl ca-certificates clang cmake cargo libc6-dbg
2727
sudo snap install valgrind --classic
2828
pip3 install https://github.com/scylladb/scylla-ccm/archive/master.zip
2929
sudo sh -c "echo 2097152 >> /proc/sys/fs/aio-max-nr"

.github/workflows/cassandra.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Setup environment
3030
run: |
3131
sudo apt-get update
32-
sudo apt-get install libssl1.1 libuv1-dev libkrb5-dev libc6-dbg
32+
sudo apt-get install libssl-dev libuv1-dev libkrb5-dev pkg-config openssl ca-certificates clang cmake cargo libc6-dbg
3333
sudo snap install valgrind --classic
3434
pip3 install https://github.com/scylladb/scylla-ccm/archive/master.zip
3535
sudo sh -c "echo 2097152 >> /proc/sys/fs/aio-max-nr"

CMakeLists.txt

+173-203
Large diffs are not rendered by default.

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,24 @@ To build deb package, run the following command:
343343
It will construct chrooted build environment of target distribution using
344344
pbuilder, and build deb in the environment.
345345
Target parameter should be debian/ubuntu codename.
346-
On Ubuntu targets, currently tested on focal (20.04), jammy (22.04), mantic (23.10), noble (24.04).
346+
On Ubuntu targets, currently tested on bionic (18.04), focal (20.04), jammy (22.04), mantic (23.10), noble (24.04).
347347
On Debian targets, currently tested on buster (10), bullseye (11), bookworm (12), trixie (13), sid (unstable).
348348
Build environment should be Fedora, Ubuntu or Debian, since these distribution
349349
provides pbuilder package.
350350
Built result will placed under build/debian/debs.
351351

352+
# Build & install HomeBrew package (macOS)
353+
354+
---
355+
356+
To build HomeBrew pacakge, run the following command:
357+
```shell
358+
cd dist/homebrew
359+
brew install --HEAD ./scylla-cpp-rust-driver.rb
360+
```
361+
It will run build & install the driver in HomeBrew environment.
362+
Tested on macOS 14.5.
363+
352364
# Getting Help
353365
___
354366

cmake/CMakeCargo.cmake

+30-6
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,60 @@ function(cargo_build)
2323
elseif(IOS)
2424
set(LIB_TARGET "universal")
2525
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
26-
set(LIB_TARGET "x86_64-apple-darwin")
27-
else()
26+
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
27+
set(LIB_TARGET "aarch64-apple-darwin")
28+
else()
29+
set(LIB_TARGET "${CMAKE_SYSTEM_PROCESSOR}-apple-darwin")
30+
endif()
31+
elseif(CMAKE_SYSTEM_NAME STREQUAL Linux)
2832
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
29-
set(LIB_TARGET "x86_64-unknown-linux-gnu")
33+
set(LIB_TARGET "${CMAKE_SYSTEM_PROCESSOR}-unknown-linux-gnu")
3034
else()
3135
set(LIB_TARGET "i686-unknown-linux-gnu")
3236
endif()
37+
else()
38+
message(FATAL_ERROR "${CMAKE_SYSTEM_NAME} is unknown system")
3339
endif()
3440

3541
if(NOT CMAKE_BUILD_TYPE)
3642
set(LIB_BUILD_TYPE "debug")
3743
elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release")
3844
set(LIB_BUILD_TYPE "release")
45+
elseif(${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo")
46+
set(LIB_BUILD_TYPE "relwithdebinfo")
3947
else()
4048
set(LIB_BUILD_TYPE "debug")
4149
endif()
4250

4351
set(LIB_FILE "${CARGO_TARGET_DIR}/${LIB_TARGET}/${LIB_BUILD_TYPE}/${CMAKE_STATIC_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
52+
if(BUILD_SHARED_LIBS)
53+
set(LIB_FILE_SHARED "${CARGO_TARGET_DIR}/${LIB_TARGET}/${LIB_BUILD_TYPE}/${CMAKE_SHARED_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
54+
endif()
4455

4556
if(IOS)
4657
set(CARGO_ARGS "lipo")
4758
else()
4859
set(CARGO_ARGS "build")
4960
list(APPEND CARGO_ARGS "--target" ${LIB_TARGET})
61+
if (CMAKE_VERBOSE_MAKEFILE)
62+
list(APPEND CARGO_ARGS "--verbose")
63+
endif()
5064
endif()
5165

5266
if(${LIB_BUILD_TYPE} STREQUAL "release")
5367
list(APPEND CARGO_ARGS "--release")
68+
elseif(${LIB_BUILD_TYPE} STREQUAL "relwithdebinfo")
69+
list(APPEND CARGO_ARGS "--profile" "relwithdebinfo")
70+
elseif(${LIB_BUILD_TYPE} STREQUAL "debug")
71+
list(APPEND CARGO_CARGS "--profile" "dev")
5472
endif()
5573

5674
file(GLOB_RECURSE LIB_SOURCES "*.rs")
5775

58-
set(CARGO_ENV_COMMAND ${CMAKE_COMMAND} -E env "CARGO_TARGET_DIR=${CARGO_TARGET_DIR}")
76+
set(CARGO_ENV_COMMAND ${CMAKE_COMMAND} -E env "CARGO_TARGET_DIR=${CARGO_TARGET_DIR}" "RUSTFLAGS=${CMAKE_Rust_FLAGS}")
5977

6078
add_custom_command(
61-
OUTPUT ${LIB_FILE}
79+
OUTPUT ${LIB_FILE} ${LIB_FILE_SHARED}
6280
COMMAND ${CARGO_ENV_COMMAND} ${CARGO_EXECUTABLE} ARGS ${CARGO_ARGS}
6381
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
6482
DEPENDS ${LIB_SOURCES}
@@ -67,4 +85,10 @@ function(cargo_build)
6785
add_library(${CARGO_NAME} STATIC IMPORTED GLOBAL)
6886
add_dependencies(${CARGO_NAME} ${CARGO_NAME}_target)
6987
set_target_properties(${CARGO_NAME} PROPERTIES IMPORTED_LOCATION ${LIB_FILE})
70-
endfunction()
88+
if(BUILD_SHARED_LIBS)
89+
add_custom_target(${CARGO_NAME}_shared_target ALL DEPENDS ${LIB_FILE_SHARED})
90+
add_library(${CARGO_NAME}_shared SHARED IMPORTED GLOBAL)
91+
add_dependencies(${CARGO_NAME}_shared ${CARGO_NAME}_shared_target)
92+
set_target_properties(${CARGO_NAME}_shared PROPERTIES IMPORTED_LOCATION ${LIB_FILE_SHARED})
93+
endif()
94+
endfunction()

cmake/Dependencies.cmake

+41-39
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,55 @@ endif()
1111
# Libuv
1212
#------------------------
1313

14-
# Setup the paths and hints for libuv
15-
if(NOT LIBUV_ROOT_DIR)
16-
if(EXISTS "${PROJECT_SOURCE_DIR}/lib/libuv/")
17-
set(LIBUV_ROOT_DIR "${PROJECT_SOURCE_DIR}/lib/libuv/")
18-
elseif(EXISTS "${PROJECT_SOURCE_DIR}/build/libs/libuv/")
19-
set(LIBUV_ROOT_DIR "${PROJECT_SOURCE_DIR}/build/libs/libuv/")
14+
if(CASS_USE_LIBUV)
15+
# Setup the paths and hints for libuv
16+
if(NOT LIBUV_ROOT_DIR)
17+
if(EXISTS "${PROJECT_SOURCE_DIR}/lib/libuv/")
18+
set(LIBUV_ROOT_DIR "${PROJECT_SOURCE_DIR}/lib/libuv/")
19+
elseif(EXISTS "${PROJECT_SOURCE_DIR}/build/libs/libuv/")
20+
set(LIBUV_ROOT_DIR "${PROJECT_SOURCE_DIR}/build/libs/libuv/")
21+
endif()
2022
endif()
21-
endif()
2223

23-
# Ensure libuv was found
24-
find_package(Libuv "1.0.0")
25-
if(WIN32 AND NOT LIBUV_FOUND)
26-
message(STATUS "Unable to Locate libuv: Third party build step will be performed")
27-
include(ExternalProject-libuv)
28-
elseif(NOT LIBUV_FOUND)
29-
message(FATAL_ERROR "Unable to Locate libuv: libuv v1.0.0+ is required")
30-
endif()
24+
# Ensure libuv was found
25+
find_package(Libuv "1.0.0")
26+
if(WIN32 AND NOT LIBUV_FOUND)
27+
message(STATUS "Unable to Locate libuv: Third party build step will be performed")
28+
include(ExternalProject-libuv)
29+
elseif(NOT LIBUV_FOUND)
30+
message(FATAL_ERROR "Unable to Locate libuv: libuv v1.0.0+ is required")
31+
endif()
3132

32-
if(LIBUV_VERSION VERSION_LESS "1.0")
33-
message(FATAL_ERROR "Libuv version ${LIBUV_VERSION} is not "
34-
" supported. Please updgrade to libuv version 1.0 or greater in order to "
35-
"utilize the driver.")
36-
endif()
33+
if(LIBUV_VERSION VERSION_LESS "1.0")
34+
message(FATAL_ERROR "Libuv version ${LIBUV_VERSION} is not "
35+
" supported. Please updgrade to libuv version 1.0 or greater in order to "
36+
"utilize the driver.")
37+
endif()
3738

38-
if(LIBUV_VERSION VERSION_LESS "1.6")
39-
message(WARNING "Libuv version ${LIBUV_VERSION} does not support custom "
40-
"memory allocators (version 1.6 or greater required)")
41-
endif()
39+
if(LIBUV_VERSION VERSION_LESS "1.6")
40+
message(WARNING "Libuv version ${LIBUV_VERSION} does not support custom "
41+
"memory allocators (version 1.6 or greater required)")
42+
endif()
4243

43-
# Assign libuv include and libraries
44-
set(CASS_INCLUDES ${CASS_INCLUDES} ${LIBUV_INCLUDE_DIRS})
45-
set(CASS_LIBS ${CASS_LIBS} ${LIBUV_LIBRARIES})
44+
# Assign libuv include and libraries
45+
set(CASS_INCLUDES ${CASS_INCLUDES} ${LIBUV_INCLUDE_DIRS})
46+
set(CASS_LIBS ${CASS_LIBS} ${LIBUV_LIBRARIES})
4647

47-
# libuv and gtests require thread library
48-
if(NOT WIN32)
49-
set(CMAKE_THREAD_PREFER_PTHREAD 1)
50-
set(THREADS_PREFER_PTHREAD_FLAG 1)
51-
endif()
48+
# libuv and gtests require thread library
49+
if(NOT WIN32)
50+
set(CMAKE_THREAD_PREFER_PTHREAD 1)
51+
set(THREADS_PREFER_PTHREAD_FLAG 1)
52+
endif()
5253

53-
find_package(Threads REQUIRED)
54+
find_package(Threads REQUIRED)
5455

55-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
56-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
57-
if(NOT WIN32 AND ${CMAKE_VERSION} VERSION_LESS "3.1.0")
58-
# FindThreads in CMake versions < v3.1.0 do not have the THREADS_PREFER_PTHREAD_FLAG to prefer -pthread
59-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
60-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
56+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
57+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
58+
if(NOT WIN32 AND ${CMAKE_VERSION} VERSION_LESS "3.1.0")
59+
# FindThreads in CMake versions < v3.1.0 do not have the THREADS_PREFER_PTHREAD_FLAG to prefer -pthread
60+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
61+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
62+
endif()
6163
endif()
6264

6365
#------------------------

cmake_uninstall.cmake.in

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
cmake_policy(SET CMP0007 OLD)
3+
4+
if (NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
5+
message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_BINARY_DIR@/install_manifest.txt\"")
6+
endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
7+
8+
file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
9+
string(REGEX REPLACE "\n" ";" files "${files}")
10+
list(REVERSE files)
11+
foreach (file ${files})
12+
message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
13+
if (EXISTS "$ENV{DESTDIR}${file}")
14+
execute_process(
15+
COMMAND "@CMAKE_COMMAND@" -E remove "$ENV{DESTDIR}${file}"
16+
OUTPUT_VARIABLE rm_out
17+
RESULT_VARIABLE rm_retval
18+
)
19+
if(NOT ${rm_retval} EQUAL 0)
20+
message("Problem when removing \"$ENV{DESTDIR}${file}\"")
21+
endif (NOT ${rm_retval} EQUAL 0)
22+
else (EXISTS "$ENV{DESTDIR}${file}")
23+
message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
24+
endif (EXISTS "$ENV{DESTDIR}${file}")
25+
endforeach(file)

dist/debian/debian/control

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Build-Depends: debhelper-compat (= 11),
1010
openssl,
1111
ca-certificates,
1212
curl,
13-
clang
13+
clang,
14+
cmake
1415

1516
Package: libscylla-cpp-driver0
1617
Architecture: any

dist/debian/debian/rules

+8-36
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,20 @@ export DH_VERBOSE=1
66
include /usr/share/dpkg/architecture.mk
77
include /usr/share/dpkg/buildflags.mk
88

9-
export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
10-
export DEB_HOST_RUST_TYPE DEB_HOST_GNU_TYPE
9+
export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS DEB_HOST_GNU_TYPE
1110
jobs := $(shell echo $$DEB_BUILD_OPTIONS | sed -r "s/.*parallel=([0-9]+).*/-j\1/")
12-
SCYLLA_VERSION := $(shell cat version | awk -F'-' '{print $1}' | sed 's/-/~/')
13-
14-
VERSION_MAJOR := $(shell sed -n -e 's/^#define CASS_VERSION_MAJOR \(.*\)/\1/p' include/cassandra.h)
15-
RUSTFLAGS := --cap-lints warn -C linker=x86_64-linux-gnu-gcc -C link-arg=-Wl,-Bsymbolic-functions -C link-arg=-Wl,-z,relro -Clink-arg=-Wl,-soname=libscylla-cpp-driver.so.$(VERSION_MAJOR)
16-
export RUSTFLAGS
11+
CARGO_HOME := $(CURDIR)/scylla-rust-wrapper/.cargo
12+
RUSTUP_HOME := $(CURDIR)/scylla-rust-wrapper/.rustup
13+
export CARGO_HOME
14+
export RUSTUP_HOME
1715

1816
%:
1917
dh $@
2018

2119
override_dh_auto_clean:
22-
rm -rf scylla-rust-wrapper/target/packaging
2320
rm -rf scylla-rust-wrapper/.cargo
24-
rm -rf scylla-rust-wrapper/.rust
21+
rm -rf scylla-rust-wrapper/.rustup
2522

2623
override_dh_auto_configure:
27-
/usr/bin/curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | CARGO_HOME=$(CURDIR)/scylla-rust-wrapper/.cargo RUSTUP_HOME=$(CURDIR)/scylla-rust-wrapper/.rust /bin/sh -s -- -v -y --no-modify-path
28-
29-
override_dh_auto_build:
30-
(cd scylla-rust-wrapper && PATH=$(CURDIR)/scylla-rust-wrapper/.cargo/bin:$$PATH CARGO_HOME=$(CURDIR)/scylla-rust-wrapper/.cargo RUSTUP_HOME=$(CURDIR)/scylla-rust-wrapper/.rust $(CURDIR)/scylla-rust-wrapper/.cargo/bin/cargo build $(jobs) --profile packaging --verbose)
31-
(cd scylla-rust-wrapper && ./versioning.sh --profile packaging)
32-
sed -e "s#@prefix@#/usr#g" \
33-
-e "s#@exec_prefix@#/usr#g" \
34-
-e "s#@libdir@#/usr/lib/$(DEB_HOST_MULTIARCH)#g" \
35-
-e "s#@includedir@#/usr/include#g" \
36-
-e "s#@version@#$(SCYLLA_VERSION)#g" \
37-
dist/common/pkgconfig/scylla-cpp-driver.pc.in > debian/scylla-cpp-driver.pc
38-
sed -e "s#@prefix@#/usr#g" \
39-
-e "s#@exec_prefix@#/usr#g" \
40-
-e "s#@libdir@#/usr/lib/$(DEB_HOST_MULTIARCH)#g" \
41-
-e "s#@includedir@#/usr/include#g" \
42-
-e "s#@version@#$(SCYLLA_VERSION)#g" \
43-
dist/common/pkgconfig/scylla-cpp-driver_static.pc.in > debian/scylla-cpp-driver_static.pc
44-
45-
override_dh_auto_install:
46-
mkdir -p "$(CURDIR)"/debian/tmp/usr/lib/"$(DEB_HOST_GNU_TYPE)"
47-
mkdir -p "$(CURDIR)"/debian/tmp/usr/lib/"$(DEB_HOST_GNU_TYPE)"/pkgconfig
48-
mkdir -p "$(CURDIR)"/debian/tmp/usr/include
49-
install -Dpm0644 "$(CURDIR)"/scylla-rust-wrapper/target/packaging/*.a "$(CURDIR)"/debian/tmp/usr/lib/"$(DEB_HOST_GNU_TYPE)"
50-
# We need to avoid dereference symlink, so can't use install here
51-
cp -a "$(CURDIR)"/scylla-rust-wrapper/target/packaging/*.so "$(CURDIR)"/scylla-rust-wrapper/target/packaging/*.so.* "$(CURDIR)"/debian/tmp/usr/lib/"$(DEB_HOST_GNU_TYPE)"/
52-
install -Dpm0644 "$(CURDIR)"/debian/*.pc "$(CURDIR)"/debian/tmp/usr/lib/"$(DEB_HOST_GNU_TYPE)"/pkgconfig
53-
install -Dpm0644 "$(CURDIR)"/include/*.h "$(CURDIR)"/debian/tmp/usr/include
24+
/usr/bin/curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | /bin/sh -s -- -v -y --no-modify-path
25+
dh_auto_configure -- -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_RustFLAGS="--cap-lints warn -C linker=$(DEB_HOST_GNU_TYPE)-gcc -C link-arg=-Wl,-Bsymbolic-functions -C link-arg=-Wl,-z,relro"

dist/homebrew/cpp-rust-driver.rb

-46
This file was deleted.
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require "formula"
2+
3+
class ScyllaCppRustDriver < Formula
4+
homepage "https://github.com/scylladb/cpp-rust-driver"
5+
head "https://github.com/scylladb/cpp-rust-driver.git", branch: "master"
6+
7+
depends_on "cmake" => :build
8+
depends_on "rust" => :build
9+
depends_on "openssl@3"
10+
11+
def install
12+
system "cmake", "-S", ".", "-B", "build", "-DCMAKE_BUILD_TYPE=RelWithDebInfo", "-DCMAKE_VERBOSE_MAKEFILE=ON", *std_cmake_args
13+
system "cmake", "--build", "build"
14+
system "cmake", "--install", "build"
15+
end
16+
end

0 commit comments

Comments
 (0)