Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ jobs:
- name: "Generate FFI"
shell: bash
run: |
chmod +x ffi-build.sh
./ffi-build.sh ${OUTPUT_FOLDER}
chmod +x build-profiling-ffi.sh
./build-profiling-ffi.sh ${OUTPUT_FOLDER}

- name: 'Publish libdatadog'
uses: actions/upload-artifact@v2
Expand All @@ -89,5 +89,5 @@ jobs:
run: |
mkdir examples/ffi/build
cd examples/ffi/build
cmake -S .. -DDDProf_ROOT=$OUTPUT_FOLDER
cmake -S .. -DDatadog_ROOT=$OUTPUT_FOLDER
cmake --build .
37 changes: 18 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

[workspace]
members = [
"ddprof-ffi",
"profiling",
"profiling-ffi",
"ddcommon",
"ddcommon-ffi",
"ddtelemetry",
Expand Down
2 changes: 1 addition & 1 deletion LICENSE-3rdparty.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
root_name: "ddprof-ffi, datadog-profiling, ddcommon, ddcommon-ffi, ddtelemetry"
root_name: "datadog-profiling, ddcommon, datadog-profiling-ffi, ddcommon-ffi, ddtelemetry"
third_party_libraries:
- package_name: aho-corasick
package_version: 0.7.18
Expand Down
59 changes: 36 additions & 23 deletions ffi-build.sh → build-profiling-ffi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ set -eu

destdir="$1"

mkdir -v -p "$destdir/include/ddprof" "$destdir/lib/pkgconfig" "$destdir/cmake"
mkdir -v -p "$destdir/include/datadog" "$destdir/lib/pkgconfig" "$destdir/cmake"

version=$(awk -F\" '$1 ~ /^version/ { print $2 }' < ddprof-ffi/Cargo.toml)
version=$(awk -F\" '$1 ~ /^version/ { print $2 }' < profiling-ffi/Cargo.toml)
target="$(rustc -vV | awk '/^host:/ { print $2 }')"
shared_library_suffix=".so"
static_library_suffix=".a"
Expand Down Expand Up @@ -63,33 +63,45 @@ case "$target" in
esac

echo "Recognized platform '${target}'. Adding libs: ${native_static_libs}"
sed < ddprof_ffi.pc.in "s/@DDProf_FFI_VERSION@/${version}/g" \
> "$destdir/lib/pkgconfig/ddprof_ffi.pc"
cd profiling-ffi
sed < datadog_profiling.pc.in "s/@Datadog_VERSION@/${version}/g" \
> "$destdir/lib/pkgconfig/datadog_profiling.pc"

sed < ddprof_ffi_with_rpath.pc.in "s/@DDProf_FFI_VERSION@/${version}/g" \
> "$destdir/lib/pkgconfig/ddprof_ffi_with_rpath.pc"
sed < datadog_profiling_with_rpath.pc.in "s/@Datadog_VERSION@/${version}/g" \
> "$destdir/lib/pkgconfig/datadog_profiling_with_rpath.pc"

sed < ddprof_ffi-static.pc.in "s/@DDProf_FFI_VERSION@/${version}/g" \
| sed "s/@DDProf_FFI_LIBRARIES@/${native_static_libs}/g" \
> "$destdir/lib/pkgconfig/ddprof_ffi-static.pc"
sed < datadog_profiling-static.pc.in "s/@Datadog_VERSION@/${version}/g" \
| sed "s/@Datadog_LIBRARIES@/${native_static_libs}/g" \
> "$destdir/lib/pkgconfig/datadog_profiling-static.pc"

# strip leading white space as per CMake policy CMP0004.
ffi_libraries="$(echo "${native_static_libs}" | sed -e 's/^[[:space:]]*//')"

sed < cmake/DDProfConfig.cmake.in \
> "$destdir/cmake/DDProfConfig.cmake" \
"s/@DDProf_FFI_LIBRARIES@/${ffi_libraries}/g"
sed < ../cmake/DatadogConfig.cmake.in \
> "$destdir/cmake/DatadogConfig.cmake" \
"s/@Datadog_LIBRARIES@/${ffi_libraries}/g"
cd -

cp -v LICENSE LICENSE-3rdparty.yml NOTICE "$destdir/"

export RUSTFLAGS="${RUSTFLAGS:- -C relocation-model=pic}"

echo "Building the ddprof_ffi library (may take some time)..."
cargo build --release --target "${target}"
datadog_profiling_ffi="datadog-profiling-ffi"
echo "Building the ${datadog_profiling_ffi} crate (may take some time)..."
cargo build --package="${datadog_profiling_ffi}" --release --target "${target}"

# Remove _ffi suffix when copying
shared_library_name="${library_prefix}datadog_profiling_ffi${shared_library_suffix}"
shared_library_rename="${library_prefix}datadog_profiling${shared_library_suffix}"

static_library_name="${library_prefix}datadog_profiling_ffi${static_library_suffix}"
static_library_rename="${library_prefix}datadog_profiling${static_library_suffix}"

shared_library_name="${library_prefix}ddprof_ffi${shared_library_suffix}"
static_library_name="${library_prefix}ddprof_ffi${static_library_suffix}"
cp -v "target/${target}/release/$static_library_name" "target/${target}/release/$shared_library_name" "$destdir/lib/"
cp -v "target/${target}/release/${shared_library_name}" "$destdir/lib/${shared_library_rename}"
cp -v "target/${target}/release/${static_library_name}" "$destdir/lib/${static_library_rename}"

shared_library_name="${shared_library_rename}"
static_library_name="${static_library_rename}"

if [[ "$remove_rpath" -eq 1 ]]; then
patchelf --remove-rpath "$destdir/lib/${shared_library_name}"
Expand All @@ -112,7 +124,7 @@ if command -v objcopy > /dev/null && [[ "$target" != "x86_64-pc-windows-msvc" ]]
fi

echo "Checking that native-static-libs are as expected for this platform..."
cd ddprof-ffi
cd profiling-ffi
actual_native_static_libs="$(cargo rustc --release --target "${target}" -- --print=native-static-libs 2>&1 | awk -F ':' '/note: native-static-libs:/ { print $3 }')"
echo "Actual native-static-libs:${actual_native_static_libs}"
echo "Expected native-static-libs:${expected_native_static_libs}"
Expand All @@ -138,11 +150,12 @@ echo "Building tools"
cargo build --package tools --bins

echo "Generating $destdir/include/libdatadog headers..."
cbindgen --crate ddcommon-ffi --config ddcommon-ffi/cbindgen.toml --output "$destdir/include/datadog/common.h"
cbindgen --crate ddprof-ffi --config ddprof-ffi/cbindgen.toml --output "$destdir/include/datadog/profiling.h"
cbindgen --crate ddcommon-ffi \
--config ddcommon-ffi/cbindgen.toml \
--output "$destdir/include/datadog/common.h"
cbindgen --crate "${datadog_profiling_ffi}" \
--config profiling-ffi/cbindgen.toml \
--output "$destdir/include/datadog/profiling.h"
./target/debug/dedup_headers "$destdir/include/datadog/common.h" "$destdir/include/datadog/profiling.h"

# CI doesn't have any clang tooling
# clang-format -i "$destdir/include/ddprof/ffi.h"

echo "Done."
41 changes: 0 additions & 41 deletions cmake/DDProfConfig.cmake.in

This file was deleted.

53 changes: 53 additions & 0 deletions cmake/DatadogConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Unless explicitly stated otherwise all files in this repository are licensed
# under the Apache License Version 2.0. This product includes software developed
# at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc.
include(FindPackageHandleStandardArgs)

if(DEFINED ENV{Datadog_ROOT})
set(Datadog_ROOT "$ENV{Datadog_ROOT}")
else()
# If the environment variable is not set, maybe we are part of a build
set(Datadog_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/..")
endif()

find_path(Datadog_INCLUDE_DIR datadog/profiling.h HINTS ${Datadog_ROOT}/include)

find_library(
Datadog_LIBRARY
NAMES datadog_profiling
HINTS ${Datadog_ROOT}/lib)

find_package_handle_standard_args(Datadog DEFAULT_MSG Datadog_LIBRARY
Datadog_INCLUDE_DIR)

if(Datadog_FOUND)
set(Datadog_INCLUDE_DIRS ${Datadog_INCLUDE_DIR})
set(Datadog_LIBRARIES ${Datadog_LIBRARY} "@Datadog_LIBRARIES@")
mark_as_advanced(Datadog_ROOT Datadog_LIBRARY Datadog_INCLUDE_DIR)

add_library(datadog_profiling INTERFACE)
target_include_directories(datadog_profiling
INTERFACE ${Datadog_INCLUDE_DIRS})
target_link_libraries(datadog_profiling INTERFACE ${Datadog_LIBRARIES})
target_compile_features(datadog_profiling INTERFACE c_std_11)

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_link_libraries(
datadog_profiling
INTERFACE NtDll
UserEnv
Bcrypt
crypt32
wsock32
ws2_32
shlwapi
Secur32
Ncrypt)
endif()

add_library(Datadog::Profiling ALIAS datadog_profiling)
else()
set(Datadog_ROOT
""
CACHE STRING "Directory containing libdatadog")
endif()
4 changes: 2 additions & 2 deletions ddcommon-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

[package]
name = "ddcommon-ffi"
version = "0.7.0-rc.1"
version = "0.8.0-alpha.1"
edition = "2021"
license = "Apache-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ddcommon = { path = "../ddcommon", version = "0.7.0-rc.1" }
ddcommon = { path = "../ddcommon" }
anyhow = "1.0"
2 changes: 1 addition & 1 deletion ddcommon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
edition = "2021"
license = "Apache-2.0"
name = "ddcommon"
version = "0.7.0-rc.1"
version = "0.8.0-alpha.1"

[lib]
crate-type = ["lib"]
Expand Down
2 changes: 1 addition & 1 deletion ddtelemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
edition = "2021"
license = "Apache 2.0"
name = "ddtelemetry"
version = "0.7.0-rc.1"
version = "0.8.0-alpha.1"

[dependencies]
anyhow = {version = "1.0"}
Expand Down
27 changes: 9 additions & 18 deletions examples/ffi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
project(ffi_examples)
project(datadog_profiling_ffi_examples LANGUAGES C CXX)
cmake_minimum_required(VERSION 3.19)

find_package(DDProf)
find_package(Datadog REQUIRED)

add_executable(exporter exporter.cpp)
# needed for designated initializers
target_compile_features(exporter PRIVATE cxx_std_20)
target_link_libraries(exporter PRIVATE Datadog::Profiling)

add_executable(profiles profiles.c)

set(EXTERNAL_LIBS DDProf::FFI)

if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(EXTERNAL_LIBS "${EXTERNAL_LIBS};NtDll;UserEnv;Bcrypt;crypt32;wsock32;ws2_32;shlwapi")
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_definitions(exporter PUBLIC _CRT_SECURE_NO_WARNINGS)
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_features(exporter PRIVATE cxx_std_20) # needed for designated initializers
target_compile_definitions(exporter PUBLIC _CRT_SECURE_NO_WARNINGS)
else()
target_compile_features(exporter PRIVATE cxx_std_11)
endif()

target_link_libraries(exporter ${EXTERNAL_LIBS})

target_link_libraries(profiles ${EXTERNAL_LIBS})
add_executable(profiles profiles.c)
target_link_libraries(profiles PRIVATE Datadog::Profiling)
Loading