diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 0000000000..bca6ee979a --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,130 @@ +on: + push: + branches: + - main + pull_request: + branches: + - main + +name: .NET + +env: + BRANCH: ${{ github.head_ref || github.ref_name }} + COMMIT_SHA: ${{ github.sha }} + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [windows-latest, macos-latest] + target: [ + x86_64-pc-windows-msvc, + i686-pc-windows-msvc, + x86_64-apple-darwin, + aarch64-apple-darwin + ] + exclude: + - os: windows-latest + target: x86_64-apple-darwin + - os: windows-latest + target: aarch64-apple-darwin + - os: macos-latest + target: x86_64-pc-windows-msvc + - os: macos-latest + target: i686-pc-windows-msvc + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install rustup + if: matrix.os == 'windows-latest' + run: | + $ProgressPreference = "SilentlyContinue" + Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe + .\rustup-init.exe -y --default-host=${{ matrix.target }} --default-toolchain=none + del rustup-init.exe + rustup target add ${{ matrix.target }} + shell: powershell + + - name: Install rustup + if: matrix.os == 'macos-latest' + run: | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + source $HOME/.cargo/env + rustup target add ${{ matrix.target }} + shell: bash + + - name: Build on Windows + if: matrix.os == 'windows-latest' + run: .\windows\build\build.ps1 -output_dir .\bin -targets ${{ matrix.target }} + shell: pwsh + + - name: Build on macOS + if: matrix.os == 'macos-latest' + run: | + ./windows/build/build.sh -o ./bin -t ${{ matrix.target }} + shell: bash + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.os }}-bin-${{ matrix.target }} + path: | + bin/* + !bin/*/*/build + !bin/*/*/deps + !bin/*/*/examples + !bin/*/*/incremental + + pack: + runs-on: windows-latest + needs: build + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download Windows artifacts + uses: actions/download-artifact@v4 + with: + name: windows-latest-bin-x86_64-pc-windows-msvc + path: bin + + - name: Download Windows artifacts + uses: actions/download-artifact@v4 + with: + name: windows-latest-bin-i686-pc-windows-msvc + path: bin + + - name: Download Mac artifacts + uses: actions/download-artifact@v4 + with: + name: macos-latest-bin-x86_64-apple-darwin + path: bin + + - name: Download Mac artifacts + uses: actions/download-artifact@v4 + with: + name: macos-latest-bin-aarch64-apple-darwin + path: bin + + - name: Pack + run: | + # 13.1.0-preview.{epoch} format + $epoch = [math]::Floor((Get-Date).Subtract([datetime]'1970-01-01').TotalSeconds) + $version = "13.1.0-preview.$epoch" + dotnet pack .\windows\libdatadog.csproj ` + -p:LibDatadogBinariesOutputDir=..\bin ` + -p:LibDatadogVersion=$version ` + -p:RepositoryBranch=$env:BRANCH ` + -p:RepositoryCommit=$env:COMMIT_SHA ` + -o .nuget\packages\ + + - name: Store artifacts + uses: actions/upload-artifact@v4 + with: + name: packages + path: .nuget/packages/* + if-no-files-found: error \ No newline at end of file diff --git a/windows/build-artifacts.ps1 b/windows/build-artifacts.ps1 old mode 100644 new mode 100755 index b1ae159682..0372a995fb --- a/windows/build-artifacts.ps1 +++ b/windows/build-artifacts.ps1 @@ -22,10 +22,12 @@ Write-Host "Building project into $($output_dir)" -ForegroundColor Magenta # build inside the crate to use the config.toml file pushd profiling-ffi -Invoke-Call -ScriptBlock { cargo build --features datadog-profiling-ffi/ddtelemetry-ffi,datadog-profiling-ffi/crashtracker-receiver,datadog-profiling-ffi/crashtracker-collector,datadog-profiling-ffi/demangler --target i686-pc-windows-msvc --release --target-dir $output_dir } -Invoke-Call -ScriptBlock { cargo build --features datadog-profiling-ffi/ddtelemetry-ffi,datadog-profiling-ffi/crashtracker-receiver,datadog-profiling-ffi/crashtracker-collector,datadog-profiling-ffi/demangler --target i686-pc-windows-msvc --target-dir $output_dir } -Invoke-Call -ScriptBlock { cargo build --features datadog-profiling-ffi/ddtelemetry-ffi,datadog-profiling-ffi/crashtracker-receiver,datadog-profiling-ffi/crashtracker-collector,datadog-profiling-ffi/demangler --target x86_64-pc-windows-msvc --release --target-dir $output_dir } -Invoke-Call -ScriptBlock { cargo build --features datadog-profiling-ffi/ddtelemetry-ffi,datadog-profiling-ffi/crashtracker-receiver,datadog-profiling-ffi/crashtracker-collector,datadog-profiling-ffi/demangler --target x86_64-pc-windows-msvc --target-dir $output_dir } +Invoke-Call -ScriptBlock { cargo build --features data-pipeline-ffi,datadog-profiling-ffi/ddtelemetry-ffi,datadog-profiling-ffi/crashtracker-receiver,datadog-profiling-ffi/crashtracker-collector,datadog-profiling-ffi/demangler --target aarch64-apple-darwin --release --target-dir $output_dir } +Invoke-Call -ScriptBlock { cargo build --features data-pipeline-ffi,datadog-profiling-ffi/ddtelemetry-ffi,datadog-profiling-ffi/crashtracker-receiver,datadog-profiling-ffi/crashtracker-collector,datadog-profiling-ffi/demangler --target aarch64-apple-darwin --target-dir $output_dir } +Invoke-Call -ScriptBlock { cargo build --features data-pipeline-ffi,datadog-profiling-ffi/ddtelemetry-ffi,datadog-profiling-ffi/crashtracker-receiver,datadog-profiling-ffi/crashtracker-collector,datadog-profiling-ffi/demangler --target i686-pc-windows-msvc --release --target-dir $output_dir } +Invoke-Call -ScriptBlock { cargo build --features data-pipeline-ffi,datadog-profiling-ffi/ddtelemetry-ffi,datadog-profiling-ffi/crashtracker-receiver,datadog-profiling-ffi/crashtracker-collector,datadog-profiling-ffi/demangler --target i686-pc-windows-msvc --target-dir $output_dir } +Invoke-Call -ScriptBlock { cargo build --features data-pipeline-ffi,datadog-profiling-ffi/ddtelemetry-ffi,datadog-profiling-ffi/crashtracker-receiver,datadog-profiling-ffi/crashtracker-collector,datadog-profiling-ffi/demangler --target x86_64-pc-windows-msvc --release --target-dir $output_dir } +Invoke-Call -ScriptBlock { cargo build --features data-pipeline-ffi,datadog-profiling-ffi/ddtelemetry-ffi,datadog-profiling-ffi/crashtracker-receiver,datadog-profiling-ffi/crashtracker-collector,datadog-profiling-ffi/demangler --target x86_64-pc-windows-msvc --target-dir $output_dir } popd Write-Host "Building tools" -ForegroundColor Magenta diff --git a/windows/build/build.ps1 b/windows/build/build.ps1 new file mode 100644 index 0000000000..f5eaea142a --- /dev/null +++ b/windows/build/build.ps1 @@ -0,0 +1,109 @@ +param ( + [string]$output_dir, + [string[]]$targets = @( + # "aarch64-apple-darwin" + # "x86_64-apple-darwin" + # "aarch64-unknown-linux-gnu", + # "x86_64-unknown-linux-gnu" + "i686-pc-windows-msvc", + "x86_64-pc-windows-msvc" + ) +) + +# Check if output directory is set +if (-not $output_dir) { + Write-Host "You must specify an output directory with -output. Example: .\build_script.ps1 -output bin" + exit 1 +} + +# Make output_dir an absolute path if it's not already +if (-not [System.IO.Path]::IsPathRooted($output_dir)) { + $output_dir = Join-Path -Path (Get-Location) -ChildPath $output_dir +} + +Write-Host "Building project into $output_dir" -ForegroundColor Magenta + +# Function to invoke a command and exit if it fails +function Invoke-Call { + param ( + [scriptblock]$ScriptBlock + ) + & $ScriptBlock + if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE + } +} + +# Function to build project with given target, features, and release flag +function Build-Project { + param ( + [string]$target, + [bool]$release = $false + ) + + Invoke-Call -ScriptBlock { + $featues = @( + "data-pipeline-ffi", + "datadog-profiling-ffi/ddtelemetry-ffi", + "datadog-profiling-ffi/crashtracker-receiver", + "datadog-profiling-ffi/crashtracker-collector", + "datadog-profiling-ffi/demangler" + ) + + # cargo has a bug when passing "" as configuration, so branch for debug and release + if ($release) { + cargo build --features $($featues -join ",") --target $target --release --target-dir $output_dir + } else { + cargo build --features $($featues -join ",") --target $target --target-dir $output_dir + } + } +} + +# Function to generate header files using cbindgen +function Generate-Header { + param ( + [string]$crateName, + [string]$configPath, + [string]$outputPath + ) + + Invoke-Call -ScriptBlock { + cbindgen --crate $crateName --config $configPath --output $outputPath + } +} + +# Build project for multiple targets + +try { + Push-Location "profiling-ffi" + foreach ($target in $targets) { + Build-Project -target $target -release $true + Build-Project -target $target + } +} +finally { + Pop-Location +} + +Write-Host "Building tools" -ForegroundColor Magenta +try { + Push-Location "tools" + Invoke-Call -ScriptBlock { cargo build --release } +} +finally { + Pop-Location +} + +Write-Host "Generating headers" -ForegroundColor Magenta + +# Generate headers for each FFI crate +Generate-Header -crateName "ddcommon-ffi" -configPath "ddcommon-ffi/cbindgen.toml" -outputPath "$output_dir\common.h" +Generate-Header -crateName "datadog-profiling-ffi" -configPath "profiling-ffi/cbindgen.toml" -outputPath "$output_dir\profiling.h" +Generate-Header -crateName "ddtelemetry-ffi" -configPath "ddtelemetry-ffi/cbindgen.toml" -outputPath "$output_dir\telemetry.h" +Generate-Header -crateName "data-pipeline-ffi" -configPath "data-pipeline-ffi/cbindgen.toml" -outputPath "$output_dir\data-pipeline.h" +Generate-Header -crateName "datadog-crashtracker-ffi" -configPath "crashtracker-ffi/cbindgen.toml" -outputPath "$output_dir\crashtracker.h" + +# Deduplicate headers +Invoke-Call -ScriptBlock { .\target\release\dedup_headers "$output_dir\common.h" "$output_dir\profiling.h" "$output_dir\telemetry.h" "$output_dir\data-pipeline.h" "$output_dir\crashtracker.h" } + +Write-Host "Build finished" -ForegroundColor Magenta diff --git a/windows/build/build.sh b/windows/build/build.sh new file mode 100755 index 0000000000..5d53983acc --- /dev/null +++ b/windows/build/build.sh @@ -0,0 +1,115 @@ +#!/bin/bash + +# Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ +# SPDX-License-Identifier: Apache-2.0 + +# Default values +output_dir="" +targets=( + # Uncomment or add targets as needed + "aarch64-apple-darwin" + "x86_64-apple-darwin" + # "aarch64-unknown-linux-gnu" + # "x86_64-unknown-linux-gnu" + # "i686-pc-windows-msvc" + # "x86_64-pc-windows-msvc" +) + +# Parse named parameters +while [[ "$#" -gt 0 ]]; do + case "$1" in + -o|--output) + output_dir="$2" + shift 2 + ;; + -t|--target) + targets=() + shift + while [[ "$1" && ! "$1" =~ ^- ]]; do + targets+=("$1") + shift + done + ;; + *) + echo "Unknown parameter: $1" + exit 1 + ;; + esac +done + +# Check if output directory is set +if [ -z "$output_dir" ]; then + echo "You must specify an output directory with -o or --output. Example: ./build_script.sh -o bin" + exit 1 +fi + +# Make output_dir an absolute path if it's not already +if [[ "$output_dir" != /* ]]; then + output_dir="$(pwd)/$output_dir" +fi + +echo -e "Building project into $output_dir" + +# Function to invoke a command and exit if it fails +invoke_call() { + "$@" + if [ $? -ne 0 ]; then + exit $? + fi +} + +# Function to build project with given target, features, and release flag +build_project() { + local target="$1" + local release_flag="$2" + + features=( + "data-pipeline-ffi" + "datadog-profiling-ffi/ddtelemetry-ffi" + "datadog-profiling-ffi/crashtracker-receiver" + "datadog-profiling-ffi/crashtracker-collector" + "datadog-profiling-ffi/demangler" + ) + + if [ "$release_flag" = "--release" ]; then + invoke_call cargo build --features "$(IFS=,; echo "${features[*]}")" --target "$target" --release --target-dir "$output_dir" + else + invoke_call cargo build --features "$(IFS=,; echo "${features[*]}")" --target "$target" --target-dir "$output_dir" + fi +} + +# Function to generate header files using cbindgen +generate_header() { + local crate_name="$1" + local config_path="$2" + local output_path="$3" + + invoke_call cbindgen --crate "$crate_name" --config "$config_path" --output "$output_path" +} + +# Build project for multiple targets +pushd profiling-ffi || exit +for target in "${targets[@]}"; do + build_project "$target" "--release" + build_project "$target" "" +done +popd || exit + +echo -e "Building tools" +pushd tools || exit +invoke_call cargo build --release +popd || exit + +echo -e "Generating headers" + +# Generate headers for each FFI crate +generate_header "ddcommon-ffi" "ddcommon-ffi/cbindgen.toml" "$output_dir/common.h" +generate_header "datadog-profiling-ffi" "profiling-ffi/cbindgen.toml" "$output_dir/profiling.h" +generate_header "ddtelemetry-ffi" "ddtelemetry-ffi/cbindgen.toml" "$output_dir/telemetry.h" +generate_header "data-pipeline-ffi" "data-pipeline-ffi/cbindgen.toml" "$output_dir/data-pipeline.h" +generate_header "datadog-crashtracker-ffi" "crashtracker-ffi/cbindgen.toml" "$output_dir/crashtracker.h" + +# Deduplicate headers +invoke_call ./target/release/dedup_headers "$output_dir/common.h" "$output_dir/profiling.h" "$output_dir/telemetry.h" "$output_dir/data-pipeline.h" "$output_dir/crashtracker.h" + +echo -e "Build finished" diff --git a/windows/libdatadog.csproj b/windows/libdatadog.csproj index eb40afbe7e..ed28afef2c 100644 --- a/windows/libdatadog.csproj +++ b/windows/libdatadog.csproj @@ -1,4 +1,4 @@ - + net7.0 libdatadog @@ -13,57 +13,110 @@ false https://github.com/DataDog/libdatadog libdatadog provides a shared library containing common code used in the - implementation of Datadog's libraries, including Datadog Continuous Profilers + implementation of Datadog's libraries, including Datadog Continuous Profilers + Release of libdatadog Copyright 2022 Datadog, Inc. Datadog;native; + https://github.com/DataDog/libdatadog + $(RepositoryBranch) + $(RepositoryCommit) git + + + $(MSBuildThisFileDirectory)..\bin true + + + true + + + + true + + + + true + + + + x64 + + + + true + ARM64 + + + + true + ARM + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/windows/libdatadog.props b/windows/libdatadog.props deleted file mode 100644 index 973cb560bb..0000000000 --- a/windows/libdatadog.props +++ /dev/null @@ -1,24 +0,0 @@ - - - - x64 - x86 - - - - - - - @(LibdatadogLibs) - PowrProf.lib;NtDll.lib;UserEnv.lib;Bcrypt.lib;crypt32.lib;wsock32.lib;ws2_32.lib;shlwapi.lib;Secur32.lib;Ncrypt.lib - - - - $(MSBuildThisFileDirectory)..\..\include\native;%(AdditionalIncludeDirectories) - - - $(LibdatadogLibraries);$(LibdatadogDependencies);%(AdditionalDependencies) - - - diff --git a/windows/libdatadog.targets b/windows/libdatadog.targets new file mode 100644 index 0000000000..b8700842c2 --- /dev/null +++ b/windows/libdatadog.targets @@ -0,0 +1,59 @@ + + + + true + + + + true + + + + true + + + + x86 + + + + x64 + + + + ARM64 + + + + ARM + + + + + datadog_profiling_ffi.dll + Always + + + + + + datadog_profiling_ffi.dll + Always + + + + + + datadog_profiling_ffi.dylib + Always + + + + + + datadog_profiling_ffi.dylib + Always + + +