Skip to content

Add compile-time version macros#2118

Draft
seladb wants to merge 2 commits intodevfrom
compile-time-version
Draft

Add compile-time version macros#2118
seladb wants to merge 2 commits intodevfrom
compile-time-version

Conversation

@seladb
Copy link
Copy Markdown
Owner

@seladb seladb commented Apr 30, 2026

Addresses #2101.

This PR adds version macros and introduces a patch version in case we need it:

#define PCAPPLUSPLUS_VERSION_YEAR 25
#define PCAPPLUSPLUS_VERSION_MONTH 5
#define PCAPPLUSPLUS_VERSION_PATCH 0
#define PCAPPLUSPLUS_VERSION_DEV 1

It also includes macros to compare versions, for example:

#if PCAPPLUSPLUS_VERSION_HIGHER_OR_EQUAL_THAN(25, 5, 0)
    /// Use new APIs introduces in v25.05
#endif

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.68%. Comparing base (36815aa) to head (3313dc7).

Additional details and impacted files
@@           Coverage Diff            @@
##              dev    #2118    +/-   ##
========================================
  Coverage   82.68%   82.68%            
========================================
  Files         332      332            
  Lines       59696    59696            
  Branches    12306    12585   +279     
========================================
+ Hits        49358    49359     +1     
+ Misses       9015     8950    -65     
- Partials     1323     1387    +64     
Flag Coverage Δ
23.11.6 7.34% <ø> (+0.03%) ⬆️
24.11.5 7.34% <ø> (ø)
25.11.1 7.31% <ø> (-0.02%) ⬇️
alpine320 76.80% <ø> (ø)
fedora42 76.40% <ø> (+0.02%) ⬆️
macos-14 82.19% <ø> (ø)
macos-15 82.18% <ø> (+<0.01%) ⬆️
mingw32 71.00% <ø> (ø)
mingw64 70.90% <ø> (+0.02%) ⬆️
npcap 85.61% <ø> (-0.01%) ⬇️
rhel94 76.20% <ø> (ø)
ubuntu2204 76.21% <ø> (ø)
ubuntu2204-icpx 59.27% <ø> (+<0.01%) ⬆️
ubuntu2404 76.51% <ø> (-0.01%) ⬇️
ubuntu2404-arm64 76.49% <ø> (-0.03%) ⬇️
ubuntu2604 76.45% <ø> (+0.03%) ⬆️
unittest 82.68% <ø> (+<0.01%) ⬆️
windows-2022 85.60% <ø> (-0.03%) ⬇️
windows-2025 85.64% <ø> (+<0.01%) ⬆️
winpcap 85.85% <ø> (+<0.01%) ⬆️
xdp 53.05% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@seladb seladb requested a review from Dimi1010 May 4, 2026 08:49
@seladb
Copy link
Copy Markdown
Owner Author

seladb commented May 4, 2026

@Dimi1010 this PR is still in draft, but I wanted to get your opinion on this approach


/// @def PCAPPLUSPLUS_VERSION
/// @brief Short version string (e.g., "25.05" for official release or "25.05+" for development)
#define PCAPPLUSPLUS_VERSION "25.05+"
Copy link
Copy Markdown
Owner Author

@seladb seladb May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to create this string using macros, but it'll be very complex, so maybe it's easier to keep it as is...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we can manually set it.

A potential alternative is to have the cmake build system generate the version file, like it does with the package config files. I think that is generally more flexible and we would only need to change the version in the CMakeLists.


Also, do you think we should include the patch number in all versions? (eg. 25.05.0), so people always expect it if they decide to do magic with the version string?

Copy link
Copy Markdown
Collaborator

@Dimi1010 Dimi1010 May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A potential alternative is to have the cmake build system generate the version file, like it does with the package config files. I think that is generally more flexible and we would only need to change the version in the CMakeLists.

@seladb Additional discussion may be needed separately, but I managed to get CMake to compile a version from the git tags. The versioning is based on the signature major.minor.patch.tweak.

It fetches the MAJOR, MINOR, PATCH from the most recent tag. (eg. last release)
It then calculates the Tweak version as the number of commits past the most recent tag the build is.

If we are precisely on the release commit, the tweak version will be 0 and the full version maj.min.patch.0, if we are 1 commit past it it will be maj.min.patch.1. This can then be used to determine official releases (tweak 0) vs nightly / dev builds (tweak != 0).

The solution will allow us to have rolling versions unique for each development build commit, so we don't have just a nebulous "DEV" version flag. For example the current master would be 25.05.0.201.

A extended version string can also be added with a commit hash, if we need to differentiate between commits on different branches, but I think most will be used from the master / dev line.

Copy link
Copy Markdown
Collaborator

@Dimi1010 Dimi1010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok. I am a bit iffy on PCAPPLUSPLUS_VERSION_DEV, but I don't have any better ideas for it, so... 🤷


/// @def PCAPPLUSPLUS_VERSION
/// @brief Short version string (e.g., "25.05" for official release or "25.05+" for development)
#define PCAPPLUSPLUS_VERSION "25.05+"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we can manually set it.

A potential alternative is to have the cmake build system generate the version file, like it does with the package config files. I think that is generally more flexible and we would only need to change the version in the CMakeLists.


Also, do you think we should include the patch number in all versions? (eg. 25.05.0), so people always expect it if they decide to do magic with the version string?

@KangLin
Copy link
Copy Markdown
Contributor

KangLin commented May 7, 2026

it is recommended to use Semantic format. the major for the API,the minor for year, the path for date.
eg:
v1.26.05-dev
1: major
26: minor, the year
05: patch, the date
dev: develop, it is can dev count. eg: 1, 2, 3 etc

@seladb
Copy link
Copy Markdown
Owner Author

seladb commented May 8, 2026

it is recommended to use Semantic format. the major for the API,the minor for year, the path for date. eg: v1.26.05-dev 1: major 26: minor, the year 05: patch, the date dev: develop, it is can dev count. eg: 1, 2, 3 etc

@KangLin I don't think we want to switch from CalVer to SemVer, at least not now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants