|
| 1 | +param( |
| 2 | + [switch]$Clean, |
| 3 | + [string]$OutputDir = (Get-Location), |
| 4 | + [string]$Version = "14.1.0" |
| 5 | +) |
| 6 | + |
| 7 | +$ErrorActionPreference = "Stop" |
| 8 | + |
| 9 | +$Artifacts = @( |
| 10 | + "libdatadog-aarch64-alpine-linux-musl.tar.gz", |
| 11 | + "libdatadog-aarch64-apple-darwin.tar.gz", |
| 12 | + "libdatadog-aarch64-unknown-linux-gnu.tar.gz", |
| 13 | + "libdatadog-x86_64-alpine-linux-musl.tar.gz", |
| 14 | + "libdatadog-x86_64-unknown-linux-gnu.tar.gz" |
| 15 | +) |
| 16 | + |
| 17 | +function Prepare-OutputDir { |
| 18 | + if (-Not (Test-Path -Path $OutputDir)) { |
| 19 | + Write-Host "Output directory $OutputDir does not exist" |
| 20 | + New-Item -ItemType Directory -Path $OutputDir | Out-Null |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +function Download-Artifacts { |
| 25 | + New-Item -ItemType Directory -Path "releases" -Force | Out-Null |
| 26 | + foreach ($Artifact in $Artifacts) { |
| 27 | + $Url = "https://github.com/DataDog/libdatadog/releases/download/v$Version/$Artifact" |
| 28 | + Write-Host "Downloading $Url to releases/$Artifact" |
| 29 | + Invoke-WebRequest -Uri $Url -OutFile "releases/$Artifact" -UseBasicParsing |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +function Extract-Artifacts { |
| 34 | + foreach ($Artifact in $Artifacts) { |
| 35 | + Write-Host "Extracting releases/$Artifact" |
| 36 | + tar -xzf "releases/$Artifact" -C "releases" |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +function Copy-ToBin { |
| 41 | + Write-Host "Copying to runtimes" |
| 42 | + |
| 43 | + # ARM64 Linux musl |
| 44 | + New-Item -ItemType Directory -Path "runtimes/linux-musl-arm64/native" -Force | Out-Null |
| 45 | + Copy-Item "releases/libdatadog-aarch64-alpine-linux-musl/lib/libdatadog_profiling.so" "runtimes/linux-musl-arm64/native/libdatadog_profiling.so" |
| 46 | + Copy-Item "releases/libdatadog-aarch64-alpine-linux-musl/lib/libdatadog_profiling.so" "runtimes/linux-musl-arm64/native/libdatadog_profiling.debug.so" |
| 47 | + |
| 48 | + # ARM64 macOS |
| 49 | + New-Item -ItemType Directory -Path "runtimes/osx-arm64/native" -Force | Out-Null |
| 50 | + Copy-Item "releases/libdatadog-aarch64-apple-darwin/lib/libdatadog_profiling.dylib" "runtimes/osx-arm64/native/libdatadog_profiling.dylib" |
| 51 | + |
| 52 | + # ARM64 Linux |
| 53 | + New-Item -ItemType Directory -Path "runtimes/linux-arm64/native" -Force | Out-Null |
| 54 | + Copy-Item "releases/libdatadog-aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so" "runtimes/linux-arm64/native/libdatadog_profiling.so" |
| 55 | + Copy-Item "releases/libdatadog-aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so" "runtimes/linux-arm64/native/libdatadog_profiling.debug.so" |
| 56 | + |
| 57 | + # x64 Linux musl |
| 58 | + New-Item -ItemType Directory -Path "runtimes/linux-musl-x64/native" -Force | Out-Null |
| 59 | + Copy-Item "releases/libdatadog-x86_64-alpine-linux-musl/lib/libdatadog_profiling.so" "runtimes/linux-musl-x64/native/libdatadog_profiling.so" |
| 60 | + Copy-Item "releases/libdatadog-x86_64-alpine-linux-musl/lib/libdatadog_profiling.so" "runtimes/linux-musl-x64/native/libdatadog_profiling.debug.so" |
| 61 | + |
| 62 | + # x64 Linux |
| 63 | + New-Item -ItemType Directory -Path "runtimes/linux-x64/native" -Force | Out-Null |
| 64 | + Copy-Item "releases/libdatadog-x86_64-unknown-linux-gnu/lib/libdatadog_profiling.so" "runtimes/linux-x64/native/libdatadog_profiling.so" |
| 65 | + Copy-Item "releases/libdatadog-x86_64-unknown-linux-gnu/lib/libdatadog_profiling.so" "runtimes/linux-x64/native/libdatadog_profiling.debug.so" |
| 66 | +} |
| 67 | + |
| 68 | +function Copy-Headers { |
| 69 | + Write-Host "Copying headers" |
| 70 | + Copy-Item -Recurse -Force "releases/libdatadog-aarch64-alpine-linux-musl/include/datadog" "include/datadog" |
| 71 | +} |
| 72 | + |
| 73 | +function Download-WindowsArtifacts { |
| 74 | + $Url = "https://globalcdn.nuget.org/packages/libdatadog.$Version.nupkg?packageVersion=$Version" |
| 75 | + Write-Host "Downloading $Url to releases/libdatadog.$Version.nupkg" |
| 76 | + Invoke-WebRequest -Uri $Url -OutFile "releases/libdatadog.$Version.nupkg" -UseBasicParsing |
| 77 | + |
| 78 | + Write-Host "Extracting releases/libdatadog.$Version.nupkg" |
| 79 | + Expand-Archive -Path "releases/libdatadog.$Version.nupkg" -DestinationPath "releases/libdatadog.$Version" -Force |
| 80 | +} |
| 81 | + |
| 82 | +function Copy-WindowsArtifacts { |
| 83 | + Write-Host "Copying to runtimes" |
| 84 | + |
| 85 | + # Windows x64 dlls for dynamic linking |
| 86 | + New-Item -ItemType Directory -Path "runtimes/win-x64/native" -Force | Out-Null |
| 87 | + Copy-Item "releases/libdatadog.$Version/build/native/lib/x64/release/datadog_profiling_ffi.dll" "runtimes/win-x64/native/libdatadog_profiling.dll" |
| 88 | + Copy-Item "releases/libdatadog.$Version/build/native/lib/x64/release/datadog_profiling_ffi.lpdb/datadog_profiling_ffi.pdb" "runtimes/win-x64/native/libdatadog_profiling.pdb" |
| 89 | + |
| 90 | + # Windows x86 dlls for dynamic linking |
| 91 | + New-Item -ItemType Directory -Path "runtimes/win-x86/native" -Force | Out-Null |
| 92 | + Copy-Item "releases/libdatadog.$Version/build/native/lib/x86/release/datadog_profiling_ffi.dll" "runtimes/win-x86/native/libdatadog_profiling.dll" |
| 93 | + Copy-Item "releases/libdatadog.$Version/build/native/lib/x86/release/datadog_profiling_ffi.pdb" "runtimes/win-x86/native/libdatadog_profiling.pdb" |
| 94 | + |
| 95 | + # Windows x64 dlls for static linking |
| 96 | + New-Item -ItemType Directory -Path "lib/win-x64/native" -Force | Out-Null |
| 97 | + Copy-Item "releases/libdatadog.$Version/build/native/lib/x64/release/datadog_profiling_ffi.lib" "lib/win-x64/native/libdatadog_profiling.lib" |
| 98 | + |
| 99 | + # Windows x86 dlls for static linking |
| 100 | + New-Item -ItemType Directory -Path "lib/win-x86/native" -Force | Out-Null |
| 101 | + Copy-Item "releases/libdatadog.$Version/build/native/lib/x86/release/datadog_profiling_ffi.lib" "lib/win-x86/native/libdatadog_profiling.lib" |
| 102 | +} |
| 103 | + |
| 104 | +function Create-NuGetPackage { |
| 105 | + Write-Host "Creating NuGet package at $OutputDir" |
| 106 | + dotnet pack "libdatadog.csproj" --output $OutputDir -p:Version=$Version |
| 107 | +} |
| 108 | + |
| 109 | +function Clean-Up { |
| 110 | + if ($Clean) { |
| 111 | + Write-Host "Cleaning up local files" |
| 112 | + $dir_to_remove = @("releases", "include", "runtimes", "lib", "~/.nuget/packages/libdatadog") |
| 113 | + |
| 114 | + foreach ($dir in $dir_to_remove) { |
| 115 | + if (Test-Path -Path $dir) { |
| 116 | + Write-Host "Removing $dir" |
| 117 | + Remove-Item -Recurse -Force $dir | Out-Null |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +# Main Script Execution |
| 124 | +Clean-Up |
| 125 | +Prepare-OutputDir |
| 126 | +Download-Artifacts |
| 127 | +Extract-Artifacts |
| 128 | +Copy-ToBin |
| 129 | +Copy-Headers |
| 130 | +Download-WindowsArtifacts |
| 131 | +Copy-WindowsArtifacts |
| 132 | +Create-NuGetPackage |
| 133 | +Clean-Up |
0 commit comments