From 94d34d79542edb2422642f9d33013ddebbf48911 Mon Sep 17 00:00:00 2001 From: Googler Date: Sun, 16 Jun 2024 22:40:12 -0700 Subject: [PATCH] Restructure rules_cc BEGIN_PUBLIC Restructure rules_cc Design doc: https://docs.google.com/document/d/1L1JFgjpZ7SrBinb24DC_5nTIELeYDacikcme-YcA7xs/edit END_PUBLIC PiperOrigin-RevId: 643879458 Change-Id: Id3fd760fde1c1145cb5044fff9020b61652d2f25 --- cc/cc_binary.bzl | 43 ++++ cc/cc_import.bzl | 17 ++ cc/cc_library.bzl | 17 ++ cc/cc_shared_library.bzl | 17 ++ cc/cc_test.bzl | 44 ++++ cc/common/BUILD | 31 +++ cc/common/cc_common.bzl | 19 ++ cc/common/cc_info.bzl | 19 ++ cc/common/cc_shared_library_hint_info.bzl | 18 ++ cc/common/cc_shared_library_info.bzl | 18 ++ cc/common/debug_package_info.bzl | 18 ++ cc/defs.bzl | 218 +++--------------- cc/objc_import.bzl | 17 ++ cc/objc_library.bzl | 17 ++ cc/private/BUILD | 25 ++ cc/private/rules_impl/BUILD | 14 ++ cc/private/rules_impl/native.bzl | 6 + cc/toolchains/BUILD | 23 ++ .../cc_flags_supplier.bzl | 4 +- cc/toolchains/cc_toolchain.bzl | 18 ++ cc/toolchains/cc_toolchain_config_info.bzl | 19 ++ cc/toolchains/cc_toolchain_suite.bzl | 18 ++ .../compiler_flag.bzl | 4 +- cc/toolchains/fdo_prefetch_hints.bzl | 18 ++ cc/toolchains/fdo_profile.bzl | 18 ++ cc/toolchains/memprof_profile.bzl | 17 ++ cc/toolchains/propeller_optimize.bzl | 17 ++ 27 files changed, 530 insertions(+), 184 deletions(-) create mode 100644 cc/cc_binary.bzl create mode 100644 cc/cc_import.bzl create mode 100644 cc/cc_library.bzl create mode 100644 cc/cc_shared_library.bzl create mode 100644 cc/cc_test.bzl create mode 100644 cc/common/BUILD create mode 100644 cc/common/cc_common.bzl create mode 100644 cc/common/cc_info.bzl create mode 100644 cc/common/cc_shared_library_hint_info.bzl create mode 100644 cc/common/cc_shared_library_info.bzl create mode 100644 cc/common/debug_package_info.bzl create mode 100644 cc/objc_import.bzl create mode 100644 cc/objc_library.bzl create mode 100644 cc/private/BUILD rename cc/{private/rules_impl => toolchains}/cc_flags_supplier.bzl (90%) create mode 100644 cc/toolchains/cc_toolchain.bzl create mode 100644 cc/toolchains/cc_toolchain_config_info.bzl create mode 100644 cc/toolchains/cc_toolchain_suite.bzl rename cc/{private/rules_impl => toolchains}/compiler_flag.bzl (88%) create mode 100644 cc/toolchains/fdo_prefetch_hints.bzl create mode 100644 cc/toolchains/fdo_profile.bzl create mode 100644 cc/toolchains/memprof_profile.bzl create mode 100644 cc/toolchains/propeller_optimize.bzl diff --git a/cc/cc_binary.bzl b/cc/cc_binary.bzl new file mode 100644 index 0000000..70810a2 --- /dev/null +++ b/cc/cc_binary.bzl @@ -0,0 +1,43 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""cc_binary rule""" + +# TODO(bazel-team): To avoid breaking changes, if the below are no longer +# forwarding to native rules, flag @bazel_tools@bazel_tools//tools/cpp:link_extra_libs +# should either: (a) alias the flag @rules_cc//:link_extra_libs, or (b) be +# added as a dependency to @rules_cc//:link_extra_lib. The intermediate library +# @bazel_tools@bazel_tools//tools/cpp:link_extra_lib should either be added as a dependency +# to @rules_cc//:link_extra_lib, or removed entirely (if possible). +_LINK_EXTRA_LIB = "@rules_cc//:link_extra_lib" # copybara-use-repo-external-label + +def cc_binary(**attrs): + """Bazel cc_binary rule. + + https://docs.bazel.build/versions/main/be/c-cpp.html#cc_binary + + Args: + **attrs: Rule attributes + """ + + is_library = "linkshared" in attrs and attrs["linkshared"] + + # Executable builds also include the "link_extra_lib" library. + if not is_library: + if "deps" in attrs and attrs["deps"] != None: + attrs["deps"] = attrs["deps"] + [_LINK_EXTRA_LIB] + else: + attrs["deps"] = [_LINK_EXTRA_LIB] + + # buildifier: disable=native-cc + native.cc_binary(**attrs) diff --git a/cc/cc_import.bzl b/cc/cc_import.bzl new file mode 100644 index 0000000..130805c --- /dev/null +++ b/cc/cc_import.bzl @@ -0,0 +1,17 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""cc_import rule""" + +def cc_import(**kwargs): + native.cc_import(**kwargs) # buildifier: disable=native-cc diff --git a/cc/cc_library.bzl b/cc/cc_library.bzl new file mode 100644 index 0000000..9ce181f --- /dev/null +++ b/cc/cc_library.bzl @@ -0,0 +1,17 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""cc_library rule""" + +def cc_library(**kwargs): + native.cc_library(**kwargs) # buildifier: disable=native-cc diff --git a/cc/cc_shared_library.bzl b/cc/cc_shared_library.bzl new file mode 100644 index 0000000..fb6be5a --- /dev/null +++ b/cc/cc_shared_library.bzl @@ -0,0 +1,17 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""cc_library rule""" + +def cc_shared_library(**kwargs): + native.cc_shared_library(**kwargs) # buildifier: disable=native-cc diff --git a/cc/cc_test.bzl b/cc/cc_test.bzl new file mode 100644 index 0000000..d3ba601 --- /dev/null +++ b/cc/cc_test.bzl @@ -0,0 +1,44 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""cc_test rule""" + +# TODO(bazel-team): To avoid breaking changes, if the below are no longer +# forwarding to native rules, flag @bazel_tools@bazel_tools//tools/cpp:link_extra_libs +# should either: (a) alias the flag @rules_cc//:link_extra_libs, or (b) be +# added as a dependency to @rules_cc//:link_extra_lib. The intermediate library +# @bazel_tools@bazel_tools//tools/cpp:link_extra_lib should either be added as a dependency +# to @rules_cc//:link_extra_lib, or removed entirely (if possible). +_LINK_EXTRA_LIB = "@rules_cc//:link_extra_lib" # copybara-use-repo-external-label + +def cc_test(**attrs): + """Bazel cc_test rule. + + https://docs.bazel.build/versions/main/be/c-cpp.html#cc_test + + Args: + **attrs: Rule attributes + """ + + is_library = "linkshared" in attrs and attrs["linkshared"] + + # Executable builds also include the "link_extra_lib" library. + if not is_library: + if "deps" in attrs and attrs["deps"] != None: + attrs["deps"] = attrs["deps"] + [_LINK_EXTRA_LIB] + else: + attrs["deps"] = [_LINK_EXTRA_LIB] + + # buildifier: disable=native-cc + native.cc_test(**attrs) diff --git a/cc/common/BUILD b/cc/common/BUILD new file mode 100644 index 0000000..5f40a3e --- /dev/null +++ b/cc/common/BUILD @@ -0,0 +1,31 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "common", + srcs = glob(["*.bzl"]), + visibility = ["//visibility:public"], + deps = ["//cc/private/rules_impl:native_bzl"], +) + +filegroup( + name = "srcs", + srcs = glob([ + "**/*.bzl", + "**/BUILD", + ]), + visibility = ["//visibility:public"], +) diff --git a/cc/common/cc_common.bzl b/cc/common/cc_common.bzl new file mode 100644 index 0000000..e2eb502 --- /dev/null +++ b/cc/common/cc_common.bzl @@ -0,0 +1,19 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""cc_common module""" + +load("//cc/private/rules_impl:native.bzl", "native_cc_common") + +cc_common = native_cc_common diff --git a/cc/common/cc_info.bzl b/cc/common/cc_info.bzl new file mode 100644 index 0000000..91f4517 --- /dev/null +++ b/cc/common/cc_info.bzl @@ -0,0 +1,19 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""CcInfo""" + +load("//cc/private/rules_impl:native.bzl", "NativeCcInfo") + +CcInfo = NativeCcInfo diff --git a/cc/common/cc_shared_library_hint_info.bzl b/cc/common/cc_shared_library_hint_info.bzl new file mode 100644 index 0000000..3a29868 --- /dev/null +++ b/cc/common/cc_shared_library_hint_info.bzl @@ -0,0 +1,18 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""CcSharedLibraryInfo""" + +load("//cc/private/rules_impl:native.bzl", "NativeCcSharedLibraryHintInfo") + +CcSharedLibraryHintInfo = NativeCcSharedLibraryHintInfo diff --git a/cc/common/cc_shared_library_info.bzl b/cc/common/cc_shared_library_info.bzl new file mode 100644 index 0000000..04c4363 --- /dev/null +++ b/cc/common/cc_shared_library_info.bzl @@ -0,0 +1,18 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""CcSharedLibraryInfo""" + +load("//cc/private/rules_impl:native.bzl", "NativeCcSharedLibraryInfo") + +CcSharedLibraryInfo = NativeCcSharedLibraryInfo diff --git a/cc/common/debug_package_info.bzl b/cc/common/debug_package_info.bzl new file mode 100644 index 0000000..8087840 --- /dev/null +++ b/cc/common/debug_package_info.bzl @@ -0,0 +1,18 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""DebugPackageInfo""" + +load("//cc/private/rules_impl:native.bzl", "NativeDebugPackageInfo") + +DebugPackageInfo = NativeDebugPackageInfo diff --git a/cc/defs.bzl b/cc/defs.bzl index 11be6fd..a09ec03 100644 --- a/cc/defs.bzl +++ b/cc/defs.bzl @@ -11,193 +11,51 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - """Starlark rules for building C++ projects.""" -load("//cc/private/rules_impl:cc_flags_supplier.bzl", _cc_flags_supplier = "cc_flags_supplier") -load("//cc/private/rules_impl:compiler_flag.bzl", _compiler_flag = "compiler_flag") -load("//cc/private/rules_impl:native.bzl", "NativeCcInfo", "NativeCcToolchainConfigInfo", "NativeDebugPackageInfo", "native_cc_common") +load("//cc:cc_binary.bzl", _cc_binary = "cc_binary") +load("//cc:cc_import.bzl", _cc_import = "cc_import") +load("//cc:cc_library.bzl", _cc_library = "cc_library") +load("//cc:cc_shared_library.bzl", _cc_shared_library = "cc_shared_library") +load("//cc:cc_test.bzl", _cc_test = "cc_test") +load("//cc:objc_import.bzl", _objc_import = "objc_import") +load("//cc:objc_library.bzl", _objc_library = "objc_library") +load("//cc/common:cc_common.bzl", _cc_common = "cc_common") +load("//cc/common:cc_info.bzl", _CcInfo = "CcInfo") +load("//cc/common:debug_package_info.bzl", _DebugPackageInfo = "DebugPackageInfo") +load("//cc/toolchains:cc_flags_supplier.bzl", _cc_flags_supplier = "cc_flags_supplier") +load("//cc/toolchains:cc_toolchain.bzl", _cc_toolchain = "cc_toolchain") +load("//cc/toolchains:cc_toolchain_config_info.bzl", _CcToolchainConfigInfo = "CcToolchainConfigInfo") +load("//cc/toolchains:cc_toolchain_suite.bzl", _cc_toolchain_suite = "cc_toolchain_suite") +load("//cc/toolchains:compiler_flag.bzl", _compiler_flag = "compiler_flag") +load("//cc/toolchains:fdo_prefetch_hints.bzl", _fdo_prefetch_hints = "fdo_prefetch_hints") +load("//cc/toolchains:fdo_profile.bzl", _fdo_profile = "fdo_profile") -_MIGRATION_TAG = "__CC_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__" +# Rules -# TODO(bazel-team): To avoid breaking changes, if the below are no longer -# forwarding to native rules, flag @bazel_tools@bazel_tools//tools/cpp:link_extra_libs -# should either: (a) alias the flag @rules_cc//:link_extra_libs, or (b) be -# added as a dependency to @rules_cc//:link_extra_lib. The intermediate library -# @bazel_tools@bazel_tools//tools/cpp:link_extra_lib should either be added as a dependency -# to @rules_cc//:link_extra_lib, or removed entirely (if possible). -_LINK_EXTRA_LIB = "@rules_cc//:link_extra_lib" # copybara-use-repo-external-label +cc_library = _cc_library +cc_binary = _cc_binary +cc_test = _cc_test +cc_import = _cc_import +cc_shared_library = _cc_shared_library -def _add_tags(attrs, is_binary = False): - if "tags" in attrs and attrs["tags"] != None: - attrs["tags"] = attrs["tags"] + [_MIGRATION_TAG] - else: - attrs["tags"] = [_MIGRATION_TAG] +objc_library = _objc_library +objc_import = _objc_import - if is_binary: - is_library = "linkshared" in attrs and attrs["linkshared"] +cc_proto_library = native.cc_proto_library # For compatibility with current users - # Executable builds also include the "link_extra_lib" library. - if not is_library: - if "deps" in attrs and attrs["deps"] != None: - attrs["deps"] = attrs["deps"] + [_LINK_EXTRA_LIB] - else: - attrs["deps"] = [_LINK_EXTRA_LIB] +# Toolchain rules - return attrs +cc_toolchain = _cc_toolchain +fdo_profile = _fdo_profile +fdo_prefetch_hints = _fdo_prefetch_hints +cc_toolchain_suite = _cc_toolchain_suite +compiler_flag = _compiler_flag +cc_flags_supplier = _cc_flags_supplier -def cc_binary(**attrs): - """Bazel cc_binary rule. +# Modules and providers - https://docs.bazel.build/versions/main/be/c-cpp.html#cc_binary - - Args: - **attrs: Rule attributes - """ - - # buildifier: disable=native-cc - native.cc_binary(**_add_tags(attrs, True)) - -def cc_test(**attrs): - """Bazel cc_test rule. - - https://docs.bazel.build/versions/main/be/c-cpp.html#cc_test - - Args: - **attrs: Rule attributes - """ - - # buildifier: disable=native-cc - native.cc_test(**_add_tags(attrs, True)) - -def cc_library(**attrs): - """Bazel cc_library rule. - - https://docs.bazel.build/versions/main/be/c-cpp.html#cc_library - - Args: - **attrs: Rule attributes - """ - - # buildifier: disable=native-cc - native.cc_library(**_add_tags(attrs)) - -def cc_import(**attrs): - """Bazel cc_import rule. - - https://docs.bazel.build/versions/main/be/c-cpp.html#cc_import - - Args: - **attrs: Rule attributes - """ - - # buildifier: disable=native-cc - native.cc_import(**_add_tags(attrs)) - -def cc_proto_library(**attrs): - """Bazel cc_proto_library rule. - - https://docs.bazel.build/versions/main/be/c-cpp.html#cc_proto_library - - Args: - **attrs: Rule attributes - """ - - # buildifier: disable=native-cc-proto - native.cc_proto_library(**_add_tags(attrs)) - -def fdo_prefetch_hints(**attrs): - """Bazel fdo_prefetch_hints rule. - - https://docs.bazel.build/versions/main/be/c-cpp.html#fdo_prefetch_hints - - Args: - **attrs: Rule attributes - """ - - # buildifier: disable=native-cc - native.fdo_prefetch_hints(**_add_tags(attrs)) - -def fdo_profile(**attrs): - """Bazel fdo_profile rule. - - https://docs.bazel.build/versions/main/be/c-cpp.html#fdo_profile - - Args: - **attrs: Rule attributes - """ - - # buildifier: disable=native-cc - native.fdo_profile(**_add_tags(attrs)) - -def cc_toolchain(**attrs): - """Bazel cc_toolchain rule. - - https://docs.bazel.build/versions/main/be/c-cpp.html#cc_toolchain - - Args: - **attrs: Rule attributes - """ - - # buildifier: disable=native-cc - native.cc_toolchain(**_add_tags(attrs)) - -def cc_toolchain_suite(**attrs): - """Bazel cc_toolchain_suite rule. - - https://docs.bazel.build/versions/main/be/c-cpp.html#cc_toolchain_suite - - Args: - **attrs: Rule attributes - """ - - # buildifier: disable=native-cc - native.cc_toolchain_suite(**_add_tags(attrs)) - -def objc_library(**attrs): - """Bazel objc_library rule. - - https://docs.bazel.build/versions/main/be/objective-c.html#objc_library - - Args: - **attrs: Rule attributes - """ - - # buildifier: disable=native-cc - native.objc_library(**_add_tags(attrs)) - -def objc_import(**attrs): - """Bazel objc_import rule. - - https://docs.bazel.build/versions/main/be/objective-c.html#objc_import - - Args: - **attrs: Rule attributes - """ - - # buildifier: disable=native-cc - native.objc_import(**_add_tags(attrs)) - -def cc_flags_supplier(**attrs): - """Bazel cc_flags_supplier rule. - - Args: - **attrs: Rule attributes - """ - _cc_flags_supplier(**_add_tags(attrs)) - -def compiler_flag(**attrs): - """Bazel compiler_flag rule. - - Args: - **attrs: Rule attributes - """ - _compiler_flag(**_add_tags(attrs)) - -cc_common = native_cc_common - -CcInfo = NativeCcInfo - -CcToolchainConfigInfo = NativeCcToolchainConfigInfo - -DebugPackageInfo = NativeDebugPackageInfo +cc_common = _cc_common +CcInfo = _CcInfo +DebugPackageInfo = _DebugPackageInfo +CcToolchainConfigInfo = _CcToolchainConfigInfo diff --git a/cc/objc_import.bzl b/cc/objc_import.bzl new file mode 100644 index 0000000..723f4c7 --- /dev/null +++ b/cc/objc_import.bzl @@ -0,0 +1,17 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""objc_import rule""" + +def objc_import(**kwargs): + native.objc_import(**kwargs) # buildifier: disable=native-cc diff --git a/cc/objc_library.bzl b/cc/objc_library.bzl new file mode 100644 index 0000000..5292be3 --- /dev/null +++ b/cc/objc_library.bzl @@ -0,0 +1,17 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""objc_library rule""" + +def objc_library(**kwargs): + native.objc_library(**kwargs) # buildifier: disable=native-cc diff --git a/cc/private/BUILD b/cc/private/BUILD new file mode 100644 index 0000000..7461e64 --- /dev/null +++ b/cc/private/BUILD @@ -0,0 +1,25 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +filegroup( + name = "srcs", + srcs = glob([ + "**/*.bzl", + "**/BUILD", + ]) + [ + "//cc/private/rules_impl:srcs", + "//cc/private/toolchain:srcs", + ], + visibility = ["//visibility:public"], +) diff --git a/cc/private/rules_impl/BUILD b/cc/private/rules_impl/BUILD index dc74dfe..88d9537 100644 --- a/cc/private/rules_impl/BUILD +++ b/cc/private/rules_impl/BUILD @@ -1,3 +1,5 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + package(default_visibility = ["//visibility:public"]) licenses(["notice"]) # Apache 2.0 @@ -16,3 +18,15 @@ filegroup( "**/BUILD", ]), ) + +bzl_library( + name = "cc_flags_supplier_lib_bzl", + srcs = ["cc_flags_supplier_lib.bzl"], + visibility = ["//cc:__subpackages__"], +) + +bzl_library( + name = "native_bzl", + srcs = ["native.bzl"], + visibility = ["//cc:__subpackages__"], +) diff --git a/cc/private/rules_impl/native.bzl b/cc/private/rules_impl/native.bzl index cce8c7f..b4c7b9c 100644 --- a/cc/private/rules_impl/native.bzl +++ b/cc/private/rules_impl/native.bzl @@ -32,3 +32,9 @@ NativeCcToolchainConfigInfo = CcToolchainConfigInfo # buildifier: disable=native-cc native_cc_common = cc_common + +# buildifier: disable=native-cc +NativeCcSharedLibraryInfo = CcSharedLibraryInfo + +# buildifier: disable=native-cc +NativeCcSharedLibraryHintInfo = CcSharedLibraryHintInfo diff --git a/cc/toolchains/BUILD b/cc/toolchains/BUILD index cde0cb5..1b001cb 100644 --- a/cc/toolchains/BUILD +++ b/cc/toolchains/BUILD @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") bool_flag( @@ -19,3 +20,25 @@ bool_flag( build_setting_default = False, visibility = ["//visibility:public"], ) + +bzl_library( + name = "toolchain_rules", + srcs = glob(["*.bzl"]), + visibility = ["//visibility:public"], + deps = [ + "//cc:action_names_bzl", + "//cc:find_cc_toolchain_bzl", + "//cc/private/rules_impl:cc_flags_supplier_lib_bzl", + "//cc/private/rules_impl:native_bzl", + "@bazel_skylib//rules/directory:glob", + ], +) + +filegroup( + name = "srcs", + srcs = glob([ + "**/*.bzl", + "**/BUILD", + ]), + visibility = ["//visibility:public"], +) diff --git a/cc/private/rules_impl/cc_flags_supplier.bzl b/cc/toolchains/cc_flags_supplier.bzl similarity index 90% rename from cc/private/rules_impl/cc_flags_supplier.bzl rename to cc/toolchains/cc_flags_supplier.bzl index 474c7ce..363575f 100644 --- a/cc/private/rules_impl/cc_flags_supplier.bzl +++ b/cc/toolchains/cc_flags_supplier.bzl @@ -13,8 +13,8 @@ # limitations under the License. """Rule that provides the CC_FLAGS Make variable.""" -load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain") load("//cc:action_names.bzl", "CC_FLAGS_MAKE_VARIABLE_ACTION_NAME") +load("//cc:find_cc_toolchain.bzl", "find_cpp_toolchain", "use_cc_toolchain") load("//cc/private/rules_impl:cc_flags_supplier_lib.bzl", "build_cc_flags") def _cc_flags_supplier_impl(ctx): @@ -30,6 +30,6 @@ cc_flags_supplier = rule( attrs = { "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), }, - toolchains = use_cpp_toolchain(), + toolchains = use_cc_toolchain(), fragments = ["cpp"], ) diff --git a/cc/toolchains/cc_toolchain.bzl b/cc/toolchains/cc_toolchain.bzl new file mode 100644 index 0000000..0272b12 --- /dev/null +++ b/cc/toolchains/cc_toolchain.bzl @@ -0,0 +1,18 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""cc_toolchain rule""" + +def cc_toolchain(**kwargs): + native.cc_toolchain(**kwargs) # buildifier: disable=native-cc diff --git a/cc/toolchains/cc_toolchain_config_info.bzl b/cc/toolchains/cc_toolchain_config_info.bzl new file mode 100644 index 0000000..cc310ab --- /dev/null +++ b/cc/toolchains/cc_toolchain_config_info.bzl @@ -0,0 +1,19 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""CcToolchainConfigInfo""" + +load("//cc/private/rules_impl:native.bzl", "NativeCcToolchainConfigInfo") + +CcToolchainConfigInfo = NativeCcToolchainConfigInfo diff --git a/cc/toolchains/cc_toolchain_suite.bzl b/cc/toolchains/cc_toolchain_suite.bzl new file mode 100644 index 0000000..66c42b2 --- /dev/null +++ b/cc/toolchains/cc_toolchain_suite.bzl @@ -0,0 +1,18 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""cc_toolchain_suite rule""" + +def cc_toolchain_suite(**kwargs): + native.cc_toolchain_suite(**kwargs) # buildifier: disable=native-cc diff --git a/cc/private/rules_impl/compiler_flag.bzl b/cc/toolchains/compiler_flag.bzl similarity index 88% rename from cc/private/rules_impl/compiler_flag.bzl rename to cc/toolchains/compiler_flag.bzl index ebbac94..ac943df 100644 --- a/cc/private/rules_impl/compiler_flag.bzl +++ b/cc/toolchains/compiler_flag.bzl @@ -14,7 +14,7 @@ """Rule that allows select() to differentiate between compilers.""" -load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain") +load("//cc:find_cc_toolchain.bzl", "find_cpp_toolchain", "use_cc_toolchain") def _compiler_flag_impl(ctx): toolchain = find_cpp_toolchain(ctx) @@ -25,5 +25,5 @@ compiler_flag = rule( attrs = { "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), }, - toolchains = use_cpp_toolchain(), + toolchains = use_cc_toolchain(), ) diff --git a/cc/toolchains/fdo_prefetch_hints.bzl b/cc/toolchains/fdo_prefetch_hints.bzl new file mode 100644 index 0000000..3215856 --- /dev/null +++ b/cc/toolchains/fdo_prefetch_hints.bzl @@ -0,0 +1,18 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""fdo_prefetch_hints rule""" + +def fdo_prefetch_hints(**kwargs): + native.fdo_prefetch_hints(**kwargs) # buildifier: disable=native-cc diff --git a/cc/toolchains/fdo_profile.bzl b/cc/toolchains/fdo_profile.bzl new file mode 100644 index 0000000..9450455 --- /dev/null +++ b/cc/toolchains/fdo_profile.bzl @@ -0,0 +1,18 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""fdo_profile rule""" + +def fdo_profile(**kwargs): + native.fdo_profile(**kwargs) # buildifier: disable=native-cc diff --git a/cc/toolchains/memprof_profile.bzl b/cc/toolchains/memprof_profile.bzl new file mode 100644 index 0000000..28bb5b3 --- /dev/null +++ b/cc/toolchains/memprof_profile.bzl @@ -0,0 +1,17 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""memprof_profile rule""" + +memprof_profile = native.memprof_profile diff --git a/cc/toolchains/propeller_optimize.bzl b/cc/toolchains/propeller_optimize.bzl new file mode 100644 index 0000000..0883cd7 --- /dev/null +++ b/cc/toolchains/propeller_optimize.bzl @@ -0,0 +1,17 @@ +# Copyright 2024 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""propeller_optimize rule""" + +propeller_optimize = native.propeller_optimize