Skip to content

Commit

Permalink
switch build to conan 1.x
Browse files Browse the repository at this point in the history
The Conan 1.x package manager for C++ is a bit easier to work with than the
Bazel system. This allows us to more easily update dependencies, to keep them
in-sync with the atlas-system-agent project, which also uses Conan.

The Address Sanitizer has been disabled for MacOS as a part of this change,
because there were some issues with segfaults when running tests locally on
the Apple silicon platform. One line of thinking is that the Address Sanitizer
compiler flags are not propagating fully through the dependency tree, but we
also do not see this issue on Linux. Otherwise, the project builds and the
tests pass.

The Address Sanitizer remains engaged for the Linux builds triggered by the
Github Actions.
  • Loading branch information
copperlight committed Dec 7, 2023
1 parent 8d9ab60 commit d83036a
Show file tree
Hide file tree
Showing 23 changed files with 175 additions and 277 deletions.
1 change: 0 additions & 1 deletion .bazeliskrc

This file was deleted.

40 changes: 0 additions & 40 deletions .bazelrc

This file was deleted.

3 changes: 1 addition & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
Expand Down Expand Up @@ -86,4 +86,3 @@ Standard: Auto
TabWidth: 8
UseTab: Never
...

39 changes: 29 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,49 @@ jobs:
if: ${{ github.repository == 'Netflix/spectator-cpp' }}
runs-on: ubuntu-latest
env:
BUILD_DIR: "cmake-build"
CC: "gcc-11"
CXX: "g++-11"
LANG: "en_US.UTF-8"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Bazel Cache
- name: Conan+Cmake Cache
uses: actions/cache@v3
with:
path: ~/.cache/bazel
key: ${{ runner.os }}-bazel
path: |
~/.conan
~/work/spectatord/spectatord/cmake-build
key: ${{ runner.os }}-conan-cmake

- name: Install System Dependencies
run: |
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
sudo mv bazel.gpg /etc/apt/trusted.gpg.d/
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update && sudo apt-get install -y bazel-5.4.0 binutils-dev g++-11
sudo apt-get update && sudo apt-get install -y binutils-dev g++-11 libiberty-dev
echo "==== cmake ===="
cmake -version
echo "==== python ===="
python3 -V
echo "==== conan ===="
pip install "conan==1.61.0"
conan --version
if [[ ! -f ~/.conan/profiles/default ]]; then conan profile new default --detect; fi
conan profile update settings.compiler.libcxx=libstdc++11 default
- name: Install Project Dependencies
run: |
conan install . --build=missing --install-folder $BUILD_DIR
- name: Build spectator-cpp
run: |
bazel-5.4.0 --output_user_root=~/.cache/bazel --batch build --config asan spectator_test spectator
cd $BUILD_DIR
cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake --build .
- name: Test spectator-cpp
run: |
GTEST_COLOR=1 ./bazel-bin/spectator_test
cd $BUILD_DIR
GTEST_COLOR=1 ctest --verbose
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.clwb/
.DS_Store
.idea/
.vscode/
bazel-*
build-*
cmake-build-debug/
cmake-build/
venv/
51 changes: 0 additions & 51 deletions BUILD.bazel

This file was deleted.

50 changes: 50 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
cmake_minimum_required(VERSION 3.13)

project(spectator)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

if(APPLE)
# Address Sanitizer is finicky on MacOS Apple Silicon, so skip it
add_compile_options(-fno-omit-frame-pointer)
add_link_options(-fno-omit-frame-pointer)
else()
add_compile_options(-fno-omit-frame-pointer "$<$<CONFIG:Debug>:-fsanitize=address>")
add_link_options(-fno-omit-frame-pointer "$<$<CONFIG:Debug>:-fsanitize=address>")
endif()

include(CTest)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

#-- spectator_test test executable
file(GLOB spectator_test_source_files
"spectator/*_test.cc"
"spectator/test_*.cc"
"spectator/test_*.h"
)
add_executable(spectator_test ${spectator_test_source_files})
target_link_libraries(spectator_test spectator ${CONAN_LIBS})
add_test(
NAME spectator_test
COMMAND spectator_test
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

#-- spectator library
add_library(spectator
"spectator/logger.cc"
"spectator/publisher.cc"
"spectator/config.h"
"spectator/id.h"
"spectator/logger.h"
"spectator/measurement.h"
"spectator/meter_type.h"
"spectator/publisher.h"
"spectator/registry.h"
"spectator/stateful_meters.h"
"spectator/stateless_meters.h"
)
target_link_libraries(spectator ${CONAN_LIBS})
target_link_options(spectator PRIVATE "$<$<CONFIG:Release>:-static-libstdc++>")
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,15 @@ int main() {
By default, the library sends every meter change to the spectatord sidecar immediately. This involves a blocking `send` call and underlying system calls, and may not be the most efficient way to publish metrics in high-volume use cases.
For this purpose a simple buffering functionality in `Publisher` is implemented, and it can be turned on by passing a buffer size to the `spectator::Config` constructor. It is important to note that, until this buffer fills up, the `Publisher` will not send nay meters to the sidecar. Therefore, if your application doesn't emit meters at a high rate, you should either keep the buffer very small, or do not configure a buffer size at all, which will fall back to the "publish immediately" mode of operation.
## Local Development
```shell
./setup-venv.sh
source venv/bin/activate
./build.sh # [clean|skiptest]
```

* CLion > Preferences > Plugins > Marketplace > Conan > Install
* CLion > Preferences > Build, Execution, Deploy > Conan > Conan Executable: $PROJECT_HOME/venv/bin/conan
* CLion > Bottom Bar: Conan > Left Button: Match Profile > CMake Profile: Debug, Conan Profile: default
5 changes: 0 additions & 5 deletions WORKSPACE

This file was deleted.

Empty file removed bazel/BUILD
Empty file.
42 changes: 0 additions & 42 deletions bazel/abseil.patch

This file was deleted.

46 changes: 43 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@
#!/bin/bash
#!/usr/bin/env bash

bazel --output_user_root=$HOME/.cache/bazel --batch build --config asan spectator_test spectator
GTEST_COLOR=1 ./bazel-bin/spectator_test
BUILD_DIR=cmake-build
# Choose: Debug, Release, RelWithDebInfo and MinSizeRel
BUILD_TYPE=Debug

BLUE="\033[0;34m"
NC="\033[0m"

if [[ "$1" == "clean" ]]; then
echo -e "${BLUE}==== clean ====${NC}"
rm -rf $BUILD_DIR
fi

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
export CC=gcc-11
export CXX=g++-11
fi

if [[ ! -d $BUILD_DIR ]]; then
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo -e "${BLUE}==== configure default profile ====${NC}"
conan profile new default --detect
conan profile update settings.compiler.libcxx=libstdc++11 default
fi

echo -e "${BLUE}==== install required dependencies ====${NC}"
conan install . --build=missing --install-folder $BUILD_DIR
fi

pushd $BUILD_DIR || exit 1

echo -e "${BLUE}==== generate build files ====${NC}"
cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE || exit 1

echo -e "${BLUE}==== build ====${NC}"
cmake --build . || exit 1

if [[ "$1" != "skiptest" ]]; then
echo -e "${BLUE}==== test ====${NC}"
GTEST_COLOR=1 ctest --verbose
fi

popd || exit 1
16 changes: 16 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from conans import ConanFile


class SpectatorDConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
requires = (
"abseil/20230125.3",
"asio/1.28.1",
"backward-cpp/1.6",
"benchmark/1.8.3",
"fmt/10.1.1",
"gtest/1.14.0",
"spdlog/1.12.0"
)
generators = "cmake"
default_options = {}
Loading

0 comments on commit d83036a

Please sign in to comment.