Skip to content
Merged
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
2 changes: 0 additions & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ platforms:
- "-//tests/core/coverage:coverage_test_test"
- "-//tests/core/coverage:cross_cover_test_test"
- "-//tests/core/cross:cross_test"
- "-//tests/core/cross:ios_select_test"
- "-//tests/core/go_binary:go_default_test"
- "-//tests/core/go_path:go_path"
- "-//tests/core/go_path:go_path_test"
Expand Down Expand Up @@ -341,7 +340,6 @@ platforms:
- "-//tests/core/coverage:coverage_test_test"
- "-//tests/core/coverage:cross_cover_test_test"
- "-//tests/core/cross:cross_test"
- "-//tests/core/cross:ios_select_test"
- "-//tests/core/go_binary:go_default_test"
- "-//tests/core/go_binary:stamp_test"
- "-//tests/core/go_path:go_path"
Expand Down
39 changes: 23 additions & 16 deletions go/platform/list.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,45 @@ GOARCH = _GOARCH
RACE_GOOS_GOARCH = _RACE_GOOS_GOARCH
MSAN_GOOS_GOARCH = _MSAN_GOOS_GOARCH

def _os_constraint(goos):
if goos == "darwin":
return "@io_bazel_rules_go//go/toolchain:is_darwin"
else:
return "@io_bazel_rules_go//go/toolchain:" + goos

def _arch_constraint(goarch):
return "@io_bazel_rules_go//go/toolchain:" + goarch

def declare_config_settings():
"""Generates config_setting targets for each goos, goarch, and valid
goos_goarch pair. These targets may be used in select expressions.
Each target refers to a corresponding constraint_value in //go/toolchain.

Note that the "darwin" targets are true when building for either
macOS or iOS.
"""
for goos in GOOS:
native.config_setting(
name = goos,
constraint_values = [_os_constraint(goos)],
constraint_values = ["@io_bazel_rules_go//go/toolchain:" + goos],
)
for goarch in GOARCH:
native.config_setting(
name = goarch,
constraint_values = [_arch_constraint(goarch)],
constraint_values = ["@io_bazel_rules_go//go/toolchain:" + goarch],
)
for goos, goarch in GOOS_GOARCH:
native.config_setting(
name = goos + "_" + goarch,
constraint_values = [
_os_constraint(goos),
_arch_constraint(goarch),
"@io_bazel_rules_go//go/toolchain:" + goos,
"@io_bazel_rules_go//go/toolchain:" + goarch,
],
)

# Additional settings for ios. Unfortunately, we cannot have a "darwin"
# setting that covers both operating systems, so "darwin" here means macOS.
# The "darwin" build tag will be true for both during execution; this only
# matters when evaluating select expressions.
native.config_setting(
name = "ios",
constraint_values = [
"@bazel_tools//platforms:ios",
],
)
for goarch in ("arm", "arm64", "386", "amd64"):
native.config_setting(
name = "ios_" + goarch,
constraint_values = [
"@bazel_tools//platforms:ios",
"@io_bazel_rules_go//go/toolchain:" + goarch,
]
)
7 changes: 0 additions & 7 deletions go/private/compat/compat_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@
load("@io_bazel_rules_go//go/private:skylib/lib/versions.bzl", "versions")

def _go_rules_compat_impl(ctx):
darwin_tpl_path = ctx.path(Label("@io_bazel_rules_go//go/private:compat/darwin.bzl.tpl"))
if "mac" in ctx.os.name:
default_darwin_constraint_value = "@io_bazel_rules_go//go/toolchain:is_darwin"
else:
default_darwin_constraint_value = "@io_bazel_rules_go//go/toolchain:not_darwin"
ctx.template("darwin.bzl", darwin_tpl_path, {"{default_darwin_constraint_value}": default_darwin_constraint_value})

ctx.file("BUILD.bazel")
ctx.symlink(ctx.attr.impl, "compat.bzl")

Expand Down
15 changes: 0 additions & 15 deletions go/private/compat/darwin.bzl.tpl

This file was deleted.

13 changes: 12 additions & 1 deletion go/private/go_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ def declare_toolchains(host, sdk, builder):

cgo_context_data = "@io_bazel_rules_go//:cgo_context_data" if p.cgo else None

constraints = p.constraints
if p.goos != host_goos or p.goarch != host_goarch:
# When cross-compiling, don't require cgo_off.
# It won't be set on a custom platform outside of //go/toolchain.
constraints = [c for c in constraints if c != "@io_bazel_rules_go//go/toolchain:cgo_off"]
else:
# When compiling for the host platform, don't require cgo_on.
# It won't be set on @bazel_tools//platforms:target_platform,
# which is probably the target.
constraints = [c for c in constraints if c != "@io_bazel_rules_go//go/toolchain:cgo_on"]

go_toolchain(
name = impl_name,
goos = p.goos,
Expand All @@ -131,6 +142,6 @@ def declare_toolchains(host, sdk, builder):
"@io_bazel_rules_go//go/toolchain:" + host_goos,
"@io_bazel_rules_go//go/toolchain:" + host_goarch,
],
target_compatible_with = p.constraints,
target_compatible_with = constraints,
toolchain = ":" + impl_name,
)
8 changes: 2 additions & 6 deletions go/private/platforms.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def _generate_platforms():
GOOS_CONSTRAINTS[goos],
GOARCH_CONSTRAINTS[goarch],
]
constraints.append("@io_bazel_rules_go//go/toolchain:" + ("is_darwin" if goos == "darwin" else "not_darwin"))
platforms.append(struct(
name = goos + "_" + goarch,
goos = goos,
Expand All @@ -162,22 +161,19 @@ def _generate_platforms():
constraints = [
"@bazel_tools//platforms:ios",
GOARCH_CONSTRAINTS[goarch],
"@io_bazel_rules_go//go/toolchain:is_darwin",
"@io_bazel_rules_go//go/toolchain:cgo_off",
]
platforms.append(struct(
name = "ios_" + goarch,
goos = "darwin",
goarch = goarch,
constraints = constraints,
constraints = constraints + ["@io_bazel_rules_go//go/toolchain:cgo_off"],
cgo = False,
))
constraints[-1] = "@io_bazel_rules_go//go/toolchain:cgo_on"
platforms.append(struct(
name = "ios_" + goarch + "_cgo",
goos = "darwin",
goarch = goarch,
constraints = constraints,
constraints = constraints + ["@io_bazel_rules_go//go/toolchain:cgo_on"],
cgo = True,
))

Expand Down
24 changes: 0 additions & 24 deletions go/toolchain/toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ load(
"GOOS_CONSTRAINTS",
"PLATFORMS",
)
load(
"@io_bazel_rules_go_compat//:darwin.bzl",
"DEFAULT_DARWIN_CONSTRAINT_VALUE",
)

# These symbols should be loaded from sdk.bzl or deps.bzl instead of here..
DEFAULT_VERSION = _DEFAULT_VERSION
Expand All @@ -48,10 +44,6 @@ def declare_constraints():
To avoid redundancy, if there is an equivalent value in @bazel_tools,
we define an alias here instead of another constraint_value.

There is a special constraint_setting for Darwin, "darwin_constraint".
The value is "is_darwin" when the target is macOS or iOS and "not_darwin"
otherwise.

Each platform defined here selects a goos and goarch constraint value.
These platforms may be used with --platforms for cross-compilation,
though users may create their own platforms (and
Expand Down Expand Up @@ -81,24 +73,8 @@ def declare_constraints():
actual = constraint,
)

native.constraint_setting(
name = "darwin_constraint",
default_constraint_value = DEFAULT_DARWIN_CONSTRAINT_VALUE,
)

native.constraint_value(
name = "is_darwin",
constraint_setting = ":darwin_constraint",
)

native.constraint_value(
name = "not_darwin",
constraint_setting = ":darwin_constraint",
)

native.constraint_setting(
name = "cgo_constraint",
default_constraint_value = ":cgo_on",
)

native.constraint_value(
Expand Down
30 changes: 2 additions & 28 deletions tests/core/cross/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,9 @@ go_test(
deps = ["//go/tools/bazel:go_default_library"],
)

bazel_test(
go_bazel_test(
name = "ios_select_test",
args = ["--platforms=@io_bazel_rules_go//go/toolchain:ios_amd64"],
command = "build",
targets = [":ios_lib"],
)

go_library(
name = "use_ios_lib",
importpath = "github.com/bazelbuild/rules_go/tests/core/cross/use_ios_lib",
deps = select({
":is_osx": [":ios_lib"],
"//conditions:default": [],
}),
)

config_setting(
name = "is_osx",
constraint_values = ["@bazel_tools//platforms:osx"],
)

go_library(
name = "ios_lib",
srcs = select({
"@io_bazel_rules_go//go/platform:darwin": ["ios_good.go"],
"//conditions:default": ["ios_bad.go"],
}),
importpath = "github.com/bazelbuild/rules_go/tests/core/cross/ios_lib",
tags = ["manual"],
srcs = ["ios_select_test.go"],
)

go_bazel_test(
Expand Down
2 changes: 0 additions & 2 deletions tests/core/cross/ios_bad.go

This file was deleted.

1 change: 0 additions & 1 deletion tests/core/cross/ios_good.go

This file was deleted.

66 changes: 66 additions & 0 deletions tests/core/cross/ios_select_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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.

package ios_select_test

import (
"testing"

"github.com/bazelbuild/rules_go/go/tools/bazel_testing"
)

func TestMain(m *testing.M) {
bazel_testing.TestMain(m, bazel_testing.Args{
Main: `
-- BUILD.bazel --
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "use_ios_lib",
importpath = "github.com/bazelbuild/rules_go/tests/core/cross/use_ios_lib",
deps = select({
":is_osx": [":ios_lib"],
"//conditions:default": [],
}),
)

config_setting(
name = "is_osx",
constraint_values = ["@bazel_tools//platforms:osx"],
)

go_library(
name = "ios_lib",
srcs = select({
"@io_bazel_rules_go//go/platform:darwin": ["ios_good.go"],
"@io_bazel_rules_go//go/platform:ios": ["ios_good.go"],
"//conditions:default": ["ios_bad.go"],
}),
importpath = "github.com/bazelbuild/rules_go/tests/core/cross/ios_lib",
)

-- ios_good.go --
package ios_lib

-- ios_bad.go --
donotbuild
`,
})
}

func Test(t *testing.T) {
if err := bazel_testing.RunBazel("build", "--platforms=@io_bazel_rules_go//go/toolchain:ios_amd64", ":ios_lib"); err != nil {
t.Fatal(err)
}
}