generated from bazel-contrib/rules-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
157 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,19 @@ | ||
# Marker that this is the root of a Bazel workspace. | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file", "http_jar") | ||
|
||
# Fetch the runtime package that applications need to marshal proto files. | ||
# This does NOT do any code generation of .pb2.py files, we still use protoc for that. | ||
# From https://pypi.org/project/protobuf/4.25.3/ | ||
http_file( | ||
name = "protobuf_4_25_3", | ||
downloaded_file_path = "protobuf-4.25.3-py3-none-any.whl", | ||
sha256 = "f0700d54bcf45424477e46a9f0944155b46fb0639d69728739c0e47bab83f2b9", | ||
urls = ["https://files.pythonhosted.org/packages/f4/d5/db585a5e8d64af6b384c7b3a63da13df2ff86933e486ba78431736c67c25/protobuf-4.25.3-py3-none-any.whl"], | ||
) | ||
|
||
http_jar( | ||
name = "protobuf-java_3_25_3", | ||
sha256 = "e90d8ddb963b20a972a6a59b5093ade2b07cbe546cab3279aaf4383260385f58", | ||
urls = ["https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java/3.25.3/protobuf-java-3.25.3.jar"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
load("@rules_proto//proto:defs.bzl", "proto_library") | ||
load("@rules_python//python:proto.bzl", "py_proto_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
proto_library( | ||
name = "foo_proto", | ||
srcs = ["foo.proto"], | ||
) | ||
|
||
py_proto_library( | ||
name = "foo_py_proto", | ||
deps = [":foo_proto"], | ||
) | ||
|
||
java_proto_library( | ||
name = "foo_java_proto", | ||
deps = [":foo_proto"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
syntax = "proto3"; | ||
|
||
option java_package = "proto"; | ||
|
||
message Foo { | ||
string msg = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
java_binary( | ||
name = "java", | ||
srcs = ["Main.java"], | ||
main_class = "Main", | ||
deps = [ | ||
"//examples:foo_java_proto", | ||
"@protobuf-java_3_25_3//jar", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import com.google.protobuf.InvalidProtocolBufferException; | ||
import static proto.FooOuterClass.Foo; | ||
|
||
public class Main { | ||
public static void main(String[] args) throws InvalidProtocolBufferException { | ||
System.out.println(makeMessage("Hello World!")); | ||
} | ||
|
||
public static Foo makeMessage(String msg) { | ||
Foo.Builder person = Foo.newBuilder(); | ||
person.setMsg(msg); | ||
return person.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
load("@aspect_rules_py//py:defs.bzl", "py_unpacked_wheel") | ||
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain") | ||
|
||
# See WORKSPACE.bazel for fetch instructions of "protobuf_4_25_3". | ||
# Turn the downloaded .whl file into a py_library-shape (provides PyInfo) | ||
# Avoids the need for any pip, requirements files, python interpreter for wheel unpacking, etc | ||
py_unpacked_wheel( | ||
name = "protobuf_wheel", | ||
src = "@protobuf_4_25_3//file", | ||
py_package_name = "protobuf", | ||
) | ||
|
||
# Configure protoc to have the right arguments for generating Python stubs. | ||
proto_lang_toolchain( | ||
name = "protoc_py_toolchain", | ||
command_line = "--python_out=%s", | ||
progress_message = "Generating Python proto_library %{label}", | ||
runtime = ":protobuf_wheel", | ||
) | ||
|
||
proto_lang_toolchain( | ||
name = "protoc_java_toolchain", | ||
command_line = "--java_out=%s", | ||
progress_message = "Generating Java proto_library %{label}", | ||
runtime = "@protobuf-java_3_25_3//jar", | ||
) | ||
|
||
# Adapters to the register_toolchains call, adding the toolchain_type to above | ||
toolchain( | ||
name = "protoc_py_toolchain.registration", | ||
toolchain = ":protoc_py_toolchain", | ||
toolchain_type = "@rules_python//python/proto:toolchain_type", | ||
) | ||
|
||
toolchain( | ||
name = "protoc_java_toolchain.registration", | ||
toolchain = ":protoc_java_toolchain", | ||
toolchain_type = "@rules_java//java/proto:toolchain_type", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
py_test( | ||
name = "message_test", | ||
srcs = ["message_test.py"], | ||
deps = ["//examples:foo_py_proto"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import sys | ||
import unittest | ||
|
||
from examples import foo_pb2 | ||
|
||
class TestCase(unittest.TestCase): | ||
def test_message(self): | ||
got = foo_pb2.Foo( | ||
msg = "hello world", | ||
) | ||
self.assertIsNotNone(got) | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(unittest.main()) |