Skip to content

Commit

Permalink
Renamed shared libraries to comply convetion (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
intuibase authored May 21, 2024
1 parent 2ca221a commit 0afd2c7
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 45 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
with:
name: build-native-${{ matrix.arch }}
path: |
prod/native/_build/${{ matrix.arch }}-release/ext/elastic_apm*.so
prod/native/_build/${{ matrix.arch }}-release/ext/elastic_apm*.debug
prod/native/_build/${{ matrix.arch }}-release/loader/code/elastic_apm_loader.so
prod/native/_build/${{ matrix.arch }}-release/loader/code/elastic_apm_loader.debug
prod/native/_build/${{ matrix.arch }}-release/ext/elastic_otel_php*.so
prod/native/_build/${{ matrix.arch }}-release/ext/elastic_otel_php*.debug
prod/native/_build/${{ matrix.arch }}-release/loader/code/elastic_otel_php_loader.so
prod/native/_build/${{ matrix.arch }}-release/loader/code/elastic_otel_php_loader.debug
5 changes: 4 additions & 1 deletion .github/workflows/build-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ jobs:
echo "Creating debug symbols artifacts"
DBGSYM="${PWD}/build/packages/elastic-otel-php-debugsymbols-${{ matrix.arch }}.tar.gz"
tar -czf ${DBGSYM} prod/native/_build/${{ matrix.arch }}-release/loader/code/elastic_apm_loader.debug prod/native/_build/${{ matrix.arch }}-release/ext/*.debug
pushd prod/native/_build/${{ matrix.arch }}-release
tar --transform 's/.*\///g' -zcvf ${DBGSYM} ext/*.debug loader/code/*.debug
popd
pushd "${PWD}/build/packages"
md5sum ${DBGSYM} >${DBGSYM}.sha512
popd
Expand Down
4 changes: 2 additions & 2 deletions packaging/nfpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ homepage: "https://github.com/elastic/elastic-otel-php"
license: "ASL 2.0"
#changelog: "changelog.yaml"
contents:
- src: /source/prod/native/_build/${ELASTIC_OTEL_PHP_PLATFORM}-release/loader/code/elastic_apm_loader.so
- src: /source/prod/native/_build/${ELASTIC_OTEL_PHP_PLATFORM}-release/loader/code/elastic_otel_php_loader.so
dst: /opt/elastic/elastic-otel-php/
expand: true
- src: /source/prod/native/_build/${ELASTIC_OTEL_PHP_PLATFORM}-release/ext/elastic_apm-*.so
- src: /source/prod/native/_build/${ELASTIC_OTEL_PHP_PLATFORM}-release/ext/elastic_otel_php_*.so
dst: /opt/elastic/elastic-otel-php/
expand: true
- src: /source/prod/php
Expand Down
3 changes: 0 additions & 3 deletions prod/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ set(_supported_php_versions 80 81 82 83)

function(get_php_api_from_release php_version ret_val)
block(SCOPE_FOR VARIABLES)
set(_php_release_72 20170718)
set(_php_release_73 20180731)
set(_php_release_74 20190902)
set(_php_release_80 20200930)
set(_php_release_81 20210902)
set(_php_release_82 20220829)
Expand Down
10 changes: 4 additions & 6 deletions prod/native/ext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
AUX_SOURCE_DIRECTORY(. SrcFiles)

foreach(_php_version ${_supported_php_versions})
set (_Target elasticapm_${_php_version})
set (_Target elastic_otel_php_${_php_version})

add_library (${_Target}
SHARED ${SrcFiles}
Expand Down Expand Up @@ -36,17 +36,15 @@ foreach(_php_version ${_supported_php_versions})
libphpbridge_${_php_version}
)

get_php_api_from_release(${_php_version} _ZEND_API_version)

set_target_properties(${_Target}
PROPERTIES OUTPUT_NAME elastic_apm-${_ZEND_API_version}
PROPERTIES OUTPUT_NAME elastic_otel_php_${_php_version}
PREFIX ""
)

set_target_properties(${_Target}
PROPERTIES OUTPUT_NAME elastic_apm-${_ZEND_API_version}
PROPERTIES OUTPUT_NAME elastic_otel_php_${_php_version}
PREFIX ""
DEBUG_SYMBOL_FILE "elastic_apm-${_ZEND_API_version}.debug"
DEBUG_SYMBOL_FILE "elastic_otel_php_${_php_version}.debug"
)

if (RELEASE_BUILD)
Expand Down
6 changes: 3 additions & 3 deletions prod/native/loader/code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#scan for source files
AUX_SOURCE_DIRECTORY(. SrcFiles)

set (_Target elasticapm_loader)
set (_Target elastic_otel_php_loader)

add_library (${_Target} SHARED ${SrcFiles})

Expand All @@ -11,9 +11,9 @@ target_link_libraries(${_Target}
)

set_target_properties(${_Target}
PROPERTIES OUTPUT_NAME elastic_apm_loader
PROPERTIES OUTPUT_NAME elastic_otel_php_loader
PREFIX ""
DEBUG_SYMBOL_FILE "elastic_apm_loader.debug"
DEBUG_SYMBOL_FILE "elastic_otel_php_loader.debug"
)

if (RELEASE_BUILD)
Expand Down
10 changes: 5 additions & 5 deletions prod/native/loader/code/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ elasticapm::loader::phpdata::zend_module_entry elastic_apm_loader_module_entry =
0, // USING_ZTS
nullptr,
nullptr,
"elastic_apm_loader", /* Extension name */
"elastic_otel_apm_loader", /* Extension name */
nullptr, /* zend_function_entry */
nullptr, /* PHP_MINIT - Module initialization */
nullptr, /* PHP_MSHUTDOWN - Module shutdown */
Expand Down Expand Up @@ -116,7 +116,7 @@ __attribute__ ((visibility("default"))) elasticapm::loader::phpdata::zend_module
return &elastic_apm_loader_module_entry;
}

auto [zendEngineVersion, zendModuleApiVersion, isVersionSupported] = elasticapm::loader::getZendModuleApiVersion(zendVersion);
auto [zendEngineVersion, phpVersion, zendModuleApiVersion, isVersionSupported] = elasticapm::loader::getZendModuleApiVersion(zendVersion);

bool isThreadSafe = elasticapm::loader::isThreadSafe();

Expand All @@ -142,14 +142,14 @@ __attribute__ ((visibility("default"))) elasticapm::loader::phpdata::zend_module
Dl_info dl_info;
dladdr((void *)get_module, &dl_info);
if (!dl_info.dli_fname) {
LOG_TO_SYSLOG_AND_STDERR( "Unable to resolve path to Elastic PHP Agent libraries\n");
LOG_TO_SYSLOG_AND_STDERR( "Unable to resolve path to Elastic OpenTelemetry PHP libraries\n");
return &elastic_apm_loader_module_entry;
}

auto elasticAgentPath = std::filesystem::path(dl_info.dli_fname).parent_path();

auto agentLibrary = (elasticAgentPath/"elastic_apm-"sv);
agentLibrary += std::to_string(zendModuleApiVersion);
auto agentLibrary = (elasticAgentPath/"elastic_otel_php_"sv);
agentLibrary += std::to_string(phpVersion);
agentLibrary += ".so"sv;

void *agentHandle = dlopen(agentLibrary.c_str(), RTLD_LAZY | RTLD_GLOBAL);
Expand Down
40 changes: 20 additions & 20 deletions prod/native/loader/code/phpdetection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,35 @@ bool isThreadSafe() {
return !coreGlobals;
}

std::tuple<std::string_view, int, bool> getZendModuleApiVersion(std::string_view zendVersion) {
std::tuple<std::string_view, int, int, bool> getZendModuleApiVersion(std::string_view zendVersion) {
using namespace std::string_view_literals;
constexpr size_t knownVersionsCount = 16;

constexpr std::array<std::tuple<std::string_view, int, bool>, knownVersionsCount> knownPhpVersions {{
{"4.3"sv, 20230831, true}, // PHP 8.3
{"4.2"sv, 20220829, true}, // PHP 8.2
{"4.1"sv, 20210902, true}, // PHP 8.1
{"4.0"sv, 20200930, true}, // PHP 8.0
{"3.4"sv, 20190902, true}, // PHP 7.4
{"3.3"sv, 20180731, false}, // PHP 7.3
{"3.2"sv, 20170718, false}, // PHP 7.2
{"3.1"sv, 20160303, false}, // PHP 7.1
{"3.0"sv, 20151012, false}, // PHP 7.0
{"2.6"sv, 20131226, false}, // PHP 5.6
{"2.5"sv, 20121212, false}, // PHP 5.5
{"2.4"sv, 20100525, false}, // PHP 5.4
{"2.3"sv, 20090626, false}, // PHP 5.3
{"2.2"sv, 20060613, false}, // PHP 5.2
{"2.1"sv, 20050922, false}, // PHP 5.1
{"2.0"sv, 20041030, false} // PHP 5.0
constexpr std::array<std::tuple<std::string_view, int, int, bool>, knownVersionsCount> knownPhpVersions {{
{"4.3"sv, 83, 20230831, true}, // PHP 8.3
{"4.2"sv, 82, 20220829, true}, // PHP 8.2
{"4.1"sv, 81, 20210902, true}, // PHP 8.1
{"4.0"sv, 80, 20200930, true}, // PHP 8.0
{"3.4"sv, 74, 20190902, true}, // PHP 7.4
{"3.3"sv, 73, 20180731, false}, // PHP 7.3
{"3.2"sv, 72, 20170718, false}, // PHP 7.2
{"3.1"sv, 71, 20160303, false}, // PHP 7.1
{"3.0"sv, 70, 20151012, false}, // PHP 7.0
{"2.6"sv, 56, 20131226, false}, // PHP 5.6
{"2.5"sv, 55, 20121212, false}, // PHP 5.5
{"2.4"sv, 54, 20100525, false}, // PHP 5.4
{"2.3"sv, 53, 20090626, false}, // PHP 5.3
{"2.2"sv, 52, 20060613, false}, // PHP 5.2
{"2.1"sv, 51, 20050922, false}, // PHP 5.1
{"2.0"sv, 50, 20041030, false} // PHP 5.0
}};

auto foundPhpVersion = std::find_if(std::begin(knownPhpVersions), std::end(knownPhpVersions), [zendVersion](std::tuple<std::string_view, int, bool> const &entry) {
auto foundPhpVersion = std::find_if(std::begin(knownPhpVersions), std::end(knownPhpVersions), [zendVersion](std::tuple<std::string_view, int, int, bool> const &entry) {
return std::get<0>(entry) == zendVersion;
});

if (foundPhpVersion == std::end(knownPhpVersions)) {
return {zendVersion, 0, false};
return {zendVersion, 0, 0, false};
}

return *foundPhpVersion;
Expand Down
2 changes: 1 addition & 1 deletion prod/native/loader/code/phpdetection.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace elasticapm::loader {

std::string_view getMajorMinorZendVersion();
std::tuple<std::string_view, int, bool> getZendModuleApiVersion(std::string_view zendVersion);
std::tuple<std::string_view, int, int, bool> getZendModuleApiVersion(std::string_view zendVersion);
bool isThreadSafe();

}

0 comments on commit 0afd2c7

Please sign in to comment.