Plumbed copts (including the crucial -std=c99) to upb_proto_library() aspect.

pull/13171/head
Joshua Haberman 4 years ago
parent 2c8bb6dd9d
commit a274ad786a
  1. 7
      BUILD
  2. 26
      bazel/upb_proto_library.bzl
  3. 3
      cmake/make_cmakelists.py

@ -8,6 +8,7 @@ load(
"upb_fasttable_enabled", "upb_fasttable_enabled",
"upb_proto_library", "upb_proto_library",
"upb_proto_reflection_library", "upb_proto_reflection_library",
"upb_proto_library_copts",
) )
# copybara:strip_for_google3_begin # copybara:strip_for_google3_begin
@ -36,6 +37,12 @@ upb_fasttable_enabled(
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
upb_proto_library_copts(
name = "upb_proto_library_copts__for_generated_code_only_do_not_use",
copts = UPB_DEFAULT_COPTS,
visibility = ["//visibility:public"],
)
# Public C/C++ libraries ####################################################### # Public C/C++ libraries #######################################################
cc_library( cc_library(

@ -52,7 +52,7 @@ def _filter_none(elems):
out.append(elem) out.append(elem)
return out return out
def _cc_library_func(ctx, name, hdrs, srcs, dep_ccinfos): def _cc_library_func(ctx, name, hdrs, srcs, copts, dep_ccinfos):
"""Like cc_library(), but callable from rules. """Like cc_library(), but callable from rules.
Args: Args:
@ -88,6 +88,7 @@ def _cc_library_func(ctx, name, hdrs, srcs, dep_ccinfos):
name = name, name = name,
srcs = srcs, srcs = srcs,
public_hdrs = hdrs, public_hdrs = hdrs,
user_compile_flags = copts,
compilation_contexts = compilation_contexts, compilation_contexts = compilation_contexts,
**blaze_only_args **blaze_only_args
) )
@ -128,6 +129,22 @@ upb_fasttable_enabled = rule(
build_setting = config.bool(flag = True) build_setting = config.bool(flag = True)
) )
# Dummy rule to expose select() copts to aspects ##############################
_UpbProtoLibraryCopts = provider(
fields = {
"copts": "copts for upb_proto_library()",
},
)
def upb_proto_library_copts_impl(ctx):
return _UpbProtoLibraryCopts(copts = ctx.attr.copts)
upb_proto_library_copts = rule(
implementation = upb_proto_library_copts_impl,
attrs = {"copts": attr.string_list(default = [])},
)
# upb_proto_library / upb_proto_reflection_library shared code ################# # upb_proto_library / upb_proto_reflection_library shared code #################
GeneratedSrcsInfo = provider( GeneratedSrcsInfo = provider(
@ -223,6 +240,7 @@ def _upb_proto_aspect_impl(target, ctx, cc_provider, file_provider):
name = ctx.rule.attr.name + ctx.attr._ext, name = ctx.rule.attr.name + ctx.attr._ext,
hdrs = files.hdrs, hdrs = files.hdrs,
srcs = files.srcs, srcs = files.srcs,
copts = ctx.attr._copts[_UpbProtoLibraryCopts].copts,
dep_ccinfos = dep_ccinfos, dep_ccinfos = dep_ccinfos,
) )
return [cc_provider(cc_info = cc_info), file_provider(srcs = files)] return [cc_provider(cc_info = cc_info), file_provider(srcs = files)]
@ -246,6 +264,9 @@ def _maybe_add(d):
_upb_proto_library_aspect = aspect( _upb_proto_library_aspect = aspect(
attrs = _maybe_add({ attrs = _maybe_add({
"_copts": attr.label(
default = "//:upb_proto_library_copts__for_generated_code_only_do_not_use",
),
"_upbc": attr.label( "_upbc": attr.label(
executable = True, executable = True,
cfg = "host", cfg = "host",
@ -292,6 +313,9 @@ upb_proto_library = rule(
_upb_proto_reflection_library_aspect = aspect( _upb_proto_reflection_library_aspect = aspect(
attrs = _maybe_add({ attrs = _maybe_add({
"_copts": attr.label(
default = "//:upb_proto_library_copts__for_generated_code_only_do_not_use",
),
"_upbc": attr.label( "_upbc": attr.label(
executable = True, executable = True,
cfg = "host", cfg = "host",

@ -129,6 +129,9 @@ class BuildFileFunctions(object):
def upb_proto_library(self, **kwargs): def upb_proto_library(self, **kwargs):
pass pass
def upb_proto_library_copts(self, **kwargs):
pass
def upb_proto_reflection_library(self, **kwargs): def upb_proto_reflection_library(self, **kwargs):
pass pass

Loading…
Cancel
Save