diff --git a/go/platform/list.bzl b/go/platform/list.bzl index 8866549362..b7355f3470 100644 --- a/go/platform/list.bzl +++ b/go/platform/list.bzl @@ -21,6 +21,7 @@ load( _MSAN_GOOS_GOARCH = "MSAN_GOOS_GOARCH", _RACE_GOOS_GOARCH = "RACE_GOOS_GOARCH", ) +load("@io_bazel_rules_go_compat//:compat.bzl", "platforms_os_constraint_value") GOOS_GOARCH = _GOOS_GOARCH GOOS = _GOOS @@ -59,14 +60,14 @@ def declare_config_settings(): native.config_setting( name = "ios", constraint_values = [ - "@bazel_tools//platforms:ios", + platforms_os_constraint_value("ios"), ], ) for goarch in ("arm", "arm64", "386", "amd64"): native.config_setting( name = "ios_" + goarch, constraint_values = [ - "@bazel_tools//platforms:ios", + platforms_os_constraint_value("ios"), "@io_bazel_rules_go//go/toolchain:" + goarch, ], ) diff --git a/go/private/compat/compat_repo.bzl b/go/private/compat/compat_repo.bzl index 1273753f50..23e7877657 100644 --- a/go/private/compat/compat_repo.bzl +++ b/go/private/compat/compat_repo.bzl @@ -38,7 +38,7 @@ _go_rules_compat = repository_rule( ) def go_rules_compat(**kwargs): - impls = [23, 25] # keep sorted + impls = [23, 25, 28] # keep sorted if not native.bazel_version: # bazel_version is None in development builds, so we can't do a # version comparison. Use the newest version of the compat file. diff --git a/go/private/compat/v23.bzl b/go/private/compat/v23.bzl index e73b5af2ab..6f8cdc81fc 100644 --- a/go/private/compat/v23.bzl +++ b/go/private/compat/v23.bzl @@ -90,3 +90,11 @@ def cc_configure_features(ctx, cc_toolchain, requested_features, unsupported_fea requested_features = requested_features, unsupported_features = unsupported_features, ) + +# Compatibility for --incompatible_use_platforms_repo_for_constraints + +def platforms_os_constraint_value(value): + return "@bazel_tools//:" + value + +def platforms_cpu_constraint_value(value): + return "@bazel_tools//:" + value diff --git a/go/private/compat/v25.bzl b/go/private/compat/v25.bzl index 1c632c5acb..3d7420e697 100644 --- a/go/private/compat/v25.bzl +++ b/go/private/compat/v25.bzl @@ -95,3 +95,11 @@ def cc_configure_features(ctx, cc_toolchain, requested_features, unsupported_fea requested_features = requested_features, unsupported_features = unsupported_features, ) + +# Compatibility for --incompatible_use_platforms_repo_for_constraints + +def platforms_os_constraint_value(value): + return "@bazel_tools//:" + value + +def platforms_cpu_constraint_value(value): + return "@bazel_tools//:" + value diff --git a/go/private/compat/v28.bzl b/go/private/compat/v28.bzl new file mode 100644 index 0000000000..ec997f2f4c --- /dev/null +++ b/go/private/compat/v28.bzl @@ -0,0 +1,105 @@ +# Copyright 2019 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("@io_bazel_rules_go//go/private:common.bzl", "as_iterable") +load( + "@bazel_tools//tools/cpp:toolchain_utils.bzl", + "find_cpp_toolchain", +) + +# Compatibility for --incompatible_disable_legacy_cc_provider + +CC_PROVIDER_NAME = CcInfo + +def has_cc(target): + return CcInfo in target + +def cc_transitive_headers(target): + return target[CcInfo].compilation_context.headers + +def cc_defines(target): + return target[CcInfo].compilation_context.defines.to_list() + +def cc_system_includes(target): + return target[CcInfo].compilation_context.system_includes.to_list() + +def cc_includes(target): + return target[CcInfo].compilation_context.includes.to_list() + +def cc_quote_includes(target): + return target[CcInfo].compilation_context.quote_includes.to_list() + +def cc_link_flags(target): + return target[CcInfo].linking_context.user_link_flags + +def cc_libs(target): + # Copied from get_libs_for_static_executable in migration instructions + # from bazelbuild/bazel#7036. + libraries_to_link = as_iterable(target[CcInfo].linking_context.libraries_to_link) + libs = [] + for library_to_link in libraries_to_link: + if library_to_link.static_library != None: + libs.append(library_to_link.static_library) + elif library_to_link.pic_static_library != None: + libs.append(library_to_link.pic_static_library) + elif library_to_link.interface_library != None: + libs.append(library_to_link.interface_library) + elif library_to_link.dynamic_library != None: + libs.append(library_to_link.dynamic_library) + return libs + +def cc_toolchain_all_files(ctx): + return find_cpp_toolchain(ctx).all_files.to_list() + +# Compatibility for --incompatible_disable_legacy_proto_provider + +PROTO_PROVIDER_NAME = ProtoInfo + +def has_proto(target): + return ProtoInfo in target + +def get_proto(target): + return target[ProtoInfo] + +def proto_check_deps_sources(target): + return target[ProtoInfo].check_deps_sources + +def proto_source_root(target): + return target[ProtoInfo].proto_source_root + +# Compatibility for --incompatible_disallow_struct_provider +def providers_with_coverage(ctx, source_attributes, dependency_attributes, extensions, providers): + return providers + [coverage_common.instrumented_files_info( + ctx, + source_attributes = source_attributes, + dependency_attributes = dependency_attributes, + extensions = extensions, + )] + +# Compatibility for --incompatible_require_ctx_in_configure_features +def cc_configure_features(ctx, cc_toolchain, requested_features, unsupported_features): + return cc_common.configure_features( + ctx = ctx, + cc_toolchain = cc_toolchain, + requested_features = requested_features, + unsupported_features = unsupported_features, + ) + +# Compatibility for --incompatible_use_platforms_repo_for_constraints + +def platforms_os_constraint_value(value): + return "@platforms//os:" + value + +def platforms_cpu_constraint_value(value): + return "@platforms//cpu:" + value diff --git a/go/private/platforms.bzl b/go/private/platforms.bzl index e22898270b..a5aca94f1a 100644 --- a/go/private/platforms.bzl +++ b/go/private/platforms.bzl @@ -16,21 +16,23 @@ # target platform. This table is used to generate config_settings, # constraint_values, platforms, and toolchains. +load("@io_bazel_rules_go_compat//:compat.bzl", "platforms_os_constraint_value", "platforms_cpu_constraint_value") + BAZEL_GOOS_CONSTRAINTS = { - "android": "@bazel_tools//platforms:android", - "darwin": "@bazel_tools//platforms:osx", - "freebsd": "@bazel_tools//platforms:freebsd", - "linux": "@bazel_tools//platforms:linux", - "windows": "@bazel_tools//platforms:windows", + "android": platforms_os_constraint_value("android"), + "darwin": platforms_os_constraint_value("osx"), + "freebsd": platforms_os_constraint_value("freebsd"), + "linux": platforms_os_constraint_value("linux"), + "windows": platforms_os_constraint_value("windows"), } BAZEL_GOARCH_CONSTRAINTS = { - "386": "@bazel_tools//platforms:x86_32", - "amd64": "@bazel_tools//platforms:x86_64", - "arm": "@bazel_tools//platforms:arm", - "arm64": "@bazel_tools//platforms:aarch64", - "ppc64le": "@bazel_tools//platforms:ppc", - "s390x": "@bazel_tools//platforms:s390x", + "386": platforms_cpu_constraint_value("x86_32"), + "amd64": platforms_cpu_constraint_value("x86_64"), + "arm": platforms_cpu_constraint_value("arm"), + "arm64": platforms_cpu_constraint_value("aarch64"), + "ppc64le": platforms_cpu_constraint_value("ppc"), + "s390x": platforms_cpu_constraint_value("s390x"), } GOOS_GOARCH = ( @@ -159,7 +161,7 @@ def _generate_platforms(): for goarch in ("arm", "arm64", "386", "amd64"): constraints = [ - "@bazel_tools//platforms:ios", + platforms_os_constraint_value("ios"), GOARCH_CONSTRAINTS[goarch], ] platforms.append(struct( diff --git a/go/private/repositories.bzl b/go/private/repositories.bzl index 194f4e91df..be6a53f39e 100644 --- a/go/private/repositories.bzl +++ b/go/private/repositories.bzl @@ -47,6 +47,17 @@ def go_rules_dependencies(): name = "io_bazel_rules_go_compat", ) + _maybe( + http_archive, + name = "platforms", + strip_prefix = "platforms-441afe1bfdadd6236988e9cac159df6b5a9f5a98", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/platforms/archive/441afe1bfdadd6236988e9cac159df6b5a9f5a98.zip", + "https://github.com/bazelbuild/platforms/archive/441afe1bfdadd6236988e9cac159df6b5a9f5a98.zip", + ], + sha256 = "a07fe5e75964361885db725039c2ba673f0ee0313d971ae4f50c9b18cd28b0b5", + ) + # Needed by rules_go implementation and tests. # We can't call bazel_skylib_workspace from here. At the moment, it's only # used to register unittest toolchains, which rules_go does not need. diff --git a/go/toolchain/toolchains.bzl b/go/toolchain/toolchains.bzl index f323f54300..53916d3df3 100644 --- a/go/toolchain/toolchains.bzl +++ b/go/toolchain/toolchains.bzl @@ -28,6 +28,7 @@ load( "GOOS_CONSTRAINTS", "PLATFORMS", ) +load("@io_bazel_rules_go_compat//:compat.bzl", "platforms_os_constraint_value", "platforms_cpu_constraint_value") # These symbols should be loaded from sdk.bzl or deps.bzl instead of here.. DEFAULT_VERSION = _DEFAULT_VERSION @@ -40,7 +41,7 @@ def declare_constraints(): Each constraint_value corresponds to a valid goos or goarch. The goos and goarch values belong to the constraint_settings - @bazel_tools//platforms:os and @bazel_tools//platforms:cpu, respectively. + @platforms//os:os and @platforms//cpu:cpu, respectively. To avoid redundancy, if there is an equivalent value in @bazel_tools, we define an alias here instead of another constraint_value. @@ -53,7 +54,7 @@ def declare_constraints(): if constraint.startswith("@io_bazel_rules_go//go/toolchain:"): native.constraint_value( name = goos, - constraint_setting = "@bazel_tools//platforms:os", + constraint_setting = platforms_os_constraint_value("os"), ) else: native.alias( @@ -65,7 +66,7 @@ def declare_constraints(): if constraint.startswith("@io_bazel_rules_go//go/toolchain:"): native.constraint_value( name = goarch, - constraint_setting = "@bazel_tools//platforms:cpu", + constraint_setting = platforms_cpu_constraint_value("cpu"), ) else: native.alias( diff --git a/tests/core/cross/ios_select_test.go b/tests/core/cross/ios_select_test.go index fa871c6289..b67f76eccd 100644 --- a/tests/core/cross/ios_select_test.go +++ b/tests/core/cross/ios_select_test.go @@ -25,6 +25,7 @@ func TestMain(m *testing.M) { Main: ` -- BUILD.bazel -- load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go_compat//:compat.bzl", "platforms_os_constraint_value") go_library( name = "use_ios_lib", @@ -37,7 +38,7 @@ go_library( config_setting( name = "is_osx", - constraint_values = ["@bazel_tools//platforms:osx"], + constraint_values = [platforms_os_constraint_value("ios")], ) go_library(