Skip to content

Commit a47efe0

Browse files
committed
wip: build shared sentry-native on windows
1 parent b6d0c37 commit a47efe0

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ jobs:
4545
- uses: actions/cache@v4
4646
id: cache
4747
with:
48-
path: src/Sentry/Platforms/Native/sentry-native
48+
path: |
49+
src/Sentry/Platforms/Native/sentry-native
50+
src/Sentry/Platforms/Native/runtimes
4951
key: sentry-native-${{ matrix.target || runner.os }}-${{ hashFiles('scripts/build-sentry-native.ps1') }}-${{ hashFiles('.git/modules/modules/sentry-native/HEAD') }}
5052
enableCrossOsArchive: true
5153

@@ -138,7 +140,9 @@ jobs:
138140
if: ${{ (env.CI_PUBLISHING_BUILD == 'true') || (runner.os == 'Windows' && runner.arch == 'X64') }}
139141
uses: actions/cache/restore@v4
140142
with:
141-
path: src/Sentry/Platforms/Native/sentry-native
143+
path: |
144+
src/Sentry/Platforms/Native/sentry-native
145+
src/Sentry/Platforms/Native/runtimes
142146
key: sentry-native-Windows-${{ hashFiles('scripts/build-sentry-native.ps1') }}-${{ hashFiles('.git/modules/modules/sentry-native/HEAD') }}
143147
fail-on-cache-miss: true
144148
enableCrossOsArchive: true
@@ -147,7 +151,9 @@ jobs:
147151
if: ${{ (env.CI_PUBLISHING_BUILD == 'true') || (runner.os == 'Windows' && runner.arch == 'ARM64') }}
148152
uses: actions/cache/restore@v4
149153
with:
150-
path: src/Sentry/Platforms/Native/sentry-native
154+
path: |
155+
src/Sentry/Platforms/Native/sentry-native
156+
src/Sentry/Platforms/Native/runtimes
151157
key: sentry-native-Windows-arm64-${{ hashFiles('scripts/build-sentry-native.ps1') }}-${{ hashFiles('.git/modules/modules/sentry-native/HEAD') }}
152158
fail-on-cache-miss: true
153159
enableCrossOsArchive: true

scripts/build-sentry-native.ps1

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ param([switch] $Clean)
22
Set-StrictMode -Version Latest
33
$ErrorActionPreference = "Stop"
44

5-
Push-Location $PSScriptRoot/..
6-
try
5+
function Build-SentryNative
76
{
7+
param([switch] $Shared)
8+
89
$submodule = 'modules/sentry-native'
910
$outDir = 'src/Sentry/Platforms/Native/sentry-native'
10-
$buildDir = "$submodule/build"
11+
$buildDir = if ($Shared) { "$submodule/build-shared" } else { "$submodule/build" }
1112
$actualBuildDir = $buildDir
1213

1314
$additionalArgs = @()
@@ -24,15 +25,15 @@ try
2425
$additionalArgs += @('-C', 'src/Sentry/Platforms/Native/windows-config.cmake')
2526
$actualBuildDir = "$buildDir/RelWithDebInfo"
2627
$libPrefix = ''
27-
$libExtension = '.lib'
28+
$libExtension = if ($Shared) { '.dll' } else { '.lib' }
2829

2930
if ("Arm64".Equals([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()))
3031
{
31-
$outDir += '/win-arm64'
32+
$outDir += if ($Shared) { '/../runtimes/win-arm64/native' } else { '/win-arm64' }
3233
}
3334
else
3435
{
35-
$outDir += '/win-x64'
36+
$outDir += if ($Shared) { '/../runtimes/win-x64/native' } else { '/win-x64' }
3637
}
3738
}
3839
elseif ($IsLinux)
@@ -62,12 +63,16 @@ try
6263
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue $buildDir
6364
}
6465

66+
if (-not $Shared)
67+
{
68+
$additionalArgs += @('-D', 'SENTRY_BUILD_SHARED_LIBS=0')
69+
}
70+
6571
cmake `
6672
-S $submodule `
6773
-B $buildDir `
6874
-D CMAKE_BUILD_TYPE=RelWithDebInfo `
6975
-D SENTRY_SDK_NAME=sentry.native.dotnet `
70-
-D SENTRY_BUILD_SHARED_LIBS=0 `
7176
-D SENTRY_BACKEND=inproc `
7277
-D SENTRY_TRANSPORT=none `
7378
$additionalArgs
@@ -90,6 +95,16 @@ try
9095
# Touch the file to mark it as up-to-date for MSBuild
9196
(Get-Item $outFile).LastWriteTime = Get-Date
9297
}
98+
99+
Push-Location $PSScriptRoot/..
100+
try
101+
{
102+
Build-SentryNative
103+
if ($IsWindows)
104+
{
105+
Build-SentryNative -Shared
106+
}
107+
}
93108
finally
94109
{
95110
Pop-Location
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
sentry-native
2+
runtimes

src/Sentry/Platforms/Native/Sentry.Native.targets

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<SentryNativeBuildScript>../../scripts/build-sentry-native.ps1</SentryNativeBuildScript>
77
<SentryNativeBuildInputs>../../.git/modules/modules/sentry-native/HEAD;$(MSBuildThisFileDirectory)Sentry.Native.targets;$(SentryNativeBuildScript)</SentryNativeBuildInputs>
88
<SentryNativeOutputDirectory>$(MSBuildThisFileDirectory)sentry-native\</SentryNativeOutputDirectory>
9+
<SentryNativeRuntimeDirectory>$(MSBuildThisFileDirectory)runtimes\</SentryNativeRuntimeDirectory>
910
<!-- List of runtime identifiers: https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.NETCore.Platforms/src/runtime.json -->
1011
<NativeLibRelativePath-win-x64>win-x64</NativeLibRelativePath-win-x64>
1112
<SentryNativeOutputDirectory-win-x64>$(SentryNativeOutputDirectory)$(NativeLibRelativePath-win-x64)\</SentryNativeOutputDirectory-win-x64>
@@ -19,8 +20,14 @@
1920
<SentryNativeOutputDirectory-linux-arm64>$(SentryNativeOutputDirectory)$(NativeLibRelativePath-linux-arm64)\</SentryNativeOutputDirectory-linux-arm64>
2021
<NativeLibRelativePath-osx>osx</NativeLibRelativePath-osx>
2122
<SentryNativeOutputDirectory-osx>$(SentryNativeOutputDirectory)$(NativeLibRelativePath-osx)\</SentryNativeOutputDirectory-osx>
22-
<SentryNativeBuildOutputs Condition="'$(RuntimeIdentifier)' == 'win-x64'">$(SentryNativeOutputDirectory-win-x64)lib$(SentryNativeLibraryName).lib</SentryNativeBuildOutputs>
23-
<SentryNativeBuildOutputs Condition="'$(RuntimeIdentifier)' == 'win-arm64'">$(SentryNativeOutputDirectory-win-arm64)lib$(SentryNativeLibraryName).lib</SentryNativeBuildOutputs>
23+
<SentryNativeBuildOutputs Condition="'$(RuntimeIdentifier)' == 'win-x64'">
24+
$(SentryNativeOutputDirectory-win-x64)lib$(SentryNativeLibraryName).lib
25+
$(SentryNativeRuntimeDirectory)win-x64\native\lib$(SentryNativeLibraryName).dll
26+
</SentryNativeBuildOutputs>
27+
<SentryNativeBuildOutputs Condition="'$(RuntimeIdentifier)' == 'win-arm64'">
28+
$(SentryNativeOutputDirectory-win-arm64)lib$(SentryNativeLibraryName).lib
29+
$(SentryNativeRuntimeDirectory)win-arm64\native\lib$(SentryNativeLibraryName).dll
30+
</SentryNativeBuildOutputs>
2431
<SentryNativeBuildOutputs Condition="'$(RuntimeIdentifier)' == 'linux-x64'">$(SentryNativeOutputDirectory-linux-x64)lib$(SentryNativeLibraryName).a</SentryNativeBuildOutputs>
2532
<SentryNativeBuildOutputs Condition="'$(RuntimeIdentifier)' == 'linux-musl-x64'">$(SentryNativeOutputDirectory-linux-musl-x64)lib$(SentryNativeLibraryName).a</SentryNativeBuildOutputs>
2633
<SentryNativeBuildOutputs Condition="'$(RuntimeIdentifier)' == 'linux-arm64'">$(SentryNativeOutputDirectory-linux-arm64)lib$(SentryNativeLibraryName).a</SentryNativeBuildOutputs>
@@ -39,13 +46,27 @@
3946
<Pack>true</Pack>
4047
<PackagePath>\sentry-native\$(NativeLibRelativePath-win-x64)</PackagePath>
4148
</None>
49+
<None Include="$(SentryNativeRuntimeDirectory)win-x64\native\$(SentryNativeLibraryName).dll"
50+
Condition="'$(NETCoreSdkRuntimeIdentifier)' == 'win-x64' and ('$(TargetPlatformIdentifier)' == '' or '$(TargetPlatformIdentifier)' == 'windows')">
51+
<Pack>true</Pack>
52+
<PackagePath>\runtimes\win-x64\native</PackagePath>
53+
<Link>%(Filename)%(Extension)</Link>
54+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
55+
</None>
4256
</ItemGroup>
4357

4458
<ItemGroup Condition="'$(CI_PUBLISHING_BUILD)' == 'true' or '$(NETCoreSdkRuntimeIdentifier)' == 'win-arm64'">
4559
<None Include="$(SentryNativeOutputDirectory-win-arm64)$(SentryNativeLibraryName).lib">
4660
<Pack>true</Pack>
4761
<PackagePath>\sentry-native\$(NativeLibRelativePath-win-arm64)</PackagePath>
4862
</None>
63+
<None Include="$(SentryNativeRuntimeDirectory)win-arm64\native\$(SentryNativeLibraryName).dll"
64+
Condition="'$(NETCoreSdkRuntimeIdentifier)' == 'win-arm64' and ('$(TargetPlatformIdentifier)' == '' or '$(TargetPlatformIdentifier)' == 'windows')">
65+
<Pack>true</Pack>
66+
<PackagePath>\runtimes\win-arm64\native</PackagePath>
67+
<Link>%(Filename)%(Extension)</Link>
68+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
69+
</None>
4970
</ItemGroup>
5071

5172
<ItemGroup Condition="'$(CI_PUBLISHING_BUILD)' == 'true' or '$(NETCoreSdkRuntimeIdentifier)' == 'linux-x64'">
@@ -79,7 +100,9 @@
79100
<Target Name="CleanNativeSDK" BeforeTargets="CoreClean" Condition="'$(_SentryIsNet8OrGreater)' == 'true'">
80101
<Message Text="Inside Custom Clean" Importance="high"/>
81102
<RemoveDir Directories="$(SentryNativeOutputDirectory)" />
103+
<RemoveDir Directories="$(SentryNativeRuntimeDirectory)" />
82104
<RemoveDir Directories="$(SentryNativeSourceDirectory)build" />
105+
<RemoveDir Directories="$(SentryNativeSourceDirectory)build-shared" />
83106
</Target>
84107

85108
<!-- Build the Sentry Native SDK (this only runs on local machines because in CI we expect the SDK to be

0 commit comments

Comments
 (0)