1# Copyright 2019 The Bazel Authors. All rights reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15# platforms.bzl defines PLATFORMS, a table that describes each possible 16# target platform. This table is used to generate config_settings, 17# constraint_values, platforms, and toolchains. 18 19BAZEL_GOOS_CONSTRAINTS = { 20 "android": "@platforms//os:android", 21 "darwin": "@platforms//os:osx", 22 "freebsd": "@platforms//os:freebsd", 23 "ios": "@platforms//os:ios", 24 "linux": "@platforms//os:linux", 25 "windows": "@platforms//os:windows", 26} 27 28BAZEL_GOARCH_CONSTRAINTS = { 29 "386": "@platforms//cpu:x86_32", 30 "amd64": "@platforms//cpu:x86_64", 31 "arm": "@platforms//cpu:arm", 32 "arm64": "@platforms//cpu:aarch64", 33 "ppc64": "@platforms//cpu:ppc", 34 "ppc64le": "@platforms//cpu:ppc", 35 "s390x": "@platforms//cpu:s390x", 36} 37 38GOOS_GOARCH = ( 39 ("aix", "ppc64"), 40 ("android", "386"), 41 ("android", "amd64"), 42 ("android", "arm"), 43 ("android", "arm64"), 44 ("darwin", "386"), 45 ("darwin", "amd64"), 46 ("darwin", "arm"), 47 ("darwin", "arm64"), 48 ("dragonfly", "amd64"), 49 ("freebsd", "386"), 50 ("freebsd", "amd64"), 51 ("freebsd", "arm"), 52 ("freebsd", "arm64"), 53 ("illumos", "amd64"), 54 ("ios", "amd64"), 55 ("ios", "arm64"), 56 ("js", "wasm"), 57 ("linux", "386"), 58 ("linux", "amd64"), 59 ("linux", "arm"), 60 ("linux", "arm64"), 61 ("linux", "mips"), 62 ("linux", "mips64"), 63 ("linux", "mips64le"), 64 ("linux", "mipsle"), 65 ("linux", "ppc64"), 66 ("linux", "ppc64le"), 67 ("linux", "riscv64"), 68 ("linux", "s390x"), 69 ("nacl", "386"), 70 ("nacl", "amd64p32"), 71 ("nacl", "arm"), 72 ("netbsd", "386"), 73 ("netbsd", "amd64"), 74 ("netbsd", "arm"), 75 ("netbsd", "arm64"), 76 ("openbsd", "386"), 77 ("openbsd", "amd64"), 78 ("openbsd", "arm"), 79 ("openbsd", "arm64"), 80 ("plan9", "386"), 81 ("plan9", "amd64"), 82 ("plan9", "arm"), 83 ("solaris", "amd64"), 84 ("windows", "386"), 85 ("windows", "amd64"), 86 ("windows", "arm"), 87 ("windows", "arm64"), 88) 89 90RACE_GOOS_GOARCH = { 91 ("darwin", "amd64"): None, 92 ("freebsd", "amd64"): None, 93 ("linux", "amd64"): None, 94 ("windows", "amd64"): None, 95} 96 97MSAN_GOOS_GOARCH = { 98 ("linux", "amd64"): None, 99} 100 101CGO_GOOS_GOARCH = { 102 ("aix", "ppc64"): None, 103 ("android", "386"): None, 104 ("android", "amd64"): None, 105 ("android", "arm"): None, 106 ("android", "arm64"): None, 107 ("darwin", "amd64"): None, 108 ("darwin", "arm"): None, 109 ("darwin", "arm64"): None, 110 ("dragonfly", "amd64"): None, 111 ("freebsd", "386"): None, 112 ("freebsd", "amd64"): None, 113 ("freebsd", "arm"): None, 114 ("illumos", "amd64"): None, 115 ("ios", "amd64"): None, 116 ("ios", "arm64"): None, 117 ("linux", "386"): None, 118 ("linux", "amd64"): None, 119 ("linux", "arm"): None, 120 ("linux", "arm64"): None, 121 ("linux", "mips"): None, 122 ("linux", "mips64"): None, 123 ("linux", "mips64le"): None, 124 ("linux", "mipsle"): None, 125 ("linux", "ppc64le"): None, 126 ("linux", "riscv64"): None, 127 ("linux", "s390x"): None, 128 ("linux", "sparc64"): None, 129 ("netbsd", "386"): None, 130 ("netbsd", "amd64"): None, 131 ("netbsd", "arm"): None, 132 ("netbsd", "arm64"): None, 133 ("openbsd", "386"): None, 134 ("openbsd", "amd64"): None, 135 ("openbsd", "arm"): None, 136 ("openbsd", "arm64"): None, 137 ("solaris", "amd64"): None, 138 ("windows", "386"): None, 139 ("windows", "amd64"): None, 140 ("windows", "arm64"): None, 141} 142 143def _generate_constraints(names, bazel_constraints): 144 return { 145 name: bazel_constraints.get(name, "@io_bazel_rules_go//go/toolchain:" + name) 146 for name in names 147 } 148 149GOOS_CONSTRAINTS = _generate_constraints([p[0] for p in GOOS_GOARCH], BAZEL_GOOS_CONSTRAINTS) 150GOARCH_CONSTRAINTS = _generate_constraints([p[1] for p in GOOS_GOARCH], BAZEL_GOARCH_CONSTRAINTS) 151 152def _generate_platforms(): 153 platforms = [] 154 for goos, goarch in GOOS_GOARCH: 155 constraints = [ 156 GOOS_CONSTRAINTS[goos], 157 GOARCH_CONSTRAINTS[goarch], 158 ] 159 platforms.append(struct( 160 name = goos + "_" + goarch, 161 goos = goos, 162 goarch = goarch, 163 constraints = constraints + ["@io_bazel_rules_go//go/toolchain:cgo_off"], 164 cgo = False, 165 )) 166 if (goos, goarch) in CGO_GOOS_GOARCH: 167 # On Windows, Bazel will pick an MSVC toolchain unless we 168 # specifically request mingw or msys. 169 mingw = ["@bazel_tools//tools/cpp:mingw"] if goos == "windows" else [] 170 platforms.append(struct( 171 name = goos + "_" + goarch + "_cgo", 172 goos = goos, 173 goarch = goarch, 174 constraints = constraints + ["@io_bazel_rules_go//go/toolchain:cgo_on"] + mingw, 175 cgo = True, 176 )) 177 178 return platforms 179 180PLATFORMS = _generate_platforms() 181