Skip to content
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

Generate Protobuf C# objects automatically in MSBuild #7063

Merged
merged 10 commits into from
Apr 22, 2024
45 changes: 0 additions & 45 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -426,51 +426,6 @@ Target "PublishNuget" (fun _ ->
printfn "%s" exn.Message
)

//--------------------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// Serialization
//--------------------------------------------------------------------------------
Target "Protobuf" <| fun _ ->

let protocPath =
if isWindows then findToolInSubPath "protoc.exe" "tools/Google.Protobuf.Tools/tools/windows_x64"
elif isMacOS then findToolInSubPath "protoc" "tools/Google.Protobuf.Tools/tools/macosx_x64"
else findToolInSubPath "protoc" "tools/Google.Protobuf.Tools/tools/linux_x64"

let protoFiles = [
("WireFormats.proto", "/src/core/Akka.Remote/Serialization/Proto/");
("ContainerFormats.proto", "/src/core/Akka.Remote/Serialization/Proto/");
("SystemMessageFormats.proto", "/src/core/Akka.Remote/Serialization/Proto/");
("ClusterMessages.proto", "/src/core/Akka.Cluster/Serialization/Proto/");
("ClusterClientMessages.proto", "/src/contrib/cluster/Akka.Cluster.Tools/Client/Serialization/Proto/");
("DistributedPubSubMessages.proto", "/src/contrib/cluster/Akka.Cluster.Tools/PublishSubscribe/Serialization/Proto/");
("ClusterShardingMessages.proto", "/src/contrib/cluster/Akka.Cluster.Sharding/Serialization/Proto/");
("ReliableDelivery.proto", "/src/core/Akka.Cluster/Serialization/Proto/");
("TestConductorProtocol.proto", "/src/core/Akka.Remote.TestKit/Proto/");
("Persistence.proto", "/src/core/Akka.Persistence/Serialization/Proto/");
("StreamRefMessages.proto", "/src/core/Akka.Streams/Serialization/Proto/");
("ReplicatorMessages.proto", "/src/contrib/cluster/Akka.DistributedData/Serialization/Proto/");
("ReplicatedDataMessages.proto", "/src/contrib/cluster/Akka.DistributedData/Serialization/Proto/"); ]

printfn "Using proto.exe: %s" protocPath

let runProtobuf assembly =
let protoName, destinationPath = assembly
let args = StringBuilder()
|> append (sprintf "-I=%s" (__SOURCE_DIRECTORY__ @@ "/src/protobuf/") )
|> append (sprintf "-I=%s" (__SOURCE_DIRECTORY__ @@ "/src/protobuf/common") )
|> append (sprintf "--csharp_out=internal_access:%s" (__SOURCE_DIRECTORY__ @@ destinationPath))
|> append "--csharp_opt=file_extension=.g.cs"
|> append (__SOURCE_DIRECTORY__ @@ "/src/protobuf" @@ protoName)
|> toText

let result = ExecProcess(fun info ->
info.FileName <- protocPath
info.WorkingDirectory <- (Path.GetDirectoryName (FullName protocPath))
info.Arguments <- args) (System.TimeSpan.FromMinutes 45.0) (* Reasonably long-running task. *)
if result <> 0 then failwithf "protoc failed. %s %s" protocPath args

protoFiles |> Seq.iter (runProtobuf)

//--------------------------------------------------------------------------------
// Documentation
//--------------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<NewtonsoftJsonVersion>[13.0.1,)</NewtonsoftJsonVersion>
<NBenchVersion>2.0.1</NBenchVersion>
<ProtobufVersion>3.26.1</ProtobufVersion>
<GrpcToolsVersion>2.60.0</GrpcToolsVersion>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

<BenchmarkDotNetVersion>0.13.12</BenchmarkDotNetVersion>
<NetTestVersion>net8.0</NetTestVersion>
<FsharpVersion>6.0.5</FsharpVersion>
Expand All @@ -36,7 +37,7 @@
<FsCheckVersion>2.16.6</FsCheckVersion>
<HoconVersion>2.0.3</HoconVersion>
<ConfigurationManagerVersion>6.0.1</ConfigurationManagerVersion>
<MultiNodeAdapterVersion>1.5.18</MultiNodeAdapterVersion>
<MultiNodeAdapterVersion>1.5.19</MultiNodeAdapterVersion>
<MicrosoftLibVersion>[6.0.*,)</MicrosoftLibVersion>
<MsExtVersion>[6.0.*,)</MsExtVersion>
<AkkaAnalyzerVersion>0.2.4</AkkaAnalyzerVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@

<ItemGroup>
<PackageReference Include="System.Diagnostics.Process" Version="4.3.0" />
<PackageReference Include="Grpc.Tools" Version="$(GrpcToolsVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Protobuf Access="internal" Include="Serialization/Proto/ClusterMetricsMessages.proto" />

</ItemGroup>

</Project>
Loading
Loading