Skip to content

Commit

Permalink
debian packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
avsej committed Nov 5, 2024
1 parent 05fd945 commit ce56ebc
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 11 deletions.
128 changes: 119 additions & 9 deletions cmake/Packaging.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,116 @@ add_custom_command(

add_custom_target(packaging_tarball DEPENDS ${COUCHBASE_CXX_CLIENT_TARBALL})

option(COUCHBASE_CXX_CLIENT_DEB_TARGETS "Enable targets for building DEBs" FALSE)
if(COUCHBASE_CXX_CLIENT_DEB_TARGETS)
find_program(DPKG_BUILDPACKAGE dpkg-buildpackage REQUIRED) # apt install -y dpkg-dev
find_program(SUDO sudo REQUIRED) # apt install -y sudo
find_program(COWBUILDER cowbuilder REQUIRED) # apt install -y cowbuilder

string(TIMESTAMP COUCHBASE_CXX_CLIENT_DEB_DATE "%a, %d %b %Y %H:%M:%S %z" UTC)

file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/packaging/workspace/debian/source/")

set(COUCHBASE_CXX_CLIENT_DEBIAN_CHANGELOG "${PROJECT_BINARY_DIR}/packaging/workspace/debian/changelog")
configure_file(${PROJECT_SOURCE_DIR}/cmake/debian/changelog.in "${COUCHBASE_CXX_CLIENT_DEBIAN_CHANGELOG}" @ONLY)

file(COPY ${PROJECT_SOURCE_DIR}/cmake/debian/compat ${PROJECT_SOURCE_DIR}/cmake/debian/control
${PROJECT_SOURCE_DIR}/cmake/debian/rules DESTINATION "${PROJECT_BINARY_DIR}/packaging/workspace/debian/")
file(COPY ${PROJECT_SOURCE_DIR}/cmake/debian/source/format
DESTINATION "${PROJECT_BINARY_DIR}/packaging/workspace/debian/source/")

set(COUCHBASE_CXX_CLIENT_DEBIAN_ORIG_TARBALL
"${PROJECT_BINARY_DIR}/packaging/couchbase-cxx-client_${COUCHBASE_CXX_CLIENT_PACKAGE_VERSION}.orig.tar.gz")
add_custom_command(
OUTPUT ${COUCHBASE_CXX_CLIENT_DEBIAN_ORIG_TARBALL}
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/packaging"
COMMAND ${CMAKE_COMMAND} -E copy "${COUCHBASE_CXX_CLIENT_TARBALL}" "${COUCHBASE_CXX_CLIENT_DEBIAN_ORIG_TARBALL}"
DEPENDS ${COUCHBASE_CXX_CLIENT_TARBALL})

set(COUCHBASE_CXX_CLIENT_DEBIAN_TARBALL_EXTRACTED "${PROJECT_BINARY_DIR}/packaging/tarball_extracted.txt")
add_custom_command(
OUTPUT ${COUCHBASE_CXX_CLIENT_DEBIAN_TARBALL_EXTRACTED}
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/packaging/workspace"
COMMAND ${TAR} --strip-components=1 -xf "${COUCHBASE_CXX_CLIENT_TARBALL}"
COMMAND touch ${COUCHBASE_CXX_CLIENT_DEBIAN_TARBALL_EXTRACTED}
DEPENDS ${COUCHBASE_CXX_CLIENT_TARBALL})

set(COUCHBASE_CXX_CLIENT_DEBIAN_DSC
"${PROJECT_BINARY_DIR}/packaging/couchbase-cxx-client_${COUCHBASE_CXX_CLIENT_PACKAGE_VERSION}-${COUCHBASE_CXX_CLIENT_PACKAGE_RELEASE}.dsc"
)
add_custom_command(
OUTPUT ${COUCHBASE_CXX_CLIENT_DEBIAN_DSC}
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/packaging/workspace"
COMMAND ${DPKG_BUILDPACKAGE} -us -uc
DEPENDS ${COUCHBASE_CXX_CLIENT_DEBIAN_ORIG_TARBALL} ${COUCHBASE_CXX_CLIENT_DEBIAN_TARBALL_EXTRACTED})

function(select_mirror_options distro options)
if(${distro} STREQUAL "bookworm")
set(${options}
--components
main
--mirror
https://ftp.debian.org/debian
PARENT_SCOPE)
else()
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
set(${options}
--components
"main universe"
--mirror
http://ports.ubuntu.com/ubuntu-ports
PARENT_SCOPE)
else()
set(${options}
--components
"main universe"
--mirror
http://archive.ubuntu.com/ubuntu
PARENT_SCOPE)
endif()
endif()
endfunction()

set(cowbuilder_results "${PROJECT_BINARY_DIR}/packaging/results")
file(MAKE_DIRECTORY "${cowbuilder_results}")

list(
APPEND
COUCHBASE_CXX_CLIENT_SUPPORTED_DISTROS
"jammy"
"noble"
"bookworm")

set(cowbuilder_root "${PROJECT_BINARY_DIR}/packaging/root.cow")
set(last_output "")
foreach(distro ${COUCHBASE_CXX_CLIENT_SUPPORTED_DISTROS})
select_mirror_options(${distro} mirror_options)
set(timestamp "${PROJECT_BINARY_DIR}/packaging/${distro}_done.txt")
set(dependencies ${COUCHBASE_CXX_CLIENT_DEBIAN_DSC})

if(last_output)
list(APPEND dependencies ${last_output})
endif()

add_custom_command(
COMMENT "Building DEB for ${distro}"
OUTPUT ${timestamp}
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/packaging"
COMMAND ${SUDO} ${CMAKE_COMMAND} -E rm -rf "${cowbuilder_root}"
COMMAND ${SUDO} ${COWBUILDER} --create --basepath "${cowbuilder_root}" --distribution ${distro} ${mirror_options}
COMMAND
${SUDO} ${COWBUILDER} --build --basepath "${cowbuilder_root}" --buildresult
"${cowbuilder_results}/couchbase-cxx-client-${COUCHBASE_CXX_CLIENT_PACKAGE_VERSION}-${COUCHBASE_CXX_CLIENT_PACKAGE_RELEASE}.${distro}.${CMAKE_SYSTEM_PROCESSOR}"
--debbuildopts -j8 --debbuildopts "-us -uc" ${COUCHBASE_CXX_CLIENT_DEBIAN_DSC}
COMMAND touch ${timestamp}
DEPENDS ${dependencies})

set(last_output ${timestamp})
endforeach()

add_custom_target(packaging_deb DEPENDS ${last_output})
endif()

option(COUCHBASE_CXX_CLIENT_RPM_TARGETS "Enable targets for building RPMs" FALSE)
if(COUCHBASE_CXX_CLIENT_RPM_TARGETS)
find_program(MOCK mock REQUIRED) # dnf install -y mock
Expand All @@ -132,35 +242,35 @@ if(COUCHBASE_CXX_CLIENT_RPM_TARGETS)

add_custom_target(packaging_srpm DEPENDS ${COUCHBASE_CXX_CLIENT_SRPM})

list(APPEND COUCHBASE_CXX_CLIENT_SUPPORTED_ROOTS
list(
APPEND
COUCHBASE_CXX_CLIENT_SUPPORTED_ROOTS
"opensuse-leap-15.5-${CMAKE_SYSTEM_PROCESSOR}"
"rocky-9-${CMAKE_SYSTEM_PROCESSOR}"
"rocky-8-${CMAKE_SYSTEM_PROCESSOR}"
"amazonlinux-2023-${CMAKE_SYSTEM_PROCESSOR}"
"fedora-41-${CMAKE_SYSTEM_PROCESSOR}"
"fedora-40-${CMAKE_SYSTEM_PROCESSOR}"
)
"fedora-40-${CMAKE_SYSTEM_PROCESSOR}")

message(STATUS "Supported build roots for RPM packages: ${COUCHBASE_CXX_CLIENT_SUPPORTED_ROOTS}")

# Build the chain of the dependencies from the timestamps, so that everything
# will be executed one-by-one in order, because the mock cannot run multiple
# roots simultaneously
# Build the chain of the dependencies from the timestamps, so that everything will be executed one-by-one in order,
# because the mock cannot run multiple roots simultaneously
set(last_output "")
foreach(root ${COUCHBASE_CXX_CLIENT_SUPPORTED_ROOTS})
set(timestamp "${PROJECT_BINARY_DIR}/packaging/rpm/${root}/done.txt")
set(dependencies ${COUCHBASE_CXX_CLIENT_SRPM})

if (last_output)
if(last_output)
list(APPEND dependencies ${last_output})
endif()

add_custom_command(
COMMENT "Building RPM for ${root}"
OUTPUT ${timestamp}
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/packaging"
COMMAND ${MOCK} --rebuild --root=${root}
--resultdir=${PROJECT_BINARY_DIR}/packaging/rpm/${root} "${COUCHBASE_CXX_CLIENT_SRPM}"
COMMAND ${MOCK} --rebuild --root=${root} --resultdir=${PROJECT_BINARY_DIR}/packaging/rpm/${root}
"${COUCHBASE_CXX_CLIENT_SRPM}"
COMMAND touch ${timestamp}
DEPENDS ${dependencies})

Expand Down
4 changes: 2 additions & 2 deletions cmake/couchbase-cxx-client.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ Source0: @[email protected]
This is the client and protocol library for Couchbase project.

%package tools
Summary: Couchbase C++ SDK - Tools
Summary: Couchbase C++ SDK, command line tools
Requires: %{name}%{?_isa} = %{version}-%{release}
%description -n %{name}-tools
CLI tools from the Couchbase C++ SDK.

%package devel
Summary: Couchbase C++ SDK - Header files
Summary: Couchbase C++ SDK, development files
Requires: %{name}%{?_isa} = %{version}-%{release}
%description devel
Development files for the Couchbase C++ SDK.
Expand Down
5 changes: 5 additions & 0 deletions cmake/debian/changelog.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
couchbase-cxx-client (@COUCHBASE_CXX_CLIENT_PACKAGE_VERSION@-@COUCHBASE_CXX_CLIENT_PACKAGE_RELEASE@) unstable; urgency=medium

* Automated build.

-- Couchbase SDK Team <[email protected]> @COUCHBASE_CXX_CLIENT_DEB_DATE@
1 change: 1 addition & 0 deletions cmake/debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
40 changes: 40 additions & 0 deletions cmake/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Source: couchbase-cxx-client
Section: libs
Priority: optional
Maintainer: Couchbase SDK Team <[email protected]>
Build-Depends: debhelper (>= 9), cmake, pkg-config
Standards-Version: 4.5.0
Vcs-Browser: https://github.com/couchbase/couchbase-cxx-client
Vcs-Git: https://github.com/couchbase/couchbase-cxx-client.git

Package: couchbase-cxx-client
Architecture: any
Multi-Arch: same
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Couchbase C++ SDK.
This is the client and protocol library for Couchbase project.

Package: couchbase-cxx-client-tools
Architecture: any
Multi-Arch: same
Section: utils
Depends: couchbase-cxx-client (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends}
Description: Couchbase C++ SDK, command line tools.
This is the command line tools for the client and protocol library for
Couchbase project.

Package: couchbase-cxx-client-dev
Architecture: any
Multi-Arch: same
Depends: couchbase-cxx-client (= ${binary:Version}), ${misc:Depends}
Description: Couchbase C++ SDK, development files.
This is the development files for the client and protocol library for
Couchbase project.

Package: couchbase-cxx-client-dbg
Architecture: any
Multi-Arch: same
Depends: couchbase-cxx-client (= ${binary:Version}), ${misc:Depends}
Description: Couchbase C++ SDK, debug symbols.
This is the debug symbols for the client and protocol library for Couchbase
project.
41 changes: 41 additions & 0 deletions cmake/debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/make -f

%:
dh $@ --buildsystem=cmake

override_dh_strip:
dh_strip -pcouchbase-cxx-client-tools -pcouchbase-cxx-client --dbg-package=couchbase-cxx-client-dbg
dh_strip --remaining-packages

override_dh_auto_configure:
echo "usr/include/couchbase" \
> debian/couchbase-cxx-client-dev.install
echo "usr/lib/$(DEB_HOST_MULTIARCH)/libcouchbase_cxx_client.so" \
>> debian/couchbase-cxx-client-dev.install
echo "usr/lib/$(DEB_HOST_MULTIARCH)/cmake" \
>> debian/couchbase-cxx-client-dev.install
echo "usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig" \
>> debian/couchbase-cxx-client-dev.install
echo "usr/bin/*" \
> debian/couchbase-cxx-client-tools.install
echo "usr/lib/$(DEB_HOST_MULTIARCH)/libcouchbase_cxx_client.so.*" \
> debian/couchbase-cxx-client.install
echo "usr/share/doc/tao/json/LICENSE" \
>> debian/couchbase-cxx-client.install
echo "usr/share/doc/tao/pegtl/LICENSE" \
>> debian/couchbase-cxx-client.install
echo "usr/share/doc/couchbase_cxx_client/LICENSE.txt" \
>> debian/couchbase-cxx-client.install
dh_auto_configure -- \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_SHARED_LIBS=OFF \
-DCOUCHBASE_CXX_CLIENT_INSTALL=ON \
-DCOUCHBASE_CXX_CLIENT_STATIC_BORINGSSL=ON \
-DCOUCHBASE_CXX_CLIENT_BUILD_EXAMPLES=OFF \
-DCOUCHBASE_CXX_CLIENT_BUILD_TESTS=OFF \
-DCOUCHBASE_CXX_CLIENT_BUILD_TOOLS=ON \
-DCOUCHBASE_CXX_CLIENT_BUILD_STATIC=OFF \
-DCOUCHBASE_CXX_CLIENT_BUILD_SHARED=ON

override_dh_auto_build:
dh_auto_build
1 change: 1 addition & 0 deletions cmake/debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (quilt)

0 comments on commit ce56ebc

Please sign in to comment.