From a274ad786a6d21d191baea321813f356d4b50104 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Wed, 28 Oct 2020 13:06:30 -0700 Subject: [PATCH] Plumbed copts (including the crucial -std=c99) to upb_proto_library() aspect. --- BUILD | 7 +++++++ bazel/upb_proto_library.bzl | 26 +++++++++++++++++++++++++- cmake/make_cmakelists.py | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/BUILD b/BUILD index dccd53185c..6c9e9a1615 100644 --- a/BUILD +++ b/BUILD @@ -8,6 +8,7 @@ load( "upb_fasttable_enabled", "upb_proto_library", "upb_proto_reflection_library", + "upb_proto_library_copts", ) # copybara:strip_for_google3_begin @@ -36,6 +37,12 @@ upb_fasttable_enabled( 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 ####################################################### cc_library( diff --git a/bazel/upb_proto_library.bzl b/bazel/upb_proto_library.bzl index 6c56293b52..6e6ec3a8ed 100644 --- a/bazel/upb_proto_library.bzl +++ b/bazel/upb_proto_library.bzl @@ -52,7 +52,7 @@ def _filter_none(elems): out.append(elem) 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. Args: @@ -88,6 +88,7 @@ def _cc_library_func(ctx, name, hdrs, srcs, dep_ccinfos): name = name, srcs = srcs, public_hdrs = hdrs, + user_compile_flags = copts, compilation_contexts = compilation_contexts, **blaze_only_args ) @@ -128,6 +129,22 @@ upb_fasttable_enabled = rule( 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 ################# 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, hdrs = files.hdrs, srcs = files.srcs, + copts = ctx.attr._copts[_UpbProtoLibraryCopts].copts, dep_ccinfos = dep_ccinfos, ) return [cc_provider(cc_info = cc_info), file_provider(srcs = files)] @@ -246,6 +264,9 @@ def _maybe_add(d): _upb_proto_library_aspect = aspect( attrs = _maybe_add({ + "_copts": attr.label( + default = "//:upb_proto_library_copts__for_generated_code_only_do_not_use", + ), "_upbc": attr.label( executable = True, cfg = "host", @@ -292,6 +313,9 @@ upb_proto_library = rule( _upb_proto_reflection_library_aspect = aspect( attrs = _maybe_add({ + "_copts": attr.label( + default = "//:upb_proto_library_copts__for_generated_code_only_do_not_use", + ), "_upbc": attr.label( executable = True, cfg = "host", diff --git a/cmake/make_cmakelists.py b/cmake/make_cmakelists.py index a750717326..1dafbbda5b 100755 --- a/cmake/make_cmakelists.py +++ b/cmake/make_cmakelists.py @@ -129,6 +129,9 @@ class BuildFileFunctions(object): def upb_proto_library(self, **kwargs): pass + def upb_proto_library_copts(self, **kwargs): + pass + def upb_proto_reflection_library(self, **kwargs): pass