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

[cc] Add cc toolchain to starlark cc_proto_library #16585

Closed
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
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