Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions go/platform/list.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
],
)
Expand Down
2 changes: 1 addition & 1 deletion go/private/compat/compat_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions go/private/compat/v23.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions go/private/compat/v25.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
105 changes: 105 additions & 0 deletions go/private/compat/v28.bzl
Original file line number Diff line number Diff line change
@@ -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
26 changes: 14 additions & 12 deletions go/private/platforms.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions go/private/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions go/toolchain/toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Expand All @@ -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(
Expand All @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion tests/core/cross/ios_select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(
Expand Down