Skip to content

Commit

Permalink
Add scripts to produce APK files for Alpine Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
avsej committed Nov 14, 2024
1 parent c24912f commit 8bf1445
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 2 deletions.
54 changes: 54 additions & 0 deletions cmake/APKBUILD.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Contributor: Couchbase SDK Team <support@couchbase.com>
# Maintainer: Couchbase SDK Team <support@couchbase.com>

pkgname=couchbase-cxx-client
pkgver=@COUCHBASE_CXX_CLIENT_PACKAGE_VERSION@
pkgrel=1
_number_of_commits=@COUCHBASE_CXX_CLIENT_NUMBER_OF_COMMITS@
if [ "${_number_of_commits}" -gt 0 ]; then
pkgver="${pkgver}_p${_number_of_commits}"
fi
source="${pkgname}-${pkgver}.tar.gz"
pkgdesc="Couchbase C++ SDK"
url="https://docs.couchbase.com/cxx-sdk/current/hello-world/overview.html"
arch="all"
license="Apache-2.0"
depends=""
makedepends="
linux-headers
cmake
ninja
"
subpackages="${pkgname}-dev ${pkgname}-tools"
options="!check"

unpack() {
(cd "${srcdir}"; tar -xzf "${source}" --strip-components=1)
}

build() {
cmake -B apk-build -S "${srcdir}" -G Ninja \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DBUILD_SHARED_LIBS=OFF \
-DCOUCHBASE_CXX_CLIENT_PKGCONFIG_VERSION="${pkgver}" \
-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
cmake --build apk-build
}

tools() {
pkgdesc="${pkgdesc} (tools)"
depends="${pkgname}=${pkgver}-r${pkgrel}"

amove usr/bin
}

package() {
DESTDIR="${pkgdir}" cmake --install apk-build
}
48 changes: 48 additions & 0 deletions cmake/Packaging.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include(CMakePackageConfigHelpers)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/couchbase DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES LICENSE.txt DESTINATION ${CMAKE_INSTALL_DOCDIR})

set(COUCHBASE_CXX_CLIENT_PKGCONFIG_VERSION "${COUCHBASE_CXX_CLIENT_SEMVER}" CACHE STRING "The version to use in couchbase_cxx_client.pc")
configure_file(${PROJECT_SOURCE_DIR}/cmake/couchbase_cxx_client.pc.in
${PROJECT_BINARY_DIR}/packaging/couchbase_cxx_client.pc @ONLY)
install(FILES ${PROJECT_BINARY_DIR}/packaging/couchbase_cxx_client.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
Expand Down Expand Up @@ -280,3 +281,50 @@ if(COUCHBASE_CXX_CLIENT_RPM_TARGETS)
# add target that depends on the last root
add_custom_target(packaging_rpm DEPENDS ${last_output})
endif()

option(COUCHBASE_CXX_CLIENT_APK_TARGETS "Enable targets for building APKs (for Alpine Linux)" FALSE)
if(COUCHBASE_CXX_CLIENT_APK_TARGETS)
find_program(ABUILD abuild REQUIRED) # apk add alpine-sdk

set(COUCHBASE_CXX_CLIENT_TARBALL_NAME_ALPINE "${COUCHBASE_CXX_CLIENT_TARBALL_NAME}")
set(COUCHBASE_CXX_CLIENT_TARBALL_ALPINE
"${PROJECT_BINARY_DIR}/packaging/${COUCHBASE_CXX_CLIENT_TARBALL_NAME_ALPINE}.tar.gz")
if(${COUCHBASE_CXX_CLIENT_NUMBER_OF_COMMITS} GREATER 0)
set(COUCHBASE_CXX_CLIENT_TARBALL_NAME_ALPINE
"couchbase-cxx-client-${COUCHBASE_CXX_CLIENT_PACKAGE_VERSION}_p${COUCHBASE_CXX_CLIENT_NUMBER_OF_COMMITS}")
set(COUCHBASE_CXX_CLIENT_TARBALL_ALPINE
"${PROJECT_BINARY_DIR}/packaging/${COUCHBASE_CXX_CLIENT_TARBALL_NAME_ALPINE}.tar.gz")
endif()

set(cxxcbc_apkbuild_file "${PROJECT_BINARY_DIR}/packaging/APKBUILD")
configure_file(${PROJECT_SOURCE_DIR}/cmake/APKBUILD.in "${cxxcbc_apkbuild_file}" @ONLY)

if(NOT
"${COUCHBASE_CXX_CLIENT_TARBALL}"
STREQUAL
"${COUCHBASE_CXX_CLIENT_TARBALL_ALPINE}")
add_custom_command(
OUTPUT ${COUCHBASE_CXX_CLIENT_TARBALL_ALPINE}
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/packaging"
COMMAND ${CMAKE_COMMAND} -E copy "${COUCHBASE_CXX_CLIENT_TARBALL}" "${COUCHBASE_CXX_CLIENT_TARBALL_ALPINE}"
DEPENDS ${COUCHBASE_CXX_CLIENT_TARBALL})
endif()

set(cxxcbc_apkbuild_checksum "${PROJECT_BINARY_DIR}/packaging/apk_checksum_updated.txt")
add_custom_command(
OUTPUT ${cxxcbc_apkbuild_checksum}
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/packaging"
COMMAND ${ABUILD} checksum
COMMAND touch ${cxxcbc_apkbuild_checksum}
DEPENDS ${COUCHBASE_CXX_CLIENT_TARBALL_ALPINE} ${cxxcbc_apkbuild_file})

set(cxxcbc_apkbuild_timestamp "${PROJECT_BINARY_DIR}/packaging/apk_timestamp.txt")
add_custom_command(
OUTPUT ${cxxcbc_apkbuild_timestamp}
WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/packaging"
COMMAND ${ABUILD} -r
COMMAND touch ${cxxcbc_apkbuild_timestamp}
DEPENDS ${COUCHBASE_CXX_CLIENT_TARBALL_ALPINE} ${cxxcbc_apkbuild_checksum})

add_custom_target(packaging_apk DEPENDS ${cxxcbc_apkbuild_timestamp})
endif()
2 changes: 2 additions & 0 deletions cmake/VersionInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ string(REGEX REPLACE "T.*" "" COUCHBASE_CXX_CLIENT_BUILD_DATE "${COUCHBASE_CXX_C
set(COUCHBASE_CXX_CLIENT_SEMVER "${couchbase_cxx_client_VERSION}")
set(COUCHBASE_CXX_CLIENT_PACKAGE_VERSION "${couchbase_cxx_client_VERSION}")
set(COUCHBASE_CXX_CLIENT_PACKAGE_RELEASE "${couchbase_cxx_client_BUILD_NUMBER}")
set(COUCHBASE_CXX_CLIENT_NUMBER_OF_COMMITS 0)
if(COUCHBASE_CXX_CLIENT_GIT_DESCRIBE MATCHES
"^([0-9]+\\.[0-9]+\\.[0-9]+)(-([a-zA-Z0-9\\.]+))?(-([0-9]+)-g([a-zA-Z0-9]+))?$")
set(COUCHBASE_CXX_CLIENT_SEMVER "${CMAKE_MATCH_1}")
Expand All @@ -67,6 +68,7 @@ if(COUCHBASE_CXX_CLIENT_GIT_DESCRIBE MATCHES
set(COUCHBASE_CXX_CLIENT_PACKAGE_RELEASE "${CMAKE_MATCH_3}.${couchbase_cxx_client_BUILD_NUMBER}")
endif()
if(CMAKE_MATCH_5 AND CMAKE_MATCH_5 GREATER 0) # number_of_commits.build_number.sha1
set(COUCHBASE_CXX_CLIENT_NUMBER_OF_COMMITS ${CMAKE_MATCH_5})
set(COUCHBASE_CXX_CLIENT_SEMVER
"${COUCHBASE_CXX_CLIENT_SEMVER}+${CMAKE_MATCH_5}.${couchbase_cxx_client_BUILD_NUMBER}.${CMAKE_MATCH_6}")
if(CMAKE_MATCH_3) # pre-release
Expand Down
4 changes: 2 additions & 2 deletions cmake/couchbase_cxx_client.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ exec_prefix=@CMAKE_INSTALL_PREFIX@
includedir=@CMAKE_INSTALL_PREFIX@/include
libdir=@CMAKE_INSTALL_LIBDIR@

Name: couchbase-cxx-client @COUCHBASE_CXX_CLIENT_SEMVER@
Name: couchbase-cxx-client @COUCHBASE_CXX_CLIENT_PKGCONFIG_VERSION@
Description: Couchbase C++ SDK
Version: @COUCHBASE_CXX_CLIENT_SEMVER@
Version: @COUCHBASE_CXX_CLIENT_PKGCONFIG_VERSION@
Libs: -L${libdir} -lcouchbase_cxx_client
Cflags: -I${includedir}

0 comments on commit 8bf1445

Please sign in to comment.