Skip to content

Commit

Permalink
packaging: add Fedora 40 and 39 support
Browse files Browse the repository at this point in the history
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
  • Loading branch information
loulou123546 authored and aberaud committed Oct 24, 2024
1 parent 08fcd48 commit 9edce5f
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 7 deletions.
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions extras/packaging/.gitignore
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions extras/packaging/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
"""
}
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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*
Expand Down
28 changes: 28 additions & 0 deletions extras/packaging/build_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
;;
Expand Down Expand Up @@ -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 <os>-${PKG_NAME}-${PKG_VERSION}.tar.gz are ready, starting builds... (will take few minutes)"

Expand Down Expand Up @@ -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)"
Expand Down
2 changes: 2 additions & 0 deletions extras/packaging/gnu-linux/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -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
77 changes: 77 additions & 0 deletions extras/packaging/gnu-linux/fedora/dhtnet.spec
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions extras/packaging/gnu-linux/fedora_39.Dockerfile
Original file line number Diff line number Diff line change
@@ -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/
24 changes: 24 additions & 0 deletions extras/packaging/gnu-linux/fedora_40.Dockerfile
Original file line number Diff line number Diff line change
@@ -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/

0 comments on commit 9edce5f

Please sign in to comment.