Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
7 changes: 2 additions & 5 deletions .devcontainer/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ RUN update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-

RUN cd /opt/ci && bash setup_ci_environment.sh
RUN cd /opt/ci && bash install_iwyu.sh

ADD https://github.com/bazelbuild/bazelisk/releases/download/v1.22.1/bazelisk-linux-amd64 /usr/local/bin

RUN git config --global core.autocrlf input \
&& chmod +x /usr/local/bin/bazelisk-linux-amd64
RUN cd /opt/ci && bash install_bazelisk.sh
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since install_bazelisk.sh accepts a version argument, should we pass v1.22.1 here to preserve the previous devcontainer Bazelisk version? Otherwise this looks like a downgrade.

Copy link
Copy Markdown
Member Author

@dbarker dbarker Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. My intent is to try to bring the dev environment closer to the ci environment with this change. All the ci workflows currently use the default version of the script. How about a separate PR for the upgrade?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Script ./ci/install_bazelisk.sh does not take a version as argument, it hard code version v1.16.0.

But I can not find where install_bazelisk.sh is used from today.

RUN git config --global core.autocrlf input

ENV INSTALL_PACKAGES=${INSTALL_PACKAGES}
ENV USER_NAME=devuser
Expand Down
2 changes: 0 additions & 2 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ third_party/ - External dependencies
cmake.test # Standard CMake build with exporters (~5.2 min)
cmake.maintainer.sync.test # Maintainer mode: -Wall -Werror -Wextra (~4-6 min)
cmake.maintainer.async.test # Maintainer mode with async export enabled
cmake.maintainer.cpp11.async.test # Maintainer mode with C++11
cmake.maintainer.abiv2.test # Maintainer mode with ABI v2
cmake.legacy.test # GCC 4.8 compatibility testing
cmake.c++20.test # C++20 standard testing
bazel.test # Standard Bazel build and test
format # Run formatting tools
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ jobs:
- name: install dependencies
run: |
sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file ./install/cmake/third_party_stable --packages "googletest;benchmark"
- name: run tests
env:
CXX_STANDARD: '14'
run: ./ci/do_ci.sh cmake.c++14.test
- name: run tests (enable stl)
env:
CXX_STANDARD: '14'
Expand All @@ -459,6 +463,10 @@ jobs:
- name: setup
run: |
sudo -E ./ci/setup_ci_environment.sh
- name: run tests
env:
CXX_STANDARD: '17'
run: ./ci/do_ci.sh cmake.c++17.test
- name: run tests (enable stl)
env:
CXX_STANDARD: '17'
Expand Down
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ if(WITH_OPENTRACING)
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/opentracing-cpp.cmake")
endif()

include(CTest)
if(BUILD_TESTING)
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/googletest.cmake")
enable_testing()
if(WITH_BENCHMARK)
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/benchmark.cmake")
endif()
endif()

if(OTELCPP_MAINTAINER_MODE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(STATUS "Building with gcc in maintainer mode.")
Expand Down Expand Up @@ -453,15 +462,6 @@ endif(OTELCPP_MAINTAINER_MODE)

list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")

include(CTest)
if(BUILD_TESTING)
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/googletest.cmake")
enable_testing()
if(WITH_BENCHMARK)
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/benchmark.cmake")
endif()
endif()

# Record build config and versions
message(STATUS "---------------------------------------------")
message(STATUS "build settings")
Expand Down
161 changes: 129 additions & 32 deletions ci/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,129 @@
# Building and running tests as a developer

CI tests can be run on docker by invoking the script `./ci/run_docker.sh
./ci/do_ci.sh {TARGET}`or inside
[devcontainer](../CONTRIBUTING.md#devcontainer-setup-for-project)
by invoking the script
`./ci/do_ci.sh {TARGET}` where the targets are:

* `cmake.test`: build cmake targets and run tests.
* `cmake.maintainer.test`: build with cmake and test, in maintainer mode.
* `cmake.legacy.test`: build cmake targets with gcc 4.8 and run tests.
* `cmake.c++20.test`: build cmake targets with the C++20 standard and run tests.
* `cmake.test_example_plugin`: build and test an example OpenTelemetry plugin.
* `cmake.exporter.otprotocol.test`: build and test the otprotocol exporter
* `bazel.test`: build bazel targets and run tests.
* `bazel.legacy.test`: build bazel targets and run tests for the targets meant
to work with older compilers.
* `bazel.noexcept`: build bazel targets and run tests with exceptions disabled.
* `bazel.nortti`: build bazel targets and run tests with runtime type
identification disabled.
* `bazel.asan`: build bazel targets and run tests with AddressSanitizer.
* `bazel.tsan`: build bazel targets and run tests with ThreadSanitizer.
* `bazel.valgrind`: build bazel targets and run tests under the valgrind memory
checker.
* `benchmark`: run all benchmarks.
* `format`: use `tools/format.sh` to enforce text formatting.
* `third_party.tags`: store third_party release tags.
* `code.coverage`: build cmake targets with CXX option `--coverage` and run
tests.

Additionally, `./ci/run_docker.sh` can be invoked with no arguments to get a
docker shell where tests can be run manually.
# CI Scripts

`./ci/do_ci.sh` is the main build, test, and validation script used by CI
and local development.

## Usage

Run targets directly inside the
[devcontainer](../CONTRIBUTING.md#devcontainer-setup-for-project):

```sh
./ci/do_ci.sh <target>
```

Run targets in Docker:

```sh
./ci/run_docker.sh ./ci/do_ci.sh <target>
```

You can also run `./ci/run_docker.sh` with no arguments to open an interactive
Docker shell and invoke targets manually.

## Examples

### Format Checks

```sh
./ci/do_ci.sh format
markdownlint .
shellcheck --severity=error <path to shell script>.sh
```

### Testing

```sh
./ci/do_ci.sh cmake.maintainer.sync.test
./ci/do_ci.sh cmake.c++20.stl.test
./ci/run_docker.sh ./ci/do_ci.sh bazel.test
```

## Build configuration

The script accepts several environment variables to configure the build:

```sh
BUILD_DIR=$HOME/build
BUILD_TYPE=Debug|Release|RelWithDebInfo|MinSizeRel
CXX_STANDARD=14|17|20|23
BUILD_SHARED_LIBS=ON|OFF
OTELCPP_CMAKE_VERBOSE_BUILD=ON|OFF
OTELCPP_CMAKE_CACHE_FILE=<cache-file-name>
```

`OTELCPP_CMAKE_CACHE_FILE` should be the basename of a cache file from
`test_common/cmake`, for example `all-options-abiv1-preview.cmake` or
`all-options-abiv2.cmake`.

## Targets

### Formatting and coverage

* `format`: Run formatting tools (`clang-format`, `cmake-format`,
`buildifier`) and fail if files change.
* `code.coverage`: Build with coverage flags and generate `coverage.info`.
* `cmake.clang_tidy.test`: Build with `clang-tidy` enabled and emit a build
log.

### Maintainer CMake builds

These targets use the `all-options-*` cache files in `test_common/cmake` and
build all CMake components with preview options enabled.

* `cmake.maintainer.sync.test`: Maintainer mode ABI v1 build with synchronous
export and tests.
* `cmake.maintainer.async.test`: Maintainer mode ABI v1 build with async export
and tests.
* `cmake.maintainer.abiv2.test`: Maintainer mode ABI v2 build and tests.
* `cmake.maintainer.yaml.test`: Maintainer mode build with YAML configuration.

### CMake language-standard matrix

These tests build the core API and SDK components in maintainer mode.

* `cmake.c++14.test`: C++14, WITH_STL=OFF
* `cmake.c++17.test`: C++17, WITH_STL=OFF
* `cmake.c++20.test`: C++20, WITH_STL=OFF
* `cmake.c++23.test`: C++23, WITH_STL=OFF
* `cmake.c++14.stl.test`: C++14, WITH_STL=CXX14
* `cmake.c++17.stl.test`: C++17, WITH_STL=CXX17
* `cmake.c++20.stl.test`: C++20, WITH_STL=CXX20
* `cmake.c++23.stl.test`: C++23, WITH_STL=CXX23

### CMake feature and packaging tests

* `cmake.with_async_export.test`: Standard CMake build with async export
enabled.
* `cmake.opentracing_shim.test`: OpenTracing shim build and tests.
* `cmake.opentracing_shim.install.test`: OpenTracing shim install validation
test.
* `cmake.exporter.otprotocol.test`: OTLP exporter build and tests.
* `cmake.exporter.otprotocol.shared_libs.with_static_grpc.test`: OTLP exporter
test with shared libraries enabled.
* `cmake.exporter.otprotocol.with_async_export.test`: OTLP exporter test with
async export enabled.
* `cmake.w3c.trace-context.build-server`: Build the W3C trace-context test
server.
* `cmake.do_not_install.test`: Build and test with installation disabled.
* `cmake.install.test`: Install-tree validation and downstream CMake package
test.
* `cmake.fetch_content.test`: Validate building the project via
`FetchContent`.
* `cmake.test_example_plugin`: Build and load-test the example plugin.

### Bazel targets

* `bazel.test`: Build and test all Bazel targets.
* `bazel.with_async_export.test`: Build and test with async export enabled.
* `bazel.macos.test`: Build and test using the macOS Bazel configuration.
* `bazel.legacy.test`: Bazel legacy compatibility test subset.
* `bazel.noexcept`: Build and test with exceptions disabled where supported.
* `bazel.nortti`: Build and test with RTTI disabled where supported.
* `bazel.asan`: Run Bazel tests with AddressSanitizer.
* `bazel.tsan`: Run Bazel tests with ThreadSanitizer.
* `bazel.valgrind`: Run Bazel tests under Valgrind.

### Benchmarks

* `benchmark`: Build benchmark binaries and collect result artifacts.
Loading
Loading