Skip to content

Commit

Permalink
Revert "Add automatic platform detection from inbound crosstool_top a…
Browse files Browse the repository at this point in the history
…nd cpu (#2859)"

This reverts commit 026db6d.

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.
  • Loading branch information
fmeum committed Apr 19, 2023
1 parent 7377180 commit 7efd136
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 87 deletions.
5 changes: 0 additions & 5 deletions go/platform/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,3 @@ bzl_library(
name = "apple",
srcs = ["apple.bzl"],
)

bzl_library(
name = "crosstool",
srcs = ["crosstool.bzl"],
)
60 changes: 0 additions & 60 deletions go/platform/crosstool.bzl

This file was deleted.

1 change: 0 additions & 1 deletion go/private/rules/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ bzl_library(
"//proto:__pkg__",
],
deps = [
"//go/platform:crosstool",
"//go/private:mode",
"//go/private:platforms",
"//go/private:providers",
Expand Down
19 changes: 0 additions & 19 deletions go/private/rules/transition.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +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"
Expand Down Expand Up @@ -101,8 +97,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":
Expand All @@ -115,17 +109,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:
Expand Down Expand Up @@ -181,8 +164,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 = [
Expand Down
2 changes: 1 addition & 1 deletion go/tools/gopackagesdriver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ go_library(
go_binary(
name = "gopackagesdriver",
embed = [":gopackagesdriver_lib"],
visibility = ["//visibility:public"],
x_defs = {
# Determine the name of the rules_go repository as we need to specify it when invoking the
# aspect.
Expand All @@ -35,5 +36,4 @@ go_binary(
# use "@" + repository_name().
"rulesGoRepositoryName": "@" + repository_name() if bazel_supports_canonical_label_literals() else repository_name(),
},
visibility = ["//visibility:public"],
)
5 changes: 4 additions & 1 deletion tests/core/cross/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ go_binary(

go_binary(
name = "asm_cross",
srcs = ["asm.s", "main.go"],
srcs = [
"asm.s",
"main.go",
],
goarch = "386",
goos = "linux",
deps = [":platform_lib"],
Expand Down

0 comments on commit 7efd136

Please sign in to comment.