Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUILD] Alternative way of exporting symbols (generating .def file) #2476

Merged
merged 13 commits into from
Jan 22, 2024
49 changes: 45 additions & 4 deletions ext/src/dll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,55 @@ if(WITH_OTLP_HTTP)
PRIVATE opentelemetry_exporter_otlp_http_log)
endif()

find_program(
_vswhere_tool
NAMES vswhere
PATHS "$ENV{ProgramFiles\(x86\)}/Microsoft Visual Studio/Installer")
if(NOT ${vswhere})
message(
FATAL_ERROR "Could not locate vswhere.exe - unable to locate dumpbin.exe")
endif()

execute_process(
COMMAND "${_vswhere_tool}" -latest -find **/dumpbin.exe
OUTPUT_VARIABLE DUMPBIN_PATHS
RESULT_VARIABLE _vs_where_exitcode
OUTPUT_STRIP_TRAILING_WHITESPACE)

message(STATUS "DUMPBIN PATHS: ${DUMPBIN_PATHS} ${RESULT_VARIABLE}")

string(REPLACE "\n" ";" DUMPBIN_PATHS_LIST ${DUMPBIN_PATHS})

list(POP_FRONT DUMPBIN_PATHS_LIST DUMPBIN_PATH)

message(STATUS "DUMPBIN PATH: ${DUMPBIN_PATH}")

# find Powershell executable find_program(DUMPBIN_PATH NAMES dumpbin REQUIRED)

# find Powershell executable
find_program(POWERSHELL_PATH NAMES pwsh powershell REQUIRED)

set(OPENTELEMETRY_INPUT_DEF "${CMAKE_CURRENT_SOURCE_DIR}/input.txt")

add_custom_command(
OUTPUT ${OPENTELEMETRY_EXPORT_DEF}
OUTPUT ${OPENTELEMETRY_INPUT_DEF}
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/input.src"
COMMAND
${CMAKE_CXX_COMPILER}
"-D$<JOIN:$<TARGET_PROPERTY:opentelemetry_cpp,COMPILE_DEFINITIONS>,;-D>" /EP
${CMAKE_CURRENT_SOURCE_DIR}/opentelemetry_cpp.src >
${OPENTELEMETRY_EXPORT_DEF}
COMMAND_EXPAND_LISTS VERBATIM)
${CMAKE_CURRENT_SOURCE_DIR}/input.src > ${OPENTELEMETRY_INPUT_DEF}
VERBATIM COMMAND_EXPAND_LISTS)

add_custom_command(
OUTPUT ${OPENTELEMETRY_EXPORT_DEF}
DEPENDS "${OPENTELEMETRY_INPUT_DEF}"
"${CMAKE_CURRENT_SOURCE_DIR}/make_def.ps1"
COMMAND
${POWERSHELL_PATH} "-ExecutionPolicy" "Bypass" "-File"
"${CMAKE_CURRENT_SOURCE_DIR}/make_def.ps1" "-dumpbin" "${DUMPBIN_PATH}"
"-bindir" ${PROJECT_BINARY_DIR} "-inputfile" ${OPENTELEMETRY_INPUT_DEF}
"-targetfile" ${OPENTELEMETRY_EXPORT_DEF}
VERBATIM)

if(OPENTELEMETRY_INSTALL)
install(
Expand Down
67 changes: 67 additions & 0 deletions ext/src/dll/input.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// clang-format off
Create@OStreamSpanExporterFactory@trace@exporter@v1@opentelemetry
Create@SimpleSpanProcessorFactory@trace@sdk@v1@opentelemetry
Create@TracerProviderFactory@trace@sdk@v1@opentelemetry
Create@LoggerProviderFactory@logs@sdk@v1@opentelemetry
Create@BatchLogRecordProcessorFactory@logs@sdk@v1@opentelemetry
Create@SimpleLogRecordProcessorFactory@logs@sdk@v1@opentelemetry
Create@MultiLogRecordProcessorFactory@logs@sdk@v1@opentelemetry
ForceFlush@TracerProvider@trace@sdk@v1@opentelemetry
ForceFlush@LoggerProvider@logs@sdk@v1@opentelemetry
OStreamLogRecordExporter@logs@exporter@v1@opentelemetry
Create@OStreamMetricExporterFactory@metrics@exporter@v1@opentelemetry
Create@PeriodicExportingMetricReaderFactory@metrics@sdk@v1@opentelemetry
Create@MeterProviderFactory@metrics@sdk@v1@opentelemetry
Create@MeterContextFactory@metrics@sdk@v1@opentelemetry
Create@ViewFactory@metrics@sdk@v1@opentelemetry
Create@MeterSelectorFactory@metrics@sdk@v1@opentelemetry
Create@InstrumentSelectorFactory@metrics@sdk@v1@opentelemetry
AddMetricReader@MeterContext@metrics@sdk@v1@opentelemetry
AddMetricReader@MeterProvider@metrics@sdk@v1@opentelemetry
AddView@MeterProvider@metrics@sdk@v1@opentelemetry

#if defined(WITH_OTLP_GRPC) || defined(WITH_OTLP_HTTP)
GetOtlpDefaultTracesTimeout@otlp@exporter@v1@opentelemetry
GetOtlpDefaultTracesHeaders@otlp@exporter@v1@opentelemetry
GetOtlpDefaultLogsTimeout@otlp@exporter@v1@opentelemetry
GetOtlpDefaultLogsHeaders@otlp@exporter@v1@opentelemetry
GetOtlpDefaultMetricsTimeout@otlp@exporter@v1@opentelemetry
GetOtlpDefaultMetricsHeaders@otlp@exporter@v1@opentelemetry
GetOtlpDefaultTracesSslCertificatePath@otlp@exporter@v1@opentelemetry
GetOtlpDefaultMetricsSslCertificatePath@otlp@exporter@v1@opentelemetry
GetOtlpDefaultLogsSslCertificatePath@otlp@exporter@v1@opentelemetry
GetOtlpDefaultTracesSslCertificateString@otlp@exporter@v1@opentelemetry
GetOtlpDefaultMetricsSslCertificateString@otlp@exporter@v1@opentelemetry
GetOtlpDefaultLogsSslCertificateString@otlp@exporter@v1@opentelemetry
#endif // defined(WITH_OTLP_GRPC) || defined(WITH_OTLP_HTTP)

#if defined(WITH_OTLP_GRPC)
Create@OtlpGrpcExporterFactory@otlp@exporter@v1@opentelemetry
Create@OtlpGrpcMetricExporterFactory@otlp@exporter@v1@opentelemetry
Create@OtlpGrpcLogRecordExporterFactory@otlp@exporter@v1@opentelemetry
OtlpGrpcExporterOptions@otlp@exporter@v1@opentelemetry
OtlpGrpcMetricExporterOptions@otlp@exporter@v1@opentelemetry
OtlpGrpcLogRecordExporterOptions@otlp@exporter@v1@opentelemetry
GetOtlpDefaultGrpcTracesEndpoint@otlp@exporter@v1@opentelemetry
GetOtlpDefaultGrpcMetricsEndpoint@otlp@exporter@v1@opentelemetry
GetOtlpDefaultGrpcLogsEndpoint@otlp@exporter@v1@opentelemetry
GetOtlpDefaultGrpcTracesIsInsecure@otlp@exporter@v1@opentelemetry
GetOtlpDefaultGrpcMetricsIsInsecure@otlp@exporter@v1@opentelemetry
GetOtlpDefaultGrpcLogsIsInsecure@otlp@exporter@v1@opentelemetry
#endif // defined(WITH_OTLP_GRPC)

#if defined(WITH_OTLP_HTTP)
Create@OtlpHttpExporterFactory@otlp@exporter@v1@opentelemetry
Create@OtlpHttpMetricExporterFactory@otlp@exporter@v1@opentelemetry
Create@OtlpHttpLogRecordExporterFactory@otlp@exporter@v1@opentelemetry
OtlpHttpExporterOptions@otlp@exporter@v1@opentelemetry
OtlpHttpMetricExporterOptions@otlp@exporter@v1@opentelemetry
OtlpHttpLogRecordExporterOptions@otlp@exporter@v1@opentelemetry
GetOtlpDefaultHttpTracesEndpoint@otlp@exporter@v1@opentelemetry
GetOtlpDefaultHttpMetricsEndpoint@otlp@exporter@v1@opentelemetry
GetOtlpDefaultHttpLogsEndpoint@otlp@exporter@v1@opentelemetry
#endif // defined(WITH_OTLP_HTTP)
// clang-format on
8 changes: 8 additions & 0 deletions ext/src/dll/make_def.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

param ($dumpbin, $bindir, $inputfile, $targetfile)

"LIBRARY opentelemetry_cpp`r`nEXPORTS`r`n" > $targetfile

Get-ChildItem -Verbose -Path $bindir/sdk/*,$bindir/exporters/* -Include *.lib -Recurse | % { & "$dumpbin" /SYMBOLS $_ | Select-String -Pattern @(Get-Content -Verbose -Path "$inputfile" | Where-Object { $_.Trim() -ne '' } | % { "External\s+\|\s+(\?+[0-9]?$_[^\s]*)\s+\((.*)\)$" }) | % { "; $($_.matches.groups[2])`r`n$($_.matches.groups[1])" } >> $targetfile }