Skip to content

CMake changes for NixOS#486

Open
christofmuc wants to merge 5 commits into
masterfrom
features/CMake_for_NixOS
Open

CMake changes for NixOS#486
christofmuc wants to merge 5 commits into
masterfrom
features/CMake_for_NixOS

Conversation

@christofmuc

@christofmuc christofmuc commented Nov 1, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Chores
    • Centralized build version calculation and propagation into CI workflows and local builds.
    • Build configuration now accepts and displays an externally computed version during configuration.
    • Added a reusable version helper to standardize how project version is determined and emitted to CI.
    • Linux packaging/archiving behavior tuned for more consistent artifacts.
    • Development-tag handling and CI environment emission added to better track build metadata.

… the NixOS build can run after determining the version and removing the .git tree.
@coderabbitai

coderabbitai Bot commented Nov 1, 2025

Copy link
Copy Markdown

Warning

Rate limit exceeded

@christofmuc has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 30 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c294a1c and ca7d0ef.

📒 Files selected for processing (1)
  • cmake/calc_version.cmake (1 hunks)

Walkthrough

Centralizes version computation in cmake/calc_version.cmake, exposes it as KNOBKRAFT_EXTERNAL_VERSION, injects that into CI workflows and the Makefile/CMake configure steps, updates The-Orm project to use the external version, and adds Linux-specific archive settings in the root CMakeLists.txt.

Changes

Cohort / File(s) Summary
Workflow Version Injection
\.github/workflows/builds-ubuntu.yml`, `.github/workflows/builds-ubuntu24.yml`, `.github/workflows/builds-windows.yml``
Added a pre-configure step that runs cmake -P cmake/calc_version.cmake, exports KNOBKRAFT_EXTERNAL_VERSION, and passes it into CMake configure as -DKNOBKRAFT_EXTERNAL_VERSION=$KNOBKRAFT_EXTERNAL_VERSION.
Makefile Build Configuration
`Makefile`
Runs cmake -P cmake/calc_version.cmake, exports KNOBKRAFT_EXTERNAL_VERSION, prints it in the configure message, and passes it to CMake via -DKNOBKRAFT_EXTERNAL_VERSION=$KNOBKRAFT_EXTERNAL_VERSION.
CMake Root Configuration
`CMakeLists.txt`
Added Linux (UNIX and not APPLE) archive configuration: set(CMAKE_AR "gcc-ar"), set(CMAKE_CXX_ARCHIVE_CREATE ...), and set(CMAKE_CXX_ARCHIVE_FINISH true).
CMake Project Configuration
`The-Orm/CMakeLists.txt`
Replaced inline git-based version retrieval with KNOBKRAFT_EXTERNAL_VERSION in project(...); added PROJECT_DEV_TAG/PROJECT_DEV handling, emits ORM_VERSION to GITHUB_ENV when present, and added Sentry/Sparkle/crash-reporting feature flags and related stubs.
Version Calculation Script
`cmake/calc_version.cmake`
New helper that runs the existing gitversion.cmake via execute_process, captures and normalizes output (trim/remove newline), fails on errors or empty output, and prints the final version string for CI/Make/CMake consumption.

Sequence Diagram

sequenceDiagram
    participant Runner as CI / Makefile
    participant Calc as calc_version.cmake
    participant GitVer as gitversion.cmake
    participant CMake as CMake configure
    participant Project as The-Orm/CMakeLists.txt

    Runner->>Calc: run `cmake -P cmake/calc_version.cmake`
    Calc->>GitVer: execute_process(`gitversion.cmake`)
    GitVer-->>Calc: raw version output / exit code
    Calc->>Calc: normalize, validate, fail on error or empty
    Calc-->>Runner: echo final version
    Runner->>Runner: export KNOBKRAFT_EXTERNAL_VERSION
    Runner->>CMake: configure with `-DKNOBKRAFT_EXTERNAL_VERSION=...`
    CMake->>Project: project(...) reads `${KNOBKRAFT_EXTERNAL_VERSION}`
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect cmake/calc_version.cmake error handling and trimming logic for edge cases (multi-line, status prefixes).
  • Verify environment export semantics in Windows workflow and Makefile contexts.
  • Review The-Orm/CMakeLists.txt changes around PROJECT_DEV_TAG and downstream packaging/version uses.
  • Confirm Linux archive CMAKE_AR and archive commands are correct for targeted toolchains.

Poem

🐇 I hop to fetch a version bright,

I trim the noise and print it right.
One env, one flag, the builds align,
Carrots for CI — and a tidy sign. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "CMake changes for NixOS" does refer to a real aspect of the changeset—specifically, the addition of Linux-specific archiving tool configuration for NixOS in CMakeLists.txt (gcc-ar and archive creation settings). However, the title does not capture the primary focus of the changeset, which is the introduction of an external versioning system (KNOBKRAFT_EXTERNAL_VERSION) across all platforms through a new calc_version.cmake script and its integration into workflows, Makefiles, and CMakeLists.txt. The title is partially related to the work but misses the dominant theme, making it potentially misleading to a teammate reviewing the PR history.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
The-Orm/CMakeLists.txt (1)

14-16: Add missing include to source PROJECT_DEV_TAG or extract it locally from KNOBKRAFT_EXTERNAL_VERSION.

Lines 14-16 reference PROJECT_DEV_TAG, but this variable is defined only in cmake/gitversion.cmake:18 and is never included in The-Orm/CMakeLists.txt. Add one of:

  1. Include the gitversion module at the top of The-Orm/CMakeLists.txt:
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/gitversion.cmake)
  1. Or extract the dev tag locally from KNOBKRAFT_EXTERNAL_VERSION:
string(REGEX MATCH "(-dev)$" PROJECT_DEV_TAG "${KNOBKRAFT_EXTERNAL_VERSION}")

Without this, PROJECT_DEV_TAG will be undefined when the conditional evaluates, causing the add_definitions(-DPROJECT_DEV) to never execute as intended.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64e3043 and 40ed7c3.

📒 Files selected for processing (7)
  • .github/workflows/builds-ubuntu.yml (1 hunks)
  • .github/workflows/builds-ubuntu24.yml (1 hunks)
  • .github/workflows/builds-windows.yml (1 hunks)
  • CMakeLists.txt (1 hunks)
  • Makefile (1 hunks)
  • The-Orm/CMakeLists.txt (1 hunks)
  • cmake/calc_version.cmake (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: macOS KnobKraft Orm
Makefile

[error] 38-38: Makefile:38: *** commands commence before first target. Stop.

🪛 GitHub Actions: Ubuntu 22 KnobKraft Orm
CMakeLists.txt

[error] 46-46: CMake configure failed: Parse error. Function missing ending ")". End of file reached. (Process completed with exit code 1.)

The-Orm/CMakeLists.txt

[error] 46-46: CMake configure failed: Parse error. Function missing ending ")". End of file reached. (Process completed with exit code 1.)

🪛 GitHub Actions: Ubuntu 24 KnobKraft Orm
CMakeLists.txt

[error] 46-46: CMake parse error: Function missing ending ')' End of file reached.


[warning] 1-1: CMake Warning: Ignoring extra path from command line: ""2.51.2")"

The-Orm/CMakeLists.txt

[error] 46-46: CMake parse error: Function missing ending ')' End of file reached.


[warning] 1-1: CMake Warning: Ignoring extra path from command line: ""2.51.2")"

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-windows
🔇 Additional comments (3)
.github/workflows/builds-ubuntu24.yml (1)

42-43: Add error handling for version computation.

If cmake/calc_version.cmake fails or produces unexpected output, the build will continue with an empty or invalid version. Consider adding validation:

 export KNOBKRAFT_EXTERNAL_VERSION="$(cmake -P cmake/calc_version.cmake)"
+if [ -z "$KNOBKRAFT_EXTERNAL_VERSION" ]; then
+  echo "Error: Failed to compute version"
+  exit 1
+fi
+echo "Computed version: $KNOBKRAFT_EXTERNAL_VERSION"
 CC=gcc-14 CXX=g++-14 cmake -S . -B builds  -DKNOBKRAFT_EXTERNAL_VERSION=$KNOBKRAFT_EXTERNAL_VERSION -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=off -DPYTHON_VERSION_TO_EMBED=3.12 -DSENTRY_CRASH_REPORTING=ON -DSENTRY_DSN=$SENTRY_DSN
.github/workflows/builds-windows.yml (1)

51-52: Add error handling for version computation.

Same as in the Ubuntu 24 workflow, add validation to ensure version computation succeeds:

 export KNOBKRAFT_EXTERNAL_VERSION="$(cmake -P cmake/calc_version.cmake)"
+if [ -z "$KNOBKRAFT_EXTERNAL_VERSION" ]; then
+  echo "Error: Failed to compute version"
+  exit 1
+fi
+echo "Computed version: $KNOBKRAFT_EXTERNAL_VERSION"
 cmake -S . -B Builds -G "Visual Studio 17 2022" -A x64 -DKNOBKRAFT_EXTERNAL_VERSION=$KNOBKRAFT_EXTERNAL_VERSION -DCRASH_REPORTING=ON -DSENTRY_DSN=$SENTRY_DSN -DSPARKLE_UPDATES=ON
.github/workflows/builds-ubuntu.yml (1)

34-35: Add error handling for version computation.

Consistent with the other workflows, add validation:

 export KNOBKRAFT_EXTERNAL_VERSION="$(cmake -P cmake/calc_version.cmake)"
+if [ -z "$KNOBKRAFT_EXTERNAL_VERSION" ]; then
+  echo "Error: Failed to compute version"
+  exit 1
+fi
+echo "Computed version: $KNOBKRAFT_EXTERNAL_VERSION"
 cmake -S . -B builds -DKNOBKRAFT_EXTERNAL_VERSION=$KNOBKRAFT_EXTERNAL_VERSION -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=off -DPYTHON_VERSION_TO_EMBED=3.12 -DSENTRY_CRASH_REPORTING=ON -DSENTRY_DSN=$SENTRY_DSN

Comment thread cmake/calc_version.cmake
Comment thread CMakeLists.txt
Comment thread Makefile
Comment on lines 36 to +39
configure:
@echo "Configuring build for type $(BUILD_TYPE) in directory $(BUILD_DIR), using Python from $(PYTHON_TO_USE)"
cmake -S . -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DPYTHON_EXECUTABLE=$(PYTHON_TO_USE) -DCODESIGN_CERTIFICATE_NAME="$(APPLE_DEVELOPER_IDENTITY)"
export KNOBKRAFT_EXTERNAL_VERSION="$(cmake -P cmake/calc_version.cmake)"
@echo "Configuring build for type $(BUILD_TYPE) in directory $(BUILD_DIR), using Python from $(PYTHON_TO_USE). Version is $KNOBKRAFT_EXTERNAL_VERSION"
cmake -S . -B $(BUILD_DIR) -DKNOBKRAFT_EXTERNAL_VERSION=$KNOBKRAFT_EXTERNAL_VERSION -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DPYTHON_EXECUTABLE=$(PYTHON_TO_USE) -DCODESIGN_CERTIFICATE_NAME="$(APPLE_DEVELOPER_IDENTITY)"

@coderabbitai coderabbitai Bot Nov 1, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical: Fix Makefile syntax error.

Line 37 is indented, making it a recipe command that appears before the target's prerequisites, which violates Make syntax. The pipeline error "commands commence before first target" confirms this.

Apply this diff to fix the syntax:

 configure:
-       export KNOBKRAFT_EXTERNAL_VERSION="$(cmake -P cmake/calc_version.cmake)"
-	@echo "Configuring build for type $(BUILD_TYPE) in directory $(BUILD_DIR), using Python from $(PYTHON_TO_USE). Version is $KNOBKRAFT_EXTERNAL_VERSION"
-	cmake -S . -B $(BUILD_DIR) -DKNOBKRAFT_EXTERNAL_VERSION=$KNOBKRAFT_EXTERNAL_VERSION -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DPYTHON_EXECUTABLE=$(PYTHON_TO_USE) -DCODESIGN_CERTIFICATE_NAME="$(APPLE_DEVELOPER_IDENTITY)"
+	$(eval KNOBKRAFT_EXTERNAL_VERSION := $(shell cmake -P cmake/calc_version.cmake))
+	@echo "Configuring build for type $(BUILD_TYPE) in directory $(BUILD_DIR), using Python from $(PYTHON_TO_USE). Version is $(KNOBKRAFT_EXTERNAL_VERSION)"
+	cmake -S . -B $(BUILD_DIR) -DKNOBKRAFT_EXTERNAL_VERSION=$(KNOBKRAFT_EXTERNAL_VERSION) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DPYTHON_EXECUTABLE=$(PYTHON_TO_USE) -DCODESIGN_CERTIFICATE_NAME="$(APPLE_DEVELOPER_IDENTITY)"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
configure:
@echo "Configuring build for type $(BUILD_TYPE) in directory $(BUILD_DIR), using Python from $(PYTHON_TO_USE)"
cmake -S . -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DPYTHON_EXECUTABLE=$(PYTHON_TO_USE) -DCODESIGN_CERTIFICATE_NAME="$(APPLE_DEVELOPER_IDENTITY)"
export KNOBKRAFT_EXTERNAL_VERSION="$(cmake -P cmake/calc_version.cmake)"
@echo "Configuring build for type $(BUILD_TYPE) in directory $(BUILD_DIR), using Python from $(PYTHON_TO_USE). Version is $KNOBKRAFT_EXTERNAL_VERSION"
cmake -S . -B $(BUILD_DIR) -DKNOBKRAFT_EXTERNAL_VERSION=$KNOBKRAFT_EXTERNAL_VERSION -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DPYTHON_EXECUTABLE=$(PYTHON_TO_USE) -DCODESIGN_CERTIFICATE_NAME="$(APPLE_DEVELOPER_IDENTITY)"
configure:
$(eval KNOBKRAFT_EXTERNAL_VERSION := $(shell cmake -P cmake/calc_version.cmake))
@echo "Configuring build for type $(BUILD_TYPE) in directory $(BUILD_DIR), using Python from $(PYTHON_TO_USE). Version is $(KNOBKRAFT_EXTERNAL_VERSION)"
cmake -S . -B $(BUILD_DIR) -DKNOBKRAFT_EXTERNAL_VERSION=$(KNOBKRAFT_EXTERNAL_VERSION) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DPYTHON_EXECUTABLE=$(PYTHON_TO_USE) -DCODESIGN_CERTIFICATE_NAME="$(APPLE_DEVELOPER_IDENTITY)"
🧰 Tools
🪛 checkmake (0.2.2)

[warning] 36-36: Target "configure" should be declared PHONY.

(phonydeclared)

🪛 GitHub Actions: macOS KnobKraft Orm

[error] 38-38: Makefile:38: *** commands commence before first target. Stop.

🤖 Prompt for AI Agents
In Makefile around lines 36 to 39, the echo line is incorrectly indented as a
recipe before the target which causes "commands commence before first target";
fix it by removing the leading tab from the echo line so it is part of the
makefile target declaration (or place it after the configure: line as a recipe
with a leading tab), ensuring only recipe lines are tab-indented and no commands
appear before the target header.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Did I fix it?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

# Check the exact indentation characters in the Makefile around the configure target
# Using cat -A to show tabs as ^I and spaces as regular spaces
echo "=== Checking indentation in Makefile around configure target ==="
sed -n '36,39p' Makefile | cat -A

echo ""
echo "=== Checking with od to see exact bytes ==="
sed -n '37p' Makefile | od -c

echo ""
echo "=== Line 37 content ==="
sed -n '37p' Makefile

Length of output: 707


@christofmuc Good news and bad news!

✅ You fixed the indentation issue - all three lines now use tabs correctly, so the "commands commence before first target" error should be gone.

⚠️ However, there's a functional problem with the export approach:

In Makefiles, each recipe line runs in its own separate shell. So when line 37 runs export KNOBKRAFT_EXTERNAL_VERSION=..., that variable is only available in that shell instance. Lines 38 and 39 run in different shells and won't see the exported variable.

Two solutions:

  1. Use the bot's suggested approach (cleanest):
configure:
	$(eval KNOBKRAFT_EXTERNAL_VERSION := $(shell cmake -P cmake/calc_version.cmake))
	@echo "Configuring build for type $(BUILD_TYPE) in directory $(BUILD_DIR), using Python from $(PYTHON_TO_USE). Version is $(KNOBKRAFT_EXTERNAL_VERSION)"
	cmake -S . -B $(BUILD_DIR) -DKNOBKRAFT_EXTERNAL_VERSION=$(KNOBKRAFT_EXTERNAL_VERSION) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DPYTHON_EXECUTABLE=$(PYTHON_TO_USE) -DCODESIGN_CERTIFICATE_NAME="$(APPLE_DEVELOPER_IDENTITY)"
  1. Join the commands with semicolons (keeps them in one shell):
configure:
	export KNOBKRAFT_EXTERNAL_VERSION="$$(cmake -P cmake/calc_version.cmake)"; \
	echo "Configuring build for type $(BUILD_TYPE) in directory $(BUILD_DIR), using Python from $(PYTHON_TO_USE). Version is $$KNOBKRAFT_EXTERNAL_VERSION"; \
	cmake -S . -B $(BUILD_DIR) -DKNOBKRAFT_EXTERNAL_VERSION=$$KNOBKRAFT_EXTERNAL_VERSION -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DPYTHON_EXECUTABLE=$(PYTHON_TO_USE) -DCODESIGN_CERTIFICATE_NAME="$(APPLE_DEVELOPER_IDENTITY)"

Note the $$ (double dollar signs) for shell variables in option 2.

I'd recommend option 1 as it's cleaner and more Makefile-idiomatic.

Comment thread The-Orm/CMakeLists.txt

# Start project
project(KnobKraftOrm VERSION ${PROJECT_VERSION})
project(KnobKraftOrm VERSION ${KNOBKRAFT_EXTERNAL_VERSION})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add validation for KNOBKRAFT_EXTERNAL_VERSION.

If KNOBKRAFT_EXTERNAL_VERSION is not set or is empty (e.g., due to the calc_version.cmake failures noted in other files), the project() command will fail or produce an invalid version.

+if(NOT DEFINED KNOBKRAFT_EXTERNAL_VERSION OR KNOBKRAFT_EXTERNAL_VERSION STREQUAL "")
+    message(FATAL_ERROR "KNOBKRAFT_EXTERNAL_VERSION must be set. Please pass -DKNOBKRAFT_EXTERNAL_VERSION=<version> to CMake.")
+endif()
+
 project(KnobKraftOrm VERSION ${KNOBKRAFT_EXTERNAL_VERSION})
🤖 Prompt for AI Agents
In The-Orm/CMakeLists.txt around line 10, the project() call uses
KNOBKRAFT_EXTERNAL_VERSION without validating it; add a check immediately before
the project() line to verify the variable is defined and non-empty and either
set a safe default (e.g., "0.0.0") or call message(FATAL_ERROR ...) with a clear
error asking to run calc_version.cmake so the build fails fast with a helpful
message instead of producing an invalid project() invocation.

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.

1 participant