Skip to content

Commit

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

Closes #16585.

PiperOrigin-RevId: 485600476
Change-Id: I3c2985731ff800a2c6136f401ed3c7e5e89518ad
  • Loading branch information
Yannic authored and copybara-github committed Nov 2, 2022
1 parent 0a23d46 commit 6c1e4b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ _cc_proto_aspect = aspect(
default = configuration_field(fragment = "proto", name = "proto_toolchain_for_cc"),
),
"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"),
"_cc_toolchain_type": attr.label(default = "@bazel_tools//tools/cpp:toolchain_type"),
},
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 6c1e4b7

Please sign in to comment.