From 7a05897ed1e73141e121ddf0926c8f412ee4b9c8 Mon Sep 17 00:00:00 2001 From: devmuaz Date: Tue, 10 Nov 2026 10:38:06 +0300 Subject: [PATCH 1/3] Build Dear ImGui as a shared library loaded by the executable (Phase 1) --- .github/scripts/linux-packaging.sh | 1 + CONTRIBUTING.md | 48 +++++++++++++++++++++++------- cmake/Dependencies.cmake | 9 +++--- cmake/Packaging.cmake | 6 ++++ cmake/Runtime.cmake | 31 +++++++++++++++++-- docs/building.md | 2 +- src/gui/CMakeLists.txt | 12 ++++++++ 7 files changed, 92 insertions(+), 17 deletions(-) diff --git a/.github/scripts/linux-packaging.sh b/.github/scripts/linux-packaging.sh index 22ac4a4..649e6d7 100755 --- a/.github/scripts/linux-packaging.sh +++ b/.github/scripts/linux-packaging.sh @@ -14,6 +14,7 @@ fi mkdir -p "release/${ARTIFACT_NAME}/share/applications" "release/${ARTIFACT_NAME}/share/icons" cp build/CoreDeck "release/${ARTIFACT_NAME}/" +cp build/libimgui.so "release/${ARTIFACT_NAME}/" cp -r build/assets "release/${ARTIFACT_NAME}/" cp "${desktop}" "release/${ARTIFACT_NAME}/share/applications/com.devmuaz.coredeck.desktop" cp -R packaging/linux/hicolor "release/${ARTIFACT_NAME}/share/icons/hicolor" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0fe81f4..d613089 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,13 +5,15 @@ project. ## Branching Model -| Branch | Purpose | -| --------- | --------------------------------------------------------- | -| `main` | Stable, release-ready code. Protected — no direct pushes. | -| `develop` | Active development. All feature work merges here first. | +| Branch | Purpose | +| --------- | -------------------------------------------------------------------------- | +| `main` | Stable, release-ready code. Protected — no direct pushes. | +| `develop` | Active development. Feature work merges here. Test tags are cut from here. | ``` -feature/* ──> develop ──> main (via PR) ──> tag vX.Y.Z ──> release +feature/* ──> develop ──> tag vX.Y.Z-label ──> pre-release + │ + └──> main (via PR) ──> tag vX.Y.Z ──> stable release ``` ## How to Contribute @@ -48,7 +50,7 @@ feature/* ──> develop ──> main (via PR) ──> tag vX.Y.Z ──> relea ## PR Guidelines -- PRs to `develop` trigger the CI build workflow across Windows, macOS, and Linux +- A pull request into `develop` runs the build on Windows, macOS, and Linux. Merge the feature there. A pull request into `main` runs that same build and is how `develop` is promoted for a stable release, not how each feature lands - Make sure the build passes on all platforms before requesting review - Keep PRs focused — avoid mixing unrelated changes - Update the [CHANGELOG.md](CHANGELOG.md) if your change is user-facing @@ -118,11 +120,37 @@ This is routine maintenance, not a hotfix: Google keeps old archives available f ## Release Process -Releases are handled by maintainers: +Maintainers publish two kinds of builds. Pushing a tag that starts with `v` starts the release workflow. The tag's commit is what gets built. `main` does not have to move for a test build. -1. `develop` is merged into `main` via PR -2. A version tag (`vX.Y.Z`) is pushed to `main` -3. The release workflow builds and publishes artifacts for all platforms +A tag with a hyphen, such as `v0.17.0-phase1`, is a pre-release. A tag with no hyphen, such as `v0.17.0`, is a stable release. A stable tag also updates the Homebrew tap. A pre-release does not. + +### Pre-release + +A pre-release is an unfinished test build. It is not battle-tested, it may crash or misbehave, and it is not a build to rely on. Install a stable release for everyday use. + +1. The approved work is on `develop`. Leave `main` where it is. +2. Tag that commit with a hyphen in the name and push the tag: + + ```bash + git checkout develop + git tag v0.17.0-phase1 + git push origin v0.17.0-phase1 + ``` + +3. The workflow publishes a GitHub pre-release with the signed installers. The Homebrew tap stays on the last stable version. + +### Stable release + +1. Open a pull request from `develop` into `main` and wait for the build. +2. Merge it, then push a tag with no hyphen to that `main` commit: + + ```bash + git checkout main + git tag v0.17.0 + git push origin v0.17.0 + ``` + +3. The workflow publishes the stable release and updates the Homebrew tap. ## Questions? diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index ff2c090..31f7371 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -30,16 +30,17 @@ coredeck_add_extern(${CMAKE_SOURCE_DIR}/extern/glfw ${CMAKE_BINARY_DIR}/extern/g find_package(OpenGL REQUIRED) set(IMGUI_DIR ${CMAKE_SOURCE_DIR}/extern/imgui) -add_library(imgui STATIC +add_library(imgui SHARED ${IMGUI_DIR}/imgui.cpp ${IMGUI_DIR}/imgui_draw.cpp ${IMGUI_DIR}/imgui_tables.cpp ${IMGUI_DIR}/imgui_widgets.cpp - ${IMGUI_DIR}/backends/imgui_impl_glfw.cpp - ${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp ) target_include_directories(imgui PUBLIC ${IMGUI_DIR} ${IMGUI_DIR}/backends) -target_link_libraries(imgui PUBLIC glfw OpenGL::GL) +if(WIN32) + target_compile_definitions(imgui PRIVATE "IMGUI_API=__declspec(dllexport)") + target_compile_definitions(imgui INTERFACE "IMGUI_API=__declspec(dllimport)") +endif() set(REFLECTCPP_BUILD_SHARED OFF CACHE BOOL "" FORCE) set(REFLECTCPP_BUILD_TESTS OFF CACHE BOOL "" FORCE) diff --git a/cmake/Packaging.cmake b/cmake/Packaging.cmake index bb7521b..67e0db9 100644 --- a/cmake/Packaging.cmake +++ b/cmake/Packaging.cmake @@ -86,6 +86,12 @@ if(WIN32 AND COREDECK_INTL_RUNTIME_DLLS) install(FILES ${COREDECK_INTL_RUNTIME_DLLS} DESTINATION .) endif() +if(WIN32) + install(TARGETS imgui RUNTIME DESTINATION .) +elseif(UNIX AND NOT APPLE) + install(TARGETS imgui LIBRARY DESTINATION .) +endif() + if(NOT APPLE) install(DIRECTORY ${CMAKE_SOURCE_DIR}/assets/fonts DESTINATION assets) install(DIRECTORY ${COREDECK_LOCALE_DIR}/ DESTINATION assets/locales) diff --git a/cmake/Runtime.cmake b/cmake/Runtime.cmake index a9f2c5e..5236158 100644 --- a/cmake/Runtime.cmake +++ b/cmake/Runtime.cmake @@ -22,9 +22,27 @@ else() ) endif() +if(APPLE) + set_target_properties(${PROJECT_NAME} PROPERTIES + SKIP_BUILD_RPATH TRUE + BUILD_WITH_INSTALL_RPATH TRUE + INSTALL_RPATH "@executable_path/../Frameworks" + ) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory "$/Frameworks" + COMMAND ${CMAKE_COMMAND} -E copy "$" "$/Frameworks/$" + VERBATIM + ) +endif() + +if(UNIX AND NOT APPLE) + set_target_properties(${PROJECT_NAME} PROPERTIES + BUILD_RPATH "\$ORIGIN" + INSTALL_RPATH "\$ORIGIN" + ) +endif() + if(APPLE AND NOT Intl_IS_BUILT_IN) - set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY BUILD_RPATH "@executable_path/../Frameworks") - set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY INSTALL_RPATH "@executable_path/../Frameworks") get_filename_component(_intl_real "${Intl_LIBRARY}" REALPATH) execute_process( COMMAND otool -D "${_intl_real}" @@ -38,6 +56,15 @@ if(APPLE AND NOT Intl_IS_BUILT_IN) COMMAND ${CMAKE_COMMAND} -E copy "${_intl_real}" "$/Frameworks/libintl.8.dylib" COMMAND install_name_tool -id "@rpath/libintl.8.dylib" "$/Frameworks/libintl.8.dylib" COMMAND install_name_tool -change "${COREDECK_INTL_INSTALL_NAME}" "@rpath/libintl.8.dylib" "$" + COMMAND codesign --force --sign - "$/Frameworks/libintl.8.dylib" + VERBATIM + ) +endif() + +if(APPLE) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND codesign --force --sign - "$/Frameworks/$" + COMMAND codesign --force --sign - "$" VERBATIM ) endif() diff --git a/docs/building.md b/docs/building.md index ff2a794..35e1cc9 100644 --- a/docs/building.md +++ b/docs/building.md @@ -67,7 +67,7 @@ The first build compiles the bundled dependencies, including sentry-native, Dear | `coredeck_platform` | `src/platform` | platform | Processes, HTTP, archives, hashing, logging, translation, paths, and generic helpers split by what they hold: `strings`, `files`, `secrets`, `desktop` | | `coredeck_core` | `src/core` | platform, core | Android logic, grouped by domain: `sdk/`, `avd/`, `adb/`, `apk/` | | `coredeck_app` | `src/app` | platform, app | Settings, app paths, crash reporting, update checks, and file dialogs | -| `coredeck_gui` | `src/gui` | all of the above | Everything that draws. Dear ImGui is its own `imgui` target | +| `coredeck_gui` | `src/gui` | all of the above | Everything that draws. Dear ImGui is the shared `imgui` library linked by the executable | Core and App do not include each other. The executable is `src/main.cpp` and links only `coredeck_gui`. A call names the layer: `Platform::JoinPaths`, `Core::SignApk`, `App::LoadAppSettings`. diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 1e4f146..9eaf94c 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -46,7 +46,19 @@ add_library(coredeck_gui STATIC ) target_precompile_headers(coredeck_gui PRIVATE ${CMAKE_SOURCE_DIR}/src/pch.h) +target_sources(coredeck_gui PRIVATE + ${IMGUI_DIR}/backends/imgui_impl_glfw.cpp + ${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp +) +if(WIN32) + set_source_files_properties( + ${IMGUI_DIR}/backends/imgui_impl_glfw.cpp + ${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp + PROPERTIES COMPILE_DEFINITIONS "IMGUI_IMPL_API=" + ) +endif() target_link_libraries(coredeck_gui PUBLIC coredeck_app coredeck_core imgui) +target_link_libraries(coredeck_gui PRIVATE glfw OpenGL::GL) if(WIN32) target_link_libraries(coredeck_gui PRIVATE dwmapi) From b8deedf9da4d82df9ca8c48f0c23fcb497be35f7 Mon Sep 17 00:00:00 2001 From: devmuaz Date: Tue, 10 Nov 2026 11:12:34 +0300 Subject: [PATCH 2/3] Fix the Windows link of the ImGui backends and the Linux clang-tidy failures --- src/app/app_paths.cpp | 2 +- src/gui/CMakeLists.txt | 6 +----- src/gui/shell/application.cpp | 4 ++-- src/gui/theme/theme.cpp | 12 +++++++----- src/platform/paths.cpp | 1 + src/platform/process.cpp | 2 +- src/platform/process_stats.cpp | 33 ++++++++++++++++++++++----------- 7 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/app/app_paths.cpp b/src/app/app_paths.cpp index 4714aaa..a7a55e1 100644 --- a/src/app/app_paths.cpp +++ b/src/app/app_paths.cpp @@ -37,7 +37,7 @@ namespace CoreDeck::App { } std::string ResolveAssetsDirectory(const std::string &resourcesDir) { - const std::string beside = Platform::JoinPaths({resourcesDir, "assets"}); + std::string beside = Platform::JoinPaths({resourcesDir, "assets"}); #ifdef __linux__ std::error_code error; if (!resourcesDir.empty() && !std::filesystem::is_directory(beside, error)) { diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 9eaf94c..e239675 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -51,11 +51,7 @@ target_sources(coredeck_gui PRIVATE ${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp ) if(WIN32) - set_source_files_properties( - ${IMGUI_DIR}/backends/imgui_impl_glfw.cpp - ${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp - PROPERTIES COMPILE_DEFINITIONS "IMGUI_IMPL_API=" - ) + target_compile_definitions(coredeck_gui PRIVATE "IMGUI_IMPL_API=") endif() target_link_libraries(coredeck_gui PUBLIC coredeck_app coredeck_core imgui) target_link_libraries(coredeck_gui PRIVATE glfw OpenGL::GL) diff --git a/src/gui/shell/application.cpp b/src/gui/shell/application.cpp index a403f6f..ce8faf9 100644 --- a/src/gui/shell/application.cpp +++ b/src/gui/shell/application.cpp @@ -428,7 +428,7 @@ namespace CoreDeck::Gui { self->m_FontPixelScale = xscale; ImGui::GetStyle().FontScaleDpi = 1.0F; - ImGuiIO &io = ImGui::GetIO(); + const ImGuiIO &io = ImGui::GetIO(); io.Fonts->Clear(); self->m_LoadFonts(); io.Fonts->Build(); @@ -624,7 +624,7 @@ namespace CoreDeck::Gui { SetThemePreference(preference); } - void ApplyWindowChrome(GLFWwindow *window) { + void ApplyWindowChrome(GLFWwindow *window) { // NOLINT(misc-const-correctness) Windows and macOS pass this pointer to GLFW. if (window == nullptr) { return; } diff --git a/src/gui/theme/theme.cpp b/src/gui/theme/theme.cpp index 9f4aa23..5c2fb23 100644 --- a/src/gui/theme/theme.cpp +++ b/src/gui/theme/theme.cpp @@ -26,6 +26,8 @@ #endif #if !defined(_WIN32) && !defined(__APPLE__) +#include + #include "platform/env.h" #include "platform/strings.h" #endif @@ -222,11 +224,11 @@ namespace CoreDeck::Gui { #else std::string TrimCopy(const std::string &text) { std::size_t begin = 0; - while (begin < text.size() && std::isspace(static_cast(text[begin]))) { + while (begin < text.size() && std::isspace(static_cast(text.at(begin)))) { ++begin; } std::size_t end = text.size(); - while (end > begin && std::isspace(static_cast(text[end - 1]))) { + while (end > begin && std::isspace(static_cast(text.at(end - 1)))) { --end; } return text.substr(begin, end - begin); @@ -237,7 +239,7 @@ namespace CoreDeck::Gui { } bool ReadCommand(const char *command, std::string &output) { - FILE *pipe = popen(command, "r"); + FILE *pipe = popen(command, "r"); // NOLINT(cert-env33-c, bugprone-command-processor) if (pipe == nullptr) { return false; } @@ -251,10 +253,10 @@ namespace CoreDeck::Gui { } std::string ConfigDirectory() { - if (const char *xdg = std::getenv(Platform::ENV_XDG_CONFIG_HOME); xdg != nullptr && xdg[0] != '\0') { + if (const char *xdg = std::getenv(Platform::ENV_XDG_CONFIG_HOME); xdg != nullptr && xdg[0] != '\0') { // NOLINT(concurrency-mt-unsafe) return xdg; } - if (const char *home = std::getenv(Platform::ENV_HOME); home != nullptr && home[0] != '\0') { + if (const char *home = std::getenv(Platform::ENV_HOME); home != nullptr && home[0] != '\0') { // NOLINT(concurrency-mt-unsafe) return std::string(home) + "/.config"; } return {}; diff --git a/src/platform/paths.cpp b/src/platform/paths.cpp index 1d6c656..8b4b9ec 100644 --- a/src/platform/paths.cpp +++ b/src/platform/paths.cpp @@ -12,6 +12,7 @@ #include #include #elif __linux__ +#include #include #endif diff --git a/src/platform/process.cpp b/src/platform/process.cpp index 099f0e9..6c6b104 100644 --- a/src/platform/process.cpp +++ b/src/platform/process.cpp @@ -22,7 +22,7 @@ #include #include -extern char **environ; // NOLINT(readability-identifier-naming) +extern char **environ; // NOLINT(readability-identifier-naming, readability-redundant-declaration) #endif namespace CoreDeck::Platform { diff --git a/src/platform/process_stats.cpp b/src/platform/process_stats.cpp index e74fcba..66d6559 100644 --- a/src/platform/process_stats.cpp +++ b/src/platform/process_stats.cpp @@ -64,35 +64,41 @@ namespace CoreDeck::Platform { #elif defined(__linux__) bool ReadProcessSnapshot(ProcessId pid, std::uint64_t &cpuTimeNs, std::uint64_t &rssBytes, std::uint64_t &diskReadBytes, std::uint64_t &diskWriteBytes) { char path[64]; - std::snprintf(path, sizeof(path), "/proc/%d/stat", static_cast(pid)); + if (std::snprintf(path, sizeof(path), "/proc/%d/stat", static_cast(pid)) < 0) { + return false; + } std::ifstream stat(path); if (!stat.is_open()) return false; - std::string contents((std::istreambuf_iterator(stat)), std::istreambuf_iterator()); + const std::string contents((std::istreambuf_iterator(stat)), std::istreambuf_iterator()); const auto rparen = contents.rfind(')'); if (rparen == std::string::npos) return false; std::istringstream rest(contents.substr(rparen + 1)); char state = 0; - unsigned long long utime = 0, stime = 0; + std::uint64_t utime = 0; + std::uint64_t stime = 0; rest >> state; for (int i = 0; i < 10; ++i) { - unsigned long long discard = 0; + std::uint64_t discard = 0; rest >> discard; } rest >> utime >> stime; if (!rest) return false; - const long ticks = sysconf(_SC_CLK_TCK); + const std::int64_t ticks = sysconf(_SC_CLK_TCK); if (ticks <= 0) return false; const double nsPerTick = 1e9 / static_cast(ticks); cpuTimeNs = static_cast( (static_cast(utime) + static_cast(stime)) * nsPerTick ); - std::snprintf(path, sizeof(path), "/proc/%d/statm", static_cast(pid)); + if (std::snprintf(path, sizeof(path), "/proc/%d/statm", static_cast(pid)) < 0) { + return false; + } if (std::ifstream statm(path); statm.is_open()) { - unsigned long long size = 0, rssPages = 0; + std::uint64_t size = 0; + std::uint64_t rssPages = 0; statm >> size >> rssPages; rssBytes = rssPages * static_cast(sysconf(_SC_PAGESIZE)); } else { @@ -101,13 +107,18 @@ namespace CoreDeck::Platform { diskReadBytes = 0; diskWriteBytes = 0; - std::snprintf(path, sizeof(path), "/proc/%d/io", static_cast(pid)); + if (std::snprintf(path, sizeof(path), "/proc/%d/io", static_cast(pid)) < 0) { + return false; + } if (std::ifstream io(path); io.is_open()) { std::string key; - unsigned long long value = 0; + std::uint64_t value = 0; while (io >> key >> value) { - if (key == "read_bytes:") diskReadBytes = value; - else if (key == "write_bytes:") diskWriteBytes = value; + if (key == "read_bytes:") { + diskReadBytes = value; + } else if (key == "write_bytes:") { + diskWriteBytes = value; + } } } return true; From 309c1f68546d294af13c98f11fa5cd1f9bc5dbe7 Mon Sep 17 00:00:00 2001 From: devmuaz Date: Tue, 10 Nov 2026 11:55:10 +0300 Subject: [PATCH 3/3] Fix the Linux clang-tidy include and run that check before the platform builds --- .github/workflows/build.yml | 9 ++- .../{lint.yml => structure-format-tidy.yml} | 4 +- .gitignore | 1 + .vscode/tasks.json | 11 ++++ CONTRIBUTING.md | 2 +- src/platform/paths.cpp | 5 +- tools/structure_format_tidy.sh | 59 +++++++++++++++++++ 7 files changed, 84 insertions(+), 7 deletions(-) rename .github/workflows/{lint.yml => structure-format-tidy.yml} (95%) create mode 100755 tools/structure_format_tidy.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e865e6e..dbe098d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,21 +5,24 @@ on: branches: [ main, develop ] jobs: - lint: - name: Lint - uses: ./.github/workflows/lint.yml + structure_format_tidy: + name: Structure, format, and tidy + uses: ./.github/workflows/structure-format-tidy.yml linux: name: Linux + needs: structure_format_tidy uses: ./.github/workflows/build-linux.yml secrets: inherit macos: name: macOS + needs: structure_format_tidy uses: ./.github/workflows/build-macos.yml secrets: inherit windows: name: Windows + needs: structure_format_tidy uses: ./.github/workflows/build-windows.yml secrets: inherit diff --git a/.github/workflows/lint.yml b/.github/workflows/structure-format-tidy.yml similarity index 95% rename from .github/workflows/lint.yml rename to .github/workflows/structure-format-tidy.yml index 82a8b18..4db0fd7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/structure-format-tidy.yml @@ -1,10 +1,10 @@ -name: Lint +name: Structure, format, and tidy on: workflow_call: jobs: - lint: + structure-format-tidy: name: Structure, format, and clang-tidy runs-on: ubuntu-latest timeout-minutes: 30 diff --git a/.gitignore b/.gitignore index 9f547e4..4cee9cb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ build/ build-release/ build-debug/ +build-tidy/ build-homebrew-gcc16-release/ build-homebrew-gcc16-debug/ build-homebrew-clang-release/ diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 643fff1..68d9c6e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -229,6 +229,17 @@ "command": "& \"${workspaceFolder}/.vscode/scripts/run-ctest.ps1\" -BuildType Debug" } }, + { + "label": "structure-format-tidy", + "type": "shell", + "command": "bash \"${workspaceFolder}/tools/structure_format_tidy.sh\"", + "problemMatcher": [], + "group": "test", + "presentation": { + "reveal": "always", + "panel": "dedicated" + } + }, { "label": "ctest-release", "type": "shell", diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d613089..f082c5a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -81,7 +81,7 @@ Prefix with `fix:`, `refactor:`, or `chore:` when it helps clarify intent, but i - C++20 standard - No comments unless the "why" is non-obvious - Keep changes minimal — don't refactor unrelated code in the same PR -- File names, layers, and entry points follow [the source layout](docs/building.md#source-layout). `tools/check_structure.py` checks them locally, and CI runs that script with `clang-format` and `clang-tidy` +- File names, layers, and entry points follow [the source layout](docs/building.md#source-layout). Run `tools/structure_format_tidy.sh` before opening a pull request. It runs the structure check, `clang-format`, and `clang-tidy` that CI runs. The Windows, macOS, and Linux builds start only after that job passes ## Bumping the bundled command-line tools diff --git a/src/platform/paths.cpp b/src/platform/paths.cpp index 8b4b9ec..c369ecc 100644 --- a/src/platform/paths.cpp +++ b/src/platform/paths.cpp @@ -12,8 +12,11 @@ #include #include #elif __linux__ -#include +#include #include +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif #endif #include "platform/env.h" diff --git a/tools/structure_format_tidy.sh b/tools/structure_format_tidy.sh new file mode 100755 index 0000000..ae883ac --- /dev/null +++ b/tools/structure_format_tidy.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env bash +# The same structure, format, and clang-tidy check as .github/workflows/structure-format-tidy.yml. +# Usage: tools/structure_format_tidy.sh [build-directory] + +set -euo pipefail + +root="$(cd "$(dirname "$0")/.." && pwd)" +cd "${root}" + +export PATH="/opt/homebrew/opt/llvm/bin:/usr/local/opt/llvm/bin:${PATH}" + +if ! command -v clang-format >/dev/null 2>&1; then + echo "error: clang-format was not found. CI uses clang-format 23.1.5." >&2 + exit 1 +fi +if ! command -v clang-tidy >/dev/null 2>&1; then + echo "error: clang-tidy was not found. CI uses clang-tidy 23.1.4." >&2 + exit 1 +fi + +echo "Checking source structure..." +python3 tools/check_structure.py + +echo "Checking format..." +git ls-files 'src/*.cpp' 'src/*.h' 'tests/*.cpp' 'tests/*.h' | xargs clang-format --dry-run --Werror +echo "Format is clean." + +build_dir="${1:-build-tidy}" +echo "Configuring ${build_dir} for clang-tidy..." +cmake -S "${root}" -B "${build_dir}" -G Ninja \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCOREDECK_BUILD_TESTS=ON \ + -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON + +if [[ "$(uname -s)" == "Darwin" ]]; then + jobs="$(sysctl -n hw.ncpu)" +else + jobs="$(nproc)" +fi + +file_list="$(mktemp)" +trap 'rm -f "${file_list}"' EXIT +python3 - "${root}" "${build_dir}/compile_commands.json" "${file_list}" <<'PY' +import json +import sys + +root, commands_path, out_path = sys.argv[1:] +commands = json.load(open(commands_path, encoding="utf-8")) +prefix = root + "/src/" +with open(out_path, "w", encoding="utf-8") as out: + for entry in commands: + path = entry["file"] + if path.startswith(prefix) and path.endswith(".cpp"): + print(path, file=out) +PY +file_count="$(wc -l < "${file_list}" | tr -d ' ')" +echo "Running clang-tidy on ${file_count} files..." +xargs -P "${jobs}" -n 1 clang-tidy -p "${build_dir}" --quiet --checks=-misc-include-cleaner --warnings-as-errors='*' < "${file_list}" +echo "clang-tidy is clean."