Skip to content

Commit 5f62437

Browse files
authored
feat: Derive baked-in version from git tag instead of hardcoding (#74)
- Telemetry app_version and `flapi --version` were always "0.3.0" (the hardcoded project() version), while real releases use CalVer tags (v26.06.11). The tag only flowed into the wheel name, never the binary. - CMakeLists.txt now resolves FLAPI_VERSION in priority order: 1. -DFLAPI_VERSION_OVERRIDE (CI sets this from the git tag) 2. `git describe --tags --dirty` (meaningful local dev versions) 3. "latest" (fallback: source tarball / no git) A leading "v" is stripped so the binary reports clean semver. - Makefile: forward $(CMAKE_EXTRA_FLAGS) on the macOS release-x86_64 / release-arm64 targets (release already forwarded it). - build.yaml: on tag pushes, inject -DFLAPI_VERSION_OVERRIDE from github.ref_name across Windows, Linux (docker -e), and macOS builds.
1 parent 291cb50 commit 5f62437

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

.github/workflows/build.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jobs:
6262
-DBUILD_TESTING=OFF `
6363
-DVCPKG_TARGET_TRIPLET=x64-windows-static `
6464
-DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake" `
65+
${{ startsWith(github.ref, 'refs/tags/v') && format('-DFLAPI_VERSION_OVERRIDE={0}', github.ref_name) || '' }} `
6566
../..
6667
6768
- name: Build
@@ -111,6 +112,7 @@ jobs:
111112
run: |
112113
docker run \
113114
${{ matrix.arch == 'arm64' && format('-e FLAPI_CROSS_COMPILE="{0}"', matrix.arch) || '' }} \
115+
${{ startsWith(github.ref, 'refs/tags/v') && format('-e CMAKE_EXTRA_FLAGS="-DFLAPI_VERSION_OVERRIDE={0}"', github.ref_name) || '' }} \
114116
-v `pwd`:/build_dir \
115117
-v ~/.ccache:/ccache_dir \
116118
${BUILD_IMAGE} \
@@ -209,6 +211,8 @@ jobs:
209211
./bootstrap-vcpkg.sh -disableMetrics
210212
211213
- name: Build
214+
env:
215+
CMAKE_EXTRA_FLAGS: ${{ startsWith(github.ref, 'refs/tags/v') && format('-DFLAPI_VERSION_OVERRIDE={0}', github.ref_name) || '' }}
212216
run: make release-arm64 && make test
213217

214218
- name: Upload artifact

CMakeLists.txt

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,30 @@ else()
102102
endif()
103103

104104
# Set project name and version
105-
project(flAPI VERSION 0.3.0 LANGUAGES CXX)
105+
project(flAPI VERSION 26.06.11 LANGUAGES CXX)
106+
107+
# Resolve the version string baked into the binary (FLAPI_VERSION), used for
108+
# telemetry app_version and `flapi --version`. Priority:
109+
# 1. -DFLAPI_VERSION_OVERRIDE=... (set by CI from the git tag)
110+
# 2. `git describe --tags --dirty` (meaningful versions for local dev builds)
111+
# 3. "latest" (fallback: source tarball / no git)
112+
# A leading "v" is stripped so the binary reports clean semver (e.g. 0.4.0),
113+
# matching the wheel pipeline.
114+
if(FLAPI_VERSION_OVERRIDE)
115+
set(FLAPI_VERSION_STR "${FLAPI_VERSION_OVERRIDE}")
116+
else()
117+
execute_process(
118+
COMMAND git describe --tags --dirty --always
119+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
120+
OUTPUT_VARIABLE FLAPI_VERSION_STR
121+
OUTPUT_STRIP_TRAILING_WHITESPACE
122+
ERROR_QUIET)
123+
if(NOT FLAPI_VERSION_STR)
124+
set(FLAPI_VERSION_STR "latest")
125+
endif()
126+
endif()
127+
string(REGEX REPLACE "^v" "" FLAPI_VERSION_STR "${FLAPI_VERSION_STR}")
128+
message(STATUS "flAPI version (FLAPI_VERSION): ${FLAPI_VERSION_STR}")
106129

107130
# Basic settings
108131
set(CMAKE_CXX_STANDARD 17)
@@ -329,7 +352,7 @@ target_link_libraries(flapi-lib PUBLIC
329352
)
330353

331354
target_compile_definitions(flapi-lib PRIVATE
332-
FLAPI_VERSION="${CMAKE_PROJECT_VERSION}"
355+
FLAPI_VERSION="${FLAPI_VERSION_STR}"
333356
)
334357

335358
# Add RPATH settings for macOS
@@ -342,7 +365,7 @@ endif()
342365
# Create main executable
343366
add_executable(flapi src/main.cpp)
344367
target_link_libraries(flapi PRIVATE flapi-lib)
345-
target_compile_definitions(flapi PRIVATE FLAPI_VERSION="${CMAKE_PROJECT_VERSION}")
368+
target_compile_definitions(flapi PRIVATE FLAPI_VERSION="${FLAPI_VERSION_STR}")
346369
set_target_properties(flapi PROPERTIES ENABLE_EXPORTS TRUE)
347370

348371
# macOS reserved-segment for self-packaging (#48). Allocates a

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ ifeq ($(shell uname),Darwin)
136136
-DCMAKE_OSX_ARCHITECTURES=x86_64 \
137137
-DVCPKG_TARGET_TRIPLET=x64-osx \
138138
-DBUILD_TESTING=ON \
139-
$(CMAKE_GENERATOR) ../..
139+
$(CMAKE_GENERATOR) $(CMAKE_EXTRA_FLAGS) ../..
140140
@$(CMAKE) --build $(RELEASE_DIR)-x86_64 --config Release
141141

142142
release-arm64:
@@ -149,7 +149,7 @@ ifeq ($(shell uname),Darwin)
149149
-DCMAKE_OSX_ARCHITECTURES=arm64 \
150150
-DVCPKG_TARGET_TRIPLET=arm64-osx \
151151
-DBUILD_TESTING=ON \
152-
$(CMAKE_GENERATOR) ../..
152+
$(CMAKE_GENERATOR) $(CMAKE_EXTRA_FLAGS) ../..
153153
@$(CMAKE) --build $(RELEASE_DIR)-arm64 --config Release
154154

155155
# Override the default release target on macOS

0 commit comments

Comments
 (0)