github.com/bazelbuild/bazel-gazelle@v0.36.1-0.20240520142334-61b277ba6fed/rule/platform.go (about) 1 /* Copyright 2017 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 16 package rule 17 18 import ( 19 "sort" 20 ) 21 22 // Platform represents a GOOS/GOARCH pair. When Platform is used to describe 23 // sources, dependencies, or flags, either OS or Arch may be empty. 24 // 25 // DEPRECATED: do not use outside language/go. This type is Go-specific 26 // and should be moved to the Go extension. 27 type Platform struct { 28 OS, Arch string 29 } 30 31 // String returns OS, Arch, or "OS_Arch" if both are set. This must match 32 // the names of config_setting rules in @io_bazel_rules_go//go/platform. 33 func (p Platform) String() string { 34 switch { 35 case p.OS != "" && p.Arch != "": 36 return p.OS + "_" + p.Arch 37 case p.OS != "": 38 return p.OS 39 case p.Arch != "": 40 return p.Arch 41 default: 42 return "" 43 } 44 } 45 46 // KnownPlatforms is the set of target platforms that Go supports. Gazelle 47 // will generate multi-platform build files using these tags. rules_go and 48 // Bazel may not actually support all of these. 49 // 50 // DEPRECATED: do not use outside language/go. 51 var KnownPlatforms = []Platform{ 52 {"aix", "ppc64"}, 53 {"android", "386"}, 54 {"android", "amd64"}, 55 {"android", "arm"}, 56 {"android", "arm64"}, 57 {"darwin", "386"}, 58 {"darwin", "amd64"}, 59 {"darwin", "arm"}, 60 {"darwin", "arm64"}, 61 {"dragonfly", "amd64"}, 62 {"freebsd", "386"}, 63 {"freebsd", "amd64"}, 64 {"freebsd", "arm"}, 65 {"freebsd", "arm64"}, 66 {"illumos", "amd64"}, 67 {"ios", "amd64"}, 68 {"ios", "arm64"}, 69 {"js", "wasm"}, 70 {"linux", "386"}, 71 {"linux", "amd64"}, 72 {"linux", "arm"}, 73 {"linux", "arm64"}, 74 {"linux", "mips"}, 75 {"linux", "mips64"}, 76 {"linux", "mips64le"}, 77 {"linux", "mipsle"}, 78 {"linux", "ppc64"}, 79 {"linux", "ppc64le"}, 80 {"linux", "riscv64"}, 81 {"linux", "s390x"}, 82 {"netbsd", "386"}, 83 {"netbsd", "amd64"}, 84 {"netbsd", "arm"}, 85 {"netbsd", "arm64"}, 86 {"openbsd", "386"}, 87 {"openbsd", "amd64"}, 88 {"openbsd", "arm"}, 89 {"openbsd", "arm64"}, 90 {"plan9", "386"}, 91 {"plan9", "amd64"}, 92 {"plan9", "arm"}, 93 {"solaris", "amd64"}, 94 {"windows", "386"}, 95 {"windows", "amd64"}, 96 {"windows", "arm"}, 97 {"windows", "arm64"}, 98 } 99 100 var OSAliases = map[string][]string{ 101 "android": {"linux"}, 102 "ios": {"darwin"}, 103 } 104 105 // UnixOS is the set of GOOS values matched by the "unix" build tag. 106 // This list is from go/src/cmd/dist/build.go. 107 var UnixOS = map[string]bool{ 108 "aix": true, 109 "android": true, 110 "darwin": true, 111 "dragonfly": true, 112 "freebsd": true, 113 "hurd": true, 114 "illumos": true, 115 "ios": true, 116 "linux": true, 117 "netbsd": true, 118 "openbsd": true, 119 "solaris": true, 120 } 121 122 var ( 123 // KnownOSs is the sorted list of operating systems that Go supports. 124 KnownOSs []string 125 126 // KnownOSSet is the set of operating systems that Go supports. 127 KnownOSSet map[string]bool 128 129 // KnownArchs is the sorted list of architectures that Go supports. 130 KnownArchs []string 131 132 // KnownArchSet is the set of architectures that Go supports. 133 KnownArchSet map[string]bool 134 135 // KnownOSArchs is a map from OS to the archictures they run on. 136 KnownOSArchs map[string][]string 137 138 // KnownArchOSs is a map from architectures to that OSs that run on them. 139 KnownArchOSs map[string][]string 140 ) 141 142 func init() { 143 KnownOSSet = make(map[string]bool) 144 KnownArchSet = make(map[string]bool) 145 KnownOSArchs = make(map[string][]string) 146 KnownArchOSs = make(map[string][]string) 147 for _, p := range KnownPlatforms { 148 KnownOSSet[p.OS] = true 149 KnownArchSet[p.Arch] = true 150 KnownOSArchs[p.OS] = append(KnownOSArchs[p.OS], p.Arch) 151 KnownArchOSs[p.Arch] = append(KnownArchOSs[p.Arch], p.OS) 152 } 153 KnownOSs = make([]string, 0, len(KnownOSSet)) 154 KnownArchs = make([]string, 0, len(KnownArchSet)) 155 for os := range KnownOSSet { 156 KnownOSs = append(KnownOSs, os) 157 } 158 for arch := range KnownArchSet { 159 KnownArchs = append(KnownArchs, arch) 160 } 161 sort.Strings(KnownOSs) 162 sort.Strings(KnownArchs) 163 }