From 4add3d9720c16fc9cb330c2f632c7b62abb96f49 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Wed, 19 Apr 2023 22:29:37 +0200 Subject: [PATCH] Revert "Add automatic platform detection from inbound crosstool_top and cpu (#2859)" (#3468) This reverts commit 026db6df5ad760e9002f627bdb4f6b695c04d76a. Bazel is migrating to platforms and toolchains resolution, but this logic frequently reset platforms back based on the value of the legacy `--cpu` and `--crosstool_top` flags. Instead, users of rules that still rely on these flags should use the `platform_mappings` file. --- go/platform/BUILD.bazel | 5 --- go/platform/crosstool.bzl | 60 --------------------------------- go/private/rules/BUILD.bazel | 1 - go/private/rules/transition.bzl | 22 ------------ 4 files changed, 88 deletions(-) delete mode 100644 go/platform/crosstool.bzl diff --git a/go/platform/BUILD.bazel b/go/platform/BUILD.bazel index 2431156237..5f31f37d92 100644 --- a/go/platform/BUILD.bazel +++ b/go/platform/BUILD.bazel @@ -36,8 +36,3 @@ bzl_library( name = "apple", srcs = ["apple.bzl"], ) - -bzl_library( - name = "crosstool", - srcs = ["crosstool.bzl"], -) diff --git a/go/platform/crosstool.bzl b/go/platform/crosstool.bzl deleted file mode 100644 index 02ec33bf75..0000000000 --- a/go/platform/crosstool.bzl +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2020 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. - -def _match_apple(_crosstool_top, cpu): - """_match_apple will try to detect wether the inbound crosstool/cpu is - targeting the Apple ecosystem. Apple crosstool CPUs are prefixed, so - matching is easy.""" - platform = { - "darwin": "darwin_amd64", - "darwin_x86_64": "darwin_amd64", - "darwin_arm64": "darwin_arm64", - "ios_arm64": "ios_arm64", - "ios_armv7": "ios_arm", - "ios_i386": "ios_386", - "ios_x86_64": "ios_amd64", - }.get(cpu) - if platform: - return "{}_cgo".format(platform) - return None - -def _match_android(crosstool_top, cpu): - """_match_android will try to detect wether the inbound crosstool is the - Android NDK toolchain. It can either be `//external:android/crosstool` or be - part of the `@androidndk` workspace. After that, translate Android CPUs to - Go CPUs.""" - if str(crosstool_top) == "//external:android/crosstool" or \ - crosstool_top.workspace_name == "androidndk": - platform_cpu = { - "arm64-v8a": "arm64", - "armeabi-v7a": "arm", - "x86": "386", - "x86_64": "amd64", - }.get(cpu) - if platform_cpu: - return "android_{}_cgo".format(platform_cpu) - return None - -def platform_from_crosstool(crosstool_top, cpu): - """platform_from_crosstool runs matchers against the crosstool_top/cpu pair - to automatically infer the target platform.""" - matchers = [ - _match_apple, - _match_android, - ] - for matcher in matchers: - platform = matcher(crosstool_top, cpu) - if platform: - return "@io_bazel_rules_go//go/toolchain:{}".format(platform) - return None diff --git a/go/private/rules/BUILD.bazel b/go/private/rules/BUILD.bazel index 2de381d597..50d2c39be3 100644 --- a/go/private/rules/BUILD.bazel +++ b/go/private/rules/BUILD.bazel @@ -144,7 +144,6 @@ bzl_library( "//proto:__pkg__", ], deps = [ - "//go/platform:crosstool", "//go/private:mode", "//go/private:platforms", "//go/private:providers", diff --git a/go/private/rules/transition.bzl b/go/private/rules/transition.bzl index 2883b9820f..8ee26ae792 100644 --- a/go/private/rules/transition.bzl +++ b/go/private/rules/transition.bzl @@ -32,13 +32,6 @@ load( "GoLibrary", "GoSource", ) -load( - "//go/platform:crosstool.bzl", - "platform_from_crosstool", -) - -_DEFAULT_PLATFORMS_VALUE = [Label("@local_config_platform//:host")] -_PLATFORMS_LABEL = "//command_line_option:platforms" # A list of rules_go settings that are possibly set by go_transition. # Keep their package name in sync with the implementation of @@ -101,8 +94,6 @@ def _go_transition_impl(settings, attr): goos = getattr(attr, "goos", "auto") goarch = getattr(attr, "goarch", "auto") - crosstool_top = settings.pop("//command_line_option:crosstool_top") - cpu = settings.pop("//command_line_option:cpu") _check_ternary("pure", pure) if goos != "auto" or goarch != "auto": if goos == "auto": @@ -115,17 +106,6 @@ def _go_transition_impl(settings, attr): fail('pure is "off" but cgo is not supported on {} {}'.format(goos, goarch)) platform = "@io_bazel_rules_go//go/toolchain:{}_{}{}".format(goos, goarch, "_cgo" if cgo else "") settings["//command_line_option:platforms"] = platform - else: - # If the current target platform differs from the default value (the - # host platform), then we don't want to override it with a value - # inferred from the legacy --cpu and --crosstool_top flags. Otherwise - # it would become impossible to "platformize" a Go build without having - # a matching platform mappings file. - if settings[_PLATFORMS_LABEL] == _DEFAULT_PLATFORMS_VALUE: - # Detect the platform the inbound crosstool/cpu. - platform = platform_from_crosstool(crosstool_top, cpu) - if platform: - settings[_PLATFORMS_LABEL] = platform tags = getattr(attr, "gotags", []) if tags: @@ -181,8 +161,6 @@ request_nogo_transition = transition( go_transition = transition( implementation = _go_transition_impl, inputs = [ - "//command_line_option:cpu", - "//command_line_option:crosstool_top", "//command_line_option:platforms", ] + TRANSITIONED_GO_SETTING_KEYS, outputs = [