Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 17 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Use clang-format 22; see docs/code-style.md.
BasedOnStyle: LLVM
IndentWidth: 4
ContinuationIndentWidth: 4
AccessModifierOffset: -4
ColumnLimit: 120
NamespaceIndentation: All
CompactNamespaces: true
BreakBeforeBraces: Attach
BreakAfterReturnType: AllDefinitions
PointerAlignment: Left
ReferenceAlignment: Left
SortIncludes: Never
ReflowComments: IndentOnly
AllowShortFunctionsOnASingleLine: Empty
BreakTemplateDeclarations: Yes
AttributeMacros: [forceinline]
24 changes: 24 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Use clang-tidy 22. Keep checks focused on correctness and useful modernization.
Checks: >-
-*,
bugprone-assert-side-effect,
bugprone-dangling-handle,
bugprone-integer-division,
bugprone-macro-repeated-side-effects,
bugprone-misplaced-widening-cast,
bugprone-move-forwarding-reference,
bugprone-sizeof-expression,
bugprone-suspicious-memset-usage,
bugprone-unused-raii,
modernize-deprecated-headers,
modernize-use-nullptr,
modernize-use-override,
performance-for-range-copy,
performance-inefficient-string-concatenation,
performance-move-const-arg,
performance-unnecessary-copy-initialization,
performance-unnecessary-value-param
WarningsAsErrors: '*'
HeaderFilterRegex: '(gecode|test|examples|tools)/'
ExcludeHeaderFilterRegex: 'gecode/third-party/|gecode/flatzinc/(parser\.tab\.(cpp|hpp)|lexer\.yy\.cpp)$'
FormatStyle: file
17 changes: 9 additions & 8 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# EditorConfig file for Gecode
# See https://EditorConfig.org for more information about the .editorconfig format

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
Expand All @@ -13,6 +8,12 @@ charset = utf-8
indent_style = space
indent_size = 2

# Makefiles need to use Tab indentation
[Makefile*]
indent_style = tab
[*.{c,cc,cpp,cxx,h,hh,hpp,hxx,lxx,yxx,vis}]
indent_size = 4
max_line_length = 120

[*.py]
indent_size = 4

[{CMakeLists.txt,*.cmake,*.yml,*.yaml}]
indent_size = 2
8 changes: 5 additions & 3 deletions .github/ci/generated-source-freshness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ prepend_brew_bin() {
fi
}

# Homebrew keeps bison and flex keg-only on macOS. Make the same helper
# Homebrew keeps these tools keg-only on macOS. Make the same helper
# work from a developer shell without requiring them to edit PATH manually.
prepend_brew_bin bison
prepend_brew_bin flex
prepend_brew_bin llvm
prepend_brew_bin llvm@22
export PATH

require_version() {
Expand Down Expand Up @@ -121,7 +123,7 @@ vis_files=(
# at the end-of-archive marker before the writer has written its final
# padding, which fails the writer with a write error.
tar -C "$repo_root" -cf "$workspace/source.tar" \
misc/genvarimp.py "${vis_files[@]}" \
.clang-format misc/genvarimp.py "${vis_files[@]}" \
gecode/flatzinc/parser.yxx gecode/flatzinc/lexer.lxx
tar -C "$source_copy" -xf "$workspace/source.tar"
rm -f -- "$workspace/source.tar"
Expand Down Expand Up @@ -196,7 +198,7 @@ if [ "$mode" = update ]; then
fi

if [ "$stale" -ne 0 ]; then
echo "Regenerate with GNU Bison 3.8.2, GNU Flex 2.6.4, and uv, then commit the reviewed outputs." >&2
echo "Regenerate with GNU Bison 3.8.2, GNU Flex 2.6.4, clang-format 22, and uv, then commit the reviewed outputs." >&2
echo "Run 'bash .github/ci/generated-source-freshness.sh --update' to use the canonical generator workflow." >&2
exit 1
fi
Expand Down
53 changes: 39 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:

jobs:
tidy:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0
Expand All @@ -26,6 +26,19 @@ jobs:
with:
enable-cache: false

- name: Install clang-format 22
shell: bash
run: |
curl --fail --location --retry 3 https://apt.llvm.org/llvm-snapshot.gpg.key -o "$RUNNER_TEMP/llvm.asc"
sudo install -m 644 "$RUNNER_TEMP/llvm.asc" /usr/share/keyrings/llvm.asc
echo 'deb [signed-by=/usr/share/keyrings/llvm.asc] https://apt.llvm.org/noble/ llvm-toolchain-noble-22 main' | sudo tee /etc/apt/sources.list.d/llvm.list
sudo apt-get update
sudo apt-get install -y clang-format-22

- name: Formatting check
shell: bash
run: uv run misc/check.py format-check

- name: Tidy checks
shell: bash
run: uv run misc/tidy.py --check
Expand All @@ -38,7 +51,7 @@ jobs:
include:
- os: macos-15
regenerate_varimp: OFF
- os: ubuntu-latest
- os: ubuntu-24.04
regenerate_varimp: ON

steps:
Expand All @@ -49,17 +62,29 @@ jobs:
with:
enable-cache: false

- name: Install clang-format 22
if: runner.os == 'Linux'
shell: bash
run: |
curl --fail --location --retry 3 https://apt.llvm.org/llvm-snapshot.gpg.key -o "$RUNNER_TEMP/llvm.asc"
sudo install -m 644 "$RUNNER_TEMP/llvm.asc" /usr/share/keyrings/llvm.asc
echo 'deb [signed-by=/usr/share/keyrings/llvm.asc] https://apt.llvm.org/noble/ llvm-toolchain-noble-22 main' | sudo tee /etc/apt/sources.list.d/llvm.list
sudo apt-get update
sudo apt-get install -y clang-format-22

- name: Install Ubuntu build deps
if: runner.os == 'Linux'
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y flex bison libgmp-dev libmpfr-dev
sudo apt-get install -y libgmp-dev libmpfr-dev

- name: Install generated-source tools
if: runner.os == 'macOS'
shell: bash
run: brew install bison flex
run: |
brew install bison flex llvm@22
echo "CLANG_FORMAT=$(brew --prefix llvm@22)/bin/clang-format" >> "$GITHUB_ENV"

- name: Check generated source freshness
if: runner.os == 'macOS'
Expand All @@ -79,7 +104,7 @@ jobs:
"-DCMAKE_BUILD_TYPE=$BUILD_TYPE"
"-DGECODE_REGENERATE_VARIMP=${{ matrix.regenerate_varimp }}"
)
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
if [ "${{ matrix.os }}" = "ubuntu-24.04" ]; then
# Keep this path absolute to validate package config handling for absolute install dirs.
cmake_args+=(
"-DCMAKE_INSTALL_INCLUDEDIR=/tmp/gecode-install-abs-include"
Expand All @@ -101,7 +126,7 @@ jobs:
cmake --build . --config $BUILD_TYPE --target check

- name: Run public test harness smokes
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'ubuntu-24.04'
working-directory: ${{github.workspace}}/build
shell: bash
run: ctest --build-config "$BUILD_TYPE" --output-on-failure -R '^public-.*-smoke$'
Expand All @@ -115,7 +140,7 @@ jobs:
shell: bash
run: |
set -euxo pipefail
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
if [ "${{ matrix.os }}" = "ubuntu-24.04" ]; then
bash .github/ci/cmake-consumer-smoke.sh \
"$GITHUB_WORKSPACE/install" \
"/tmp/gecode-install-abs-include" \
Expand All @@ -132,22 +157,22 @@ jobs:
run: bash .github/ci/cmake-package-version-checks.sh "$GITHUB_WORKSPACE/install"

- name: Disabled module closure checks
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'ubuntu-24.04'
shell: bash
run: bash .github/ci/cmake-closure-checks.sh

- name: CMake custom VIS checks
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'ubuntu-24.04'
shell: bash
run: bash .github/ci/cmake-custom-vis-smoke.sh

- name: Gist static macro compatibility
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'ubuntu-24.04'
shell: bash
run: bash .github/ci/gist-static-macro-smoke.sh

- name: Qt minimum version checks
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'ubuntu-24.04'
shell: bash
run: bash .github/ci/qt-minimum-version-checks.sh

Expand All @@ -166,7 +191,7 @@ jobs:
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y flex bison libgmp-dev libmpfr-dev ninja-build
sudo apt-get install -y libgmp-dev libmpfr-dev ninja-build

- name: Install MiniZinc 2.10.1
shell: bash
Expand Down Expand Up @@ -346,7 +371,7 @@ jobs:
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y flex bison qt6-base-dev qt6-base-dev-tools libgl1-mesa-dev
sudo apt-get install -y qt6-base-dev qt6-base-dev-tools libgl1-mesa-dev

- name: Configure CMake with Qt/Gist
shell: bash
Expand Down Expand Up @@ -385,7 +410,7 @@ jobs:
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y flex bison qtbase5-dev qtbase5-dev-tools libgl1-mesa-dev
sudo apt-get install -y qtbase5-dev qtbase5-dev-tools libgl1-mesa-dev

- name: Configure CMake with Qt 5/Gist
shell: bash
Expand Down
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ solution so far.

## Code conventions

New code follows these rules, even where older code does not:
Formatting, naming, and the format and lint commands are described in
[the code style guide](docs/code-style.md). New code follows these rules, even
where older code does not:

- Name functions and variables in snake_case (`read_file`, `parse_int`).
- Use `enum class`, unless an existing API requires a plain `enum`.
Expand Down
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ if(GECODE_REGENERATE_VARIMP)
-DOUT_FILE=${GECODE_VAR_TYPE_HPP}
-DVIS_FILES_SERIALIZED=${GECODE_VIS_FILES_SERIALIZED}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateVarImp.cmake
DEPENDS ${GECODE_VIS_DEPENDS} ${CMAKE_CURRENT_SOURCE_DIR}/misc/genvarimp.py ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
DEPENDS ${GECODE_VIS_DEPENDS} ${CMAKE_CURRENT_SOURCE_DIR}/misc/genvarimp.py ${CMAKE_CURRENT_SOURCE_DIR}/.clang-format ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
VERBATIM
)
Expand All @@ -827,7 +827,7 @@ if(GECODE_REGENERATE_VARIMP)
-DOUT_FILE=${GECODE_VAR_IMP_HPP}
-DVIS_FILES_SERIALIZED=${GECODE_VIS_FILES_SERIALIZED}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateVarImp.cmake
DEPENDS ${GECODE_VIS_DEPENDS} ${CMAKE_CURRENT_SOURCE_DIR}/misc/genvarimp.py ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
DEPENDS ${GECODE_VIS_DEPENDS} ${CMAKE_CURRENT_SOURCE_DIR}/misc/genvarimp.py ${CMAKE_CURRENT_SOURCE_DIR}/.clang-format ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
VERBATIM
)
Expand All @@ -836,6 +836,10 @@ else()
add_custom_target(gecode-varimp-gen)
endif()

if(PROJECT_IS_TOP_LEVEL)
include(cmake/GecodeChecks.cmake)
endif()

# Regenerate the checked-in parser and variable headers with pinned tools.
add_custom_target(regenerate
COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/.github/ci/generated-source-freshness.sh" --update
Expand Down
25 changes: 25 additions & 0 deletions cmake/GecodeChecks.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Developer checks are explicit targets; ordinary builds need no LLVM tools.
if(GECODE_UV_EXECUTABLE)
set(_gecode_check_uv "${GECODE_UV_EXECUTABLE}")
else()
set(_gecode_check_uv uv)
endif()

foreach(command IN ITEMS format format-check lint all)
if(command STREQUAL "format")
set(target format)
elseif(command STREQUAL "format-check")
set(target check-format)
elseif(command STREQUAL "lint")
set(target check-lint)
else()
set(target check-extended)
endif()
add_custom_target(${target}
COMMAND "${_gecode_check_uv}" run "${PROJECT_SOURCE_DIR}/misc/check.py" ${command}
--build-dir "${PROJECT_BINARY_DIR}" --config "$<CONFIG>"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
USES_TERMINAL
VERBATIM)
endforeach()
unset(_gecode_check_uv)
74 changes: 74 additions & 0 deletions docs/code-style.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Code style

Use clang-format **22** for first-party C and C++ sources. `.clang-format`
defines the exact formatting; `.editorconfig` supplies the matching editor
defaults. Keep upstream third-party files in their original style.

## Formatting

C++ uses four-space indentation and a 120-column limit. Braces stay on the
opening line, compact nested namespaces remain indented, and pointer and
reference markers bind to the type. Function definitions retain a separate
return-type line. Include order and comment wrapping are preserved, including
copyright notices and Doxygen text.

Four spaces distinguish nested control flow. The 120-column limit leaves room
for namespace-qualified calls, templates, and generated scheduling expressions.
A comparison across six representative files produced 9,411 lines at 100 columns
and 9,299 at 120, versus 9,665 at 80. Only 146 additional lines exceeded 100
columns at 120, so the wider limit mainly avoids awkward wrapping. Continuation
indentation stays at four spaces; comments retain their existing wrapping.

Python uses four spaces; CMake and YAML use two. Editor settings belong in
`.editorconfig` rather than per-file indentation headers.

## Generated files

The variable-header generator formats its output with clang-format 22. Set
`CLANG_FORMAT` to its executable, or put `clang-format-22` or `clang-format`
on `PATH`. Builds using the checked-in headers do not require this tool.
Apply changes to the generator or its inputs, regenerate the outputs, and
check freshness. Formatting the checked-in outputs alone would make the next
regeneration undo the change.

The generated FlatZinc parser and lexer retain Bison and Flex formatting;
their upstream scaffolding is excluded from clang-format. Regenerate these
files from `.yxx` and `.lxx` inputs rather than editing the output by hand.

## Naming migration

The naming migration is pending a decision on which identifier categories
change, including types and namespaces. Names should separate words with
underscores and describe their purpose. A casing check cannot identify word
boundaries in existing names such as `dfsengine` and `modeventdelta`; those
need explicit review.

Changing every category requires resolving collisions before applying fixes.
For example, `Int` cannot become the keyword `int`, and the `DFS` class
template cannot take the existing `dfs` function's name. Review those choices
alongside the public API, generated code, and documentation.

## Checking changes

Put LLVM 22 tools on `PATH`, or set `CLANG_FORMAT` and `CLANG_TIDY` to their
executables. The checker rejects other major versions. Use:

```sh
uv run misc/check.py format
uv run misc/check.py format-check
uv run misc/check.py lint --build-dir build/local
uv run misc/check.py all --build-dir build/local --jobs 4
```

CMake provides `format`, `check-format`, `check-lint`, and `check-extended`
targets for the same commands. Formatting checks need no configured build.
Lint requires a Ninja or Makefiles compilation database configured with
`-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`; it checks compiled sources and their
maintained headers. The command reports sources outside that build so optional
modules cannot silently disappear from the coverage report.

The extended command also checks the changelog and generated-source freshness,
builds the configured targets, runs the standard test suite, and runs CTest.
Enable optional and experimental modules in the build when checking them;
platform-specific code also needs its corresponding CI toolchain. Normal
builds use checked-in generated sources and do not require LLVM tools.
Loading
Loading