|
1 | 1 | # Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/ |
2 | 2 | # SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | | -# Build and run the CXX crashinfo example on Windows |
5 | | -$ErrorActionPreference = "Stop" |
6 | | - |
| 4 | +# Build and run the CXX crashinfo example |
7 | 5 | $SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path |
8 | | -$PROJECT_ROOT = (Get-Item (Join-Path $SCRIPT_DIR ".." "..")).FullName |
9 | | -Set-Location $PROJECT_ROOT |
10 | | - |
11 | | -Write-Host "🔨 Building libdd-crashtracker with cxx feature..." -ForegroundColor Cyan |
12 | | -cargo build -p libdd-crashtracker --features cxx --release |
13 | | - |
14 | | -Write-Host "🔍 Finding CXX bridge headers..." -ForegroundColor Cyan |
15 | | -$CXX_BRIDGE_INCLUDE = Get-ChildItem -Path "target\release\build\libdd-crashtracker-*\out\cxxbridge\include" -Directory -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName |
16 | | -$CXX_BRIDGE_CRATE = Get-ChildItem -Path "target\release\build\libdd-crashtracker-*\out\cxxbridge\crate" -Directory -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName |
17 | | -$RUST_CXX_INCLUDE = Get-ChildItem -Path "target\release\build\cxx-*\out" -Directory -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName |
18 | | - |
19 | | -if (-not $CXX_BRIDGE_INCLUDE -or -not $CXX_BRIDGE_CRATE -or -not $RUST_CXX_INCLUDE) { |
20 | | - Write-Host "❌ Error: Could not find CXX bridge directories" -ForegroundColor Red |
21 | | - exit 1 |
22 | | -} |
23 | | - |
24 | | -Write-Host "📁 CXX include: $CXX_BRIDGE_INCLUDE" -ForegroundColor Green |
25 | | -Write-Host "📁 CXX crate: $CXX_BRIDGE_CRATE" -ForegroundColor Green |
26 | | -Write-Host "📁 Rust CXX: $RUST_CXX_INCLUDE" -ForegroundColor Green |
27 | | - |
28 | | -# Check if we have MSVC (cl.exe) or MinGW (g++/clang++) |
29 | | -# Note: Prefer MSVC on Windows as it's the default Rust toolchain |
30 | | -$MSVC = Get-Command cl.exe -ErrorAction SilentlyContinue |
31 | | -$GPP = Get-Command g++.exe -ErrorAction SilentlyContinue |
32 | | -$CLANGPP = Get-Command clang++.exe -ErrorAction SilentlyContinue |
33 | | - |
34 | | -# Auto-detect which toolchain Rust used by checking which library exists |
35 | | -# Note: On Windows, Rust still uses 'lib' prefix even for MSVC .lib files |
36 | | -$HAS_MSVC_LIB = Test-Path (Join-Path $PROJECT_ROOT "target\release\libdd_crashtracker.lib") |
37 | | -$HAS_GNU_LIB = (Test-Path (Join-Path $PROJECT_ROOT "target\release\libdd_crashtracker.a")) -or ` |
38 | | - (Test-Path (Join-Path $PROJECT_ROOT "target\release\liblibdd_crashtracker.a")) |
39 | | - |
40 | | -if ($HAS_MSVC_LIB -and $MSVC) { |
41 | | - $USE_MSVC = $true |
42 | | - Write-Host "Detected MSVC Rust toolchain" -ForegroundColor Cyan |
43 | | -} elseif ($HAS_GNU_LIB -and ($GPP -or $CLANGPP)) { |
44 | | - $USE_MSVC = $false |
45 | | - Write-Host "Detected GNU Rust toolchain" -ForegroundColor Cyan |
46 | | -} elseif ($MSVC) { |
47 | | - $USE_MSVC = $true |
48 | | - Write-Host "Defaulting to MSVC (library not found yet, will check after)" -ForegroundColor Yellow |
49 | | -} elseif ($GPP -or $CLANGPP) { |
50 | | - $USE_MSVC = $false |
51 | | - Write-Host "Defaulting to GNU toolchain (library not found yet, will check after)" -ForegroundColor Yellow |
52 | | -} else { |
53 | | - Write-Host "❌ Error: No C++ compiler found. Please install MSVC (via Visual Studio) or MinGW/LLVM" -ForegroundColor Red |
54 | | - exit 1 |
55 | | -} |
56 | | - |
57 | | -Write-Host "🔨 Finding libraries..." -ForegroundColor Cyan |
58 | | -# Note: Rust library naming varies by platform and toolchain |
59 | | -if ($USE_MSVC) { |
60 | | - # MSVC: libdd_crashtracker.lib (Rust keeps the lib prefix even on Windows) |
61 | | - $CRASHTRACKER_LIB = Join-Path $PROJECT_ROOT "target\release\libdd_crashtracker.lib" |
62 | | - $CXX_BRIDGE_LIB = Get-ChildItem -Path "target\release\build\libdd-crashtracker-*\out" -Filter "libdd-crashtracker-cxx.lib" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName |
63 | | -} else { |
64 | | - # MinGW: Try both possible naming patterns |
65 | | - $CRASHTRACKER_LIB_1 = Join-Path $PROJECT_ROOT "target\release\libdd_crashtracker.a" |
66 | | - $CRASHTRACKER_LIB_2 = Join-Path $PROJECT_ROOT "target\release\liblibdd_crashtracker.a" |
67 | | - |
68 | | - if (Test-Path $CRASHTRACKER_LIB_1) { |
69 | | - $CRASHTRACKER_LIB = $CRASHTRACKER_LIB_1 |
70 | | - } elseif (Test-Path $CRASHTRACKER_LIB_2) { |
71 | | - $CRASHTRACKER_LIB = $CRASHTRACKER_LIB_2 |
72 | | - } else { |
73 | | - $CRASHTRACKER_LIB = $CRASHTRACKER_LIB_1 # Use this for error message |
74 | | - } |
75 | | - |
76 | | - # Try both naming patterns for CXX bridge |
77 | | - $CXX_BRIDGE_LIB = Get-ChildItem -Path "target\release\build\libdd-crashtracker-*\out" -Filter "libdd-crashtracker-cxx.a" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName |
78 | | - if (-not $CXX_BRIDGE_LIB) { |
79 | | - $CXX_BRIDGE_LIB = Get-ChildItem -Path "target\release\build\libdd-crashtracker-*\out" -Filter "liblibdd-crashtracker-cxx.a" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName |
80 | | - } |
81 | | -} |
82 | | - |
83 | | -if (-not (Test-Path $CRASHTRACKER_LIB)) { |
84 | | - Write-Host "❌ Error: Could not find libdd-crashtracker library at $CRASHTRACKER_LIB" -ForegroundColor Red |
85 | | - if (-not $MSVC) { |
86 | | - Write-Host "Searched for: libdd_crashtracker.a and liblibdd_crashtracker.a" -ForegroundColor Yellow |
87 | | - Write-Host "Files in target/release/:" -ForegroundColor Yellow |
88 | | - Get-ChildItem -Path "target\release" -Filter "*crashtracker*" | Select-Object -First 10 | ForEach-Object { Write-Host " $_" -ForegroundColor Gray } |
89 | | - } |
90 | | - exit 1 |
91 | | -} |
92 | | - |
93 | | -if (-not $CXX_BRIDGE_LIB) { |
94 | | - if ($USE_MSVC) { |
95 | | - Write-Host "❌ Error: Could not find CXX bridge library (looking for libdd-crashtracker-cxx.lib)" -ForegroundColor Red |
96 | | - } else { |
97 | | - Write-Host "❌ Error: Could not find CXX bridge library" -ForegroundColor Red |
98 | | - Write-Host "Searched for: libdd-crashtracker-cxx.a and liblibdd-crashtracker-cxx.a" -ForegroundColor Yellow |
99 | | - } |
100 | | - exit 1 |
101 | | -} |
102 | | - |
103 | | -Write-Host "📚 Crashtracker library: $CRASHTRACKER_LIB" -ForegroundColor Green |
104 | | -Write-Host "📚 CXX bridge library: $CXX_BRIDGE_LIB" -ForegroundColor Green |
105 | | - |
106 | | -Write-Host "🔨 Compiling C++ example..." -ForegroundColor Cyan |
107 | | - |
108 | | -if ($USE_MSVC) { |
109 | | - Write-Host "Using MSVC compiler" -ForegroundColor Yellow |
110 | | - |
111 | | - # MSVC compilation |
112 | | - cl.exe /std:c++20 /EHsc ` |
113 | | - /I"$CXX_BRIDGE_INCLUDE" ` |
114 | | - /I"$CXX_BRIDGE_CRATE" ` |
115 | | - /I"$RUST_CXX_INCLUDE" ` |
116 | | - /I"$PROJECT_ROOT" ` |
117 | | - examples\cxx\crashinfo.cpp ` |
118 | | - "$CRASHTRACKER_LIB" ` |
119 | | - "$CXX_BRIDGE_LIB" ` |
120 | | - ws2_32.lib advapi32.lib userenv.lib ntdll.lib bcrypt.lib ` |
121 | | - /Fe:examples\cxx\crashinfo.exe |
122 | | - |
123 | | - if ($LASTEXITCODE -ne 0) { |
124 | | - Write-Host "❌ Compilation failed" -ForegroundColor Red |
125 | | - exit 1 |
126 | | - } |
127 | | -} elseif ($GPP -or $CLANGPP) { |
128 | | - $COMPILER = if ($GPP) { "g++" } else { "clang++" } |
129 | | - Write-Host "Using $COMPILER compiler" -ForegroundColor Yellow |
130 | | - |
131 | | - # MinGW/Clang compilation - needs proper library ordering and Rust std lib |
132 | | - & $COMPILER -std=c++20 ` |
133 | | - -I"$CXX_BRIDGE_INCLUDE" ` |
134 | | - -I"$CXX_BRIDGE_CRATE" ` |
135 | | - -I"$RUST_CXX_INCLUDE" ` |
136 | | - -I"$PROJECT_ROOT" ` |
137 | | - examples/cxx/crashinfo.cpp ` |
138 | | - "$CXX_BRIDGE_LIB" ` |
139 | | - "$CRASHTRACKER_LIB" ` |
140 | | - -lws2_32 -ladvapi32 -luserenv -lntdll -lbcrypt -lgcc_eh -lpthread ` |
141 | | - -o examples/cxx/crashinfo.exe |
142 | | - |
143 | | - if ($LASTEXITCODE -ne 0) { |
144 | | - Write-Host "❌ Compilation failed" -ForegroundColor Red |
145 | | - exit 1 |
146 | | - } |
147 | | -} |
148 | | - |
149 | | -Write-Host "🚀 Running example..." -ForegroundColor Cyan |
150 | | -& ".\examples\cxx\crashinfo.exe" |
151 | | - |
152 | | -if ($LASTEXITCODE -ne 0) { |
153 | | - Write-Host "❌ Example failed with exit code $LASTEXITCODE" -ForegroundColor Red |
154 | | - exit 1 |
155 | | -} |
156 | | - |
157 | | -Write-Host "" |
158 | | -Write-Host "✅ Success!" -ForegroundColor Green |
159 | | - |
| 6 | +& "$SCRIPT_DIR\build-and-run.ps1" -CrateName "libdd-crashtracker" -ExampleName "crashinfo" |
| 7 | +exit $LASTEXITCODE |
0 commit comments