From 9edce5fe78afe1f3859a447e99a6d2ad295858eb Mon Sep 17 00:00:00 2001 From: Louis Maillard Date: Wed, 23 Oct 2024 09:31:39 -0400 Subject: [PATCH] packaging: add Fedora 40 and 39 support Add dhtnet.spec for RPM build and fedora_40,39 dockerfile for env build. Fix and changes was required in Cmake instruction in order to build: - Dependencies can now be built in static mode even with dynamic library - Remove occurence of INSTALL_DIR path in dhtnet.pc and dnc.service but only when option TRIM_PREFIX_PATH is turned On. Fix and replace previously-reverted review 28703 Replace change id (I2f2161d7c65241a35c4acbcc006ba27bfcc1f176) Change-Id: I5a80317d83791743ba6ee443fae7f89156e8013b --- CMakeLists.txt | 15 +++- extras/packaging/.gitignore | 7 +- extras/packaging/Jenkinsfile | 7 +- extras/packaging/build_packages.sh | 28 +++++++ extras/packaging/gnu-linux/debian/rules | 2 + extras/packaging/gnu-linux/fedora/dhtnet.spec | 77 +++++++++++++++++++ .../packaging/gnu-linux/fedora_39.Dockerfile | 24 ++++++ .../packaging/gnu-linux/fedora_40.Dockerfile | 24 ++++++ 8 files changed, 177 insertions(+), 7 deletions(-) create mode 100644 extras/packaging/gnu-linux/fedora/dhtnet.spec create mode 100644 extras/packaging/gnu-linux/fedora_39.Dockerfile create mode 100644 extras/packaging/gnu-linux/fedora_40.Dockerfile diff --git a/CMakeLists.txt b/CMakeLists.txt index 22d1be10..49245956 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,8 @@ set (VERSION ${CMAKE_PROJECT_VERSION}) option(DHTNET_PUPNP "Enable UPnP support" ON) option(DHTNET_NATPMP "Enable NAT-PMP support" ON) +option(BUILD_DEPS_STATIC "Enable to force building dependencies as static" OFF) +option(TRIM_PREFIX_PATH "Used for some RPM build, trim INSTALL_PREFIX from absolute path" OFF) option(BUILD_TOOLS "Build tools" ON) option(BUILD_BENCHMARKS "Build benchmarks" ON) option(BUILD_DEPENDENCIES "Build dependencies" ON) @@ -77,7 +79,7 @@ if (NOT MSVC) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) list(APPEND CMAKE_PREFIX_PATH ${DEPENDENCIES_PATH}) find_package (PkgConfig REQUIRED) - if(NOT BUILD_SHARED_LIBS) + if(BUILD_DEPS_STATIC OR NOT BUILD_SHARED_LIBS) list(APPEND PKG_CONFIG_EXECUTABLE "--static") endif() @@ -160,6 +162,12 @@ if (DNC_SYSTEMD AND BUILD_TOOLS AND NOT MSVC) systemd/dnc.service @ONLY ) + if (TRIM_PREFIX_PATH) + file(READ ${CMAKE_CURRENT_BINARY_DIR}/systemd/dnc.service FILE_CONTENTS) + string(REPLACE "${CMAKE_INSTALL_PREFIX}" "" FILE_CONTENTS "${FILE_CONTENTS}") + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/systemd/dnc.service "${FILE_CONTENTS}") + endif() + if (SYSTEMD_UNIT_INSTALL_DIR) string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_UNIT_INSTALL_DIR "${SYSTEMD_UNIT_INSTALL_DIR}") set (systemdunitdir "${SYSTEMD_UNIT_INSTALL_DIR}") @@ -311,6 +319,11 @@ if (BUILD_TESTING AND NOT MSVC) endif() configure_file(dhtnet.pc.in dhtnet.pc @ONLY) +if (TRIM_PREFIX_PATH) + file(READ ${CMAKE_CURRENT_BINARY_DIR}/dhtnet.pc FILE_CONTENTS) + string(REPLACE "${CMAKE_INSTALL_PREFIX}" "" FILE_CONTENTS "${FILE_CONTENTS}") + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dhtnet.pc "${FILE_CONTENTS}") +endif() # Install targets install(TARGETS dhtnet) diff --git a/extras/packaging/.gitignore b/extras/packaging/.gitignore index 043509b8..cd9ae2be 100644 --- a/extras/packaging/.gitignore +++ b/extras/packaging/.gitignore @@ -1,9 +1,8 @@ gnu-linux/debian/dhtnet gnu-linux/debian/.debhelper -ubuntu-*/*.deb -ubuntu-*/build-at-* +**/*.deb +**/*.rpm +**/build-at-* **/build.log -debian-*/*.deb -debian-*/build-at-* *dhtnet-*.tar.gz diff --git a/extras/packaging/Jenkinsfile b/extras/packaging/Jenkinsfile index 9f14524c..2252cc69 100644 --- a/extras/packaging/Jenkinsfile +++ b/extras/packaging/Jenkinsfile @@ -86,6 +86,9 @@ pipeline { cp -Rf "./gnu-linux/debian" "$FOLDER_NAME/debian" tar -czf "deb-${FOLDER_NAME}.tar.gz" "$FOLDER_NAME" rm -Rf "$FOLDER_NAME/debian" + + # create archive for rpm-based distro like fedora + tar -czf "rpm-${FOLDER_NAME}.tar.gz" "${FOLDER_NAME}" """ } } @@ -95,7 +98,7 @@ pipeline { axes { axis { name 'TARGET' - values 'ubuntu_22.04', 'ubuntu_24.04', 'debian_12'/*, 'fedora_39', 'fedora_40', 'almalinux_9'*/ + values 'ubuntu_22.04', 'ubuntu_24.04', 'debian_12', 'fedora_39', 'fedora_40'/*, 'almalinux_9'*/ } } stages { @@ -124,7 +127,7 @@ pipeline { mkdir -p publish cp -R --parents ubuntu_*/dhtnet_*.deb publish/ cp -R --parents debian_*/dhtnet_*.deb publish/ - # cp -R --parents fedora_*/dhtnet-*.rpm publish/ + cp -R --parents fedora_*/dhtnet-*.rpm publish/ # cp -R --parents almalinux_*/dhtnet-*.rpm publish/ rm -Rf publish/**/*debug* diff --git a/extras/packaging/build_packages.sh b/extras/packaging/build_packages.sh index 95588ca5..b23ab982 100755 --- a/extras/packaging/build_packages.sh +++ b/extras/packaging/build_packages.sh @@ -28,6 +28,9 @@ build_debian=false build_debian10=false build_debian11=false build_debian12=false +build_fedora=false +build_fedora39=false +build_fedora40=false parse_args() { while [ "$1" != "" ]; do @@ -60,6 +63,16 @@ parse_args() { -d12 | --debian12 ) build_debian12=true build_debian=true ;; + -f | --fedora ) build_fedora=true + build_fedora39=true + build_fedora40=true + ;; + -f40 | --fedora40 ) build_fedora40=true + build_fedora=true + ;; + -f39 | --fedora39 ) build_fedora39=true + build_fedora=true + ;; -a | --all ) build_ubuntu=true # not working: build_ubuntu20=true build_ubuntu22_04=true @@ -68,6 +81,9 @@ parse_args() { # not working: build_debian10=true # not working: build_debian11=true build_debian12=true + build_fedora=true + build_fedora39=true + build_fedora40=true ;; * ) echo "Argument '$1' is not recognized" ;; @@ -97,6 +113,10 @@ if [ "$build_ubuntu" == true ] || [ "$build_debian" == true ]; then rm -Rf "${FOLDER_NAME}/debian" fi +if [ "$build_fedora" == true ]; then + tar -czf "rpm-${PKG_NAME}-${PKG_VERSION}.tar.gz" "${FOLDER_NAME}" +fi + rm -Rf "${FOLDER_NAME}" echo "Archives -${PKG_NAME}-${PKG_VERSION}.tar.gz are ready, starting builds... (will take few minutes)" @@ -153,6 +173,14 @@ if [ "$build_debian10" == true ]; then build_target "debian_10" fi +if [ "$build_fedora40" == true ]; then + build_target "fedora_40" +fi + +if [ "$build_fedora39" == true ]; then + build_target "fedora_39" +fi + while [ $remainning_builds -gt 0 ]; do time="$(date +%T)" diff --git a/extras/packaging/gnu-linux/debian/rules b/extras/packaging/gnu-linux/debian/rules index 05695450..76b2cb0d 100755 --- a/extras/packaging/gnu-linux/debian/rules +++ b/extras/packaging/gnu-linux/debian/rules @@ -17,4 +17,6 @@ override_dh_auto_configure: -DBUILD_TESTING=OFF \ -DBUILD_BENCHMARKS=OFF \ -DBUILD_SHARED_LIBS=ON \ + -DBUILD_DEPS_STATIC=ON \ + -DTRIM_PREFIX_PATH=ON \ -DDNC_SYSTEMD=ON diff --git a/extras/packaging/gnu-linux/fedora/dhtnet.spec b/extras/packaging/gnu-linux/fedora/dhtnet.spec new file mode 100644 index 00000000..f5e1d275 --- /dev/null +++ b/extras/packaging/gnu-linux/fedora/dhtnet.spec @@ -0,0 +1,77 @@ +Name: dhtnet +Version: 0.3.0 +Release: %autorelease +Summary: DHTNet, a Lightweight Peer-to-Peer Communication Library +License: GPL-2.0+ AND BSL-1.0 AND GPL-3.0+ AND BSD-3-Clause AND Apache-2.0 AND Expat AND LGPL-2.0+ +URL: https://git.jami.net/savoirfairelinux/dhtnet +Source: ./dhtnet-%{version}.tar.gz +BuildRequires: gcc +BuildRequires: g++ +BuildRequires: make +BuildRequires: cmake +%global __requires_exclude pkgconfig\\((libpjproject|opendht)\\) + +%description +DHTNet, a Lightweight Peer-to-Peer Communication Library, +allows you to connect with a device simply by knowing its public key and +efficiently manages peer discovery and connectivity establishment, including NAT traversal. + +%prep +%autosetup + +%build +mkdir build +cd build +cmake .. -DBUILD_TESTING=OFF \ + -DBUILD_BENCHMARKS=OFF \ + -DBUILD_SHARED_LIBS=ON \ + -DBUILD_DEPS_STATIC=ON \ + -DTRIM_PREFIX_PATH=ON \ + -DDNC_SYSTEMD=ON \ + -DCMAKE_INSTALL_PREFIX=%{buildroot} \ + -DCMAKE_INSTALL_BINDIR=%{buildroot}%{_bindir} \ + -DCMAKE_INSTALL_MANDIR=%{buildroot}%{_mandir} \ + -DCMAKE_INSTALL_DOCDIR=%{buildroot}%{_docdir}/dhtnet \ + -DCMAKE_INSTALL_LIBDIR=%{buildroot}%{_libdir} \ + -DCMAKE_INSTALL_INCLUDEDIR=%{buildroot}%{_includedir} \ + -DCMAKE_INSTALL_SYSCONFDIR=%{buildroot}%{_sysconfdir} \ + -DDNC_SYSTEMD_UNIT_FILE_LOCATION=%{buildroot}/usr/lib/systemd/system \ + -DDNC_SYSTEMD_PRESET_FILE_LOCATION=%{buildroot}/usr/lib/systemd/system-preset + +%install +cd build +make -j +sudo make install + +%files +%{_bindir}/dnc +%{_bindir}/dvpn +%{_bindir}/dsh +%{_bindir}/peerDiscovery +%{_bindir}/upnpctrl +%{_bindir}/dhtnet-crtmgr +%{_mandir}/man1/dnc.1.* +%{_mandir}/man1/dsh.1.* +%{_mandir}/man1/dvpn.1.* +%{_mandir}/man1/dhtnet-crtmgr.1.* +%{_docdir}/dhtnet/* +%{_libdir}/* +%{_includedir}/dhtnet/* +%{_sysconfdir}/dhtnet/* +/usr/lib/systemd/system/dnc.service +/usr/lib/systemd/system-preset/dhtnet-dnc.preset + +%post +mkdir -p /etc/dhtnet +echo "====================" +echo "dnc server installed." +echo "To configure your dnc client and/or server, run:" +echo " dhtnet-crtmgr --interactive" +echo "Server configuration is in /etc/dhtnet/dnc.yaml" +echo "After configuration, enable and start server with:" +echo " systemctl enable dnc.service" +echo " systemctl start dnc.service" +echo "====================" + +%changelog +%autochangelog diff --git a/extras/packaging/gnu-linux/fedora_39.Dockerfile b/extras/packaging/gnu-linux/fedora_39.Dockerfile new file mode 100644 index 00000000..493cebd0 --- /dev/null +++ b/extras/packaging/gnu-linux/fedora_39.Dockerfile @@ -0,0 +1,24 @@ +FROM fedora:39 + +WORKDIR /build + +RUN mkdir -p /build/artifacts && \ + dnf install -y fedora-packager fedora-review git gcc g++ make cmake wget \ + pkg-config dpkg-dev libtool autoconf automake systemd \ + python3-devel python3-setuptools python3-build python3-virtualenv \ + ncurses-devel readline-devel nettle-devel cppunit-devel \ + gnutls-devel libuv-devel jsoncpp-devel libargon2-devel libunistring-devel \ + openssl-devel fmt-devel asio-devel msgpack-devel yaml-cpp-devel \ + http-parser-devel zlib-devel llhttp-devel \ + libupnp-devel libnatpmp-devel + +COPY gnu-linux/fedora /build/fedora + +ARG PKG_NAME +COPY rpm-${PKG_NAME}.tar.gz /build/fedora/${PKG_NAME}.tar.gz + +CMD cd /build/fedora && \ + fedpkg --release f39 local && \ + (fedpkg --release f39 lint || true) && \ + cp /build/fedora/*.rpm /build/artifacts/ && \ + cp /build/fedora/$(uname -m)/*.rpm /build/artifacts/ diff --git a/extras/packaging/gnu-linux/fedora_40.Dockerfile b/extras/packaging/gnu-linux/fedora_40.Dockerfile new file mode 100644 index 00000000..6f198bfc --- /dev/null +++ b/extras/packaging/gnu-linux/fedora_40.Dockerfile @@ -0,0 +1,24 @@ +FROM fedora:40 + +WORKDIR /build + +RUN mkdir -p /build/artifacts && \ + dnf install -y fedora-packager fedora-review git gcc g++ make cmake wget \ + pkg-config dpkg-dev libtool autoconf automake systemd \ + python3-devel python3-setuptools python3-build python3-virtualenv \ + ncurses-devel readline-devel nettle-devel cppunit-devel \ + gnutls-devel libuv-devel jsoncpp-devel libargon2-devel libunistring-devel \ + openssl-devel fmt-devel asio-devel msgpack-devel yaml-cpp-devel \ + http-parser-devel zlib-devel llhttp-devel \ + libupnp-devel libnatpmp-devel + +COPY gnu-linux/fedora /build/fedora + +ARG PKG_NAME +COPY rpm-${PKG_NAME}.tar.gz /build/fedora/${PKG_NAME}.tar.gz + +CMD cd /build/fedora && \ + fedpkg --release f40 local && \ + (fedpkg --release f40 lint || true) && \ + cp /build/fedora/*.rpm /build/artifacts/ && \ + cp /build/fedora/$(uname -m)/*.rpm /build/artifacts/