Skip to content

Commit

Permalink
Enable generating deb, rpm, NuGet, tgz, zip package through cmake bui…
Browse files Browse the repository at this point in the history
…ld (#1662)
  • Loading branch information
lalitb authored Dec 13, 2022
1 parent dfff693 commit e7579ed
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -542,3 +542,8 @@ install(
EXPORT "${PROJECT_NAME}-target"
NAMESPACE "${PROJECT_NAME}::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

if(BUILD_PACKAGE)
include(cmake/package.cmake)
include(CPack)
endif()
36 changes: 36 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,42 @@ work on Windows, specifically we can't safely allocate memory in one DLL and
free it in another. For now, OpenTelemetry C++ targets need to be statically
linked into the Windows applications.

## Generatring binary packages

OpenTelemetry C++ supports generating plateform specific binary packages from CMake
configuration. The packages generated through this mayn't be production ready,
and user may have to customize it further before using it as distribution.

- Linux : deb, rpm, tgz
- MacOS : tgz
- Windows : NuGet, zip

This requires platform specific package generators already installed. The package
generation can subsequently be enabled by using BUILD_PACKAGE option during cmake
configuration

```console
$ cd opentelemetry-cpp
$ mkdir build && cd build && cmake -DBUILD_PACKAGE ..

-- Package name: opentelemetry-cpp-1.8.1-ubuntu-20.04-x86_64.deb
-- Configuring done
-- Generating done
...
$
```

Once build is complete as specified in [standalone build section](#building-as-standalone-cmake-project),
the package can be generated as below.

```console
$ cpack -C debug
CPack: Create package using DEB
...
CPack: - package: /home/<user>/opentelemetry-cpp/build/opentelemetry-cpp-1.8.1-ubuntu-20.04-x86_64.deb generated.
$
```

## Using Package Managers

If you are using [Conan](https://www.conan.io/) to manage your dependencies, add
Expand Down
22 changes: 22 additions & 0 deletions cmake/ParseOsRelease.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Parse /etc/os-release to determine Linux distro

if(EXISTS /etc/os-release)
file(STRINGS /etc/os-release OS_RELEASE)
foreach(NameAndValue ${OS_RELEASE})
# Strip leading spaces
string(REGEX REPLACE "^[ ]+" "" NameAndValue ${NameAndValue})
# Find variable name
string(REGEX MATCH "^[^=]+" Name ${NameAndValue})
# Find the value
string(REPLACE "${Name}=" "" Value ${NameAndValue})
# Strip quotes from value
string(REPLACE "\"" "" Value ${Value})
# Set the variable
message("-- /etc/os-release : ${Name}=${Value}")
set("OS_RELEASE_${Name}" "${Value}")
endforeach()
else()
set("OS_RELEASE_NAME" ${CMAKE_SYSTEM_NAME})
set("OS_RELEASE_ID" ${CMAKE_SYSTEM_NAME})
set("OS_RELEASE_VERSION_ID" "1.0")
endif()
71 changes: 71 additions & 0 deletions cmake/package.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

set(CPACK_PACKAGE_DESCRIPTION "OpenTelemetry C++ for Linux")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OpenTelemetry C++ for Linux - C++ Implementation of OpenTelemetry Specification")
set(CPACK_PACKAGE_VENDOR "OpenTelemetry")
set(CPACK_PACKAGE_CONTACT "OpenTelemetry-cpp")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://opentelemetry.io/")
set(CMAKE_PROJECT_NAME "opentelemetry-cpp")

option(TARBALL "Build a tarball package" OFF)

if (UNIX AND NOT APPLE)
include(cmake/ParseOsRelease.cmake)
set(CPACK_SYSTEM_NAME "${OS_RELEASE_ID}-${OS_RELEASE_VERSION_ID}")
#set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local")
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${OPENTELEMETRY_VERSION}-${CPACK_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")

# Check if system is deb or rpm capable
find_program(RPMCAPABLE rpmbuild)
find_program(DEBCAPABLE dpkg-buildpackage)
if (TARBALL)
set(CPACK_GENERATOR "TGZ")
message("-- Package name: ${CPACK_PACKAGE_FILE_NAME}.tar.gz")
elseif (DEBCAPABLE MATCHES "NOTFOUND" AND RPMCAPABLE MATCHES "NOTFOUND")
message(FATAL_ERROR "Required Package generator not found for either deb or rpm."
" Install required package generation software and try again")
elseif (NOT DEBCAPABLE MATCHES "NOTFOUND")
if (NOT RPMCAPABLE MATCHES "NOTFOUND")
message(WARNING "Both deb and rpm package generator found."
"Selecting deb as default packager.")
endif()
set(CPACK_GENERATOR "DEB")
set(INSTALL_LIB_DIR
${CMAKE_INSTALL_PREFIX}/lib/${CPACK_DEBIAN_ARCHITECTURE}-linux-gnu)
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
#set(CPACK_COMPONENTS_ALL headers libraries)
set (CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
message("-- Package name: ${CPACK_PACKAGE_FILE_NAME}.deb")
elseif(NOT RPMCAPABLE MATCHES "NOTFOUND")
set(CPACK_GENERATOR "RPM")
set(INSTALL_LIB_DIR
${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu)
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/lib64/cmake")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/lib64/pkgconfig")
set(CPACK_RPM_PACKAGE_LICENSE "Apache-2.0")
message("-- Package name: ${CPACK_PACKAGE_FILE_NAME}.rpm")
endif()
elseif(APPLE)
if (TARBALL)
set(CPACK_GENERATOR "TGZ")
message("-- Package name: ${CPACK_PACKAGE_FILE_NAME}.tar.gz")
endif()
elseif(WIN32)
find_program(NUGETCAPABLE nuget)
if(NOT NUGETCAPABLE MATCHES "NOTFOUND")
set(CPACK_NUGET_PACKAGE_NAME "${CPACK_PROJECT_NAME}")
set(CPACK_NUGET_PACKAGE_VERSION "${OPENTELEMETRY_VERSIOM}")
set(CPACK_NUGET_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}")
set(CPACK_NUGET_PACKAGE_AUTHORS "${CPACK_PACKAGE_VENDOR}")
set(CPACK_NUGET_PACKAGE_TITLE "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}")
set(CPACK_NUGET_PACKAGE_OWNERS "${CPACK_PACKAGE_VENDOR}")
set(CPACK_NUGET_PACKAGE_HOMEPAGE_URL "${CPACK_PACKAGE_HOMEPAGE_URL}")
set(CPACK_NUGET_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}")
set(CPACK_NUGET_PACKAGE_COPYRIGHT "${CPACK_PACKAGE_VENDOR}")
set(CPACK_NUGET_PACKAGE_LICENSEURL "https://www.apache.org/licenses/LICENSE-2.0.txt")
set(CPACK_NUGET_PACKAGE_LANGUAGE "en_US")
set(CPACK_GENERATOR NuGet)
else()
set(CPACK_GENERATOR ZIP)
endif()
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@

#pragma once

#include "opentelemetry/exporters/otlp/protobuf_include_prefix.h"

#include "google/protobuf/message.h"

#include "opentelemetry/exporters/otlp/protobuf_include_suffix.h"

#include "opentelemetry/common/spin_lock_mutex.h"
#include "opentelemetry/ext/http/client/http_client.h"
#include "opentelemetry/nostd/variant.h"
Expand All @@ -28,6 +22,15 @@
#include <string>
#include <unordered_map>

// forward declare google::protobuf::Message
namespace google
{
namespace protobuf
{
class Message;
}
} // namespace google

OPENTELEMETRY_BEGIN_NAMESPACE
namespace exporter
{
Expand Down

2 comments on commit e7579ed

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp api Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: e7579ed Previous: dfff693 Ratio
BM_CreateBaggageFrom180Entries 155821.59782449403 ns/iter 74281.50511269105 ns/iter 2.10
BM_SetValueBaggageWithTenEntries 1762.0648591322229 ns/iter 684.9692611409571 ns/iter 2.57
BM_SpanCreationWitContextPropagation 2550.3563158439865 ns/iter 994.8018564233569 ns/iter 2.56

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp sdk Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: e7579ed Previous: dfff693 Ratio
BM_BaselineBuffer/1 2649228.096008301 ns/iter 1184659.0042114258 ns/iter 2.24
BM_LockFreeBuffer/1 3066151.6189575195 ns/iter 1511765.0035667757 ns/iter 2.03

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.