Skip to content

Commit

Permalink
[cc] Add cc toolchain to starlark cc_proto_library (bazelbuild#16661)
Browse files Browse the repository at this point in the history
Fixes bazelbuild#16577

Closes bazelbuild#16585.

PiperOrigin-RevId: 485600476
Change-Id: I3c2985731ff800a2c6136f401ed3c7e5e89518ad

Co-authored-by: Yannic <[email protected]>
  • Loading branch information
ShreeM01 and Yannic authored Nov 4, 2022
1 parent 56f54da commit 72e6e94
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ _cc_proto_aspect = aspect(
),
"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"),
},
toolchains = cc_helper.use_cpp_toolchain(),
)

def _impl(ctx):
Expand Down
29 changes: 29 additions & 0 deletions src/test/shell/bazel/bazel_proto_library_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,35 @@ EOF
bazel build //a:c || fail "build failed"
}

function test_cc_proto_library_with_toolchain_resolution() {
write_workspace ""
mkdir -p a
cat > a/BUILD <<EOF
load("@rules_proto//proto:defs.bzl", "proto_library")
proto_library(name='p', srcs=['p.proto'])
cc_proto_library(name='cp', deps=[':p'])
cc_library(name='c', srcs=['c.cc'], deps=[':cp'])
EOF

cat > a/p.proto <<EOF
syntax = "proto2";
package a;
message A {
optional int32 a = 1;
}
EOF

cat > a/c.cc <<EOF
#include "a/p.pb.h"
void f() {
a::A a;
}
EOF

bazel build --incompatible_enable_cc_toolchain_resolution //a:c || fail "build failed"
}

function test_cc_proto_library_import_prefix_stripping() {
write_workspace ""
mkdir -p a/dir
Expand Down

0 comments on commit 72e6e94

Please sign in to comment.