Add testing for Bazel@HEAD and Bazel 6

PiperOrigin-RevId: 684046113
Change-Id: I98875f8c67b491759f121c21e33ed04ec1d590e0
This commit is contained in:
Googler 2024-10-09 08:25:32 -07:00 committed by Copybara-Service
parent 7782be6db1
commit 56f4a8bfa1
11 changed files with 139 additions and 54 deletions

View File

@ -1,54 +1,111 @@
---
x_defaults:
# YAML has a feature for "repeated nodes", BazelCI is fine with extra nodes
# it doesn't know about; so that is used to avoid repeating common subparts.
common: &common
# We have to list every package because even with exclusion notation -//foo
# Bazel will load the excluded package and it will be an error because at
# release Bazel the cc_libraries do not have all the attributes.
build_targets:
- "//:all"
- "//cc:all"
- "//cc/private/rules_impl:all"
- "//cc/private/toolchain:all"
- "//cc/runfiles:all"
- "//examples:all"
- "//examples/my_c_archive:all"
- "//examples/my_c_compile:all"
- "//examples/write_cc_toolchain_cpu:all"
- "//tests/..."
test_flags:
- "--test_timeout=120"
test_targets:
- "//:all"
- "//cc:all"
- "//cc/private/rules_impl:all"
- "//cc/private/toolchain:all"
- "//examples:all"
- "//examples/my_c_archive:all"
- "//examples/my_c_compile:all"
- "//examples/write_cc_toolchain_cpu:all"
- "//tests/..."
build_targets: &build_targets
- "//:all"
- "//cc/..."
- "//examples/..."
- "//tests/..."
- "-//examples/custom_toolchain:legacy_selector" # Example only works on Linux
test_targets: &test_targets
- "//:all"
- "//cc/..."
- "//examples/..."
- "//tests/..."
- "-//examples/custom_toolchain:legacy_selector" # Example only works on Linux
build_targets_bazel_6: &build_targets_bazel_6
- "//:all"
- "//cc:all"
- "//examples/..."
- "//tests/..."
- "-//examples/custom_toolchain:legacy_selector" # Example only works on Linux
- "-//tests/rule_based_toolchain/..." # proto.encode_text doesn't support None
- "-//cc:optional_current_cc_toolchain" # Not supported in Bazel 6
test_targets_bazel_6: &test_targets_bazel_6
- "//:all"
- "//cc:all"
- "//examples/..."
- "//tests/..."
- "-//examples/custom_toolchain:legacy_selector" # Example only works on Linux
- "-//tests/rule_based_toolchain/..." # proto.encode_text doesn't support None
- "-//cc:optional_current_cc_toolchain" # Not supported in Bazel 6
buildifier:
version: latest
warnings: "all"
tasks:
ubuntu1804:
<<: *common
ubuntu2004:
name: Docs
test_targets:
- "//docs/..."
- "-//docs:toolchain_api_diff_test" # Bazel adds loads statements in examples
# Bazel LTS
ubuntu2004:
name: Ubuntu 20.04 (Bazel LTS)
build_targets: *build_targets
test_targets: *test_targets
macos:
<<: *common
name: MacOS (Bazel LTS)
build_targets: *build_targets
test_targets: *test_targets
windows:
<<: *common
name: Windows (Bazel LTS)
build_targets: *build_targets
test_targets: *test_targets
ubuntu_bzlmod:
name: Bzlmod
platform: ubuntu1804
name: Ubuntu 20.04 (Bazel LTS, bzlmod)
platform: ubuntu2004
build_flags:
- "--enable_bzlmod"
- "--ignore_dev_dependency"
build_targets:
# Bazel@HEAD
ubuntu2004_head:
name: Ubuntu 20.04 (Bazel HEAD)
bazel: last_green
platform: ubuntu2004
build_targets: *build_targets
test_targets:
- "//:all"
- "//cc/..."
- "//examples/..."
- "//tests/..."
- "-//examples/custom_toolchain:legacy_selector" # Example only works on Linux
- "-//tests/system_library:system_library_test" # Fails because of repo setup
macos_head:
name: MacOS (Bazel HEAD)
bazel: last_green
platform: macos
build_targets: *build_targets
test_targets: *test_targets
windows_head:
name: Windows (Bazel HEAD)
bazel: last_green
platform: macos
build_targets: *build_targets
test_targets: *test_targets
# Bazel 6
ubuntu2004_bazel_6:
name: Ubuntu 20.04 (Bazel 6)
bazel: 6.3.0
platform: ubuntu2004
build_targets: *build_targets_bazel_6
test_targets: *test_targets_bazel_6
macos_bazel_6:
name: MacOS (Bazel 6)
bazel: 6.3.0
platform: macos
build_targets: *build_targets_bazel_6
test_targets: *test_targets_bazel_6
windows_bazel_6:
name: Windows (Bazel 6)
bazel: 6.3.0
platform: macos
build_targets: *build_targets_bazel_6
test_targets: *test_targets_bazel_6
ubuntu_rule_based_toolchains:
name: Ubuntu rule-based toolchains
platform: ubuntu1804

View File

@ -4,10 +4,10 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "bazel_skylib",
sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7",
sha256 = "bc283cdfcd526a52c3201279cda4bc298652efa898b10b4db0837dc51652756f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.1/bazel-skylib-1.7.1.tar.gz",
],
)
@ -30,3 +30,10 @@ http_archive(
strip_prefix = "rules_testing-0.6.0",
url = "https://github.com/bazelbuild/rules_testing/releases/download/v0.6.0/rules_testing-v0.6.0.tar.gz",
)
http_archive(
name = "protobuf",
sha256 = "da288bf1daa6c04d03a9051781caa52aceb9163586bff9aa6cfb12f69b9395aa",
strip_prefix = "protobuf-27.0",
url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protobuf-27.0.tar.gz",
)

View File

@ -102,9 +102,10 @@ bzl_library(
cc_toolchain_alias(name = "current_cc_toolchain")
cc_toolchain_alias(
# Use alias, because it doesn't build on Bazel 6.
alias(
name = "optional_current_cc_toolchain",
mandatory = False,
actual = "//cc/private/bazel7:optional_current_cc_toolchain",
)
cc_libc_top_alias(name = "current_libc_top")

View File

@ -13,6 +13,5 @@
# limitations under the License.
"""CcSharedLibraryInfo"""
load("//cc/private/rules_impl:native.bzl", "NativeCcSharedLibraryHintInfo")
CcSharedLibraryHintInfo = NativeCcSharedLibraryHintInfo
# Backward compatibility with Bazel 6
CcSharedLibraryHintInfo = getattr(cc_common, "CcSharedLibraryHintInfo", provider("CcSharedLibraryHintInfo", fields = ["attributes", "owners"]))

24
cc/private/bazel7/BUILD Normal file
View File

@ -0,0 +1,24 @@
# 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.
package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0
# The target is here, because it's doesn't build on Bazel 6.
# Unfortunately, rules_cc doesn't have a WORKSPACE setup and thus can't use bazel_features check.
cc_toolchain_alias(
name = "optional_current_cc_toolchain",
mandatory = False,
)

View File

@ -35,6 +35,3 @@ native_cc_common = cc_common
# buildifier: disable=native-cc
NativeCcSharedLibraryInfo = CcSharedLibraryInfo
# buildifier: disable=native-cc
NativeCcSharedLibraryHintInfo = CcSharedLibraryHintInfo

View File

@ -40,7 +40,7 @@ cc_action_type = rule(
`cc_action_type` rules are used to associate arguments and tools together to
perform a specific action. Bazel prescribes a set of known action types that are used to drive
typical C/C++/ObjC actions like compiling, linking, and archiving. The set of well-known action
types can be found in [//third_party/bazel_rules/rules_cc/cc/toolchains/actions:BUILD](https://github.com/bazelbuild/rules_cc/tree/main/cc/toolchains/actions/BUILD).
types can be found in [@rules_cc//cc/toolchains/actions:BUILD](https://github.com/bazelbuild/rules_cc/tree/main/cc/toolchains/actions/BUILD).
It's possible to create project-specific action types for use in toolchains. Be careful when
doing this, because every toolchain that encounters the action will need to be configured to

View File

@ -75,7 +75,7 @@ def cc_variable(name, type, **kwargs):
it's not possible to declare custom variables.
For a full list of available variables, see
[//third_party/bazel_rules/rules_cc/cc/toolchains/varaibles:BUILD](https://github.com/bazelbuild/rules_cc/tree/main/cc/toolchains/variables/BUILD).
[@rules_cc//cc/toolchains/varaibles:BUILD](https://github.com/bazelbuild/rules_cc/tree/main/cc/toolchains/variables/BUILD).
Example:
```
@ -91,7 +91,7 @@ def cc_variable(name, type, **kwargs):
Args:
name: (str) The name of the outer variable, and the rule.
type: The type of the variable, constructed using `types` factory in
[//third_party/bazel_rules/rules_cc/cc/toolchains/impl:variables.bzl](https://github.com/bazelbuild/rules_cc/tree/main/cc/toolchains/impl/variables.bzl).
[@rules_cc//cc/toolchains/impl:variables.bzl](https://github.com/bazelbuild/rules_cc/tree/main/cc/toolchains/impl/variables.bzl).
**kwargs: [common attributes](https://bazel.build/reference/be/common-definitions#common-attributes) that should be applied to this rule.
"""
_cc_variable(name = name, type = json.encode(type), **kwargs)

View File

@ -102,7 +102,7 @@ This can help work around errors like:
providers = [ToolCapabilityInfo],
doc = """Declares that a tool is capable of doing something.
For example, `//third_party/bazel_rules/rules_cc/cc/toolchains/capabilities:supports_pic`.
For example, `@rules_cc//cc/toolchains/capabilities:supports_pic`.
""",
),
},

View File

@ -75,7 +75,7 @@ def cc_tool_map(name, tools, **kwargs):
`CXX=/path/to/clang++` environment variables that most build systems use to determine which
tools to use for a given action. To simplify usage, some actions have been grouped together (for
example,
[//third_party/bazel_rules/rules_cc/cc/toolchains/actions:cpp_compile_actions](https://github.com/bazelbuild/rules_cc/tree/main/cc/toolchains/actions/BUILD)) to
[@rules_cc//cc/toolchains/actions:cpp_compile_actions](https://github.com/bazelbuild/rules_cc/tree/main/cc/toolchains/actions/BUILD)) to
logically express "all the C++ compile actions".
In Bazel, there is a little more granularity to the mapping, so the mapping doesn't follow the

View File

@ -81,7 +81,7 @@ filegroup(
cc_toolchain_suite(
name = "legacy_selector",
toolchains = {
"x86": ":my_custom_toolchain",
"k8": ":my_custom_toolchain",
},
)