Skip to content

C#: add option and code generation for null reference types (#20242) #20561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions .github/workflows/test_csharp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ jobs:
cd csharp &&
dotnet restore src/Google.Protobuf.sln &&
dotnet build -c Release src/Google.Protobuf.sln &&
dotnet test -c Release -f net6.0 src/Google.Protobuf.Test/Google.Protobuf.Test.csproj"
dotnet test -c Release -f net6.0 src/Google.Protobuf.Test/Google.Protobuf.Test.csproj &&
dotnet test -c Release -f net8.0 src/Google.Protobuf.Test/Google.Protobuf.Test.csproj"

- name: Clear bazel between docker instances
run: sudo rm -rf _build .repository-cache
Expand All @@ -60,7 +61,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
with:
dotnet-version: '6.0.x'
dotnet-version: '8.0.x'

# Workaround for incompatibility between gcloud and windows-2019 runners.
- name: Install Python
Expand Down Expand Up @@ -94,15 +95,15 @@ jobs:
# (we want to avoid references to ~/.nuget that won't be available in the subsequent docker run)
uses: protocolbuffers/protobuf-ci/docker@v4
with:
image: mcr.microsoft.com/dotnet/sdk:6.0.100-bullseye-slim
image: mcr.microsoft.com/dotnet/sdk:8.0.100-bookworm-slim
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
command: >-
/bin/bash -cex '
DOTNET_CLI_TELEMETRY_OPTOUT=true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
dotnet publish -c Release -f net6.0 /workspace/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj'
dotnet publish -c Release /workspace/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj'

- name: Use an actual aarch64 docker image to run protobuf C# tests with an emulator
- name: Use an actual aarch64 docker image to run protobuf C# tests with an emulator (.NET 6)
# "dotnet vstest" allows running tests from a pre-built project.
# * mount the protobuf root as /work to be able to access the crosscompiled files
# * to avoid running the process inside docker as root (which can pollute the workspace with files owned by root), we force
Expand All @@ -119,3 +120,21 @@ jobs:
DOTNET_CLI_TELEMETRY_OPTOUT=true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
dotnet vstest /workspace/csharp/src/Google.Protobuf.Test/bin/Release/net6.0/publish/Google.Protobuf.Test.dll'

- name: Use an actual aarch64 docker image to run protobuf C# tests with an emulator (.NET 8)
# "dotnet vstest" allows running tests from a pre-built project.
# * mount the protobuf root as /work to be able to access the crosscompiled files
# * to avoid running the process inside docker as root (which can pollute the workspace with files owned by root), we force
# running under current user's UID and GID. To be able to do that, we need to provide a home directory for the user
# otherwise the UID would be homeless under the docker container and pip install wouldn't work. For simplicity,
# we just run map the user's home to a throwaway temporary directory
uses: protocolbuffers/protobuf-ci/docker@v4
with:
image: mcr.microsoft.com/dotnet/sdk:8.0.100-bookworm-slim-arm64v8
skip-staleness-check: true
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
command: >-
/bin/bash -cex '
DOTNET_CLI_TELEMETRY_OPTOUT=true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
dotnet vstest /workspace/csharp/src/Google.Protobuf.Test/bin/Release/net8.0/publish/Google.Protobuf.Test.dll'
35 changes: 35 additions & 0 deletions csharp/generate_protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \
src/google/protobuf/type.proto \
src/google/protobuf/wrappers.proto \
src/google/protobuf/compiler/plugin.proto
# We are NOT generating NRT variants for Google.Protobuf right now to avoid breaking/unexpected changes!

# Test protos
# Note that this deliberately does *not* include old_extensions1.proto
Expand Down Expand Up @@ -81,13 +82,47 @@ $PROTOC -Isrc -I. \
src/google/protobuf/unittest_legacy_features.proto \
src/google/protobuf/unittest_proto3_optional.proto \
src/google/protobuf/unittest_retention.proto
$PROTOC -Isrc -I. \
--experimental_allow_proto3_optional \
--experimental_editions \
--csharp_out=csharp/src/Google.Protobuf.Test.TestProtos/Nrt \
--csharp_opt=enable_nrt,file_extension=.pb.nrt.cs \
conformance/test_protos/test_messages_edition2023.proto \
csharp/protos/map_unittest_proto3.proto \
csharp/protos/unittest_issues.proto \
csharp/protos/unittest_custom_options_proto3.proto \
csharp/protos/unittest_proto3.proto \
csharp/protos/unittest_import_proto3.proto \
csharp/protos/unittest_import_public_proto3.proto \
csharp/protos/unittest.proto \
csharp/protos/unittest_import.proto \
csharp/protos/unittest_import_public.proto \
csharp/protos/unittest_issue6936_a.proto \
csharp/protos/unittest_issue6936_b.proto \
csharp/protos/unittest_issue6936_c.proto \
csharp/protos/unittest_selfreferential_options.proto \
editions/golden/test_messages_proto3_editions.proto \
editions/golden/test_messages_proto2_editions.proto \
src/google/protobuf/unittest_well_known_types.proto \
src/google/protobuf/test_messages_proto3.proto \
src/google/protobuf/test_messages_proto2.proto \
src/google/protobuf/unittest_features.proto \
src/google/protobuf/unittest_legacy_features.proto \
src/google/protobuf/unittest_proto3_optional.proto \
src/google/protobuf/unittest_retention.proto

# AddressBook sample protos
$PROTOC -Iexamples -Isrc --csharp_out=csharp/src/AddressBook \
--csharp_opt=file_extension=.pb.cs \
examples/addressbook.proto
$PROTOC -Iexamples -Isrc --csharp_out=csharp/src/AddressBook/Nrt \
--csharp_opt=enable_nrt,file_extension=.pb.nrt.cs \
examples/addressbook.proto

# Conformance tests
$PROTOC -I. --csharp_out=csharp/src/Google.Protobuf.Conformance \
--csharp_opt=file_extension=.pb.cs \
conformance/conformance.proto
$PROTOC -I. --csharp_out=csharp/src/Google.Protobuf.Conformance/Nrt \
--csharp_opt=enable_nrt,file_extension=.pb.nrt.cs \
conformance/conformance.proto
2 changes: 1 addition & 1 deletion csharp/install_dotnet_sdk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ Invoke-WebRequest -Uri $InstallScriptUrl -OutFile $InstallScriptPath
# The SDK versions to install should be kept in sync with versions
# installed by kokoro/linux/dockerfile/test/csharp/Dockerfile
&$InstallScriptPath -Version 3.1.415
&$InstallScriptPath -Version 6.0.100
&$InstallScriptPath -Version 8.0.100
15 changes: 14 additions & 1 deletion csharp/src/AddressBook/AddressBook.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<StartupObject>Google.Protobuf.Examples.AddressBook.Program</StartupObject>
<IsPackable>False</IsPackable>
Expand All @@ -11,4 +11,17 @@
<ProjectReference Include="..\Google.Protobuf\Google.Protobuf.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Remove="**/*.pb*.cs" />
<None Include="**/*.pb*.cs" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'net8.0' ">
<Compile Include="**/*.pb.cs" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<Compile Include="**/*.pb.nrt.cs" />
</ItemGroup>

</Project>
Loading
Loading