Skip to content

Commit e41eef6

Browse files
committed
custom matrix
1 parent adfdc47 commit e41eef6

File tree

6 files changed

+212
-11
lines changed

6 files changed

+212
-11
lines changed

.github/workflows/dotnet.yml

+122-7
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,33 @@ on:
88

99
name: .NET
1010

11+
env:
12+
OUTPUT_DIR: bin
13+
PACKAGES_DIR: packages
14+
1115
jobs:
1216
build:
1317
runs-on: ${{ matrix.os }}
1418

1519
strategy:
1620
matrix:
17-
os: [windows-latest, macos-latest, ubuntu-latest]
1821
include:
1922
- os: windows-latest
20-
target: [x86_64-pc-windows-msvc, i686-pc-windows-msvc]
23+
target: x86_64-pc-windows-msvc
24+
- os: windows-latest
25+
target: i686-pc-windows-msvc
2126
- os: macos-latest
22-
target: [x86_64-apple-darwin, arch64-apple-darwin]
27+
target: x86_64-apple-darwin
28+
- os: macos-latest
29+
target: aarch64-apple-darwin
2330
- os: ubuntu-latest
24-
target: [x86_64-alpine-linux-musl, aarch64-alpine-linux-musl, x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu]
31+
target: x86_64-unknown-linux-gnu
32+
# - os: ubuntu-latest
33+
# target: aarch64-unknown-linux-gnu
34+
# - os: ubuntu-latest
35+
# target: x86_64-alpine-linux-musl
36+
# - os: ubuntu-latest
37+
# target: aarch64-alpine-linux-musl
2538

2639
steps:
2740
- name: Checkout
@@ -32,7 +45,7 @@ jobs:
3245
run: |
3346
$ProgressPreference = "SilentlyContinue"
3447
Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe
35-
.\rustup-init.exe -y --default-host=${{ matrix.target }} --default-toolchain=none
48+
.\rustup-init.exe -y --default-host=${{ matrix.target }} --default-toolchain stable --profile minimal
3649
del rustup-init.exe
3750
rustup target add ${{ matrix.target }}
3851
shell: powershell
@@ -43,12 +56,114 @@ jobs:
4356
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
4457
source $HOME/.cargo/env
4558
rustup target add ${{ matrix.target }}
59+
cargo install cbindgen
4660
shell: bash
4761

4862
- name: Build
4963
if: matrix.os == 'windows-latest'
50-
run: ./windows/build-artifacts.ps1 bin
64+
run: ./windows/build-artifacts.ps1 ${{ env.OUTPUT_DIR }} ${{ matrix.target }}
65+
shell: pwsh
5166

5267
- name: Build
5368
if: matrix.os == 'macos-latest' || matrix.os == 'ubuntu-latest'
54-
run: ./build-profiling-ffi.sh
69+
run: ./windows/build-artifacts.sh ${{ env.OUTPUT_DIR }} ${{ matrix.target }}
70+
shell: bash
71+
72+
- name: Upload artifacts
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: ${{ env.OUTPUT_DIR }}-${{ matrix.target }}
76+
path: |
77+
bin/*
78+
!bin/*/*/build
79+
!bin/*/*/deps
80+
!bin/*/*/examples
81+
!bin/*/*/incremental
82+
!bin/*/*/.fingerprint
83+
!bin/debug
84+
!bin/release
85+
86+
pack:
87+
runs-on: windows-latest
88+
needs: build
89+
steps:
90+
- name: Checkout code
91+
uses: actions/checkout@v4
92+
93+
- name: Download x86_64-pc-windows-msvc
94+
uses: actions/download-artifact@v4
95+
with:
96+
name: ${{ env.OUTPUT_DIR }}-x86_64-pc-windows-msvc
97+
path: bin
98+
99+
- name: Download i686-pc-windows-msvc
100+
uses: actions/download-artifact@v4
101+
with:
102+
name: ${{ env.OUTPUT_DIR }}-i686-pc-windows-msvc
103+
path: bin
104+
105+
- name: Download x86_64-apple-darwin
106+
uses: actions/download-artifact@v4
107+
with:
108+
name: ${{ env.OUTPUT_DIR }}-x86_64-apple-darwin
109+
path: bin/x86_64-apple-darwin
110+
111+
- name: Download aarch64-apple-darwin
112+
uses: actions/download-artifact@v4
113+
with:
114+
name: ${{ env.OUTPUT_DIR }}-aarch64-apple-darwin
115+
path: bin/aarch64-apple-darwin
116+
117+
- name: Download x86_64-unknown-linux-gnu
118+
uses: actions/download-artifact@v4
119+
with:
120+
name: ${{ env.OUTPUT_DIR }}-x86_64-unknown-linux-gnu
121+
path: bin/x86_64-unknown-linux-gnu
122+
123+
- name: dotnet pack
124+
run: |
125+
$cargo_content=Get-Content Cargo.toml -Raw
126+
$cargo_content -match '(?m)^version += +"([^"]+)"'
127+
$current_version=$Matches[1]
128+
$version_suffix="ci.${{ github.event.number }}.${{ github.run_number }}"
129+
$version="$current_version-$version_suffix"
130+
echo "NUGET_VERSION=$version" >> "$GITHUB_OUTPUT"
131+
dotnet pack windows/libdatadog.csproj -p:LibDatadogBinariesOutputDir=../${{ env.OUTPUT_DIR }} -p:LibDatadogVersion=$version -o ${{ env.PACKAGES_DIR }}
132+
133+
- name: Upload package
134+
uses: actions/upload-artifact@v4
135+
with:
136+
name: ${{ env.PACKAGES_DIR }}
137+
path: ${{ env.PACKAGES_DIR }}
138+
139+
test:
140+
runs-on: ${{ matrix.os }}
141+
needs: pack
142+
143+
strategy:
144+
matrix:
145+
include:
146+
- os: windows-latest
147+
target: x86_64-pc-windows-msvc
148+
- os: windows-latest
149+
target: i686-pc-windows-msvc
150+
151+
steps:
152+
- name: Checkout code
153+
uses: actions/checkout@v4
154+
155+
- name: Download package
156+
uses: actions/download-artifact@v4
157+
with:
158+
name: ${{ env.PACKAGES_DIR }}
159+
160+
- name: Install .NET SDK
161+
uses: actions/setup-dotnet@v1
162+
with:
163+
dotnet-version: 7.0
164+
165+
- name: Run
166+
run: |
167+
cd tests/nuget_package
168+
dotnet add nuget_package.csproj package libdatadog --source local --version ${{ steps.pack.outputs.NUGET_VERSION }}
169+
dotnet run

nuget.config

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
5+
<clear />
6+
<add key="local" value="packages" />
7+
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
8+
</packageSources>
9+
</configuration>

tests/nuget_package/Program.cs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// See https://aka.ms/new-console-template for more information
2+
Console.WriteLine("Hello, World!");
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="libdatadog" Version="1.0.0-ci.1.1" />
12+
</ItemGroup>
13+
14+
</Project>

windows/build-artifacts.ps1

+10-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ function Invoke-Call {
99
}
1010

1111
$output_dir = $args[0]
12+
$target = $args[1]
1213

1314
if ([string]::IsNullOrEmpty($output_dir)) {
1415
throw "You must specify an output directory. Ex: $($myInvocation.InvocationName) my_rust_project/ bin"
1516
}
1617

18+
$targets = @("i686-pc-windows-msvc", "x86_64-pc-windows-msvc")
19+
if (![string]::IsNullOrEmpty($target)) {
20+
$targets = @($target)
21+
}
22+
1723
if (![System.IO.Path]::IsPathRooted($output_dir)) {
1824
$output_dir = [System.IO.Path]::Combine($(Get-Location), $output_dir)
1925
}
@@ -32,10 +38,10 @@ $features = @(
3238
Write-Host "Building for features: $features" -ForegroundColor Magenta
3339

3440
pushd profiling-ffi
35-
Invoke-Call -ScriptBlock { cargo build --features $features --target i686-pc-windows-msvc --release --target-dir $output_dir }
36-
Invoke-Call -ScriptBlock { cargo build --features $features --target i686-pc-windows-msvc --target-dir $output_dir }
37-
Invoke-Call -ScriptBlock { cargo build --features $features --target x86_64-pc-windows-msvc --release --target-dir $output_dir }
38-
Invoke-Call -ScriptBlock { cargo build --features $features --target x86_64-pc-windows-msvc --target-dir $output_dir }
41+
foreach ($target in $targets) {
42+
Invoke-Call -ScriptBlock { cargo build --features $features --target $target --release --target-dir $output_dir }
43+
Invoke-Call -ScriptBlock { cargo build --features $features --target $target --target-dir $output_dir }
44+
}
3945
popd
4046

4147
Write-Host "Building tools" -ForegroundColor Magenta

windows/build-artifacts.sh

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
output_dir=$1
6+
target=$2
7+
8+
if [[ -z "$output_dir" ]]; then
9+
echo "You must specify an output directory. Ex: $(basename $0) my_rust_project/ bin"
10+
exit 1
11+
fi
12+
13+
targets=("i686-pc-windows-msvc" "x86_64-pc-windows-msvc")
14+
if [[ -n "$target" ]]; then
15+
targets=("$target")
16+
fi
17+
18+
if [[ ! "$output_dir" = /* ]]; then
19+
output_dir=$(pwd)/"$output_dir"
20+
fi
21+
22+
echo -e "Building project into $output_dir"
23+
24+
features=(
25+
"cbindgen"
26+
"crashtracker-collector"
27+
"crashtracker-receiver"
28+
"data-pipeline-ffi"
29+
"datadog-profiling-ffi/ddtelemetry-ffi"
30+
"datadog-profiling-ffi/demangler"
31+
)
32+
features=$(IFS=, ; echo "${features[*]}")
33+
echo -e "Building for features: $features"
34+
35+
pushd profiling-ffi > /dev/null
36+
for target in "${targets[@]}"; do
37+
cargo build --features "$features" --target "$target" --release --target-dir "$output_dir"
38+
cargo build --features "$features" --target "$target" --target-dir "$output_dir"
39+
done
40+
popd > /dev/null
41+
42+
echo -e "Building tools"
43+
cd tools
44+
cargo build --release
45+
cd ..
46+
47+
echo -e "Generating headers"
48+
cbindgen --crate ddcommon-ffi --config ddcommon-ffi/cbindgen.toml --output "$output_dir/common.h"
49+
cbindgen --crate datadog-profiling-ffi --config profiling-ffi/cbindgen.toml --output "$output_dir/profiling.h"
50+
cbindgen --crate ddtelemetry-ffi --config ddtelemetry-ffi/cbindgen.toml --output "$output_dir/telemetry.h"
51+
cbindgen --crate data-pipeline-ffi --config data-pipeline-ffi/cbindgen.toml --output "$output_dir/data-pipeline.h"
52+
cbindgen --crate datadog-crashtracker-ffi --config crashtracker-ffi/cbindgen.toml --output "$output_dir/crashtracker.h"
53+
./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"
54+
55+
echo -e "Build finished"

0 commit comments

Comments
 (0)