Skip to content

Commit 6179dbd

Browse files
authored
Packages on develop (#6)
* new: dev: add some workflows and simple tox file, cleanup cmake warnings * add conda-dev environment file, boost plus gtest only * both gtest and gmock are required in conda deps * refactor conda build matrix * add missing ip2string.h header on windows * set MSVC compiler in windows env * use platform compiler deps * update gtest submodule to v1.12.x and use gtest lib var * replace gtest submodule with find_package or fetch_content * fall back to FetchContent_Populate in buster action * cleanup find_threads and find_pcap issues * add latest debian build files from gitlab, update ci build steps Signed-off-by: Stephen L Arnold <sarnold@vctlabs.com>
1 parent 2641b1e commit 6179dbd

29 files changed

+521
-59
lines changed

.github/workflows/conda-dev.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: CondaDev
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
10+
jobs:
11+
build:
12+
name: libtins ${{ matrix.python-version }} ${{ matrix.os }}
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
# does not like windows
18+
os: ['ubuntu-22.04', 'ubuntu-24.04']
19+
python-version: ['3.9', '3.11']
20+
include:
21+
- os: 'ubuntu-22.04'
22+
generator: 'Ninja'
23+
build_type: 'Release'
24+
- os: 'ubuntu-24.04'
25+
generator: 'Ninja'
26+
build_type: 'RelWithDebInfo'
27+
28+
env:
29+
OS: ${{ matrix.os }}
30+
PYTHON: ${{ matrix.python-version }}
31+
PYTHONIOENCODING: utf-8
32+
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Setup base python
37+
uses: actions/setup-python@v5
38+
with:
39+
python-version: '3.x'
40+
41+
- name: Cache conda
42+
id: cache
43+
uses: actions/cache@v4
44+
env:
45+
# Increase this value to reset cache if environment.devenv.yml has not changed
46+
CACHE_NUMBER: 1
47+
with:
48+
path: ~/conda_pkgs_dir
49+
key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('environment.devenv.yml') }}
50+
51+
- uses: conda-incubator/setup-miniconda@v3
52+
with:
53+
auto-update-conda: true
54+
python-version: ${{ matrix.python-version }}
55+
channels: conda-forge,defaults
56+
channel-priority: strict
57+
conda-remove-defaults: true
58+
use-only-tar-bz2: true
59+
60+
- name: Configure condadev environment
61+
shell: bash -el {0}
62+
env:
63+
PY_VER: ${{ matrix.python-version }}
64+
run: |
65+
conda config --set always_yes yes --set changeps1 no
66+
conda config --add channels conda-forge
67+
conda install conda-devenv
68+
conda info -a
69+
conda devenv
70+
71+
- name: Build and test
72+
shell: bash -el {0}
73+
env:
74+
PY_VER: ${{ matrix.python-version }}
75+
run: |
76+
source activate libtins-test
77+
cmake \
78+
-G "${{ matrix.generator }}" -S . -B build \
79+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
80+
-DLIBTINS_ENABLE_CXX11=ON \
81+
-DCMAKE_INSTALL_PREFIX:PATH=${CONDA_PREFIX}
82+
cmake --build build --target install --parallel 4
83+
cmake --build build --target tests --parallel 4
84+
ctest -V --test-dir build/

.github/workflows/debs.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Debian packages
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
10+
jobs:
11+
get_version:
12+
name: Get version info
13+
runs-on: ubuntu-22.04
14+
defaults:
15+
run:
16+
shell: bash
17+
outputs:
18+
version: ${{ steps.git_ver.outputs.version }}
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Get package version
26+
id: git_ver
27+
run: |
28+
version=$(git describe --tags | sed -e "s|v||" -e "s|-g|+g|")
29+
echo "Version from git: ${version}"
30+
echo "version=${version}" >> $GITHUB_OUTPUT
31+
32+
build_debs:
33+
name: ${{ matrix.name }}
34+
runs-on: ubuntu-22.04
35+
needs: [get_version]
36+
37+
strategy:
38+
fail-fast: false
39+
matrix:
40+
name: [
41+
x64_bookworm,
42+
x64_trixie,
43+
x64_sid,
44+
]
45+
46+
include:
47+
- name: x64_bookworm
48+
dist: bookworm
49+
50+
- name: x64_trixie
51+
dist: trixie
52+
53+
- name: x64_sid
54+
dist: sid
55+
56+
steps:
57+
- name: Check github variables
58+
env:
59+
VERSION: ${{ needs.get_version.outputs.version }}
60+
run: |
61+
echo "Package version from git: ${VERSION}"
62+
63+
- uses: actions/checkout@v4
64+
with:
65+
fetch-depth: 0
66+
67+
- name: Install deps and update debian changelog
68+
run: |
69+
sudo apt-get update
70+
sudo apt-get install devscripts
71+
debchange -v ${{ needs.get_version.outputs.version }}-${{ matrix.dist }} -b -M --distribution ${{ matrix.dist }} "ci build"
72+
73+
- name: Build deb packages
74+
uses: jtdor/build-deb-action@v1
75+
env:
76+
DEB_BUILD_OPTIONS: noautodbgsym
77+
with:
78+
apt-opts: --install-recommends
79+
docker-image: "debian:${{ matrix.dist }}-slim"
80+
buildpackage-opts: --build=binary --no-sign
81+
extra-build-deps: git cmake
82+
83+
- name: Upload deb files
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: "libtins_${{ needs.get_version.outputs.version }}-${{ matrix.dist }}"
87+
path: ./debian/artifacts/*.deb

.github/workflows/tests.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v6
14+
with:
15+
fetch-depth: 0
16+
submodules: true
1417

1518
- name: Install libpcap
1619
run: sudo apt-get install -y libpcap-dev
1720

18-
- name: Initialize submodules
19-
run: git submodule init && git submodule update
20-
2121
- name: Initialize build system
22-
run: mkdir build && cd build && cmake ..
22+
run: cmake -G "Unix Makefiles" -S . -B build -DCMAKE_BUILD_TYPE=Release
2323

2424
- name: Build tests
2525
run: cmake --build build --target tests
2626

2727
- name: Run tests
28-
run: ctest build
28+
run: ctest -V --test-dir build/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
build/**
22
include/tins/config.h
3+
.tox/

.gitmodules

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
[submodule "googletest"]
2-
path = googletest
3-
url = https://github.com/google/googletest.git
4-
ignore = dirty

CMakeLists.txt

Lines changed: 60 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.1)
2-
PROJECT(libtins)
1+
# pre-test discovery mode for gtest_discover_tests was added in 3.18
2+
cmake_minimum_required(VERSION 3.12...3.18)
3+
4+
if(POLICY CMP0167)
5+
cmake_policy(SET CMP0167 NEW)
6+
endif()
7+
8+
if(POLICY CMP0135)
9+
cmake_policy(SET CMP0135 NEW)
10+
endif()
11+
12+
# Add cmake modules of this project to the module path
13+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
314

415
OPTION(LIBTINS_BUILD_EXAMPLES "Build examples" ON)
516
OPTION(LIBTINS_BUILD_TESTS "Build tests" ON)
@@ -12,6 +23,21 @@ ELSE(NOT CMAKE_BUILD_TYPE)
1223
MESSAGE(STATUS "Using specified '${CMAKE_BUILD_TYPE}' build type.")
1324
ENDIF(NOT CMAKE_BUILD_TYPE)
1425

26+
project(
27+
libtins
28+
LANGUAGES CXX
29+
)
30+
31+
# Check the thread library info early as setting compiler flags seems to
32+
# interfere with the detection and causes CMAKE_THREAD_LIBS_INIT to not
33+
# include -lpthread when it should.
34+
if(LIBTINS_BUILD_TESTS)
35+
if (NOT TARGET Threads::Threads)
36+
find_package(Threads REQUIRED)
37+
endif ()
38+
set(LINK_LIBS ${LINK_LIBS} Threads::Threads)
39+
endif()
40+
1541
# Compilation flags.
1642
IF(MSVC)
1743
# Don't always use Wall, since VC's /Wall is ridiculously verbose.
@@ -50,8 +76,14 @@ SET(TINS_VERSION_MINOR 6)
5076
SET(TINS_VERSION_PATCH 0)
5177
SET(LIBTINS_VERSION "${TINS_VERSION_MAJOR}.${TINS_VERSION_MINOR}")
5278

53-
# Required Packages
54-
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
79+
set(CMAKE_CXX_STANDARD 14)
80+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
81+
set(CMAKE_CXX_EXTENSIONS ON)
82+
83+
if(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
84+
set(CLANG_DEFAULT_CXX_STDLIB libc++)
85+
set(CLANG_DEFAULT_RTLIB compiler-rt)
86+
endif()
5587

5688
# Allow disabling packet capture mechanism
5789
OPTION(LIBTINS_ENABLE_PCAP "Enable capturing packets via libpcap" ON)
@@ -87,7 +119,9 @@ IF(WIN32)
87119

88120
ENDIF(WIN32)
89121

90-
INCLUDE(ExternalProject)
122+
INCLUDE(CTest)
123+
INCLUDE(GNUInstallDirs)
124+
#INCLUDE(ExternalProject)
91125

92126
# *******************
93127
# Compilation options
@@ -155,7 +189,7 @@ ELSE()
155189
ENDIF()
156190

157191
# Search for libboost
158-
FIND_PACKAGE(Boost)
192+
FIND_PACKAGE(Boost, CONFIG)
159193

160194
# Optionally enable the ACK tracker (on by default)
161195
OPTION(LIBTINS_ENABLE_ACK_TRACKER "Enable TCP ACK tracking support" ON)
@@ -279,38 +313,29 @@ IF(LIBTINS_BUILD_EXAMPLES)
279313
ENDIF()
280314

281315
IF(LIBTINS_BUILD_TESTS)
282-
# Only include googletest if the git submodule has been fetched
283-
IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/googletest/CMakeLists.txt")
284-
# Enable tests and add the test directory
285-
MESSAGE(STATUS "Tests have been enabled")
286-
SET(GOOGLETEST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
287-
SET(GOOGLETEST_INCLUDE ${GOOGLETEST_ROOT}/googletest/include)
288-
SET(GOOGLETEST_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/googletest)
289-
SET(GOOGLETEST_LIBRARY ${GOOGLETEST_BINARY_DIR}/googletest)
290-
291-
ExternalProject_Add(
316+
find_package(GTest)
317+
include_directories(${GTEST_INCLUDE_DIRS})
318+
IF(NOT GTEST_FOUND)
319+
message (WARNING "Can't find system Google Test")
320+
include(FetchContent)
321+
FetchContent_Declare(
292322
googletest
293-
DOWNLOAD_COMMAND ""
294-
SOURCE_DIR ${GOOGLETEST_ROOT}
295-
BINARY_DIR ${GOOGLETEST_BINARY_DIR}
296-
CMAKE_CACHE_ARGS "-DBUILD_GTEST:bool=ON" "-DBUILD_GMOCK:bool=OFF"
297-
"-Dgtest_force_shared_crt:bool=ON"
298-
"-DCMAKE_CXX_COMPILER:path=${CMAKE_CXX_COMPILER}"
299-
INSTALL_COMMAND ""
323+
# Specify the commit => this is release 1.12.1
324+
URL https://github.com/google/googletest/archive/58d77fa8070e8cec2dc1ed015d66b454c8d78850.zip
300325
)
301-
# Make sure we build googletest before anything else
302-
ADD_DEPENDENCIES(tins googletest)
303-
ENABLE_TESTING()
304-
ADD_SUBDIRECTORY(tests)
305-
ELSE()
306-
FIND_PACKAGE(GTest QUIET)
307-
IF(${GTest_FOUND})
308-
ENABLE_TESTING()
309-
ADD_SUBDIRECTORY(tests)
310-
ELSE()
311-
MESSAGE(STATUS "googletest git submodule is absent. Run `git submodule init && git submodule update` to get it")
312-
ENDIF()
326+
FetchContent_GetProperties(googletest)
327+
if(NOT googletest_POPULATED)
328+
# Fetch the content using previously declared details
329+
FetchContent_Populate(googletest)
330+
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
331+
endif()
332+
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
313333
ENDIF()
334+
# For Windows: Prevent overriding the parent project's compiler/linker settings
335+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
336+
ENABLE_TESTING()
337+
set(GTEST_LINK_LIBRARIES gtest gtest_main)
338+
ADD_SUBDIRECTORY(tests)
314339
ENDIF()
315340

316341
# **********************************

cmake/Modules/CheckCXXFeatures.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ if (NOT CMAKE_CXX_COMPILER_LOADED)
5050
message(FATAL_ERROR "CheckCXX11Features modules only works if language CXX is enabled")
5151
endif ()
5252

53-
cmake_minimum_required(VERSION 2.8.3)
53+
#cmake_minimum_required(VERSION 2.8.3)
5454

5555
#
5656
### Check for needed compiler flags

cmake/Modules/FindPCAP.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ endif (NOT PCAP_LINKS_SOLO)
7373

7474
include(CheckFunctionExists)
7575
set(CMAKE_REQUIRED_LIBRARIES ${PCAP_LIBRARY})
76-
check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
76+
# this is not actually used, is not part of normal libpcap, and
77+
# causes breakage in some build environments, eg, bookworm docker image
78+
#check_function_exists(pcap_get_pfring_id HAVE_PF_RING)
7779
check_function_exists(pcap_set_immediate_mode HAVE_PCAP_IMMEDIATE_MODE)
7880
check_function_exists(pcap_set_tstamp_precision HAVE_PCAP_TIMESTAMP_PRECISION)
7981
set(CMAKE_REQUIRED_LIBRARIES)

0 commit comments

Comments
 (0)