Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 45 additions & 6 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,19 +1,58 @@
# AddressSanitizer: bazel test //phaser/... --config=asan
# Do not pass -fsanitize to host/exec tools (protoc, plugins); that breaks codegen.
# On Apple Silicon, also pass --config=apple_silicon (it adds -arch arm64, which
# is macOS-only and must not be applied on Linux).
build:asan --strip=never
build:asan --copt -fsanitize=address
build:asan --copt -DADDRESS_SANITIZER
build:asan --copt -g
build:asan --copt -fno-omit-frame-pointer
build:asan --linkopt -fsanitize=address
build:asan -c dbg
build:asan --copt=-fsanitize=address
build:asan --copt=-fno-omit-frame-pointer
build:asan --linkopt=-fsanitize=address

test:asan --test_output=errors
test:asan --test_env=ASAN_OPTIONS=abort_on_error=1:symbolize=1:fast_unwind_on_malloc=0

# Valgrind (memcheck): bazel test //phaser/... --config=valgrind
# Build with debug symbols (and no optimization) so valgrind reports useful
# stack traces. Do not combine with --config=asan; the two are incompatible.
build:valgrind --strip=never
build:valgrind -c dbg
build:valgrind --copt=-g
build:valgrind --copt=-fno-omit-frame-pointer

test:valgrind --test_output=errors
# Valgrind is slow; give tests plenty of time.
test:valgrind --test_timeout=900
# Only fail on definite leaks: protobuf/abseil keep global state that valgrind
# reports as "possibly lost"/"still reachable", which are benign false positives.
# The suppressions file silences protobuf resize-uninitialized reads surfaced
# via debug Hexdump calls.
test:valgrind --run_under='valgrind --leak-check=full --show-leak-kinds=definite --errors-for-leak-kinds=definite --error-exitcode=1 --num-callers=30 --suppressions=phaser/valgrind.supp'

build --enable_platform_specific_config

# For all builds, use C++17
build --cxxopt="-std=c++17"
build --cxxopt='-Wno-sign-compare'
build --host_cxxopt="-std=c++17"

# For Apple Silicon
# For Apple Silicon (required when Bazel itself is x86_64 under Rosetta).
build:apple_silicon --cpu=darwin_arm64 --host_cpu=darwin_arm64 --host_cxxopt="-std=c++17"
build:apple_silicon --copt=-arch
build:apple_silicon --copt=arm64
build:apple_silicon --linkopt=-arch
build:apple_silicon --linkopt=arm64
build:apple_silicon --host_copt=-arch
build:apple_silicon --host_copt=arm64
build:apple_silicon --host_linkopt=-arch
build:apple_silicon --host_linkopt=arm64
build:apple_silicon --features=oso_prefix_is_pwd

# std::filesystem requires macOS 10.15+
build:macos --cxxopt=-mmacosx-version-min=10.15
build:macos --linkopt=-mmacosx-version-min=10.15
build:macos --host_cxxopt=-mmacosx-version-min=10.15
build:macos --host_linkopt=-mmacosx-version-min=10.15

# Common flags for Clang
build:clang --action_env=BAZEL_COMPILER=clang
build:clang --action_env=CC=clang --action_env=CXX=clang++
Expand Down
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9.1.0
112 changes: 112 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: CI

on:
push:
branches: [main, master]
pull_request:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
# Build and run every test target except perf_test.
test:
name: test (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Cache Bazel
uses: actions/cache@v4
with:
path: ~/.cache/bazel-disk
key: bazel-disk-test-${{ matrix.os }}-${{ hashFiles('MODULE.bazel', 'MODULE.bazel.lock', '.bazelrc', '.bazelversion') }}
restore-keys: |
bazel-disk-test-${{ matrix.os }}-

# Apple Silicon runners need the apple_silicon config (adds -arch arm64),
# which must not be applied on Linux.
- name: Select macOS config
if: runner.os == 'macOS'
run: echo "EXTRA_CONFIG=--config=apple_silicon" >> "$GITHUB_ENV"

- name: Test (everything except perf_test)
run: |
bazel test --disk_cache="$HOME/.cache/bazel-disk" $EXTRA_CONFIG \
-- //... -//phaser:perf_test

# AddressSanitizer runs on macOS (Apple Silicon).
asan:
name: asan (macOS)
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

- name: Cache Bazel
uses: actions/cache@v4
with:
path: ~/.cache/bazel-disk
key: bazel-disk-asan-macos-${{ hashFiles('MODULE.bazel', 'MODULE.bazel.lock', '.bazelrc', '.bazelversion') }}
restore-keys: |
bazel-disk-asan-macos-

- name: Test with ASan (everything except perf_test)
run: |
bazel test --disk_cache="$HOME/.cache/bazel-disk" \
--config=asan --config=apple_silicon \
-- //... -//phaser:perf_test

# AddressSanitizer runs on Linux (no apple_silicon config).
asan-linux:
name: asan (Linux)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Cache Bazel
uses: actions/cache@v4
with:
path: ~/.cache/bazel-disk
key: bazel-disk-asan-linux-${{ hashFiles('MODULE.bazel', 'MODULE.bazel.lock', '.bazelrc', '.bazelversion') }}
restore-keys: |
bazel-disk-asan-linux-

- name: Test with ASan (everything except perf_test)
run: |
bazel test --disk_cache="$HOME/.cache/bazel-disk" \
--config=asan \
-- //... -//phaser:perf_test

# Valgrind (memcheck) runs on Linux only.
valgrind:
name: valgrind (Linux)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install valgrind
run: |
sudo apt-get update
sudo apt-get install -y valgrind

- name: Cache Bazel
uses: actions/cache@v4
with:
path: ~/.cache/bazel-disk
key: bazel-disk-valgrind-linux-${{ hashFiles('MODULE.bazel', 'MODULE.bazel.lock', '.bazelrc', '.bazelversion') }}
restore-keys: |
bazel-disk-valgrind-linux-

- name: Test under Valgrind (everything except perf_test)
run: |
bazel test --disk_cache="$HOME/.cache/bazel-disk" --config=valgrind \
-- //... -//phaser:perf_test
60 changes: 24 additions & 36 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,47 +1,35 @@
module(
name = "phaser",
version = "1.1.0"
)

http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "platforms", version = "1.1.0")
bazel_dep(name = "abseil-cpp", version = "20250814.1", repo_name = "com_google_absl")
bazel_dep(name = "googletest", version = "1.17.0.bcr.2", repo_name = "com_google_googletest")

bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "abseil-cpp", version = "20230802.0", repo_name = "com_google_absl")
bazel_dep(name = "googletest", version = "1.14.0", repo_name = "com_google_googletest")
# Aliased as "com_google_protobuf" to match implicit dependency within bazel_tools.
# See https://github.com/bazelbuild/bazel/issues/19973
bazel_dep(name = "protobuf", version = "34.1", repo_name = "com_google_protobuf")

# Note, see https://github.com/bazelbuild/bazel/issues/19973
# Protobuf must be aliased as "com_google_protobuf" to match implicit dependency within bazel_tools.
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_cc", version = "0.2.17")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "zlib", version = "1.3.1.bcr.5")

bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_pkg", version = "0.9.1")
bazel_dep(name = "zlib", version = "1.3.1.bcr.3")
bazel_dep(name = "cpp_toolbelt", version = "2.1.2")
bazel_dep(name = "coroutines", version = "3.3.2")

http_archive(
name = "toolbelt",
integrity = "sha256-RwYojmkQeMEBe/jDW1BR9BTdGa0CVcxne46X9Qdxvh0=",
strip_prefix = "cpp_toolbelt-1.2.9",
urls = ["https://github.com/dallison/cpp_toolbelt/archive/refs/tags/1.2.9.tar.gz"],
# protobuf pulls an older rules_go via gazelle; Bazel 9 needs a current rules_go.
single_version_override(
module_name = "rules_go",
version = "0.61.0",
)

# For local debugging of toolbelt coroutine library.
# local_repository(
# name = "toolbelt",
# path = "../cpp_toolbelt",
# )

# Coroutines
http_archive(
name = "coroutines",
integrity = "sha256-cJ3a89VebabjRgLjHNsEsjIQE+hi+5vdtuAh4RfTXCI=",
strip_prefix = "co-1.3.7",
urls = ["https://github.com/dallison/co/archive/refs/tags/1.3.7.tar.gz"],
# protobuf -> rules_jvm_external pulls rules_android 0.6.4, whose Android SDK
# toolchain still references the removed @local_config_platform repo. Bazel 9
# enables --incompatible_disable_native_repo_rules, so resolving that globally
# registered toolchain breaks every target (even C++). 0.7.2 is Bazel 9 ready.
single_version_override(
module_name = "rules_android",
version = "0.7.2",
)

# For local debugging of co coroutine library.
# local_repository(
# name = "coroutines",
# path = "../co",
# )

Loading
Loading