-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: setup building nuget packages in CI
- Loading branch information
Showing
7 changed files
with
485 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
name: .NET | ||
|
||
jobs: | ||
windows-build: | ||
runs-on: windows-latest | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install rustup using win.rustup.rs | ||
run: | | ||
# disable download progress bar | ||
$ProgressPreference = "SilentlyContinue" | ||
Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe | ||
.\rustup-init.exe -y --default-host=x86_64-pc-windows-msvc --default-toolchain=none | ||
del rustup-init.exe | ||
rustup target add x86_64-pc-windows-msvc | ||
rustup target add i686-pc-windows-msvc | ||
shell: powershell | ||
|
||
- name: build | ||
run: | | ||
.\windows\build\build.ps1 -output_dir .\bin | ||
- name: Upload artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: windows-bin | ||
path: | | ||
bin/x86_64-pc-windows-msvc/*/datadog_profiling_ffi.dll | ||
bin/x86_64-pc-windows-msvc/*/datadog_profiling_ffi.lib | ||
bin/x86_64-pc-windows-msvc/*/datadog_profiling_ffi.pdb | ||
bin/i686-pc-windows-msvc/*/datadog_profiling_ffi.dll | ||
bin/i686-pc-windows-msvc/*/datadog_profiling_ffi.lib | ||
bin/i686-pc-windows-msvc/*/datadog_profiling_ffi.pdb | ||
if-no-files-found: error | ||
|
||
macos-build: | ||
runs-on: macos-latest | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install rustup using rustup.rs | ||
run: | | ||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
source $HOME/.cargo/env | ||
rustup target add x86_64-apple-darwin | ||
rustup target add aarch64-apple-darwin | ||
shell: bash | ||
|
||
- name: build | ||
run: | | ||
chmod +x ./windows/build/build.sh | ||
./windows/build/build.sh -o ./bin | ||
- name: Upload artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: macos-bin | ||
path: | | ||
bin/x86_64-apple-darwin/*/libdatadog_profiling_ffi.dylib | ||
bin/x86_64-apple-darwin/*/libdatadog_profiling_ffi.a | ||
bin/aarch64-apple-darwin/*/libdatadog_profiling_ffi.dylib | ||
bin/aarch64-apple-darwin/*/libdatadog_profiling_ffi.a | ||
if-no-files-found: error | ||
|
||
pack: | ||
runs-on: windows-latest | ||
needs: [windows-build, macos-build] | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Download Windows artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: windows-bin | ||
path: bin | ||
|
||
- name: Download mac artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: macos-bin | ||
path: bin | ||
|
||
- name: pack | ||
run: | | ||
dotnet pack .\windows\libdatadog.csproj -p:LibDatadogBinariesOutputDir=..\bin -p:LibDatadogVersion="42.0.0" -o .nuget\packages\ | ||
- name: store artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: packages | ||
path: .nuget/packages/* | ||
if-no-files-found: error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
Oops, something went wrong.