diff --git a/README.md b/README.md index 4d94dc8b..afc4f2a3 100644 --- a/README.md +++ b/README.md @@ -318,6 +318,37 @@ Now, use `--gtest_filter` to run certain integration tests: ##### 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. +# Build rpm package +___ + +To build rpm package, run the following command: +```shell +./dist/redhat/build_rpm.sh --target rocky-8-x86_64 +``` +It will construct chrooted build environment of target distribution using mock, +and build rpm in the environment. +Target parameter should be mock .cfg file name. +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. +Build environment should be Fedora or RHEL variants + EPEL, since +other distribution does not provide mock package. +Built result will placed under build/redhat/{rpms,srpms}. + +# Build deb package +___ + +To build deb package, run the following command: +```shell +./dist/redhat/build_deb.sh --target mantic +``` +It will construct chrooted build environment of target distribution using +pbuilder, and build deb in the environment. +Target parameter should be debian/ubuntu codename. +On Ubuntu targets, currently tested on focal (20.04), jammy (22.04), mantic (23.10), noble (24.04). +On Debian targets, currently tested on buster (10), bullseye (11), bookworm (12), trixie (13), sid (unstable). +Build environment should be Fedora, Ubuntu or Debian, since these distribution +provides pbuilder package. +Built result will placed under build/debian/debs. + # Getting Help ___ @@ -338,4 +369,4 @@ ___ # License ___ -This project is licensed under the GNU Lesser General Public License v2.1 \ No newline at end of file +This project is licensed under the GNU Lesser General Public License v2.1 diff --git a/SCYLLA-VERSION-GEN b/SCYLLA-VERSION-GEN new file mode 100755 index 00000000..865f360c --- /dev/null +++ b/SCYLLA-VERSION-GEN @@ -0,0 +1,110 @@ +#!/bin/bash -e + +USAGE="$(cat <<-END +Usage: $(basename "$0") [-h|--help] [-o|--output-dir PATH] [--date-stamp DATE] -- generate Scylla version and build information files. + +Options: + -h|--help show this help message. + -o|--output-dir PATH specify destination path at which the version files are to be created. + -d|--date-stamp DATE manually set date for release parameter + -v|--verbose also print out the version number + +By default, the script will attempt to parse 'version' file +in the current directory, which should contain a string of +'\$version-\$release' form. + +Otherwise, it will call 'git log' on the source tree (the +directory, which contains the script) to obtain current +commit hash and use it for building the version and release +strings. + +The script assumes that it's called from the Scylla source +tree. + +The files created are: + SCYLLA-VERSION-FILE + SCYLLA-RELEASE-FILE + +By default, these files are created in the 'build' +subdirectory under the directory containing the script. +The destination directory can be overridden by +using '-o PATH' option. +END +)" + +DATE="" +PRINT_VERSION=0 + +while [[ $# -gt 0 ]]; do + opt="$1" + case "${opt}" in + -h|--help) + echo "${USAGE}" + exit 0 + ;; + -o|--output-dir) + OUTPUT_DIR="$2" + shift 2 + ;; + --date-stamp) + DATE="$2" + shift 2 + ;; + -v|--verbose) + PRINT_VERSION=1 + shift 1 + ;; + *) + echo "Unexpected argument found: $1" + echo + echo "${USAGE}" + exit 1 + ;; + esac +done + +SCRIPT_DIR="$(dirname "$0")" + +if [[ -z "${OUTPUT_DIR}" ]]; then + OUTPUT_DIR="${SCRIPT_DIR}/build" +fi + +if [[ -z "${DATE}" ]]; then + DATE="$(date --utc +%Y%m%d)" +fi + +# Default scylla version tags +VERSION="$(sed -n -e 's/^version = \"\(.*\)\"$/\1/p' scylla-rust-wrapper/Cargo.toml)" + +if [[ -f version ]]; then + SCYLLA_VERSION="$(cat version | awk -F'-' '{print $1}')" + SCYLLA_RELEASE="$(cat version | awk -F'-' '{print $2}')" +else + SCYLLA_VERSION="${VERSION}" + if [[ -z "${SCYLLA_RELEASE}" ]]; then + GIT_COMMIT="$(git -C "${SCRIPT_DIR}" log --pretty=format:'%h' -n 1 --abbrev=12)" + # For custom package builds, replace "0" with "counter.your_name", + # where counter starts at 1 and increments for successive versions. + # This ensures that the package manager will select your custom + # package over the standard release. + SCYLLA_BUILD=0 + SCYLLA_RELEASE="${SCYLLA_BUILD}.${DATE}.${GIT_COMMIT}" + elif [[ -f "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE" ]]; then + echo "setting SCYLLA_RELEASE only makes sense in clean builds" 1>&2 + exit 1 + fi +fi + +if [[ -f "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE" ]]; then + GIT_COMMIT_FILE=$(cat "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE" |cut -d . -f 3) + if [[ "${GIT_COMMIT}" = "${GIT_COMMIT_FILE}" ]]; then + exit 0 + fi +fi + +if [[ ${PRINT_VERSION} -eq 1 ]]; then + echo "${SCYLLA_VERSION}-${SCYLLA_RELEASE}" +fi +mkdir -p "${OUTPUT_DIR}" +echo "${SCYLLA_VERSION}" > "${OUTPUT_DIR}/SCYLLA-VERSION-FILE" +echo "${SCYLLA_RELEASE}" > "${OUTPUT_DIR}/SCYLLA-RELEASE-FILE" diff --git a/dist/common/pkgconfig/scylla-cpp-driver.pc.in b/dist/common/pkgconfig/scylla-cpp-driver.pc.in new file mode 100644 index 00000000..976e3786 --- /dev/null +++ b/dist/common/pkgconfig/scylla-cpp-driver.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: scylla-cpp-rust-driver +Description: ScyllaDB Cpp-Rust Driver +Version: @version@ +Libs: -L${libdir} -lscylla-cpp-driver +Cflags: -I${includedir} +URL: https://github.com/scylladb/cpp-rust-driver/ diff --git a/dist/common/pkgconfig/scylla-cpp-driver_static.pc.in b/dist/common/pkgconfig/scylla-cpp-driver_static.pc.in new file mode 100644 index 00000000..bad1b3c1 --- /dev/null +++ b/dist/common/pkgconfig/scylla-cpp-driver_static.pc.in @@ -0,0 +1,12 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: scylla-cpp-rust-driver +Description: ScyllaDB Cpp-Rust Driver +Version: @version@ +Requires: openssl +Libs: -L${libdir} -lscylla-cpp-driver_static +Cflags: -I${includedir} +URL: https://github.com/scylladb/cpp-rust-driver/ diff --git a/dist/debian/build_deb.sh b/dist/debian/build_deb.sh new file mode 100755 index 00000000..10173a28 --- /dev/null +++ b/dist/debian/build_deb.sh @@ -0,0 +1,146 @@ +#!/bin/bash -e + +. /etc/os-release +print_usage() { + echo "build_deb.sh --jobs 2 --target jammy" + echo " --target target distribution codename" + echo " --no-clean don't rebuild pbuilder tgz" + echo " --jobs specify number of jobs" + exit 1 +} + +TARGET= +NO_CLEAN=0 +JOBS="$(nproc)" +while [ $# -gt 0 ]; do + case "$1" in + "--target") + TARGET=$2 + shift 2 + ;; + "--no-clean") + NO_CLEAN=1 + shift 1 + ;; + "--jobs") + JOBS=$2 + shift 2 + ;; + *) + print_usage + ;; + esac +done + +is_redhat_variant() { + [[ -f /etc/redhat-release ]] +} +is_debian_variant() { + [[ -f /etc/debian_version ]] +} +is_debian() { + case "$1" in + buster|bullseye|bookworm|trixie|sid) return 0;; + *) return 1;; + esac +} +is_ubuntu() { + case "$1" in + bionic|focal|jammy|mantic|noble) return 0;; + *) return 1;; + esac +} + + +APT_UPDATED=0 +declare -A DEB_PKG=( + ["debian-keyring"]="debian-archive-keyring" + ["ubu-keyring"]="ubuntu-keyring" +) +pkg_install() { + if is_redhat_variant; then + sudo yum install -y "$1" + elif is_debian_variant; then + if [[ "${APT_UPDATED}" -eq 0 ]]; then + sudo apt-get -y update + APT_UPDATED=1 + fi + if [[ -n "${DEB_PKG[$1]}" ]]; then + pkg="${DEB_PKG[$1]}" + else + pkg="$1" + fi + sudo apt-get install -y "$pkg" + else + echo "Requires to install following command: $1" + exit 1 + fi +} + +if [[ ! -e dist/debian/build_deb.sh ]]; then + echo "run build_deb.sh in top of scylla dir" + exit 1 +fi + +if [[ -z "${TARGET}" ]]; then + echo "Please specify target" + exit 1 +fi + +if [[ ! -f /usr/bin/git ]]; then + pkg_install git +fi +if [[ ! -f /usr/sbin/pbuilder ]]; then + pkg_install pbuilder +fi +if [[ ! -f /usr/bin/dh_testdir ]]; then + pkg_install debhelper +fi +if is_debian "${TARGET}" && [[ ! -f /usr/share/keyrings/debian-archive-keyring.gpg ]]; then + pkg_install debian-keyring +fi +if is_ubuntu "${TARGET}" && [[ ! -f /usr/share/keyrings/ubuntu-archive-keyring.gpg ]]; then + pkg_install ubu-keyring +fi + +./SCYLLA-VERSION-GEN +DRIVER_NAME=scylla-cpp-rust-driver +DRIVER_VERSION="$(sed 's/-/~/' build/SCYLLA-VERSION-FILE)" +DRIVER_RELEASE="$(cat build/SCYLLA-RELEASE-FILE)" +ARCH="$(dpkg --print-architecture)" + +mkdir -p build/debian/debs +git archive HEAD --prefix "${DRIVER_NAME}-${DRIVER_VERSION}/" --output "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar" +echo "$(cat build/SCYLLA-VERSION-FILE)-$(cat build/SCYLLA-RELEASE-FILE)" > version +tar --xform "s#^#${DRIVER_NAME}-${DRIVER_VERSION}/#" -rf "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar" version +gzip -f --fast "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar" + +if is_debian "${TARGET}"; then + DRIVER_REVISION="1~${TARGET}" +elif is_ubuntu "${TARGET}"; then + DRIVER_REVISION="0ubuntu1~${TARGET}" +else + echo "Unknown distribution: ${TARGET}" +fi +tar xpvf "build/debian/${DRIVER_NAME}_${DRIVER_VERSION}-${DRIVER_RELEASE}.orig.tar.gz" -C build/debian + +./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 + +# pbuilder generates files owned by root, fix this up +fix_ownership() { + CURRENT_UID="$(id -u)" + CURRENT_GID="$(id -g)" + sudo chown "${CURRENT_UID}":"${CURRENT_GID}" -R "$@" +} + +# use from pbuilderrc +if [[ "${NO_CLEAN}" -eq 0 ]]; then + sudo rm -fv "/var/cache/pbuilder/${DRIVER_NAME}-${TARGET}-${ARCH}-base.tgz" + sudo mkdir -p "/var/cache/pbuilder/${DRIVER_NAME}-${TARGET}-${ARCH}/aptcache" + sudo DRIVER_NAME="${DRIVER_NAME}" DIST="${TARGET}" ARCH="${ARCH}" /usr/sbin/pbuilder clean --configfile ./dist/debian/pbuilderrc + sudo DRIVER_NAME="${DRIVER_NAME}" DIST="${TARGET}" ARCH="${ARCH}" /usr/sbin/pbuilder create --configfile ./dist/debian/pbuilderrc +fi +sudo DRIVER_NAME="${DRIVER_NAME}" DIST="${TARGET}" ARCH="${ARCH}" /usr/sbin/pbuilder update --configfile ./dist/debian/pbuilderrc +(cd "build/debian/${DRIVER_NAME}"-"${DRIVER_VERSION}"; dpkg-source -b .) +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" +fix_ownership build/debian/debs diff --git a/dist/debian/changelog.template b/dist/debian/changelog.template new file mode 100644 index 00000000..ef9b40c8 --- /dev/null +++ b/dist/debian/changelog.template @@ -0,0 +1,5 @@ +scylla-cpp-rust-driver (%{version}-%{release}-%{revision}) %{codename}; urgency=medium + + * Initial release. + + -- Takuya ASADA Wed, 1 May 2024 11:02:04 +0000 diff --git a/dist/debian/debian/control b/dist/debian/debian/control new file mode 100644 index 00000000..6e9d9d42 --- /dev/null +++ b/dist/debian/debian/control @@ -0,0 +1,32 @@ +Source: scylla-cpp-rust-driver +Maintainer: Takuya ASADA +Homepage: https://github.com/scylladb/cpp-rust-driver +Section: libs +Priority: optional +Standards-Version: 4.6.0 +Build-Depends: debhelper-compat (= 11), + libssl-dev, + libclang-dev, + pkg-config, + openssl, + ca-certificates, + curl, + clang, + patchelf + +Package: libscylla-cpp-driver0 +Architecture: any +Depends: ${misc:Depends}, + ${shlibs:Depends}, +Conflicts: scylla-cpp-driver +Description: ScyllaDB Cpp-Rust Driver + API-compatible rewrite of https://github.com/scylladb/cpp-driver as a wrapper for Rust driver. + +Package: libscylla-cpp-driver-dev +Section: libdevel +Architecture: any +Depends: libscylla-cpp-driver0 (= ${binary:Version}), + ${misc:Depends}, +Conflicts: scylla-cpp-driver-dev +Description: Development libraries for ScyllaDB Cpp-Rust Driver + API-compatible rewrite of https://github.com/scylladb/cpp-driver as a wrapper for Rust driver. diff --git a/dist/debian/debian/copyright b/dist/debian/debian/copyright new file mode 100644 index 00000000..6b5e7c7d --- /dev/null +++ b/dist/debian/debian/copyright @@ -0,0 +1,25 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: Scylla DB +Upstream-Contact: http://www.scylladb.com/ +Source: https://github.com/scylladb/cpp-rust-driver + +Files: * +Copyright: Copyright (C) 2024 ScyllaDB +License: LGPL-2.1+ + +License: LGPL-2.1+ + This package is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + . + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + . + You should have received a copy of the GNU Lesser General Public + License along with this package; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +X-Comment: on Debian systems, the complete text of the GNU Lesser General + Public License v2.1 can be found in `/usr/share/common-licenses/LGPL-2.1'. diff --git a/dist/debian/debian/debcargo.toml b/dist/debian/debian/debcargo.toml new file mode 100644 index 00000000..20e07a16 --- /dev/null +++ b/dist/debian/debian/debcargo.toml @@ -0,0 +1,5 @@ +overlay = "." +uploaders = ["Takuya ASADA "] + +[source] +section = "libs" diff --git a/dist/debian/debian/debhelper-build-stamp b/dist/debian/debian/debhelper-build-stamp new file mode 100644 index 00000000..db9ee593 --- /dev/null +++ b/dist/debian/debian/debhelper-build-stamp @@ -0,0 +1,2 @@ +libscylla-cpp-driver0 +libscylla-cpp-driver-dev diff --git a/dist/debian/debian/files b/dist/debian/debian/files new file mode 100644 index 00000000..d19c5ef4 --- /dev/null +++ b/dist/debian/debian/files @@ -0,0 +1,4 @@ +libscylla-cpp-driver-dev_0.0.1-0.20240328.f143d09a2057-1_amd64.deb libdevel optional +libscylla-cpp-driver0-dbgsym_0.0.1-0.20240328.f143d09a2057-1_amd64.ddeb debug optional automatic=yes +libscylla-cpp-driver0_0.0.1-0.20240328.f143d09a2057-1_amd64.deb libs optional +scylla-cpp-rust-driver_0.0.1-0.20240328.f143d09a2057-1_amd64.buildinfo libs optional diff --git a/dist/debian/debian/libscylla-cpp-driver-dev.install b/dist/debian/debian/libscylla-cpp-driver-dev.install new file mode 100644 index 00000000..a1a1516d --- /dev/null +++ b/dist/debian/debian/libscylla-cpp-driver-dev.install @@ -0,0 +1,4 @@ +usr/include/* +usr/lib/*/*.so +usr/lib/*/*.a +usr/lib/*/pkgconfig/*.pc diff --git a/dist/debian/debian/libscylla-cpp-driver0.install b/dist/debian/debian/libscylla-cpp-driver0.install new file mode 100644 index 00000000..3de3b10a --- /dev/null +++ b/dist/debian/debian/libscylla-cpp-driver0.install @@ -0,0 +1 @@ +usr/lib/*/*.so.* diff --git a/dist/debian/debian/rules b/dist/debian/debian/rules new file mode 100755 index 00000000..2a4f28d3 --- /dev/null +++ b/dist/debian/debian/rules @@ -0,0 +1,50 @@ +#!/usr/bin/make -f +# -*- makefile -*- + +export DH_VERBOSE=1 + +include /usr/share/dpkg/architecture.mk +include /usr/share/dpkg/buildflags.mk + +export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS +export DEB_HOST_RUST_TYPE DEB_HOST_GNU_TYPE +jobs := $(shell echo $$DEB_BUILD_OPTIONS | sed -r "s/.*parallel=([0-9]+).*/-j\1/") +SCYLLA_VERSION := $(shell cat version | awk -F'-' '{print $1}' | sed 's/-/~/') + +%: + dh $@ + +override_dh_auto_clean: + rm -rf scylla-rust-wrapper/target + rm -rf scylla-rust-wrapper/.cargo + rm -rf scylla-rust-wrapper/.rust + +export CARGO_CONFIG +override_dh_auto_configure: + /usr/bin/curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | CARGO_HOME=$(CURDIR)/debian/.cargo RUSTUP_HOME=$(CURDIR)/debian/.rust /bin/sh -s -- -v -y --no-modify-path + +override_dh_auto_build: + (cd scylla-rust-wrapper && PATH=$(CURDIR)/debian/.cargo/bin:$$PATH CARGO_HOME=$(CURDIR)/debian/.cargo RUSTUP_HOME=$(CURDIR)/debian/.rust $(CURDIR)/debian/.cargo/bin/cargo build $(jobs) --profile packaging --verbose) + (cd scylla-rust-wrapper && ./versioning.sh --profile packaging) + sed -e "s#@prefix@#/usr#g" \ + -e "s#@exec_prefix@#/usr#g" \ + -e "s#@libdir@#/usr/lib/$(DEB_HOST_MULTIARCH)#g" \ + -e "s#@includedir@#/usr/include#g" \ + -e "s#@version@#$(SCYLLA_VERSION)#g" \ + dist/common/pkgconfig/scylla-cpp-driver.pc.in > debian/scylla-cpp-driver.pc + sed -e "s#@prefix@#/usr#g" \ + -e "s#@exec_prefix@#/usr#g" \ + -e "s#@libdir@#/usr/lib/$(DEB_HOST_MULTIARCH)#g" \ + -e "s#@includedir@#/usr/include#g" \ + -e "s#@version@#$(SCYLLA_VERSION)#g" \ + dist/common/pkgconfig/scylla-cpp-driver_static.pc.in > debian/scylla-cpp-driver_static.pc + +override_dh_auto_install: + mkdir -p "$(CURDIR)"/debian/tmp/usr/lib/"$(DEB_HOST_GNU_TYPE)" + mkdir -p "$(CURDIR)"/debian/tmp/usr/lib/"$(DEB_HOST_GNU_TYPE)"/pkgconfig + mkdir -p "$(CURDIR)"/debian/tmp/usr/include + install -Dpm0644 "$(CURDIR)"/scylla-rust-wrapper/target/packaging/*.a "$(CURDIR)"/debian/tmp/usr/lib/"$(DEB_HOST_GNU_TYPE)" + # We need to avoid dereference symlink, so can't use install here + 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)"/ + install -Dpm0644 "$(CURDIR)"/debian/*.pc "$(CURDIR)"/debian/tmp/usr/lib/"$(DEB_HOST_GNU_TYPE)"/pkgconfig + install -Dpm0644 "$(CURDIR)"/include/*.h "$(CURDIR)"/debian/tmp/usr/include diff --git a/dist/debian/debian/source/format b/dist/debian/debian/source/format new file mode 100644 index 00000000..163aaf8d --- /dev/null +++ b/dist/debian/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/dist/debian/debian_files_gen.py b/dist/debian/debian_files_gen.py new file mode 100755 index 00000000..4dc102f4 --- /dev/null +++ b/dist/debian/debian_files_gen.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Copyright (C) 2020-present ScyllaDB +# + +# +# SPDX-License-Identifier: AGPL-3.0-or-later +# + +import argparse +import string +import os +import shutil +import re +import subprocess +from pathlib import Path + +class DebianFilesTemplate(string.Template): + delimiter = '%' + +def generate_changelog(scriptdir, outputdir, version, release, revision, codename): + with open(os.path.join(scriptdir, 'changelog.template')) as f: + changelog_template = f.read() + s = DebianFilesTemplate(changelog_template) + changelog_applied = s.substitute(version=version, + release=release, + revision=revision, + codename=codename) + with open(os.path.join(outputdir, 'changelog'), 'w', encoding='utf-8') as f: + f.write(changelog_applied) + +def main(): + arg_parser = argparse.ArgumentParser() + arg_parser.add_argument('--version', action='store', help='specify version') + arg_parser.add_argument('--release', action='store', help='specify release') + arg_parser.add_argument('--revision', action='store', help='specify revision') + arg_parser.add_argument('--codename', action='store', help='specify distribution codename') + arg_parser.add_argument('--output-dir', action='store', default='debian/debian', + help='output directory') + args = arg_parser.parse_args() + outputdir = args.output_dir + if os.path.exists(outputdir): + shutil.rmtree(outputdir) + shutil.copytree('dist/debian/debian', outputdir) + scriptdir = os.path.dirname(__file__) + generate_changelog(scriptdir, outputdir, args.version, args.release, args.revision, args.codename) + + +if __name__ == '__main__': + main() diff --git a/dist/debian/pbuilderrc b/dist/debian/pbuilderrc new file mode 100644 index 00000000..684220b8 --- /dev/null +++ b/dist/debian/pbuilderrc @@ -0,0 +1,20 @@ +USENETWORK=yes +BUILD_HOME=/tmp +ARCHITECTURE="$ARCH" +DISTRIBUTION="$DIST" +BASETGZ="/var/cache/pbuilder/$DRIVER_NAME-$DIST-$ARCH-base.tgz" +APTCACHE="/var/cache/pbuilder/$DRIVER_NAME-$DIST-$ARCH/aptcache/" +EXTRAPACKAGES="sudo" + +if [ "$DIST" = "bionic" ] || [ "$DIST" = "focal" ] || [ "$DIST" = "jammy" ] || [ "$DIST" = "mantic" ] || [ "$DIST" = "noble" ]; then + MIRRORSITE="http://archive.ubuntu.com/ubuntu/" + COMPONENTS="main restricted universe multiverse" + DEBOOTSTRAPOPTS="--keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg" +elif [ "$DIST" = "buster" ] || [ "$DIST" = "bullseye" ] || [ "$DIST" = "bookworm" ] || [ "$DIST" = "trixie" ] || [ "$DIST" = "sid" ]; then + MIRRORSITE="http://deb.debian.org/debian/" + COMPONENTS="main contrib non-free" + DEBOOTSTRAPOPTS="--keyring=/usr/share/keyrings/debian-archive-keyring.gpg" +else + echo "Unknown distribution: $DIST" + exit 1 +fi diff --git a/dist/redhat/build_rpm.sh b/dist/redhat/build_rpm.sh new file mode 100755 index 00000000..212363fb --- /dev/null +++ b/dist/redhat/build_rpm.sh @@ -0,0 +1,88 @@ +#!/bin/bash -e + +. /etc/os-release +print_usage() { + echo "build_rpm.sh --jobs 2 --target rocky+epel-9-x86_64" + echo " --jobs specify number of jobs" + echo " --target target distribution in mock cfg name" + exit 1 +} +JOBS="$(nproc)" +TARGET= +while [[ $# -gt 0 ]]; do + case "$1" in + "--jobs") + JOBS="$2" + shift 2 + ;; + "--target") + TARGET="$2" + shift 2 + ;; + *) + print_usage + ;; + esac +done + +is_redhat_variant() { + [[ -f /etc/redhat-release ]] +} + +pkg_install() { + if is_redhat_variant; then + sudo dnf install -y "$1" + else + echo "Requires to install following command: $1" + exit 1 + fi +} + +TOPDIR="$(pwd)" +if [[ ! -e dist/redhat/build_rpm.sh ]]; then + echo "run build_rpm.sh in top of scylla dir" + exit 1 +fi + +if [[ -z "${TARGET}" ]]; then + echo "Please specify target" + exit 1 +fi + +if [[ ! -f /usr/bin/mock ]]; then + pkg_install mock +fi +if [[ ! -f /usr/bin/git ]]; then + pkg_install git +fi + +echo "Selected target: ${TARGET}" + +./SCYLLA-VERSION-GEN +DRIVER_NAME=scylla-cpp-rust-driver +DRIVER_VERSION="$(sed 's/-/~/' build/SCYLLA-VERSION-FILE)" +DRIVER_RELEASE="$(cat build/SCYLLA-RELEASE-FILE)" + +mkdir -p build/redhat/sources +git archive HEAD --prefix "${DRIVER_NAME}-${DRIVER_VERSION}/" --output "build/redhat/sources/${DRIVER_NAME}-${DRIVER_VERSION}-${DRIVER_RELEASE}.tar" +echo "$(cat build/SCYLLA-VERSION-FILE)-$(cat build/SCYLLA-RELEASE-FILE)" > version +tar --xform "s#^#${DRIVER_NAME}-${DRIVER_VERSION}/#" -rf "build/redhat/sources/${DRIVER_NAME}-${DRIVER_VERSION}-${DRIVER_RELEASE}.tar" version + +# mock generates files owned by root, fix this up +fix_ownership() { + CURRENT_UID="$(id -u)" + CURRENT_GID="$(id -g)" + sudo chown "${CURRENT_UID}":"${CURRENT_GID}" -R "$@" +} + +MOCK_OPTS=( + -D"driver_version ${DRIVER_VERSION}" + -D"driver_release ${DRIVER_RELEASE}" + -D"_smp_mflags -j${JOBS}" +) +sudo mock "${MOCK_OPTS[@]}" --rootdir="${TOPDIR}/build/redhat/mock" --buildsrpm --root="${TARGET}" --resultdir="${TOPDIR}/build/redhat/srpms" --spec="dist/redhat/${DRIVER_NAME}.spec" --sources="build/redhat/sources/${DRIVER_NAME}-${DRIVER_VERSION}-${DRIVER_RELEASE}.tar" +SRPM="$(sed -n -e "s@Wrote: /builddir/build/SRPMS/\(${DRIVER_NAME}-${DRIVER_VERSION//./\.}-${DRIVER_RELEASE}\..*\.src\.rpm\)@\1@p" build/redhat/srpms/build.log | tail -n1)" +sudo mock "${MOCK_OPTS[@]}" --rootdir="${TOPDIR}/build/redhat/mock" --enable-network --rebuild --root="${TARGET}" --resultdir="${TOPDIR}/build/redhat/rpms" "build/redhat/srpms/${SRPM}" +fix_ownership build/redhat/sources +fix_ownership build/redhat/srpms +fix_ownership build/redhat/rpms diff --git a/dist/redhat/scylla-cpp-rust-driver.spec b/dist/redhat/scylla-cpp-rust-driver.spec new file mode 100644 index 00000000..502de60f --- /dev/null +++ b/dist/redhat/scylla-cpp-rust-driver.spec @@ -0,0 +1,80 @@ +Name: scylla-cpp-rust-driver +Version: %{driver_version} +Release: %{driver_release}%{?dist} +Summary: ScyllaDB Cpp-Rust Driver +Group: Development/Tools + +License: LGPLv2.1 +URL: https://github.com/scylladb/cpp-rust-driver +Source0: %{name}-%{driver_version}-%{driver_release}.tar +BuildRequires: openssl-devel +BuildRequires: clang-devel +BuildRequires: curl +BuildRequires: patchelf +Conflicts: scylla-cpp-driver + +%description +API-compatible rewrite of https://github.com/scylladb/cpp-driver as a wrapper for Rust driver. + +%package devel +Summary: Development libraries for ${name} +Group: Development/Tools +Requires: %{name} = %{version}-%{release} +Requires: pkgconfig +Conflicts: scylla-cpp-driver-devel + +%description devel +Development libraries for %{name} + +%prep +%autosetup +%{__rm} -rf scylla-rust-wrapper/.cargo +%{__mkdir} -p scylla-rust-wrapper/.cargo +/usr/bin/curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | CARGO_HOME=$(pwd)/scylla-rust-wrapper/.cargo RUSTUP_HOME=$(pwd)/scylla-rust-wrapper/.rust RUSTUP_INIT_SKIP_PATH_CHECK=yes /bin/sh -s -- -y +set -euo pipefail + +%build +(cd scylla-rust-wrapper && PATH=$(pwd)/.cargo/bin:$PATH CARGO_HOME=$(pwd)/.cargo RUSTUP_HOME=$(pwd)/.rust $(pwd)/.cargo/bin/cargo build %{?_smp_mflags} --profile packaging --verbose) +(cd scylla-rust-wrapper && ./versioning.sh --profile packaging) +sed -e "s#@prefix@#%{_prefix}#g" \ + -e "s#@exec_prefix@#%{_exec_prefix}#g" \ + -e "s#@libdir@#%{_libdir}#g" \ + -e "s#@includedir@#%{_includedir}#g" \ + -e "s#@version@#%{version}#g" \ + dist/common/pkgconfig/scylla-cpp-driver.pc.in > scylla-cpp-driver.pc +sed -e "s#@prefix@#%{_prefix}#g" \ + -e "s#@exec_prefix@#%{_exec_prefix}#g" \ + -e "s#@libdir@#%{_libdir}#g" \ + -e "s#@includedir@#%{_includedir}#g" \ + -e "s#@version@#%{version}#g" \ + dist/common/pkgconfig/scylla-cpp-driver_static.pc.in > scylla-cpp-driver_static.pc + +%install +rm -rf %{buildroot} +install -Dpm0644 scylla-rust-wrapper/target/packaging/*.a -t %{buildroot}%{_libdir} +# We need to avoid dereference symlink, so can't use install here +cp -a scylla-rust-wrapper/target/packaging/{*.so.*,*.so} %{buildroot}%{_libdir} +install -Dpm0644 *.pc -t %{buildroot}%{_libdir}/pkgconfig +install -Dpm0644 include/*.h -t %{buildroot}%{_includedir} + +%ldconfig_scriptlets + +%clean +rm -rf %{buildroot} + +%files +%defattr(-,root,root) +%doc README.md LICENSE +%{_libdir}/*.so.* + +%files devel +%defattr(-,root,root) +%doc README.md LICENSE +%{_includedir}/*.h +%{_libdir}/*.so +%{_libdir}/*.a +%{_libdir}/pkgconfig/*.pc + +%changelog +* Thu Mar 28 2024 Takuya ASADA +- initial version of scylla-cpp-rust-driver.spec diff --git a/scylla-rust-wrapper/Cargo.toml b/scylla-rust-wrapper/Cargo.toml index 5e32ad82..2ac22f1c 100644 --- a/scylla-rust-wrapper/Cargo.toml +++ b/scylla-rust-wrapper/Cargo.toml @@ -44,3 +44,10 @@ panic = "abort" [profile.release] lto = true panic = "abort" + +[profile.packaging] +inherits = "release" +opt-level = 3 +codegen-units = 1 +debug = 2 +strip = "none" diff --git a/scylla-rust-wrapper/versioning.sh b/scylla-rust-wrapper/versioning.sh new file mode 100755 index 00000000..6be3fb20 --- /dev/null +++ b/scylla-rust-wrapper/versioning.sh @@ -0,0 +1,53 @@ +#!/bin/bash -e + +print_usage() { + echo "$0 --profile release" + echo " --profile specify profile" + exit 1 +} +PROFILE="release" +while [[ $# -gt 0 ]]; do + case "$1" in + "--profile") + PROFILE="$2" + shift 2 + ;; + *) + print_usage + ;; + esac +done + +TARGET="$PROFILE" +case "$PROFILE" in + "dev") + TARGET="debug" + ;; +esac + +if [[ ! -d target/"${TARGET}" ]]; then + echo "Failed to locate build directory: target/${TARGET}" + exit 1 +fi + +VERSION_MAJOR=$(sed -n -e 's/^#define CASS_VERSION_MAJOR \(.*\)/\1/p' ../include/cassandra.h) +VERSION_MINOR=$(sed -n -e 's/^#define CASS_VERSION_MINOR \(.*\)/\1/p' ../include/cassandra.h) +VERSION_PATCH=$(sed -n -e 's/^#define CASS_VERSION_PATCH \(.*\)/\1/p' ../include/cassandra.h) +VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" + +if [[ ! -f /usr/bin/patchelf ]]; then + echo "patchelf is not installed." +fi + +# library name should be "libscylla-cpp-driver", but since Cargo doesn't allow this library name we have to rename it here +cp --remove-destination -v target/"${TARGET}"/libscylla_cpp_driver.so target/"${TARGET}"/libscylla-cpp-driver.so +cp --remove-destination -v target/"${TARGET}"/libscylla_cpp_driver.a target/"${TARGET}"/libscylla-cpp-driver_static.a +rm -fv target/"${TARGET}"/libscylla_cpp_driver.{so,a} + +# add SONAME to .so +patchelf --debug --set-soname libscylla-cpp-driver.so."${VERSION_MAJOR}" target/"${TARGET}"/libscylla-cpp-driver.so + +# make .so "versioned" style using symlinks +cp --remove-destination -v target/"${TARGET}"/libscylla-cpp-driver.so target/"${TARGET}"/libscylla-cpp-driver.so."${VERSION}" +ln -vsf libscylla-cpp-driver.so."${VERSION}" target/"${TARGET}"/libscylla-cpp-driver.so."${VERSION_MAJOR}" +ln -vsf libscylla-cpp-driver.so."${VERSION}" target/"${TARGET}"/libscylla-cpp-driver.so