Skip to content

Commit

Permalink
Use cc_shared_library instead of cc_binary with linkshared=True to bu…
Browse files Browse the repository at this point in the history
…ild the .dll. This would allow us to move .so and .dylib on Linux/OSX
  • Loading branch information
malkia committed Jun 24, 2024
1 parent c9d9ecb commit 69741a3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

build --experimental_cc_shared_library

common --noenable_workspace
common --remote_download_minimal

Expand Down
34 changes: 24 additions & 10 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ config_setting(
cc_library(
name = "otel_sdk_deps",
visibility = ["//visibility:private"],
target_compatible_with = select({
# To compile you need `--//:with_dll=true` on the command line
"with_dll_enabled": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
deps = [
"//exporters/elasticsearch:es_log_record_exporter",
"//exporters/etw:etw_exporter",
Expand Down Expand Up @@ -101,37 +106,46 @@ genquery(
("otel_sdk_rd", ":reldeb"),
]]

# Conveniently place all Open Telemetry C++ dependencies required to build otel_sdk
[cc_binary(
name = otel_sdk_binary,

cc_library(
name = "api_sdk_includes",
# Almost all headers are included here, such that the compiler can notice the __declspec(dllexport) members.
visibility = ["//visibility:private"],
target_compatible_with = select({
# To compile you need `--//:with_dll=true` on the command line
"with_dll_enabled": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
srcs = [
"all_api_includes.cc",
"all_sdk_includes.cc",
],
deps = ["otel_sdk_deps"],
)

# Conveniently place all Open Telemetry C++ dependencies required to build otel_sdk
[cc_shared_library(
name = otel_sdk_binary,
# Force generation of .pdb file for for opt builds
features = [
"generate_pdb_file",
# Below was an attempt to use the export all symbols feature, but it failed with:
# LINK : fatal error LNK1189: library limit of 65535 objects exceeded
# "windows_export_all_symbols"
],

# https://learn.microsoft.com/en-us/cpp/build/reference/wholearchive-include-all-library-object-files?view=msvc-170
linkopts = ["/WHOLEARCHIVE"],

# Make a .dll
linkshared = True,
target_compatible_with = select({
# To compile you need `--//:with_dll=true` on the command line
"with_dll_enabled": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
# TODO: Add more missing headers to api_sdk_includes above and we'll no longer need /WHOLEARCHIVE
user_link_flags = select({
"@@platforms//os:windows": ["/WHOLEARCHIVE"],
"//conditions:default": [],
}),
visibility = ["//visibility:private"],
deps = [
otel_sdk_binary + "_restrict_compilation_mode",
"api_sdk_includes",
"otel_sdk_deps",
],
) for (otel_sdk_binary, otel_sdk_config_name) in [
Expand Down

0 comments on commit 69741a3

Please sign in to comment.