Skip to content

Commit c31489e

Browse files
committed
Support rpm and deb packaging
Add build_rpm.sh and build_deb.sh build scripts to produce rpm & deb package. closes scylladb/scylla-pkg#3714 closes scylladb#121
1 parent 1814a0f commit c31489e

21 files changed

+704
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,37 @@ Now, use `--gtest_filter` to run certain integration tests:
318318

319319
##### Note: Tests that pass with ScyllaDB and Cassandra clusters can be found in GitHub Actions [`build.yml`](https://github.com/scylladb/cpp-rust-driver/blob/master/.github/workflows/build.yml) and [`cassandra.yml`](https://github.com/scylladb/cpp-rust-driver/blob/master/.github/workflows/cassandra.yml) workflows.
320320

321+
# Build rpm package
322+
___
323+
324+
To build rpm package, run follow command:
325+
```shell
326+
./dist/redhat/build_rpm.sh --target rocky-8-x86_64
327+
```
328+
It will construct chrooted build environment of target distribution using mock,
329+
and build rpm in the environment.
330+
Target parameter should be mock .cfg file name.
331+
Currently tested on rocky-8-x86_64, rocky-9-x86_64, fedora-38-x86_64, fedora-39-x86_64, fedora-40-x86_64, fedora-rawhide-x86_64.
332+
Build environment should be Fedora or RHEL variants + EPEL, since
333+
other distribution does not provide mock package.
334+
Built result will placed under build/redhat/{rpms,srpms}.
335+
336+
# Build rpm package
337+
___
338+
339+
To build rpm package, run follow command:
340+
```shell
341+
./dist/redhat/build_deb.sh --target mantic
342+
```
343+
It will construct chrooted build environment of target distribution using
344+
pbuilder, and build deb in the environment.
345+
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).
347+
On Debian targets, currently tested on buster (10), bullseye (11), bookworm (12), trixie (13), sid (unstable).
348+
Build environment should be Fedora, Ubuntu or Debian, since these distribution
349+
provides pbuilder package.
350+
Built result will placed under build/debian/debs.
351+
321352
# Getting Help
322353
___
323354

SCYLLA-VERSION-GEN

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/sh
2+
3+
USAGE=$(cat <<-END
4+
Usage: $(basename "$0") [-h|--help] [-o|--output-dir PATH] [--date-stamp DATE] -- generate Scylla version and build information files.
5+
6+
Options:
7+
-h|--help show this help message.
8+
-o|--output-dir PATH specify destination path at which the version files are to be created.
9+
-d|--date-stamp DATE manually set date for release parameter
10+
-v|--verbose also print out the version number
11+
12+
By default, the script will attempt to parse 'version' file
13+
in the current directory, which should contain a string of
14+
'\$version-\$release' form.
15+
16+
Otherwise, it will call 'git log' on the source tree (the
17+
directory, which contains the script) to obtain current
18+
commit hash and use it for building the version and release
19+
strings.
20+
21+
The script assumes that it's called from the Scylla source
22+
tree.
23+
24+
The files created are:
25+
SCYLLA-VERSION-FILE
26+
SCYLLA-RELEASE-FILE
27+
28+
By default, these files are created in the 'build'
29+
subdirectory under the directory containing the script.
30+
The destination directory can be overridden by
31+
using '-o PATH' option.
32+
END
33+
)
34+
35+
DATE=""
36+
PRINT_VERSION=false
37+
38+
while [ $# -gt 0 ]; do
39+
opt="$1"
40+
case $opt in
41+
-h|--help)
42+
echo "$USAGE"
43+
exit 0
44+
;;
45+
-o|--output-dir)
46+
OUTPUT_DIR="$2"
47+
shift
48+
shift
49+
;;
50+
--date-stamp)
51+
DATE="$2"
52+
shift
53+
shift
54+
;;
55+
-v|--verbose)
56+
PRINT_VERSION=true
57+
shift
58+
;;
59+
*)
60+
echo "Unexpected argument found: $1"
61+
echo
62+
echo "$USAGE"
63+
exit 1
64+
;;
65+
esac
66+
done
67+
68+
SCRIPT_DIR="$(dirname "$0")"
69+
70+
if [ -z "$OUTPUT_DIR" ]; then
71+
OUTPUT_DIR="$SCRIPT_DIR/build"
72+
fi
73+
74+
if [ -z "$DATE" ]; then
75+
DATE=$(date --utc +%Y%m%d)
76+
fi
77+
78+
# Default scylla version tags
79+
VERSION="$(sed -n -e 's/^version = \"\(.*\)\"$/\1/p' scylla-rust-wrapper/Cargo.toml)"
80+
81+
if test -f version
82+
then
83+
SCYLLA_VERSION=$(cat version | awk -F'-' '{print $1}')
84+
SCYLLA_RELEASE=$(cat version | awk -F'-' '{print $2}')
85+
else
86+
SCYLLA_VERSION=$VERSION
87+
if [ -z "$SCYLLA_RELEASE" ]; then
88+
GIT_COMMIT=$(git -C "$SCRIPT_DIR" log --pretty=format:'%h' -n 1 --abbrev=12)
89+
# For custom package builds, replace "0" with "counter.your_name",
90+
# where counter starts at 1 and increments for successive versions.
91+
# This ensures that the package manager will select your custom
92+
# package over the standard release.
93+
SCYLLA_BUILD=0
94+
SCYLLA_RELEASE=$SCYLLA_BUILD.$DATE.$GIT_COMMIT
95+
elif [ -f "$OUTPUT_DIR/SCYLLA-RELEASE-FILE" ]; then
96+
echo "setting SCYLLA_RELEASE only makes sense in clean builds" 1>&2
97+
exit 1
98+
fi
99+
fi
100+
101+
if [ -f "$OUTPUT_DIR/SCYLLA-RELEASE-FILE" ]; then
102+
GIT_COMMIT_FILE=$(cat "$OUTPUT_DIR/SCYLLA-RELEASE-FILE" |cut -d . -f 3)
103+
if [ "$GIT_COMMIT" = "$GIT_COMMIT_FILE" ]; then
104+
exit 0
105+
fi
106+
fi
107+
108+
if $PRINT_VERSION; then
109+
echo "$SCYLLA_VERSION-$SCYLLA_RELEASE"
110+
fi
111+
mkdir -p "$OUTPUT_DIR"
112+
echo "$SCYLLA_VERSION" > "$OUTPUT_DIR/SCYLLA-VERSION-FILE"
113+
echo "$SCYLLA_RELEASE" > "$OUTPUT_DIR/SCYLLA-RELEASE-FILE"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
prefix=@prefix@
2+
exec_prefix=@exec_prefix@
3+
libdir=@libdir@
4+
includedir=@includedir@
5+
6+
Name: scylla-cpp-rust-driver
7+
Description: ScyllaDB Cpp-Rust Driver
8+
Version: @version@
9+
Libs: -L${libdir} -lscylla_cpp_driver
10+
Cflags: -I${includedir}/scylladb
11+
URL: https://github.com/scylladb/cpp-rust-driver
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
prefix=@prefix@
2+
exec_prefix=@exec_prefix@
3+
libdir=@libdir@
4+
includedir=@includedir@
5+
6+
Name: scylla-cpp-rust-driver
7+
Description: ScyllaDB Cpp-Rust Driver
8+
Version: @version@
9+
Requires: openssl
10+
Libs: -L${libdir} -llibscylla_cpp_driver.a
11+
Cflags: -I${includedir}/scylladb
12+
URL: https://github.com/scylladb/cpp-rust-driver

dist/debian/build_deb.sh

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/bin/bash -e
2+
3+
CURDIR="$(dirname "$(readlink -f "$0")")"
4+
BASEDIR="$(readlink -f "$CURDIR"/../../)"
5+
. /etc/os-release
6+
print_usage() {
7+
echo "build_deb.sh --jobs 2 --target jammy"
8+
echo " --target target distribution codename"
9+
echo " --no-clean don't rebuild pbuilder tgz"
10+
echo " --jobs specify number of jobs"
11+
exit 1
12+
}
13+
14+
TARGET=
15+
NO_CLEAN=0
16+
JOBS="$(nproc)"
17+
while [ $# -gt 0 ]; do
18+
case "$1" in
19+
"--target")
20+
TARGET=$2
21+
shift 2
22+
;;
23+
"--no-clean")
24+
NO_CLEAN=1
25+
shift 1
26+
;;
27+
"--jobs")
28+
JOBS=$2
29+
shift 2
30+
;;
31+
*)
32+
print_usage
33+
;;
34+
esac
35+
done
36+
37+
is_redhat_variant() {
38+
[ -f /etc/redhat-release ]
39+
}
40+
is_debian_variant() {
41+
[ -f /etc/debian_version ]
42+
}
43+
is_debian() {
44+
case "$1" in
45+
buster|bullseye|bookworm|trixie|sid) return 0;;
46+
*) return 1;;
47+
esac
48+
}
49+
is_ubuntu() {
50+
case "$1" in
51+
bionic|focal|jammy|mantic|noble) return 0;;
52+
*) return 1;;
53+
esac
54+
}
55+
56+
57+
APT_UPDATED=0
58+
declare -A DEB_PKG=(
59+
["debian-keyring"]="debian-archive-keyring"
60+
["ubu-keyring"]="ubuntu-keyring"
61+
)
62+
pkg_install() {
63+
if is_redhat_variant; then
64+
sudo yum install -y $1
65+
elif is_debian_variant; then
66+
if [ $APT_UPDATED -eq 0 ]; then
67+
sudo apt-get -y update
68+
APT_UPDATED=1
69+
fi
70+
if [ -n "${DEB_PKG[$1]}" ]; then
71+
pkg="${DEB_PKG[$1]}"
72+
else
73+
pkg="$1"
74+
fi
75+
sudo apt-get install -y $pkg
76+
else
77+
echo "Requires to install following command: $1"
78+
exit 1
79+
fi
80+
}
81+
82+
if [ ! -e dist/debian/build_deb.sh ]; then
83+
echo "run build_deb.sh in top of scylla dir"
84+
exit 1
85+
fi
86+
87+
if [[ -z "$TARGET" ]]; then
88+
echo "Please specify target"
89+
exit 1
90+
fi
91+
92+
if [ ! -f /usr/bin/git ]; then
93+
pkg_install git
94+
fi
95+
if [ ! -f /usr/sbin/pbuilder ]; then
96+
pkg_install pbuilder
97+
fi
98+
if [ ! -f /usr/bin/dh_testdir ]; then
99+
pkg_install debhelper
100+
fi
101+
if is_debian $TARGET && [ ! -f /usr/share/keyrings/debian-archive-keyring.gpg ]; then
102+
pkg_install debian-keyring
103+
fi
104+
if is_ubuntu $TARGET && [ ! -f /usr/share/keyrings/ubuntu-archive-keyring.gpg ]; then
105+
pkg_install ubu-keyring
106+
fi
107+
108+
./SCYLLA-VERSION-GEN
109+
DRIVER_NAME=scylla-cpp-rust-driver
110+
DRIVER_VERSION=$(sed 's/-/~/' build/SCYLLA-VERSION-FILE)
111+
DRIVER_RELEASE=$(cat build/SCYLLA-RELEASE-FILE)
112+
ARCH="$(dpkg --print-architecture)"
113+
114+
mkdir -p build/debian/debs
115+
git archive HEAD --prefix "$DRIVER_NAME-$DRIVER_VERSION/" --output "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar.gz"
116+
117+
if is_debian $TARGET; then
118+
DRIVER_REVISION="1~$TARGET"
119+
elif is_ubuntu $TARGET; then
120+
DRIVER_REVISION="0ubuntu1~$TARGET"
121+
else
122+
echo "Unknown distribution: $TARGET"
123+
fi
124+
tar xpvf "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar.gz" -C build/debian
125+
126+
./dist/debian/debian_files_gen.py --version "$DRIVER_VERSION" --release "$DRIVER_RELEASE" --revision "$DRIVER_REVISION" --codename "$TARGET" --output-dir "build/debian/$DRIVER_NAME"-"$DRIVER_VERSION"/debian
127+
128+
BASETGZ="/var/cache/pbuilder/$DRIVER_NAME-$TARGET-$ARCH-base.tgz"
129+
# use from pbuilderrc
130+
if [ $NO_CLEAN -eq 0 ]; then
131+
sudo rm -fv "/var/cache/pbuilder/$DRIVER_NAME-$TARGET-$ARCH-base.tgz"
132+
sudo mkdir -p /var/cache/pbuilder/$DRIVER_NAME-$TARGET-$ARCH/aptcache
133+
sudo DRIVER_NAME=$DRIVER_NAME DIST=$TARGET ARCH=$ARCH /usr/sbin/pbuilder clean --configfile ./dist/debian/pbuilderrc
134+
sudo DRIVER_NAME=$DRIVER_NAME DIST=$TARGET ARCH=$ARCH /usr/sbin/pbuilder create --configfile ./dist/debian/pbuilderrc
135+
fi
136+
sudo DRIVER_NAME=$DRIVER_NAME DIST=$TARGET ARCH=$ARCH /usr/sbin/pbuilder update --configfile ./dist/debian/pbuilderrc
137+
(cd "build/debian/$DRIVER_NAME"-"$DRIVER_VERSION"; dpkg-source -b .)
138+
sudo DRIVER_NAME=$DRIVER_NAME DIST=$TARGET ARCH=$ARCH /usr/sbin/pbuilder build --configfile ./dist/debian/pbuilderrc --buildresult build/debian/debs build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}-${DRIVER_REVISION}.dsc
139+
sudo chown -Rv $(id -u -n):$(id -g -n) build/debian/debs

dist/debian/changelog.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
scylla-cpp-rust-driver (%{version}-%{release}-%{revision}) %{codename}; urgency=medium
2+
3+
* Initial release.
4+
5+
-- Takuya ASADA <[email protected]> Mon, 24 Aug 2015 09:22:55 +0000

dist/debian/debian/control

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Source: scylla-cpp-rust-driver
2+
Maintainer: Takuya ASADA <[email protected]>
3+
Homepage: https://github.com/scylladb/cpp-rust-driver
4+
Section: libs
5+
Priority: optional
6+
Standards-Version: 4.6.1
7+
Build-Depends: debhelper-compat (= 11),
8+
libssl-dev,
9+
libclang-dev,
10+
pkg-config,
11+
openssl,
12+
ca-certificates,
13+
curl,
14+
clang
15+
16+
Package: libscylla-cpp-driver0
17+
Architecture: any
18+
Depends: ${misc:Depends},
19+
${shlibs:Depends},
20+
Description: ScyllaDB Cpp-Rust Driver
21+
API-compatible rewrite of https://github.com/scylladb/cpp-driver as a wrapper for Rust driver.
22+
23+
Package: libscylla-cpp-driver-dev
24+
Section: libdevel
25+
Architecture: any
26+
Depends: libscylla-cpp-driver0 (= ${binary:Version}),
27+
${misc:Depends},
28+
${shlibs:Depends},
29+
Description: Development libraries for ScyllDB Cpp-Rust Driver
30+
API-compatible rewrite of https://github.com/scylladb/cpp-driver as a wrapper for Rust driver.

dist/debian/debian/copyright

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2+
Upstream-Name: Scylla DB
3+
Upstream-Contact: http://www.scylladb.com/
4+
Source: https://github.com/scylladb/scylla
5+
6+
Files: *
7+
Copyright: Copyright (C) 2024 ScyllaDB
8+
License: GPL-2.1

dist/debian/debian/debcargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
overlay = "."
2+
uploaders = ["Takuya ASADA <[email protected]>"]
3+
4+
[source]
5+
section = "libs"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
libscylla-cpp-driver0
2+
libscylla-cpp-driver-dev

dist/debian/debian/files

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
libscylla-cpp-driver-dev_0.0.1-0.20240328.f143d09a2057-1_amd64.deb libdevel optional
2+
libscylla-cpp-driver0-dbgsym_0.0.1-0.20240328.f143d09a2057-1_amd64.ddeb debug optional automatic=yes
3+
libscylla-cpp-driver0_0.0.1-0.20240328.f143d09a2057-1_amd64.deb libs optional
4+
scylla-cpp-rust-driver_0.0.1-0.20240328.f143d09a2057-1_amd64.buildinfo libs optional
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
usr/include/*
2+
usr/lib/*/lib*.a
3+
usr/lib/*/pkgconfig/*.pc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
usr/lib/*/*.so
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#! /bin/sh
2+
3+
set -e
4+
5+
if [ "$1" = "configure" ]; then
6+
ldconfig
7+
fi
8+
9+
#DEBHELPER#

0 commit comments

Comments
 (0)