Protocol buffer compiler for Scala. Consider sponsoring ScalaPB: https://github.com/sponsors/thesamet
mergify[bot] on master
Update scalafmt-core to 3.5.9 (… (compare)
mergify[bot] on master
Update scalafmt-core to 3.5.9 (… (compare)
mergify[bot] on master
Update mockito-core to 4.7.0 (#… (compare)
mergify[bot] on master
Update scalafmt-core to 3.5.9 (… (compare)
mergify[bot] on master
Update scalafmt-core to 3.5.9 (… (compare)
mergify[bot] on master
Update scalafmt-core to 3.5.9 (… (compare)
Hello community. My client has a central repo containing all protobufs for messages going out over the Kafka backbone.
Given we are talking 'backbone' infrastructure, the protobufs are used to generate code for several languages, including Go and Python.
We have specified options for ScalaPB, e.g.
syntax="proto3";
package x.y.z.service.some_service;
import "scalapb/scalapb.proto";
import "google/protobuf/timestamp.proto";
import "messages/common/common.proto";
message SomeServiceEvent {
option (scalapb.message).extends = "x.y.z.HasMessageMetadata[SomeServiceEvent]";
option (scalapb.message).companion_extends = "x.y.z.HasKafkaMetadata[SomeServiceEvent]";
...
}
but other language (i.e. Python) processors fail with
Import "scalapb/scalapb.proto" was not found or had errors.
Is there a way to use language (ScalaPB) specific options that are ignored by other language processors?
oneof xyz
to a oneof sealed_value
?
@thesamet apologies, having read over the docs a number of times now, I realise my last question a) does not make sense and b) won't give me mileage
What I was trying to do was create a sealed oneof (idiomatic-Scala) that can take a case object or a case class i.e. something structurally equivalent to Option[Boolean]
with values of None
and Some(true)
.
Unfortunately, sealed oneof does not allow enums:
java.lang.UnsupportedOperationException: This field is not of message type.
Is there a trick to generating objects or case objects but extending scalapb.GeneratedMessage
?
@thesamet I think the ideal solution would be the ability to specify the name of the Empty
case in a sealed oneof
to something more meaningful
message Some {
<your-type> = 1;
}
message Option {
oneof sealed_value {
option (scalapb.oneof).empty_name = "None";
Some some = 1;
}
}
wdyt?
ThisBuild / scalaVersion := "2.13.8"
ThisBuild / version := "0.1.0"
ThisBuild / organization := "Jure"
Compile / scalaSource := baseDirectory.value / "chisel4ml" / "scala" / "main"
Compile / unmanagedSourceDirectories += baseDirectory.value / "chisel4ml" / "scala" / "lbir"
Compile / unmanagedSourceDirectories += baseDirectory.value / "chisel4ml" / "scala" / "services"
crossTarget := baseDirectory.value / "bin"
assembly / assemblyJarName := "chisel4ml.jar"
ThisBuild / assemblyMergeStrategy := {
case PathList("META-INF", "MANIFEST.MF") => MergeStrategy.discard
case _ => MergeStrategy.first
}
PB.deleteTargetDirectory := false
PB.additionalDependencies := Nil
Compile / PB.includePaths += file(root.base.getAbsolutePath)
Compile / PB.protoSources := Seq(baseDirectory.value / "chisel4ml" / "lbir")
Compile / PB.targets := Seq(
scalapb.gen(flatPackage = true) -> baseDirectory.value / "chisel4ml" / "scala"
)
val chiselVersion = "3.5.1"
lazy val root = (project in file("."))
.settings(
name := "chisel4ml",
libraryDependencies ++= Seq(
"edu.berkeley.cs" %% "chisel3" % chiselVersion,
//"edu.berkeley.cs" %% "chiseltest" % "0.5.2" % "test",
"edu.berkeley.cs" %% "treadle" % "1.5.3",
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf",
"io.grpc" % "grpc-netty" % scalapb.compiler.Version.grpcJavaVersion,
"com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion,
"org.slf4j" % "slf4j-api" % "1.7.5",
"org.slf4j" % "slf4j-simple" % "1.7.5"
),
scalacOptions ++= Seq(
"-language:reflectiveCalls",
"-deprecation",
"-feature",
"-Xcheckinit",
"-P:chiselplugin:genBundleElements",
),
addCompilerPlugin("edu.berkeley.cs" % "chisel3-plugin" % chiselVersion cross CrossVersion.full),
)
PB.deleteTargetDirectory
and PB.additionalDependencies
. The latter can cause the generated classes directory get out of sync with the protos in case you remove messages or proto files, removing the latter will allow you to manually remove the dependency on scalapb-runtime since it will get added automatically.
sourceDirectories
should have an entry for the src_managed
directory.
main
directory is added automatically which should be sufficient.