From 095a29a4a05b193a9900d36f338ba2abb4b90a91 Mon Sep 17 00:00:00 2001 From: Dan Crosby Date: Fri, 26 Jun 2026 07:28:26 -0700 Subject: [PATCH] Centralize Shardok C++ standard settings (#8197) --- .bazelrc | 1 + scripts/check_shardok_clang_tidy.sh | 3 ++- scripts/run-clang-tidy.sh | 3 ++- scripts/shardok_cpp_config.sh | 5 +++++ tools/copts.bzl | 12 +++++++++++- 5 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 scripts/shardok_cpp_config.sh diff --git a/.bazelrc b/.bazelrc index ce416fa8a5..7aecde2e7f 100644 --- a/.bazelrc +++ b/.bazelrc @@ -14,6 +14,7 @@ common --worker_sandboxing common --local_test_jobs=64 common --jobs=64 +# Keep these C++ standard flags in sync with tools/copts.bzl and scripts/shardok_cpp_config.sh. common --cxxopt="--std=c++23" common --cxxopt="-Wno-deprecated-non-prototype" common --per_file_copt=src/test/cpp/.*@-Wno-character-conversion diff --git a/scripts/check_shardok_clang_tidy.sh b/scripts/check_shardok_clang_tidy.sh index b61069495b..60bfb55682 100755 --- a/scripts/check_shardok_clang_tidy.sh +++ b/scripts/check_shardok_clang_tidy.sh @@ -7,6 +7,7 @@ set -euo pipefail repo_root="$(git rev-parse --show-toplevel)" +source "$repo_root/scripts/shardok_cpp_config.sh" files=( "src/main/cpp/net/eagle0/shardok/library/ActionCost.hpp" @@ -15,7 +16,7 @@ files=( compiler_args=( "-I$repo_root" - "-std=c++23" + "$SHARDOK_CXX_STANDARD_ARG" ) if command -v xcrun >/dev/null 2>&1; then diff --git a/scripts/run-clang-tidy.sh b/scripts/run-clang-tidy.sh index fb1bbab509..932cd1131a 100755 --- a/scripts/run-clang-tidy.sh +++ b/scripts/run-clang-tidy.sh @@ -10,13 +10,14 @@ set -e export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH" repo_root="$(git rev-parse --show-toplevel)" +source "$repo_root/scripts/shardok_cpp_config.sh" if [ "$#" -eq 0 ]; then echo "Usage: scripts/run-clang-tidy.sh [clang-tidy args] [-- ]" echo "" echo "Examples:" echo " scripts/run-clang-tidy.sh --verify-config" - echo " scripts/run-clang-tidy.sh src/main/cpp/net/eagle0/shardok/library/CombatDamage.hpp -- -I$repo_root -std=c++23" + echo " scripts/run-clang-tidy.sh src/main/cpp/net/eagle0/shardok/library/CombatDamage.hpp -- -I$repo_root $SHARDOK_CXX_STANDARD_ARG" exit 2 fi diff --git a/scripts/shardok_cpp_config.sh b/scripts/shardok_cpp_config.sh new file mode 100644 index 0000000000..2e589a7df9 --- /dev/null +++ b/scripts/shardok_cpp_config.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# Shared C++ settings for shell scripts that invoke Shardok tooling outside Bazel. + +SHARDOK_CXX_STANDARD="c++23" +SHARDOK_CXX_STANDARD_ARG="-std=${SHARDOK_CXX_STANDARD}" diff --git a/tools/copts.bzl b/tools/copts.bzl index 633183fd1a..46826d7435 100644 --- a/tools/copts.bzl +++ b/tools/copts.bzl @@ -1,4 +1,14 @@ # Suppress -Wdeprecated-copy-with-dtor after -Wdeprecated due to protobuf 32.x warning -COPTS = ["--std=c++23", "-Werror", "-Wall", "-Wextra", "-Wdeprecated", "-Wno-deprecated-copy-with-dtor"] +CXX_STANDARD = "c++23" +CXX_STANDARD_COPT = "--std=" + CXX_STANDARD + +COPTS = [ + CXX_STANDARD_COPT, + "-Werror", + "-Wall", + "-Wextra", + "-Wdeprecated", + "-Wno-deprecated-copy-with-dtor", +] TEST_COPTS = COPTS + ["-Iexternal/gtest/include"]