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

add scala protobuf example #10

Closed
wants to merge 5 commits 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
6 changes: 6 additions & 0 deletions 3rdparty/jvm/com/thesamet/scalapb/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
jvm_artifact(
name="scalapb-runtime_2.13",
group="com.thesamet.scalapb",
artifact="scalapb-runtime_2.13",
version="0.11.6",
)
157 changes: 157 additions & 0 deletions 3rdparty/jvm/default.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# This lockfile was autogenerated by Pants. To regenerate, run:
#
# ./pants generate-lockfiles
#
# --- BEGIN PANTS LOCKFILE METADATA: DO NOT EDIT OR REMOVE ---
# {
# "version": 1,
# "generated_with_requirements": [
# "com.thesamet.scalapb:scalapb-runtime_2.13:0.11.6,url=not_provided,jar=not_provided",
# "org.scala-lang:scala-library:2.13.8,url=not_provided,jar=not_provided"
# ]
# }
# --- END PANTS LOCKFILE METADATA ---

[[entries]]
directDependencies = []
dependencies = []
file_name = "com.google.protobuf_protobuf-java_3.15.8.jar"

[entries.coord]
group = "com.google.protobuf"
artifact = "protobuf-java"
version = "3.15.8"
packaging = "jar"
[entries.file_digest]
fingerprint = "8d0e2f9834f4fc1a083a65239adc507ca83682c754a27f4c80e4f21990eff686"
serialized_bytes_length = 1674945
[[entries]]
file_name = "com.thesamet.scalapb_lenses_2.13_0.11.6.jar"
[[entries.directDependencies]]
group = "org.scala-lang"
artifact = "scala-library"
version = "2.13.8"
packaging = "jar"

[[entries.directDependencies]]
group = "org.scala-lang.modules"
artifact = "scala-collection-compat_2.13"
version = "2.5.0"
packaging = "jar"

[[entries.dependencies]]
group = "org.scala-lang"
artifact = "scala-library"
version = "2.13.8"
packaging = "jar"

[[entries.dependencies]]
group = "org.scala-lang.modules"
artifact = "scala-collection-compat_2.13"
version = "2.5.0"
packaging = "jar"


[entries.coord]
group = "com.thesamet.scalapb"
artifact = "lenses_2.13"
version = "0.11.6"
packaging = "jar"
[entries.file_digest]
fingerprint = "d1882eebf6deb4b1bb85c3c188790b28985214ac0dcfd79617fd04cc2e6df2de"
serialized_bytes_length = 34801
[[entries]]
file_name = "com.thesamet.scalapb_scalapb-runtime_2.13_0.11.6.jar"
[[entries.directDependencies]]
group = "com.google.protobuf"
artifact = "protobuf-java"
version = "3.15.8"
packaging = "jar"

[[entries.directDependencies]]
group = "com.thesamet.scalapb"
artifact = "lenses_2.13"
version = "0.11.6"
packaging = "jar"

[[entries.directDependencies]]
group = "org.scala-lang"
artifact = "scala-library"
version = "2.13.8"
packaging = "jar"

[[entries.directDependencies]]
group = "org.scala-lang.modules"
artifact = "scala-collection-compat_2.13"
version = "2.5.0"
packaging = "jar"

[[entries.dependencies]]
group = "com.google.protobuf"
artifact = "protobuf-java"
version = "3.15.8"
packaging = "jar"

[[entries.dependencies]]
group = "com.thesamet.scalapb"
artifact = "lenses_2.13"
version = "0.11.6"
packaging = "jar"

[[entries.dependencies]]
group = "org.scala-lang"
artifact = "scala-library"
version = "2.13.8"
packaging = "jar"

[[entries.dependencies]]
group = "org.scala-lang.modules"
artifact = "scala-collection-compat_2.13"
version = "2.5.0"
packaging = "jar"


[entries.coord]
group = "com.thesamet.scalapb"
artifact = "scalapb-runtime_2.13"
version = "0.11.6"
packaging = "jar"
[entries.file_digest]
fingerprint = "439b613f40b9ac43db4d68de5bef36befc56393d9c9cd002e2b965ce94f6f793"
serialized_bytes_length = 2426575
[[entries]]
file_name = "org.scala-lang.modules_scala-collection-compat_2.13_2.5.0.jar"
[[entries.directDependencies]]
group = "org.scala-lang"
artifact = "scala-library"
version = "2.13.8"
packaging = "jar"

[[entries.dependencies]]
group = "org.scala-lang"
artifact = "scala-library"
version = "2.13.8"
packaging = "jar"


[entries.coord]
group = "org.scala-lang.modules"
artifact = "scala-collection-compat_2.13"
version = "2.5.0"
packaging = "jar"
[entries.file_digest]
fingerprint = "93f8bf202ac28c4ca13562e31f6881a7770768e12b056b568139f37c025a3841"
serialized_bytes_length = 5610
[[entries]]
directDependencies = []
dependencies = []
file_name = "org.scala-lang_scala-library_2.13.8.jar"

[entries.coord]
group = "org.scala-lang"
artifact = "scala-library"
version = "2.13.8"
packaging = "jar"
[entries.file_digest]
fingerprint = "a0882b82514190c2bac7d1a459872a75f005fc0f3e88b2bc0390367146e35db7"
serialized_bytes_length = 6003601
6 changes: 6 additions & 0 deletions 3rdparty/jvm/org/scala-lang/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
jvm_artifact(
name="org.scala-lang_scala-library_2.13.8",
group="org.scala-lang",
artifact="scala-library",
version="2.13.8"
)
24 changes: 17 additions & 7 deletions pants.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[GLOBAL]
pants_version = "2.10.0"
pants_version = "2.11.0rc0"
backend_packages = [
"pants.backend.codegen.protobuf.python",
# TODO: There is a conflict between the runtime dependencies for Python and Scala:
# see https://github.com/pantsbuild/pants/issues/14694#issuecomment-1083565675
#"pants.backend.codegen.protobuf.python",
"pants.backend.codegen.thrift.apache.python",
"pants.backend.experimental.codegen.protobuf.scala",
"pants.backend.experimental.java",
"pants.backend.experimental.scala",
"pants.backend.python",
]

# This will become the default in 2.11, and is only explicitly set to not break
# backwards-compatibility for existing users. If you are setting up Pants for
# the first time, set this to false.
use_deprecated_python_macros = false

[anonymous-telemetry]
enabled = true
repo_id = "205E301D-44A4-42FF-8495-C9D41871A431"
Expand All @@ -23,3 +23,13 @@ interpreter_constraints = ["CPython>=3.8,<3.11"]
# `generate-lockfiles` goal for Pants to generate the lockfile for you, although in some
# situations you may need to manually generate it, as explained in the docs.
enable_resolves = true

[scala.version_for_resolve]
"jvm-default" = "2.13.8"

[scalapb]
# In Pants `2.11.x`, the runtime dependency of `scalapb` targets must be explicitly specified. But
# in `2.12.x`, it is inferred via #14898 based on its presence in the relevant thirdparty resolve.
runtime_dependencies = [
'3rdparty/jvm/com/thesamet/scalapb:scalapb-runtime_2.13'
]
4 changes: 4 additions & 0 deletions src/jvm/org/pantsbuild/example/codegen/scala/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# NB: Dependency inference is not yet implemented for JVM targets depending on protobuf targets,
# and so this dependency must be specified explicitly.
# see https://github.com/pantsbuild/pants/issues/14960
scala_sources(dependencies=["src/protobuf/simple_example"])
15 changes: 15 additions & 0 deletions src/jvm/org/pantsbuild/example/codegen/scala/PersonSample.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.pantsbuild.example.codegen.scala

import org.pantsbuild.example.codegen.protos.person.Person

object PersonSample {
def main(args: Array[String]): Unit = {
val p = Person(
name = "Someone",
id = 1234,
email = "someone@example.com",
)
println(p)
}
}

2 changes: 1 addition & 1 deletion src/protobuf/simple_example/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ protobuf_sources(
# This will generate files under `src/python`, rather than `src/protobuf`, which is convenient
# so that we do not need to add `__init__.py` files to `src/protobuf`. See
# https://www.pantsbuild.org/docs/protobuf-python#protobuf-and-source-roots
python_source_root="src/python",
#python_source_root="src/python",
)
2 changes: 2 additions & 0 deletions src/protobuf/simple_example/person.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ syntax = "proto3";

package simple_example;

option java_package = "org.pantsbuild.example.codegen.protos";

message Person {
string name = 1;
int32 id = 2;
Expand Down