Skip to content

Commit 0e7d481

Browse files
Allow the proto! proc impl to be built on bazel
PiperOrigin-RevId: 738871947
1 parent ad11535 commit 0e7d481

File tree

6 files changed

+125
-7
lines changed

6 files changed

+125
-7
lines changed

Cargo.bazel.lock

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"checksum": "422d164988d36886ae9aef8b60e233d67aac121356b66f1452c469f912cc0148",
2+
"checksum": "1c2d7323790fa56253530c4ad5ac09639afa6de134dfeae8959f863aab3a6631",
33
"crates": {
44
"aho-corasick 1.1.2": {
55
"name": "aho-corasick",
@@ -125,7 +125,15 @@
125125
{
126126
"id": "googletest 0.12.0",
127127
"target": "googletest"
128-
}
128+
},
129+
{
130+
"id": "quote 1.0.33",
131+
"target": "quote"
132+
},
133+
{
134+
"id": "syn 2.0.43",
135+
"target": "syn"
136+
}
129137
],
130138
"selects": {}
131139
},
@@ -919,13 +927,55 @@
919927
"clone-impls",
920928
"default",
921929
"derive",
922-
"full",
923930
"parsing",
924931
"printing",
925932
"proc-macro",
926933
"quote"
927934
],
928-
"selects": {}
935+
"selects": {
936+
"aarch64-apple-darwin": [
937+
"full"
938+
],
939+
"aarch64-pc-windows-msvc": [
940+
"full"
941+
],
942+
"aarch64-unknown-linux-gnu": [
943+
"full"
944+
],
945+
"aarch64-unknown-nixos-gnu": [
946+
"full"
947+
],
948+
"arm-unknown-linux-gnueabi": [
949+
"full"
950+
],
951+
"i686-pc-windows-msvc": [
952+
"full"
953+
],
954+
"i686-unknown-linux-gnu": [
955+
"full"
956+
],
957+
"powerpc-unknown-linux-gnu": [
958+
"full"
959+
],
960+
"s390x-unknown-linux-gnu": [
961+
"full"
962+
],
963+
"x86_64-apple-darwin": [
964+
"full"
965+
],
966+
"x86_64-pc-windows-msvc": [
967+
"full"
968+
],
969+
"x86_64-unknown-freebsd": [
970+
"full"
971+
],
972+
"x86_64-unknown-linux-gnu": [
973+
"full"
974+
],
975+
"x86_64-unknown-nixos-gnu": [
976+
"full"
977+
]
978+
}
929979
},
930980
"deps": {
931981
"common": [
@@ -1108,7 +1158,9 @@
11081158
},
11091159
"direct_deps": [
11101160
"googletest 0.12.0",
1111-
"paste 1.0.14"
1161+
"paste 1.0.14",
1162+
"quote 1.0.33",
1163+
"syn 2.0.43"
11121164
],
11131165
"direct_dev_deps": []
11141166
}

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MODULE.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ crate.spec(
140140
package = "paste",
141141
version = ">=1",
142142
)
143+
crate.spec(
144+
package = "quote",
145+
version = ">=1",
146+
)
147+
crate.spec(
148+
package = "syn",
149+
version = ">=2",
150+
)
143151
crate.from_specs()
144152
use_repo(crate, crate_index = "crates")
145153

WORKSPACE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ crates_repository(
273273
"paste": crate.spec(
274274
version = ">=1",
275275
),
276+
"quote": crate.spec(
277+
version = ">=1",
278+
),
279+
"syn": crate.spec(
280+
version = ">=2",
281+
),
276282
},
277283
)
278284

rust/proto_proc_macro/BUILD

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1-
# This directory contains the implementation of the proto! macro as a proc macro.
2-
# It has not yet been made to work with bazel and so no targets are defined here.
1+
# An alternate implementation of the proto! macro as a proc macro instead of macro_rules.
2+
3+
# This is only in a separate directory due to the top level package being part of the 'core'
4+
# component, and it not being a resolved decision if we want to add all deps of this proc macro to
5+
# the core component.
36

47
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix")
8+
load("@rules_rust//rust:defs.bzl", "rust_proc_macro")
59

610
PROC_MACRO_SRCS = ["proto_proc_macro_impl.rs"]
711

12+
rust_proc_macro(
13+
name = "proto_proc_macro",
14+
srcs = PROC_MACRO_SRCS,
15+
visibility = ["//rust/test:__subpackages__"],
16+
deps = [
17+
"@crate_index//:quote",
18+
"@crate_index//:syn",
19+
],
20+
)
21+
822
pkg_files(
923
name = "rust_protobuf_macros_src",
1024
srcs = PROC_MACRO_SRCS,

rust/test/shared/BUILD

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,42 @@ rust_test(
484484
],
485485
)
486486

487+
rust_test(
488+
name = "proto_proc_macro_cpp_test",
489+
srcs = ["proto_proc_macro_test.rs"],
490+
aliases = {
491+
"//rust:protobuf_cpp": "protobuf",
492+
},
493+
proc_macro_deps = [
494+
"//rust/proto_proc_macro",
495+
],
496+
deps = [
497+
"//rust:protobuf_cpp",
498+
"//rust/test:map_unittest_cpp_rust_proto",
499+
"//rust/test:unittest_cpp_rust_proto",
500+
"@crate_index//:googletest",
501+
],
502+
)
503+
504+
rust_test(
505+
name = "proto_proc_macro_upb_test",
506+
srcs = ["proto_proc_macro_test.rs"],
507+
aliases = {
508+
"//rust:protobuf_upb": "protobuf",
509+
"//rust:protobuf_gtest_matchers_upb": "protobuf_gtest_matchers",
510+
},
511+
proc_macro_deps = [
512+
"//rust/proto_proc_macro",
513+
],
514+
deps = [
515+
"//rust:protobuf_gtest_matchers_upb",
516+
"//rust:protobuf_upb",
517+
"//rust/test:map_unittest_upb_rust_proto",
518+
"//rust/test:unittest_upb_rust_proto",
519+
"@crate_index//:googletest",
520+
],
521+
)
522+
487523
rust_test(
488524
name = "gtest_matchers_cpp_test",
489525
srcs = ["gtest_matchers_test.rs"],

0 commit comments

Comments
 (0)