|
|
@ -2,7 +2,10 @@ |
|
|
|
load("@bazel_skylib//lib:paths.bzl", "paths") |
|
|
|
load("@bazel_skylib//lib:paths.bzl", "paths") |
|
|
|
load("@bazel_skylib//lib:versions.bzl", "versions") |
|
|
|
load("@bazel_skylib//lib:versions.bzl", "versions") |
|
|
|
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") |
|
|
|
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# copybara:strip_for_google3_begin |
|
|
|
load("@bazel_version//:bazel_version.bzl", "bazel_version") |
|
|
|
load("@bazel_version//:bazel_version.bzl", "bazel_version") |
|
|
|
|
|
|
|
# copybara:strip_end |
|
|
|
|
|
|
|
|
|
|
|
_shell_find_runfiles = """ |
|
|
|
_shell_find_runfiles = """ |
|
|
|
# --- begin runfiles.bash initialization --- |
|
|
|
# --- begin runfiles.bash initialization --- |
|
|
@ -227,6 +230,8 @@ is_bazel = not hasattr(native, "genmpm") |
|
|
|
google3_dep_map = { |
|
|
|
google3_dep_map = { |
|
|
|
"@absl//absl/base:core_headers": "//third_party/absl/base:core_headers", |
|
|
|
"@absl//absl/base:core_headers": "//third_party/absl/base:core_headers", |
|
|
|
"@absl//absl/strings": "//third_party/absl/strings", |
|
|
|
"@absl//absl/strings": "//third_party/absl/strings", |
|
|
|
|
|
|
|
"@bazel_tools//tools/cpp:current_cc_toolchain": "//tools/cpp:current_cc_toolchain", |
|
|
|
|
|
|
|
"@com_google_protobuf//:descriptor_proto": "//net/proto2/proto:descriptor", |
|
|
|
"@com_google_protobuf//:protoc": "//third_party/protobuf:protoc", |
|
|
|
"@com_google_protobuf//:protoc": "//third_party/protobuf:protoc", |
|
|
|
"@com_google_protobuf//:protobuf": "//third_party/protobuf:protobuf", |
|
|
|
"@com_google_protobuf//:protobuf": "//third_party/protobuf:protobuf", |
|
|
|
"@com_google_protobuf//:protoc_lib": "//third_party/protobuf:libprotoc", |
|
|
|
"@com_google_protobuf//:protoc_lib": "//third_party/protobuf:libprotoc", |
|
|
@ -260,7 +265,10 @@ def _get_real_roots(files): |
|
|
|
return roots.keys() |
|
|
|
return roots.keys() |
|
|
|
|
|
|
|
|
|
|
|
def _generate_output_file(ctx, src, extension): |
|
|
|
def _generate_output_file(ctx, src, extension): |
|
|
|
|
|
|
|
if is_bazel: |
|
|
|
real_short_path = _get_real_short_path(src) |
|
|
|
real_short_path = _get_real_short_path(src) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
real_short_path = paths.relativize(src.short_path, ctx.label.package) |
|
|
|
output_filename = paths.replace_extension(real_short_path, extension) |
|
|
|
output_filename = paths.replace_extension(real_short_path, extension) |
|
|
|
ret = ctx.new_file(ctx.genfiles_dir, output_filename) |
|
|
|
ret = ctx.new_file(ctx.genfiles_dir, output_filename) |
|
|
|
return ret |
|
|
|
return ret |
|
|
@ -284,7 +292,7 @@ def cc_library_func(ctx, name, hdrs, srcs, dep_ccinfos): |
|
|
|
unsupported_features = ctx.disabled_features, |
|
|
|
unsupported_features = ctx.disabled_features, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if is_bazel: |
|
|
|
# copybara:strip_for_google3_begin |
|
|
|
if bazel_version == "0.24.1": |
|
|
|
if bazel_version == "0.24.1": |
|
|
|
# Compatibility code until gRPC is on 0.25.2 or later. |
|
|
|
# Compatibility code until gRPC is on 0.25.2 or later. |
|
|
|
compilation_info = cc_common.compile( |
|
|
|
compilation_info = cc_common.compile( |
|
|
@ -309,6 +317,12 @@ def cc_library_func(ctx, name, hdrs, srcs, dep_ccinfos): |
|
|
|
|
|
|
|
|
|
|
|
if not versions.is_at_least("0.25.2", bazel_version): |
|
|
|
if not versions.is_at_least("0.25.2", bazel_version): |
|
|
|
fail("upb requires Bazel >=0.25.2 or 0.24.1") |
|
|
|
fail("upb requires Bazel >=0.25.2 or 0.24.1") |
|
|
|
|
|
|
|
# copybara:strip_end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
blaze_only_args = {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not is_bazel: |
|
|
|
|
|
|
|
blaze_only_args["grep_includes"] = ctx.file._grep_includes |
|
|
|
|
|
|
|
|
|
|
|
(compilation_context, compilation_outputs) = cc_common.compile( |
|
|
|
(compilation_context, compilation_outputs) = cc_common.compile( |
|
|
|
actions = ctx.actions, |
|
|
|
actions = ctx.actions, |
|
|
@ -318,6 +332,7 @@ def cc_library_func(ctx, name, hdrs, srcs, dep_ccinfos): |
|
|
|
srcs = srcs, |
|
|
|
srcs = srcs, |
|
|
|
public_hdrs = hdrs, |
|
|
|
public_hdrs = hdrs, |
|
|
|
compilation_contexts = compilation_contexts, |
|
|
|
compilation_contexts = compilation_contexts, |
|
|
|
|
|
|
|
**blaze_only_args |
|
|
|
) |
|
|
|
) |
|
|
|
(linking_context, linking_outputs) = cc_common.create_linking_context_from_compilation_outputs( |
|
|
|
(linking_context, linking_outputs) = cc_common.create_linking_context_from_compilation_outputs( |
|
|
|
actions = ctx.actions, |
|
|
|
actions = ctx.actions, |
|
|
@ -326,6 +341,7 @@ def cc_library_func(ctx, name, hdrs, srcs, dep_ccinfos): |
|
|
|
cc_toolchain = toolchain, |
|
|
|
cc_toolchain = toolchain, |
|
|
|
compilation_outputs = compilation_outputs, |
|
|
|
compilation_outputs = compilation_outputs, |
|
|
|
linking_contexts = linking_contexts, |
|
|
|
linking_contexts = linking_contexts, |
|
|
|
|
|
|
|
**blaze_only_args |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return CcInfo( |
|
|
|
return CcInfo( |
|
|
@ -383,7 +399,7 @@ def _upb_proto_aspect_impl(target, ctx): |
|
|
|
dep_ccinfos = [dep[CcInfo] for dep in deps if CcInfo in dep] |
|
|
|
dep_ccinfos = [dep[CcInfo] for dep in deps if CcInfo in dep] |
|
|
|
cc_info = cc_library_func( |
|
|
|
cc_info = cc_library_func( |
|
|
|
ctx = ctx, |
|
|
|
ctx = ctx, |
|
|
|
name = ctx.rule.attr.name, |
|
|
|
name = ctx.rule.attr.name + "_upb", |
|
|
|
hdrs = files.hdrs, |
|
|
|
hdrs = files.hdrs, |
|
|
|
srcs = files.srcs, |
|
|
|
srcs = files.srcs, |
|
|
|
dep_ccinfos = dep_ccinfos, |
|
|
|
dep_ccinfos = dep_ccinfos, |
|
|
@ -392,8 +408,17 @@ def _upb_proto_aspect_impl(target, ctx): |
|
|
|
|
|
|
|
|
|
|
|
# upb_proto_library() ########################################################## |
|
|
|
# upb_proto_library() ########################################################## |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def maybe_add(d): |
|
|
|
|
|
|
|
if not is_bazel: |
|
|
|
|
|
|
|
d["_grep_includes"] = attr.label( |
|
|
|
|
|
|
|
allow_single_file = True, |
|
|
|
|
|
|
|
cfg = "host", |
|
|
|
|
|
|
|
default = "//tools/cpp:grep-includes", |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
return d |
|
|
|
|
|
|
|
|
|
|
|
_upb_proto_library_aspect = aspect( |
|
|
|
_upb_proto_library_aspect = aspect( |
|
|
|
attrs = { |
|
|
|
attrs = maybe_add({ |
|
|
|
"_upbc": attr.label( |
|
|
|
"_upbc": attr.label( |
|
|
|
executable = True, |
|
|
|
executable = True, |
|
|
|
cfg = "host", |
|
|
|
cfg = "host", |
|
|
@ -404,10 +429,12 @@ _upb_proto_library_aspect = aspect( |
|
|
|
cfg = "host", |
|
|
|
cfg = "host", |
|
|
|
default = map_dep("@com_google_protobuf//:protoc"), |
|
|
|
default = map_dep("@com_google_protobuf//:protoc"), |
|
|
|
), |
|
|
|
), |
|
|
|
"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:current_cc_toolchain"), |
|
|
|
"_cc_toolchain": attr.label( |
|
|
|
|
|
|
|
default = map_dep("@bazel_tools//tools/cpp:current_cc_toolchain"), |
|
|
|
|
|
|
|
), |
|
|
|
"_upb": attr.label(default = ":upb"), |
|
|
|
"_upb": attr.label(default = ":upb"), |
|
|
|
"_ext": attr.string(default = ".upb"), |
|
|
|
"_ext": attr.string(default = ".upb"), |
|
|
|
}, |
|
|
|
}), |
|
|
|
implementation = _upb_proto_aspect_impl, |
|
|
|
implementation = _upb_proto_aspect_impl, |
|
|
|
attr_aspects = ["deps"], |
|
|
|
attr_aspects = ["deps"], |
|
|
|
fragments = ["cpp"], |
|
|
|
fragments = ["cpp"], |
|
|
|