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
57 changes: 54 additions & 3 deletions ext/src/dll/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,65 @@ 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 >
${CMAKE_CURRENT_SOURCE_DIR}/input.src >
${OPENTELEMETRY_INPUT_DEF}
VERBATIM)

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}
COMMAND_EXPAND_LISTS VERBATIM)
VERBATIM)

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

// clang-format off
External\s+\|\s+(\?Create@OStreamSpanExporterFactory@trace@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@SimpleSpanProcessorFactory@trace@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@TracerProviderFactory@trace@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@LoggerProviderFactory@logs@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@BatchLogRecordProcessorFactory@logs@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@SimpleLogRecordProcessorFactory@logs@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@MultiLogRecordProcessorFactory@logs@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?ForceFlush@TracerProvider@trace@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?ForceFlush@LoggerProvider@logs@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?\?0OStreamLogRecordExporter@logs@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@OStreamMetricExporterFactory@metrics@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@PeriodicExportingMetricReaderFactory@metrics@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@MeterProviderFactory@metrics@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@MeterContextFactory@metrics@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@MeterProviderFactory@metrics@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@ViewFactory@metrics@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@MeterSelectorFactory@metrics@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@InstrumentSelectorFactory@metrics@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?AddMetricReader@MeterContext@metrics@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?AddMetricReader@MeterProvider@metrics@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?AddView@MeterProvider@metrics@sdk@v1@opentelemetry[^\s]*)\s+\((.*)\)$

#if defined(WITH_OTLP_GRPC) || defined(WITH_OTLP_HTTP)
External\s+\|\s+(\?GetOtlpDefaultTracesTimeout@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultTracesHeaders@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultLogsTimeout@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultLogsHeaders@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultMetricsTimeout@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultMetricsHeaders@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultTracesSslCertificatePath@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultMetricsSslCertificatePath@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultLogsSslCertificatePath@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultTracesSslCertificateString@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultMetricsSslCertificateString@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultLogsSslCertificateString@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
#endif // defined(WITH_OTLP_GRPC) || defined(WITH_OTLP_HTTP)

#if defined(WITH_OTLP_GRPC)
External\s+\|\s+(\?Create@OtlpGrpcExporterFactory@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@OtlpGrpcMetricExporterFactory@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@OtlpGrpcLogRecordExporterFactory@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?\?0OtlpGrpcExporterOptions@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?\?1OtlpGrpcExporterOptions@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?\?0OtlpGrpcMetricExporterOptions@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?\?1OtlpGrpcMetricExporterOptions@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?\?0OtlpGrpcLogRecordExporterOptions@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?\?1OtlpGrpcLogRecordExporterOptions@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultGrpcTracesEndpoint@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultGrpcMetricsEndpoint@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultGrpcLogsEndpoint@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultGrpcTracesIsInsecure@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultGrpcMetricsIsInsecure@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultGrpcLogsIsInsecure@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
#endif // defined(WITH_OTLP_GRPC)

#if defined(WITH_OTLP_HTTP)
External\s+\|\s+(\?Create@OtlpHttpExporterFactory@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@OtlpHttpMetricExporterFactory@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?Create@OtlpHttpLogRecordExporterFactory@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?\?0OtlpHttpExporterOptions@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?\?1OtlpHttpExporterOptions@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?\?0OtlpHttpMetricExporterOptions@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?\?1OtlpHttpMetricExporterOptions@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?\?0OtlpHttpLogRecordExporterOptions@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?\?1OtlpHttpLogRecordExporterOptions@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultHttpTracesEndpoint@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultHttpMetricsEndpoint@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
External\s+\|\s+(\?GetOtlpDefaultHttpLogsEndpoint@otlp@exporter@v1@opentelemetry[^\s]*)\s+\((.*)\)$
#endif // defined(WITH_OTLP_HTTP)
// clang-format on
5 changes: 5 additions & 0 deletions ext/src/dll/make_def.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
param ($dumpbin, $bindir, $inputfile, $targetfile)

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

Get-ChildItem -Verbose -Path $bindir/*.lib -Recurse | % { & "$dumpbin" /SYMBOLS $_ | Select-String -Pattern @(Get-Content -Verbose -Path "$inputfile" | Where-Object { $_.Trim() -ne '' }) | % { "; $($_.matches.groups[2])`r`n$($_.matches.groups[1])" } >> $targetfile }
Loading