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:
- Add `llhttp` and `neddle` library linking when building tools
- `llhttp` liking is disabled by default for debian, enabled for fedora
- Remove occurence of INSTALL_DIR path in dhtnet.pc and dnc.service

Change-Id: I2f2161d7c65241a35c4acbcc006ba27bfcc1f176
  • Loading branch information
loulou123546 committed Oct 9, 2024
1 parent f6b2962 commit eab419d
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 14 deletions.
58 changes: 50 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set (VERSION ${CMAKE_PROJECT_VERSION})

option(DHTNET_PUPNP "Enable UPnP support" ON)
option(DHTNET_NATPMP "Enable NAT-PMP support" ON)
option(DHTNET_LLHTTP "Include llhttp in compilation" OFF)
option(DHTNET_TESTABLE "Enable API for tests" ON)
option(BUILD_TOOLS "Build tools" ON)
option(BUILD_BENCHMARKS "Build benchmarks" ON)
Expand Down Expand Up @@ -161,13 +162,17 @@ if (DNC_SYSTEMD AND BUILD_TOOLS AND NOT MSVC)
systemd/dnc.service
@ONLY
)
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}")

if (SYSTEMD_UNIT_INSTALL_DIR)
string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_UNIT_INSTALL_DIR "${SYSTEMD_UNIT_INSTALL_DIR}")
set (systemdunitdir "${SYSTEMD_UNIT_INSTALL_DIR}")
set (systemdunitdir "${CMAKE_INSTALL_PREFIX}${SYSTEMD_UNIT_INSTALL_DIR}")
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/systemd/dnc.service DESTINATION ${systemdunitdir})

string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_PRESET_INSTALL_DIR "${SYSTEMD_PRESET_INSTALL_DIR}")
set (systemdpresetdir "${SYSTEMD_PRESET_INSTALL_DIR}")
set (systemdpresetdir "${CMAKE_INSTALL_PREFIX}${SYSTEMD_PRESET_INSTALL_DIR}")
install (FILES tools/dnc/systemd/dhtnet-dnc.preset DESTINATION ${systemdpresetdir})

install (FILES tools/dnc/dnc.yaml DESTINATION ${sysconfdir}/dhtnet/)
Expand Down Expand Up @@ -283,7 +288,12 @@ target_include_directories(dhtnet PUBLIC
)

target_compile_definitions(dhtnet PRIVATE ${dhtnet_PRIVATE_DEFS})
target_link_libraries(dhtnet PRIVATE ${dhtnet_PRIVATELIBS})
if (DHTNET_LLHTTP)
target_link_libraries(dhtnet PRIVATE ${dhtnet_PRIVATELIBS} llhttp nettle)
else()
target_link_libraries(dhtnet PRIVATE ${dhtnet_PRIVATELIBS} nettle)
endif()

if (MSVC)
target_compile_definitions(dhtnet PRIVATE
_CRT_SECURE_NO_WARNINGS
Expand Down Expand Up @@ -312,6 +322,9 @@ if (BUILD_TESTING AND NOT MSVC)
endif()

configure_file(dhtnet.pc.in dhtnet.pc @ONLY)
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}")

# Install targets
install(TARGETS dhtnet)
Expand All @@ -324,7 +337,12 @@ if (BUILD_TOOLS AND NOT MSVC)
tools/dnc/dnc.cpp
tools/common.cpp
tools/dhtnet_crtmgr/dhtnet_crtmgr.cpp)
target_link_libraries(dnc PRIVATE dhtnet fmt::fmt yaml-cpp)
if (DHTNET_LLHTTP)
target_link_libraries(dnc PRIVATE dhtnet fmt::fmt yaml-cpp llhttp nettle)
else()
target_link_libraries(dnc PRIVATE dhtnet fmt::fmt yaml-cpp nettle)
endif()

target_include_directories(dnc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tools)
install(TARGETS dnc RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

Expand All @@ -333,7 +351,13 @@ if (BUILD_TOOLS AND NOT MSVC)
tools/dsh/dsh.cpp
tools/common.cpp
tools/dhtnet_crtmgr/dhtnet_crtmgr.cpp)
target_link_libraries(dsh PRIVATE dhtnet fmt::fmt yaml-cpp)

if (DHTNET_LLHTTP)
target_link_libraries(dsh PRIVATE dhtnet fmt::fmt yaml-cpp llhttp nettle)
else()
target_link_libraries(dsh PRIVATE dhtnet fmt::fmt yaml-cpp nettle)
endif()

target_include_directories(dsh PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tools)
install(TARGETS dsh RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

Expand All @@ -344,7 +368,13 @@ if (BUILD_TOOLS AND NOT MSVC)
tools/dvpn/dvpn.cpp
tools/common.cpp
tools/dhtnet_crtmgr/dhtnet_crtmgr.cpp)
target_link_libraries(dvpn PRIVATE dhtnet fmt::fmt yaml-cpp)

if (DHTNET_LLHTTP)
target_link_libraries(dvpn PRIVATE dhtnet fmt::fmt yaml-cpp llhttp nettle)
else()
target_link_libraries(dvpn PRIVATE dhtnet fmt::fmt yaml-cpp nettle)
endif()

target_include_directories(dvpn PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tools)
install(TARGETS dvpn RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
Expand All @@ -364,13 +394,25 @@ if (BUILD_TOOLS AND NOT MSVC)
add_executable(dhtnet-crtmgr
tools/dhtnet_crtmgr/main.cpp
tools/dhtnet_crtmgr/dhtnet_crtmgr.cpp)
target_link_libraries(dhtnet-crtmgr PRIVATE dhtnet fmt::fmt)

if (DHTNET_LLHTTP)
target_link_libraries(dhtnet-crtmgr PRIVATE dhtnet fmt::fmt yaml-cpp llhttp nettle)
else()
target_link_libraries(dhtnet-crtmgr PRIVATE dhtnet fmt::fmt yaml-cpp nettle)
endif()

target_include_directories(dhtnet-crtmgr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tools)
install(TARGETS dhtnet-crtmgr RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

add_executable(peerDiscovery
tools/peerdiscovery/peerDiscovery.cpp)
target_link_libraries(peerDiscovery PRIVATE dhtnet fmt::fmt readline)

if (DHTNET_LLHTTP)
target_link_libraries(peerDiscovery PRIVATE dhtnet fmt::fmt readline llhttp nettle)
else()
target_link_libraries(peerDiscovery PRIVATE dhtnet fmt::fmt readline nettle)
endif()

target_include_directories(peerDiscovery PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tools/peerdiscovery)
install(TARGETS peerDiscovery RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

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
36 changes: 34 additions & 2 deletions extras/packaging/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,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 fedora archive
tar -czf "rpm-${FOLDER_NAME}.tar.gz" "$FOLDER_NAME"
"""
}
}
Expand Down Expand Up @@ -127,14 +130,43 @@ pipeline {
}
}
}
stage('Fedora 39') {
steps {
dir('extras/packaging') {
sh """
target="fedora-39"
mkdir -p "\$target"
docker build -t "dhtnet-builder:\$target" -f "gnu-linux/\$target.Dockerfile" --build-arg PKG_NAME="$FOLDER_NAME" .
docker run --rm \
-v "\$(pwd)/\$target/":/build/artifacts \
-e PKG_NAME="$FOLDER_NAME" "dhtnet-builder:\$target"
"""
}
}
}
stage('Fedora 40') {
steps {
dir('extras/packaging') {
sh """
target="fedora-40"
mkdir -p "\$target"
docker build -t "dhtnet-builder:\$target" -f "gnu-linux/\$target.Dockerfile" --build-arg PKG_NAME="$FOLDER_NAME" .
docker run --rm \
-v "\$(pwd)/\$target/":/build/artifacts \
-e PKG_NAME="$FOLDER_NAME" "dhtnet-builder:\$target"
"""
}
}
}
}
}
}
post {
success {
dir('extras/packaging') {
archiveArtifacts artifacts: 'ubuntu-*/dhtnet_*.deb, debian-*/dhtnet_*.deb',
caseSensitive: false
archiveArtifacts artifacts: 'ubuntu-*/dhtnet_*.deb, debian-*/dhtnet_*.deb, fedora-*/dhtnet-*.rpm',
caseSensitive: false,
excludes: '**/*debug*'
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions extras/packaging/build_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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 @@ -59,6 +62,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=true
Expand All @@ -67,6 +80,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 @@ -96,6 +112,14 @@ if [ "$build_ubuntu" == true ] || [ "$build_debian" == true ]; then
rm -Rf "${FOLDER_NAME}/debian"
fi

if [ "$build_fedora" == true ]; then
# copy fedora conf
#cp -Rf "./gnu-linux/fedora" "${FOLDER_NAME}/fedora"

tar -czf "rpm-${PKG_NAME}-${PKG_VERSION}.tar.gz" "${FOLDER_NAME}"
#rm -Rf "${FOLDER_NAME}/fedora"
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 @@ -152,6 +176,15 @@ if [ "$build_debian10" == true ]; then
build_target "debian-10"
fi

# build Fedora package (rpm-*)
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
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/
64 changes: 64 additions & 0 deletions extras/packaging/gnu-linux/fedora/dhtnet.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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 \
-DDHTNET_LLHTTP=ON \
-DDNC_SYSTEMD=ON \
-DCMAKE_INSTALL_PREFIX=%{buildroot} \
-DCMAKE_INSTALL_BINDIR=%{buildroot}%{_bindir} \
-DCMAKE_INSTALL_MANDIR=%{buildroot}%{_mandir} \
-DCMAKE_INSTALL_DOCDIR=%{buildroot}%{_docdir} \
-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}/*
%{_libdir}/*
%{_includedir}/dhtnet/*
%{_sysconfdir}/dhtnet/*
/usr/lib/systemd/system/dnc.service
/usr/lib/systemd/system-preset/dhtnet-dnc.preset

%changelog
%autochangelog

0 comments on commit eab419d

Please sign in to comment.