Skip to content

Commit 9f19104

Browse files
authored
Merge pull request #783 from dotnet/NativeAOT
Assert that the library is NativeAOT-friendly
2 parents ac0a32b + 89de3ca commit 9f19104

File tree

11 files changed

+351
-4
lines changed

11 files changed

+351
-4
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<AnalysisLevel>latest</AnalysisLevel>
1212
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1313
<GenerateDocumentationFile>true</GenerateDocumentationFile>
14-
<DefineConstants Condition=" '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'net6.0' ">$(DefineConstants);SPAN_BUILTIN</DefineConstants>
14+
<DefineConstants Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netstandard2.1'))">$(DefineConstants);SPAN_BUILTIN</DefineConstants>
1515
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1616
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
1717

azure-pipelines/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
- template: dotnet.yml
2828
parameters:
2929
RunTests: ${{ parameters.RunTests }}
30+
osRID: win
3031
- template: node.yml
3132
- template: collect-artifacts.yml
3233
parameters:
@@ -45,6 +46,7 @@ jobs:
4546
- template: dotnet.yml
4647
parameters:
4748
RunTests: ${{ parameters.RunTests }}
49+
osRID: linux
4850
- script: dotnet format --verify-no-changes --no-restore
4951
displayName: 💅 Verify formatted code
5052
- template: node.yml
@@ -65,6 +67,7 @@ jobs:
6567
- template: dotnet.yml
6668
parameters:
6769
RunTests: ${{ parameters.RunTests }}
70+
osRID: osx
6871
- template: node.yml
6972
- template: collect-artifacts.yml
7073
parameters:

azure-pipelines/dotnet.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
parameters:
2-
RunTests:
2+
- name: RunTests
3+
type: boolean
4+
- name: osRID
5+
type: string
36

47
steps:
58

@@ -9,3 +12,7 @@ steps:
912
- powershell: azure-pipelines/dotnet-test-cloud.ps1 -Configuration $(BuildConfiguration) -Agent $(Agent.JobName) -PublishResults
1013
displayName: 🧪 dotnet test
1114
condition: and(succeeded(), ${{ parameters.RunTests }})
15+
16+
- script: dotnet publish -c Release -r ${{ parameters.osRID }}-x64 -warnaserror
17+
displayName: 🧪 NativeAOT test
18+
workingDirectory: test/NativeAOTCompatibility

ext/.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ dotnet_analyzer_diagnostic.severity = none
55

66
[*.cs]
77
dotnet_diagnostic.DOC104.severity = silent
8+
dotnet_diagnostic.SYSLIB0051.severity = silent # Type or member is obsolete

src/Nerdbank.Streams/MultiplexingProtocolException.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Nerdbank.Streams
88
/// <summary>
99
/// An exception that is thrown when an error occurs on the remote side of a multiplexed connection.
1010
/// </summary>
11-
[System.Serializable]
11+
[Serializable]
1212
public class MultiplexingProtocolException : Exception
1313
{
1414
/// <summary>
@@ -44,7 +44,9 @@ public MultiplexingProtocolException(string? message, Exception? inner)
4444
/// <param name="info">The serialization info.</param>
4545
/// <param name="context">The serialization context.</param>
4646
protected MultiplexingProtocolException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
47+
#pragma warning disable SYSLIB0051 // Type or member is obsolete
4748
: base(info, context)
49+
#pragma warning restore SYSLIB0051 // Type or member is obsolete
4850
{
4951
}
5052
}

src/Nerdbank.Streams/MultiplexingStream.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,11 @@ public async ValueTask DisposeAsync()
671671
return;
672672
}
673673

674+
#if NET8_0_OR_GREATER
675+
await this.disposalTokenSource.CancelAsync().ConfigureAwait(false);
676+
#else
674677
this.disposalTokenSource.Cancel();
678+
#endif
675679
try
676680
{
677681
if (this.TraceSource.Switch.ShouldTrace(TraceEventType.Information))

src/Nerdbank.Streams/Nerdbank.Streams.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net6.0;netstandard2.0;netstandard2.1</TargetFrameworks>
3+
<TargetFrameworks>net8.0;net6.0;netstandard2.0;netstandard2.1</TargetFrameworks>
44
<DefineConstants>$(DefineConstants);MESSAGEPACK_INTERNAL;CSHARP8</DefineConstants>
55

66
<Summary>Streams for full duplex in-proc communication, wrap a WebSocket, split a stream into multiple channels, etc.</Summary>
77
<Description>$(Summary)</Description>
88
<PackageTags>Stream full-duplex websocket multiplexing</PackageTags>
9+
<!-- Enable warnings regarding AOT compatibility. Learn more about testing strategies at https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/ -->
10+
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</IsAotCompatible>
911
</PropertyGroup>
1012

1113
<ItemGroup>

src/Nerdbank.Streams/net8.0/PublicAPI.Shipped.txt

Lines changed: 305 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
static Nerdbank.Streams.PipeExtensions.UseUtf8TextPipe(this System.Net.WebSockets.WebSocket! webSocket, int sizeHint = 0, System.IO.Pipelines.PipeOptions? pipeOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.IO.Pipelines.IDuplexPipe!
2+
static Nerdbank.Streams.PipeExtensions.UseUtf8TextPipeWriter(this System.Net.WebSockets.WebSocket! webSocket, System.IO.Pipelines.PipeOptions? pipeOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.IO.Pipelines.PipeWriter!
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<PublishAot>true</PublishAot>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\src\Nerdbank.Streams\Nerdbank.Streams.csproj" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<TrimmerRootAssembly Include="Nerdbank.Streams" />
15+
</ItemGroup>
16+
17+
</Project>

0 commit comments

Comments
 (0)