Skip to content
Open
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: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,31 @@ jobs:
CXX_STANDARD: '23'
run: ./ci/do_ci.sh cmake.c++23.stl.test

cmake_test_different_std_for_protobuf_and_otel_gcc:
name: CMake C++23 test with protobuf built with C++17 (GCC)
runs-on: ubuntu-latest
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
with:
egress-policy: audit

- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
submodules: 'recursive'
- name: setup
run: |
sudo -E ./ci/setup_ci_environment.sh
- name: install dependencies
env:
CXX_STANDARD: '17'
run: |
sudo -E ./ci/install_thirdparty.sh --install-dir /usr/local --tags-file install/cmake/third_party_latest --build-shared-libs "ON" --packages "zlib;abseil;protobuf;nlohmann-json;curl;grpc;googletest;benchmark"
- name: run tests
env:
CXX_STANDARD: '23'
run: ./ci/do_ci.sh cmake.different_std.test

cmake_otprotocol_test:
name: CMake test (with otlp-exporter)
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -1044,6 +1069,32 @@ jobs:
- name: run otprotocol test
run: ./ci/do_ci.ps1 cmake.exporter.otprotocol.with_async_export.test

# TODO: Test case where protobuf is built with C++17 and OpenTelemetry with C++20 on MSVC will trigger a Internal compiler error
# We can enable this test case when MSVC on github runner is upgraded.
# Logs can be found at https://github.com/open-telemetry/opentelemetry-cpp/actions/runs/20818142168/job/59799024061
# cmake_test_different_std_for_protobuf_and_otel_msvc:
# name: CMake C++20 test with protobuf built with C++17 (MSVC)
# runs-on: windows-2022
# steps:
# - name: Harden the runner (Audit all outbound calls)
# uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
# with:
# egress-policy: audit
#
# - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
# with:
# submodules: 'recursive'
# - name: setup
# run: |
# ./ci/setup_windows_ci_environment.ps1
# - name: install dependencies
# env:
# CXX_STANDARD: '17'
# run: |
# pwsh -File ./ci/install_thirdparty.ps1 --install-dir "$HOME/otel-third_party" --tags-file install/cmake/third_party_latest --build-type Debug --build-shared-libs "ON" --packages "zlib;abseil;protobuf;nlohmann-json;curl;grpc;googletest;benchmark"
# - name: run cmake test
# run: ./ci/do_ci.ps1 cmake.different_std.test

windows_bazel:
name: Bazel Windows
runs-on: windows-2022
Expand Down
29 changes: 29 additions & 0 deletions ci/do_ci.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,35 @@ switch ($action) {
exit $exit
}
}
"cmake.different_std.test" {
cd "$BUILD_DIR"
cmake $SRC_DIR `
"-DCMAKE_PREFIX_PATH=$HOME/otel-third_party" `
"-DCMAKE_FIND_ROOT_PATH=$HOME/otel-third_party" `
-DCMAKE_BUILD_TYPE=Debug `
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON `
-DWITH_ASYNC_EXPORT_PREVIEW=ON `
-DWITH_STL=CXX23 `
-DCMAKE_CXX_STANDARD=23 `
-DCMAKE_CXX_STANDARD_REQUIRED=ON `
-DWITH_OTLP_GRPC=ON `
-DWITH_OTLP_HTTP=ON `
-DWITH_OTLP_FILE=ON
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
cmake --build . -j $nproc --config Debug
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
ctest -C Debug
$exit = $LASTEXITCODE
if ($exit -ne 0) {
exit $exit
}
}
"cmake.build_example_plugin" {
cd "$BUILD_DIR"
cmake $SRC_DIR `
Expand Down
16 changes: 16 additions & 0 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,22 @@ elif [[ "$1" == "cmake.c++23.stl.test" ]]; then
eval "$MAKE_COMMAND"
make test
exit 0
elif [[ "$1" == "cmake.different_std.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
cmake "${CMAKE_OPTIONS[@]}" \
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
-DBUILD_SHARED_LIBS=ON \
-DWITH_STL=CXX23 \
-DWITH_OTLP_GRPC=ON \
-DWITH_OTLP_HTTP=ON \
-DWITH_OTLP_FILE=ON \
"${SRC_DIR}"
eval "$MAKE_COMMAND"
make test
exit 0
elif [[ "$1" == "cmake.legacy.test" ]]; then
cd "${BUILD_DIR}"
rm -rf *
Expand Down
220 changes: 220 additions & 0 deletions ci/install_thirdparty.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
<#
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

.SYNOPSIS
Install OpenTelemetry C++ third-party dependencies using CMake.

.DESCRIPTION
PowerShell counterpart to ci/install_thirdparty.sh.

This script configures and builds the CMake project in install/cmake to
install third-party packages into a provided prefix.

.PARAMETER --install-dir
Path where third-party packages will be installed (required).

.PARAMETER --tags-file
File containing tags for third-party packages (optional).

.PARAMETER --packages
Semicolon-separated list of packages to build (optional). Default installs all.

.EXAMPLE
./ci/install_thirdparty.ps1 --install-dir C:/third_party

.EXAMPLE
./ci/install_thirdparty.ps1 --install-dir C:/third_party --tags-file C:/tags.txt --packages "grpc;protobuf"
#>

Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

function Show-Usage {
$scriptName = Split-Path -Leaf $PSCommandPath
Write-Host ('Usage: {0} --install-dir <path> [--tags-file <file>] [--packages "<pkg1>;<pkg2>"]' -f $scriptName)
Write-Host " --install-dir <path> Path where third-party packages will be installed (required)"
Write-Host " --tags-file <file> File containing tags for third-party packages (optional)"
Write-Host ' --packages "<pkg1>;<pkg2>;..." Semicolon-separated list of packages to build (optional). Default installs all third-party packages.'
Write-Host ' --build-type <build type> CMake build type (optional)'
Write-Host ' --build-shared-libs <ON|OFF> Build shared libraries (optional)'
Write-Host " -h, --help Show this help message"
}

function Invoke-External {
param(
[Parameter(Mandatory = $true)]
[string] $FilePath,

[Parameter(Mandatory = $false)]
[string[]] $Arguments = @()
)

& $FilePath @Arguments
$exitCode = $LASTEXITCODE
if ($exitCode -ne 0) {
throw "Command failed (exit $exitCode): $FilePath $($Arguments -join ' ')"
}
}

$ThirdpartyTagsFile = ''
$ThirdpartyPackages = ''
$ThirdpartyInstallDir = ''
$CmakeBuildType = ''
$CmakeBuildSharedLibs = ''

# Match install_thirdparty.sh behavior: parse GNU-style args from $args.
for ($i = 0; $i -lt $args.Count; ) {
$a = [string]$args[$i]

switch ($a) {
'--install-dir' {
if (($i + 1) -ge $args.Count -or ([string]$args[$i + 1]).StartsWith('--')) {
[Console]::Error.WriteLine('Error: --install-dir requires a value')
Show-Usage
exit 1
}
$ThirdpartyInstallDir = [string]$args[$i + 1]
$i += 2
continue
}
'--tags-file' {
if (($i + 1) -ge $args.Count -or ([string]$args[$i + 1]).StartsWith('--')) {
[Console]::Error.WriteLine('Error: --tags-file requires a value')
Show-Usage
exit 1
}
$ThirdpartyTagsFile = [string]$args[$i + 1]
$i += 2
continue
}
'--packages' {
if (($i + 1) -ge $args.Count -or ([string]$args[$i + 1]).StartsWith('--')) {
[Console]::Error.WriteLine('Error: --packages requires a value')
Show-Usage
exit 1
}
$ThirdpartyPackages = [string]$args[$i + 1]
$i += 2
continue
}
'--build-type' {
if (($i + 1) -ge $args.Count -or ([string]$args[$i + 1]).StartsWith('--')) {
[Console]::Error.WriteLine('Error: --build-type requires a value')
Show-Usage
exit 1
}
$CmakeBuildType = [string]$args[$i + 1]
$i += 2
continue
}
'--build-shared-libs' {
if (($i + 1) -ge $args.Count -or ([string]$args[$i + 1]).StartsWith('--')) {
[Console]::Error.WriteLine('Error: --build-shared-libs requires a value')
Show-Usage
exit 1
}
$CmakeBuildSharedLibs = [string]$args[$i + 1]
$i += 2
continue
}
'-h' { Show-Usage; exit 0 }
'--help' { Show-Usage; exit 0 }
default {
[Console]::Error.WriteLine(("Unknown option: {0}" -f $a))
Show-Usage
exit 1
}
}
}

if ([string]::IsNullOrWhiteSpace($ThirdpartyInstallDir)) {
[Console]::Error.WriteLine('Error: --install-dir is a required argument.')
Show-Usage
exit 1
}

$SrcDir = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Definition)

$CxxStandard = $env:CXX_STANDARD
if ([string]::IsNullOrWhiteSpace($CxxStandard)) {
$CxxStandard = '17'
}

$TempRoot = $env:TEMP
if ([string]::IsNullOrWhiteSpace($TempRoot)) {
# Fallback if TEMP isn't set.
$TempRoot = [System.IO.Path]::GetTempPath()
}

$ThirdpartyBuildDir = Join-Path $TempRoot 'otel-cpp-third-party-build'
if (Test-Path -LiteralPath $ThirdpartyBuildDir) {
Remove-Item -LiteralPath $ThirdpartyBuildDir -Recurse -Force
}

if (-not (Get-Command cmake -ErrorAction SilentlyContinue)) {
throw 'cmake was not found in PATH. Please install CMake and ensure it is available on PATH.'
}

$CmakeSourceDir = Join-Path $SrcDir 'install' 'cmake'
if (-not (Test-Path -LiteralPath $CmakeSourceDir)) {
throw "CMake source directory not found: $CmakeSourceDir"
}

$OtelcppProtoPath = $env:OTELCPP_PROTO_PATH
if ($null -eq $OtelcppProtoPath) {
$OtelcppProtoPath = ''
}

$CmakeConfigureArgs = @(
'-S', $CmakeSourceDir,
'-B', $ThirdpartyBuildDir,
"-DCMAKE_INSTALL_PREFIX=$ThirdpartyInstallDir",
"-DCMAKE_CXX_STANDARD=$CxxStandard",
"-DOTELCPP_THIRDPARTY_TAGS_FILE=$ThirdpartyTagsFile",
"-DOTELCPP_PROTO_PATH=$OtelcppProtoPath",
"-DOTELCPP_THIRDPARTY_INSTALL_LIST=$ThirdpartyPackages"
)

$parallel = [Math]::Max([Environment]::ProcessorCount, 1)

$CmakeBuildArgs = @(
'--build', $ThirdpartyBuildDir,
'--clean-first',
'--parallel', $parallel
)

if (-not [string]::IsNullOrWhiteSpace($CmakeBuildType)) {
$CmakeConfigureArgs += "-DCMAKE_BUILD_TYPE=$CmakeBuildType"
$CmakeBuildArgs += @('--config', $CmakeBuildType)
}

if (-not [string]::IsNullOrWhiteSpace($CmakeBuildSharedLibs)) {
$CmakeConfigureArgs += "-DBUILD_SHARED_LIBS=$CmakeBuildSharedLibs"
}

Invoke-External -FilePath 'cmake' -Arguments $CmakeConfigureArgs

# Use CMake's cross-generator parallel flag.
Invoke-External -FilePath 'cmake' -Arguments $CmakeBuildArgs

# Keep parity with the bash script (no-op on Windows).
if ($ThirdpartyInstallDir -eq '/usr/local') {
if (Get-Command ldconfig -ErrorAction SilentlyContinue) {
Invoke-External -FilePath 'ldconfig' -Arguments @()
}
}

Write-Host 'Third-party packages installed successfully.'
Write-Host "-- THIRDPARTY_INSTALL_DIR: $ThirdpartyInstallDir"
Write-Host "-- THIRDPARTY_TAGS_FILE: $ThirdpartyTagsFile"
if ([string]::IsNullOrWhiteSpace($ThirdpartyPackages)) {
Write-Host '-- THIRDPARTY_PACKAGES: all'
}
else {
Write-Host "-- THIRDPARTY_PACKAGES: $ThirdpartyPackages"
}
Write-Host "-- CXX_STANDARD: $CxxStandard"
if (-not [string]::IsNullOrWhiteSpace($CmakeBuildType)) {
Write-Host "-- CMAKE_BUILD_TYPE: $CmakeBuildType"
}
Loading
Loading