Skip to content

Commit 6929949

Browse files
committed
Reproduce #3799
Fixes third_party_latest PATH install latest third party libs for windows Fixes copyright and parallel Fixes cmake args Restore windows version try to reproduce link error add --build-shared-libs "ON" Allow install_thirdparty to set BUILD_SHARED_LIBS Make the proto targets follow the CXX_STANDARD using by protobuf Fixes the compatibility for old version of protobuf with C++14 used Fixes DEFINED CMAKE_CXX_STANDARD checking Fixes compiling Fixes spelling Patch protobuf v31 only is enough Fixes cmake var Add TODO
1 parent cb5528d commit 6929949

File tree

8 files changed

+531
-52
lines changed

8 files changed

+531
-52
lines changed

.github/workflows/ci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,31 @@ jobs:
587587
CXX_STANDARD: '23'
588588
run: ./ci/do_ci.sh cmake.c++23.stl.test
589589

590+
cmake_test_different_std_for_protobuf_and_otel_gcc:
591+
name: CMake C++23 test with protobuf built with C++17 (GCC)
592+
runs-on: ubuntu-latest
593+
steps:
594+
- name: Harden the runner (Audit all outbound calls)
595+
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
596+
with:
597+
egress-policy: audit
598+
599+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
600+
with:
601+
submodules: 'recursive'
602+
- name: setup
603+
run: |
604+
sudo -E ./ci/setup_ci_environment.sh
605+
- name: install dependencies
606+
env:
607+
CXX_STANDARD: '17'
608+
run: |
609+
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"
610+
- name: run tests
611+
env:
612+
CXX_STANDARD: '23'
613+
run: ./ci/do_ci.sh cmake.different_std.test
614+
590615
cmake_otprotocol_test:
591616
name: CMake test (with otlp-exporter)
592617
runs-on: ubuntu-22.04
@@ -1044,6 +1069,32 @@ jobs:
10441069
- name: run otprotocol test
10451070
run: ./ci/do_ci.ps1 cmake.exporter.otprotocol.with_async_export.test
10461071

1072+
# TODO: Test case where protobuf is built with C++17 and OpenTelemetry with C++20 on MSVC will trigger a Internal compiler error
1073+
# We can enable this test case when MSVC on github runner is upgraded.
1074+
# Logs can be found at https://github.com/open-telemetry/opentelemetry-cpp/actions/runs/20818142168/job/59799024061
1075+
# cmake_test_different_std_for_protobuf_and_otel_msvc:
1076+
# name: CMake C++20 test with protobuf built with C++17 (MSVC)
1077+
# runs-on: windows-2022
1078+
# steps:
1079+
# - name: Harden the runner (Audit all outbound calls)
1080+
# uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
1081+
# with:
1082+
# egress-policy: audit
1083+
#
1084+
# - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
1085+
# with:
1086+
# submodules: 'recursive'
1087+
# - name: setup
1088+
# run: |
1089+
# ./ci/setup_windows_ci_environment.ps1
1090+
# - name: install dependencies
1091+
# env:
1092+
# CXX_STANDARD: '17'
1093+
# run: |
1094+
# 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"
1095+
# - name: run cmake test
1096+
# run: ./ci/do_ci.ps1 cmake.different_std.test
1097+
10471098
windows_bazel:
10481099
name: Bazel Windows
10491100
runs-on: windows-2022

ci/do_ci.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,35 @@ switch ($action) {
323323
exit $exit
324324
}
325325
}
326+
"cmake.different_std.test" {
327+
cd "$BUILD_DIR"
328+
cmake $SRC_DIR `
329+
"-DCMAKE_PREFIX_PATH=$HOME/otel-third_party" `
330+
"-DCMAKE_FIND_ROOT_PATH=$HOME/otel-third_party" `
331+
-DCMAKE_BUILD_TYPE=Debug `
332+
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON `
333+
-DWITH_ASYNC_EXPORT_PREVIEW=ON `
334+
-DWITH_STL=CXX23 `
335+
-DCMAKE_CXX_STANDARD=23 `
336+
-DCMAKE_CXX_STANDARD_REQUIRED=ON `
337+
-DWITH_OTLP_GRPC=ON `
338+
-DWITH_OTLP_HTTP=ON `
339+
-DWITH_OTLP_FILE=ON
340+
$exit = $LASTEXITCODE
341+
if ($exit -ne 0) {
342+
exit $exit
343+
}
344+
cmake --build . -j $nproc --config Debug
345+
$exit = $LASTEXITCODE
346+
if ($exit -ne 0) {
347+
exit $exit
348+
}
349+
ctest -C Debug
350+
$exit = $LASTEXITCODE
351+
if ($exit -ne 0) {
352+
exit $exit
353+
}
354+
}
326355
"cmake.build_example_plugin" {
327356
cd "$BUILD_DIR"
328357
cmake $SRC_DIR `

ci/do_ci.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,22 @@ elif [[ "$1" == "cmake.c++23.stl.test" ]]; then
335335
eval "$MAKE_COMMAND"
336336
make test
337337
exit 0
338+
elif [[ "$1" == "cmake.different_std.test" ]]; then
339+
cd "${BUILD_DIR}"
340+
rm -rf *
341+
cmake "${CMAKE_OPTIONS[@]}" \
342+
-DWITH_METRICS_EXEMPLAR_PREVIEW=ON \
343+
-DCMAKE_CXX_FLAGS="-Werror $CXXFLAGS" \
344+
-DWITH_ASYNC_EXPORT_PREVIEW=ON \
345+
-DBUILD_SHARED_LIBS=ON \
346+
-DWITH_STL=CXX23 \
347+
-DWITH_OTLP_GRPC=ON \
348+
-DWITH_OTLP_HTTP=ON \
349+
-DWITH_OTLP_FILE=ON \
350+
"${SRC_DIR}"
351+
eval "$MAKE_COMMAND"
352+
make test
353+
exit 0
338354
elif [[ "$1" == "cmake.legacy.test" ]]; then
339355
cd "${BUILD_DIR}"
340356
rm -rf *

ci/install_thirdparty.ps1

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
<#
2+
# Copyright The OpenTelemetry Authors
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
.SYNOPSIS
6+
Install OpenTelemetry C++ third-party dependencies using CMake.
7+
8+
.DESCRIPTION
9+
PowerShell counterpart to ci/install_thirdparty.sh.
10+
11+
This script configures and builds the CMake project in install/cmake to
12+
install third-party packages into a provided prefix.
13+
14+
.PARAMETER --install-dir
15+
Path where third-party packages will be installed (required).
16+
17+
.PARAMETER --tags-file
18+
File containing tags for third-party packages (optional).
19+
20+
.PARAMETER --packages
21+
Semicolon-separated list of packages to build (optional). Default installs all.
22+
23+
.EXAMPLE
24+
./ci/install_thirdparty.ps1 --install-dir C:/third_party
25+
26+
.EXAMPLE
27+
./ci/install_thirdparty.ps1 --install-dir C:/third_party --tags-file C:/tags.txt --packages "grpc;protobuf"
28+
#>
29+
30+
Set-StrictMode -Version Latest
31+
$ErrorActionPreference = 'Stop'
32+
33+
function Show-Usage {
34+
$scriptName = Split-Path -Leaf $PSCommandPath
35+
Write-Host ('Usage: {0} --install-dir <path> [--tags-file <file>] [--packages "<pkg1>;<pkg2>"]' -f $scriptName)
36+
Write-Host " --install-dir <path> Path where third-party packages will be installed (required)"
37+
Write-Host " --tags-file <file> File containing tags for third-party packages (optional)"
38+
Write-Host ' --packages "<pkg1>;<pkg2>;..." Semicolon-separated list of packages to build (optional). Default installs all third-party packages.'
39+
Write-Host ' --build-type <build type> CMake build type (optional)'
40+
Write-Host ' --build-shared-libs <ON|OFF> Build shared libraries (optional)'
41+
Write-Host " -h, --help Show this help message"
42+
}
43+
44+
function Invoke-External {
45+
param(
46+
[Parameter(Mandatory = $true)]
47+
[string] $FilePath,
48+
49+
[Parameter(Mandatory = $false)]
50+
[string[]] $Arguments = @()
51+
)
52+
53+
& $FilePath @Arguments
54+
$exitCode = $LASTEXITCODE
55+
if ($exitCode -ne 0) {
56+
throw "Command failed (exit $exitCode): $FilePath $($Arguments -join ' ')"
57+
}
58+
}
59+
60+
$ThirdpartyTagsFile = ''
61+
$ThirdpartyPackages = ''
62+
$ThirdpartyInstallDir = ''
63+
$CmakeBuildType = ''
64+
$CmakeBuildSharedLibs = ''
65+
66+
# Match install_thirdparty.sh behavior: parse GNU-style args from $args.
67+
for ($i = 0; $i -lt $args.Count; ) {
68+
$a = [string]$args[$i]
69+
70+
switch ($a) {
71+
'--install-dir' {
72+
if (($i + 1) -ge $args.Count -or ([string]$args[$i + 1]).StartsWith('--')) {
73+
[Console]::Error.WriteLine('Error: --install-dir requires a value')
74+
Show-Usage
75+
exit 1
76+
}
77+
$ThirdpartyInstallDir = [string]$args[$i + 1]
78+
$i += 2
79+
continue
80+
}
81+
'--tags-file' {
82+
if (($i + 1) -ge $args.Count -or ([string]$args[$i + 1]).StartsWith('--')) {
83+
[Console]::Error.WriteLine('Error: --tags-file requires a value')
84+
Show-Usage
85+
exit 1
86+
}
87+
$ThirdpartyTagsFile = [string]$args[$i + 1]
88+
$i += 2
89+
continue
90+
}
91+
'--packages' {
92+
if (($i + 1) -ge $args.Count -or ([string]$args[$i + 1]).StartsWith('--')) {
93+
[Console]::Error.WriteLine('Error: --packages requires a value')
94+
Show-Usage
95+
exit 1
96+
}
97+
$ThirdpartyPackages = [string]$args[$i + 1]
98+
$i += 2
99+
continue
100+
}
101+
'--build-type' {
102+
if (($i + 1) -ge $args.Count -or ([string]$args[$i + 1]).StartsWith('--')) {
103+
[Console]::Error.WriteLine('Error: --build-type requires a value')
104+
Show-Usage
105+
exit 1
106+
}
107+
$CmakeBuildType = [string]$args[$i + 1]
108+
$i += 2
109+
continue
110+
}
111+
'--build-shared-libs' {
112+
if (($i + 1) -ge $args.Count -or ([string]$args[$i + 1]).StartsWith('--')) {
113+
[Console]::Error.WriteLine('Error: --build-shared-libs requires a value')
114+
Show-Usage
115+
exit 1
116+
}
117+
$CmakeBuildSharedLibs = [string]$args[$i + 1]
118+
$i += 2
119+
continue
120+
}
121+
'-h' { Show-Usage; exit 0 }
122+
'--help' { Show-Usage; exit 0 }
123+
default {
124+
[Console]::Error.WriteLine(("Unknown option: {0}" -f $a))
125+
Show-Usage
126+
exit 1
127+
}
128+
}
129+
}
130+
131+
if ([string]::IsNullOrWhiteSpace($ThirdpartyInstallDir)) {
132+
[Console]::Error.WriteLine('Error: --install-dir is a required argument.')
133+
Show-Usage
134+
exit 1
135+
}
136+
137+
$SrcDir = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Definition)
138+
139+
$CxxStandard = $env:CXX_STANDARD
140+
if ([string]::IsNullOrWhiteSpace($CxxStandard)) {
141+
$CxxStandard = '17'
142+
}
143+
144+
$TempRoot = $env:TEMP
145+
if ([string]::IsNullOrWhiteSpace($TempRoot)) {
146+
# Fallback if TEMP isn't set.
147+
$TempRoot = [System.IO.Path]::GetTempPath()
148+
}
149+
150+
$ThirdpartyBuildDir = Join-Path $TempRoot 'otel-cpp-third-party-build'
151+
if (Test-Path -LiteralPath $ThirdpartyBuildDir) {
152+
Remove-Item -LiteralPath $ThirdpartyBuildDir -Recurse -Force
153+
}
154+
155+
if (-not (Get-Command cmake -ErrorAction SilentlyContinue)) {
156+
throw 'cmake was not found in PATH. Please install CMake and ensure it is available on PATH.'
157+
}
158+
159+
$CmakeSourceDir = Join-Path $SrcDir 'install' 'cmake'
160+
if (-not (Test-Path -LiteralPath $CmakeSourceDir)) {
161+
throw "CMake source directory not found: $CmakeSourceDir"
162+
}
163+
164+
$OtelcppProtoPath = $env:OTELCPP_PROTO_PATH
165+
if ($null -eq $OtelcppProtoPath) {
166+
$OtelcppProtoPath = ''
167+
}
168+
169+
$CmakeConfigureArgs = @(
170+
'-S', $CmakeSourceDir,
171+
'-B', $ThirdpartyBuildDir,
172+
"-DCMAKE_INSTALL_PREFIX=$ThirdpartyInstallDir",
173+
"-DCMAKE_CXX_STANDARD=$CxxStandard",
174+
"-DOTELCPP_THIRDPARTY_TAGS_FILE=$ThirdpartyTagsFile",
175+
"-DOTELCPP_PROTO_PATH=$OtelcppProtoPath",
176+
"-DOTELCPP_THIRDPARTY_INSTALL_LIST=$ThirdpartyPackages"
177+
)
178+
179+
$parallel = [Math]::Max([Environment]::ProcessorCount, 1)
180+
181+
$CmakeBuildArgs = @(
182+
'--build', $ThirdpartyBuildDir,
183+
'--clean-first',
184+
'--parallel', $parallel
185+
)
186+
187+
if (-not [string]::IsNullOrWhiteSpace($CmakeBuildType)) {
188+
$CmakeConfigureArgs += "-DCMAKE_BUILD_TYPE=$CmakeBuildType"
189+
$CmakeBuildArgs += @('--config', $CmakeBuildType)
190+
}
191+
192+
if (-not [string]::IsNullOrWhiteSpace($CmakeBuildSharedLibs)) {
193+
$CmakeConfigureArgs += "-DBUILD_SHARED_LIBS=$CmakeBuildSharedLibs"
194+
}
195+
196+
Invoke-External -FilePath 'cmake' -Arguments $CmakeConfigureArgs
197+
198+
# Use CMake's cross-generator parallel flag.
199+
Invoke-External -FilePath 'cmake' -Arguments $CmakeBuildArgs
200+
201+
# Keep parity with the bash script (no-op on Windows).
202+
if ($ThirdpartyInstallDir -eq '/usr/local') {
203+
if (Get-Command ldconfig -ErrorAction SilentlyContinue) {
204+
Invoke-External -FilePath 'ldconfig' -Arguments @()
205+
}
206+
}
207+
208+
Write-Host 'Third-party packages installed successfully.'
209+
Write-Host "-- THIRDPARTY_INSTALL_DIR: $ThirdpartyInstallDir"
210+
Write-Host "-- THIRDPARTY_TAGS_FILE: $ThirdpartyTagsFile"
211+
if ([string]::IsNullOrWhiteSpace($ThirdpartyPackages)) {
212+
Write-Host '-- THIRDPARTY_PACKAGES: all'
213+
}
214+
else {
215+
Write-Host "-- THIRDPARTY_PACKAGES: $ThirdpartyPackages"
216+
}
217+
Write-Host "-- CXX_STANDARD: $CxxStandard"
218+
if (-not [string]::IsNullOrWhiteSpace($CmakeBuildType)) {
219+
Write-Host "-- CMAKE_BUILD_TYPE: $CmakeBuildType"
220+
}

0 commit comments

Comments
 (0)