Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. 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 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 15 | package android |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 16 | |
| 17 | import ( |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 18 | "fmt" |
| 19 | "reflect" |
| 20 | "runtime" |
| 21 | "strings" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 22 | |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint/proptools" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 24 | ) |
| 25 | |
| 26 | var ( |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 27 | archTypeList []ArchType |
| 28 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 29 | Arm = newArch("arm", "lib32") |
| 30 | Arm64 = newArch("arm64", "lib64") |
| 31 | Mips = newArch("mips", "lib32") |
| 32 | Mips64 = newArch("mips64", "lib64") |
| 33 | X86 = newArch("x86", "lib32") |
| 34 | X86_64 = newArch("x86_64", "lib64") |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 35 | |
| 36 | Common = ArchType{ |
| 37 | Name: "common", |
| 38 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 39 | ) |
| 40 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 41 | var archTypeMap = map[string]ArchType{ |
| 42 | "arm": Arm, |
| 43 | "arm64": Arm64, |
| 44 | "mips": Mips, |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 45 | "mips64": Mips64, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 46 | "x86": X86, |
| 47 | "x86_64": X86_64, |
| 48 | } |
| 49 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 50 | /* |
| 51 | Example blueprints file containing all variant property groups, with comment listing what type |
| 52 | of variants get properties in that group: |
| 53 | |
| 54 | module { |
| 55 | arch: { |
| 56 | arm: { |
| 57 | // Host or device variants with arm architecture |
| 58 | }, |
| 59 | arm64: { |
| 60 | // Host or device variants with arm64 architecture |
| 61 | }, |
| 62 | mips: { |
| 63 | // Host or device variants with mips architecture |
| 64 | }, |
| 65 | mips64: { |
| 66 | // Host or device variants with mips64 architecture |
| 67 | }, |
| 68 | x86: { |
| 69 | // Host or device variants with x86 architecture |
| 70 | }, |
| 71 | x86_64: { |
| 72 | // Host or device variants with x86_64 architecture |
| 73 | }, |
| 74 | }, |
| 75 | multilib: { |
| 76 | lib32: { |
| 77 | // Host or device variants for 32-bit architectures |
| 78 | }, |
| 79 | lib64: { |
| 80 | // Host or device variants for 64-bit architectures |
| 81 | }, |
| 82 | }, |
| 83 | target: { |
| 84 | android: { |
| 85 | // Device variants |
| 86 | }, |
| 87 | host: { |
| 88 | // Host variants |
| 89 | }, |
Dan Willemsen | 5746bd4 | 2017-10-02 19:42:01 -0700 | [diff] [blame] | 90 | linux_glibc: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 91 | // Linux host variants |
| 92 | }, |
| 93 | darwin: { |
| 94 | // Darwin host variants |
| 95 | }, |
| 96 | windows: { |
| 97 | // Windows host variants |
| 98 | }, |
| 99 | not_windows: { |
| 100 | // Non-windows host variants |
| 101 | }, |
| 102 | }, |
| 103 | } |
| 104 | */ |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 105 | |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 106 | var archVariants = map[ArchType][]string{ |
| 107 | Arm: { |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 108 | "armv7-a-neon", |
| 109 | "armv8-a", |
| 110 | "armv8-2a", |
| 111 | "cortex-a7", |
| 112 | "cortex-a8", |
| 113 | "cortex-a9", |
| 114 | "cortex-a15", |
| 115 | "cortex-a53", |
| 116 | "cortex-a53-a57", |
| 117 | "cortex-a55", |
| 118 | "cortex-a72", |
| 119 | "cortex-a73", |
| 120 | "cortex-a75", |
| 121 | "cortex-a76", |
| 122 | "krait", |
| 123 | "kryo", |
| 124 | "kryo385", |
| 125 | "exynos-m1", |
| 126 | "exynos-m2", |
| 127 | }, |
| 128 | Arm64: { |
| 129 | "armv8_a", |
| 130 | "armv8_2a", |
| 131 | "cortex-a53", |
| 132 | "cortex-a55", |
| 133 | "cortex-a72", |
| 134 | "cortex-a73", |
| 135 | "cortex-a75", |
| 136 | "cortex-a76", |
| 137 | "kryo", |
| 138 | "kryo385", |
| 139 | "exynos-m1", |
| 140 | "exynos-m2", |
| 141 | }, |
| 142 | Mips: { |
| 143 | "mips32_fp", |
| 144 | "mips32r2_fp", |
| 145 | "mips32r2_fp_xburst", |
| 146 | "mips32r2dsp_fp", |
| 147 | "mips32r2dspr2_fp", |
| 148 | "mips32r6", |
| 149 | }, |
| 150 | Mips64: { |
| 151 | "mips64r2", |
| 152 | "mips64r6", |
| 153 | }, |
| 154 | X86: { |
| 155 | "atom", |
| 156 | "haswell", |
| 157 | "ivybridge", |
| 158 | "sandybridge", |
| 159 | "silvermont", |
| 160 | "x86_64", |
| 161 | }, |
| 162 | X86_64: { |
| 163 | "haswell", |
| 164 | "ivybridge", |
| 165 | "sandybridge", |
| 166 | "silvermont", |
| 167 | }, |
| 168 | } |
| 169 | |
| 170 | var archFeatures = map[ArchType][]string{ |
| 171 | Arm: { |
| 172 | "neon", |
| 173 | }, |
| 174 | Mips: { |
| 175 | "dspr2", |
| 176 | "rev6", |
| 177 | "msa", |
| 178 | }, |
| 179 | Mips64: { |
| 180 | "rev6", |
| 181 | "msa", |
| 182 | }, |
| 183 | X86: { |
| 184 | "ssse3", |
| 185 | "sse4", |
| 186 | "sse4_1", |
| 187 | "sse4_2", |
| 188 | "aes_ni", |
| 189 | "avx", |
| 190 | "popcnt", |
| 191 | "movbe", |
| 192 | }, |
| 193 | X86_64: { |
| 194 | "ssse3", |
| 195 | "sse4", |
| 196 | "sse4_1", |
| 197 | "sse4_2", |
| 198 | "aes_ni", |
| 199 | "avx", |
| 200 | "popcnt", |
| 201 | }, |
| 202 | } |
| 203 | |
| 204 | var archFeatureMap = map[ArchType]map[string][]string{ |
| 205 | Arm: { |
| 206 | "armv7-a-neon": { |
| 207 | "neon", |
| 208 | }, |
| 209 | "armv8-a": { |
| 210 | "neon", |
| 211 | }, |
| 212 | "armv8-2a": { |
| 213 | "neon", |
| 214 | }, |
| 215 | }, |
| 216 | Mips: { |
| 217 | "mips32r2dspr2_fp": { |
| 218 | "dspr2", |
| 219 | }, |
| 220 | "mips32r6": { |
| 221 | "rev6", |
| 222 | }, |
| 223 | }, |
| 224 | Mips64: { |
| 225 | "mips64r6": { |
| 226 | "rev6", |
| 227 | }, |
| 228 | }, |
| 229 | X86: { |
| 230 | "atom": { |
| 231 | "ssse3", |
| 232 | "movbe", |
| 233 | }, |
| 234 | "haswell": { |
| 235 | "ssse3", |
| 236 | "sse4", |
| 237 | "sse4_1", |
| 238 | "sse4_2", |
| 239 | "aes_ni", |
| 240 | "avx", |
| 241 | "popcnt", |
| 242 | "movbe", |
| 243 | }, |
| 244 | "ivybridge": { |
| 245 | "ssse3", |
| 246 | "sse4", |
| 247 | "sse4_1", |
| 248 | "sse4_2", |
| 249 | "aes_ni", |
| 250 | "avx", |
| 251 | "popcnt", |
| 252 | }, |
| 253 | "sandybridge": { |
| 254 | "ssse3", |
| 255 | "sse4", |
| 256 | "sse4_1", |
| 257 | "sse4_2", |
| 258 | "popcnt", |
| 259 | }, |
| 260 | "silvermont": { |
| 261 | "ssse3", |
| 262 | "sse4", |
| 263 | "sse4_1", |
| 264 | "sse4_2", |
| 265 | "aes_ni", |
| 266 | "popcnt", |
| 267 | "movbe", |
| 268 | }, |
| 269 | "x86_64": { |
| 270 | "ssse3", |
| 271 | "sse4", |
| 272 | "sse4_1", |
| 273 | "sse4_2", |
| 274 | "popcnt", |
| 275 | }, |
| 276 | }, |
| 277 | X86_64: { |
| 278 | "haswell": { |
| 279 | "ssse3", |
| 280 | "sse4", |
| 281 | "sse4_1", |
| 282 | "sse4_2", |
| 283 | "aes_ni", |
| 284 | "avx", |
| 285 | "popcnt", |
| 286 | }, |
| 287 | "ivybridge": { |
| 288 | "ssse3", |
| 289 | "sse4", |
| 290 | "sse4_1", |
| 291 | "sse4_2", |
| 292 | "aes_ni", |
| 293 | "avx", |
| 294 | "popcnt", |
| 295 | }, |
| 296 | "sandybridge": { |
| 297 | "ssse3", |
| 298 | "sse4", |
| 299 | "sse4_1", |
| 300 | "sse4_2", |
| 301 | "popcnt", |
| 302 | }, |
| 303 | "silvermont": { |
| 304 | "ssse3", |
| 305 | "sse4", |
| 306 | "sse4_1", |
| 307 | "sse4_2", |
| 308 | "aes_ni", |
| 309 | "popcnt", |
| 310 | }, |
| 311 | }, |
| 312 | } |
| 313 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 314 | var defaultArchFeatureMap = map[OsType]map[ArchType][]string{} |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 315 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 316 | func RegisterDefaultArchVariantFeatures(os OsType, arch ArchType, features ...string) { |
| 317 | checkCalledFromInit() |
| 318 | |
| 319 | for _, feature := range features { |
| 320 | if !InList(feature, archFeatures[arch]) { |
| 321 | panic(fmt.Errorf("Invalid feature %q for arch %q variant \"\"", feature, arch)) |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | if defaultArchFeatureMap[os] == nil { |
| 326 | defaultArchFeatureMap[os] = make(map[ArchType][]string) |
| 327 | } |
| 328 | defaultArchFeatureMap[os][arch] = features |
| 329 | } |
| 330 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 331 | // An Arch indicates a single CPU architecture. |
| 332 | type Arch struct { |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 333 | ArchType ArchType |
| 334 | ArchVariant string |
| 335 | CpuVariant string |
| 336 | Abi []string |
| 337 | ArchFeatures []string |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 338 | Native bool |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | func (a Arch) String() string { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 342 | s := a.ArchType.String() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 343 | if a.ArchVariant != "" { |
| 344 | s += "_" + a.ArchVariant |
| 345 | } |
| 346 | if a.CpuVariant != "" { |
| 347 | s += "_" + a.CpuVariant |
| 348 | } |
| 349 | return s |
| 350 | } |
| 351 | |
| 352 | type ArchType struct { |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 353 | Name string |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 354 | Field string |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 355 | Multilib string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 356 | } |
| 357 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 358 | func newArch(name, multilib string) ArchType { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 359 | archType := ArchType{ |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 360 | Name: name, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 361 | Field: proptools.FieldNameForProperty(name), |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 362 | Multilib: multilib, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 363 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 364 | archTypeList = append(archTypeList, archType) |
| 365 | return archType |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | func (a ArchType) String() string { |
| 369 | return a.Name |
| 370 | } |
| 371 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 372 | var BuildOs = func() OsType { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 373 | switch runtime.GOOS { |
| 374 | case "linux": |
| 375 | return Linux |
| 376 | case "darwin": |
| 377 | return Darwin |
| 378 | default: |
| 379 | panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS)) |
| 380 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 381 | }() |
| 382 | |
| 383 | var ( |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 384 | osTypeList []OsType |
| 385 | commonTargetMap = make(map[string]Target) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 386 | |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 387 | NoOsType OsType |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 388 | Linux = NewOsType("linux_glibc", Host, false) |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 389 | Darwin = NewOsType("darwin", Host, false) |
Dan Willemsen | 9ff34c0 | 2018-10-10 17:58:19 -0700 | [diff] [blame] | 390 | LinuxBionic = NewOsType("linux_bionic", Host, false) |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 391 | Windows = NewOsType("windows", HostCross, true) |
| 392 | Android = NewOsType("android", Device, false) |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 393 | Fuchsia = NewOsType("fuchsia", Device, false) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 394 | |
| 395 | osArchTypeMap = map[OsType][]ArchType{ |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 396 | Linux: []ArchType{X86, X86_64}, |
| 397 | LinuxBionic: []ArchType{X86_64}, |
Dan Willemsen | e97e68a | 2018-08-28 17:12:56 -0700 | [diff] [blame] | 398 | Darwin: []ArchType{X86_64}, |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 399 | Windows: []ArchType{X86, X86_64}, |
| 400 | Android: []ArchType{Arm, Arm64, Mips, Mips64, X86, X86_64}, |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 401 | Fuchsia: []ArchType{Arm64, X86_64}, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 402 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 403 | ) |
| 404 | |
| 405 | type OsType struct { |
| 406 | Name, Field string |
| 407 | Class OsClass |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 408 | |
| 409 | DefaultDisabled bool |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 412 | type OsClass int |
| 413 | |
| 414 | const ( |
Dan Willemsen | 0e2d97b | 2016-11-28 17:50:06 -0800 | [diff] [blame] | 415 | Generic OsClass = iota |
| 416 | Device |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 417 | Host |
| 418 | HostCross |
| 419 | ) |
| 420 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 421 | func (class OsClass) String() string { |
| 422 | switch class { |
| 423 | case Generic: |
| 424 | return "generic" |
| 425 | case Device: |
| 426 | return "device" |
| 427 | case Host: |
| 428 | return "host" |
| 429 | case HostCross: |
| 430 | return "host cross" |
| 431 | default: |
| 432 | panic(fmt.Errorf("unknown class %d", class)) |
| 433 | } |
| 434 | } |
| 435 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 436 | func (os OsType) String() string { |
| 437 | return os.Name |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 440 | func (os OsType) Bionic() bool { |
| 441 | return os == Android || os == LinuxBionic |
| 442 | } |
| 443 | |
| 444 | func (os OsType) Linux() bool { |
| 445 | return os == Android || os == Linux || os == LinuxBionic |
| 446 | } |
| 447 | |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 448 | func NewOsType(name string, class OsClass, defDisabled bool) OsType { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 449 | os := OsType{ |
| 450 | Name: name, |
| 451 | Field: strings.Title(name), |
| 452 | Class: class, |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 453 | |
| 454 | DefaultDisabled: defDisabled, |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 455 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 456 | osTypeList = append(osTypeList, os) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 457 | |
| 458 | if _, found := commonTargetMap[name]; found { |
| 459 | panic(fmt.Errorf("Found Os type duplicate during OsType registration: %q", name)) |
| 460 | } else { |
| 461 | commonTargetMap[name] = Target{Os: os, Arch: Arch{ArchType: Common}} |
| 462 | } |
| 463 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 464 | return os |
| 465 | } |
| 466 | |
| 467 | func osByName(name string) OsType { |
| 468 | for _, os := range osTypeList { |
| 469 | if os.Name == name { |
| 470 | return os |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | return NoOsType |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 475 | } |
| 476 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 477 | type Target struct { |
| 478 | Os OsType |
| 479 | Arch Arch |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 480 | } |
| 481 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 482 | func (target Target) String() string { |
| 483 | return target.Os.String() + "_" + target.Arch.String() |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 484 | } |
| 485 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 486 | // archMutator splits a module into a variant for each Target requested by the module. Target selection |
| 487 | // for a module is in three levels, OsClass, mulitlib, and then Target. |
| 488 | // OsClass selection is determined by: |
| 489 | // - The HostOrDeviceSupported value passed in to InitAndroidArchModule by the module type factory, which selects |
| 490 | // whether the module type can compile for host, device or both. |
| 491 | // - The host_supported and device_supported properties on the module. |
| 492 | // If host is supported for the module, the Host and HostCross OsClasses are are selected. If device is supported |
| 493 | // for the module, the Device OsClass is selected. |
| 494 | // Within each selected OsClass, the multilib selection is determined by: |
| 495 | // - The compile_multilib property if it set (which may be overriden by target.android.compile_multlib or |
| 496 | // target.host.compile_multilib). |
| 497 | // - The default multilib passed to InitAndroidArchModule if compile_multilib was not set. |
| 498 | // Valid multilib values include: |
| 499 | // "both": compile for all Targets supported by the OsClass (generally x86_64 and x86, or arm64 and arm). |
| 500 | // "first": compile for only a single preferred Target supported by the OsClass. This is generally x86_64 or arm64, |
| 501 | // but may be arm for a 32-bit only build or a build with TARGET_PREFER_32_BIT=true set. |
| 502 | // "32": compile for only a single 32-bit Target supported by the OsClass. |
| 503 | // "64": compile for only a single 64-bit Target supported by the OsClass. |
| 504 | // "common": compile a for a single Target that will work on all Targets suported by the OsClass (for example Java). |
| 505 | // |
| 506 | // Once the list of Targets is determined, the module is split into a variant for each Target. |
| 507 | // |
| 508 | // Modules can be initialized with InitAndroidMultiTargetsArchModule, in which case they will be split by OsClass, |
| 509 | // but will have a common Target that is expected to handle all other selected Targets via ctx.MultiTargets(). |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 510 | func archMutator(mctx BottomUpMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 511 | var module Module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 512 | var ok bool |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 513 | if module, ok = mctx.Module().(Module); !ok { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 514 | return |
| 515 | } |
| 516 | |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 517 | base := module.base() |
| 518 | |
| 519 | if !base.ArchSpecific() { |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 520 | return |
| 521 | } |
| 522 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 523 | var moduleTargets []Target |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 524 | moduleMultiTargets := make(map[int][]Target) |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 525 | primaryModules := make(map[int]bool) |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 526 | osClasses := base.OsClassSupported() |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 527 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 528 | for _, os := range osTypeList { |
| 529 | supportedClass := false |
| 530 | for _, osClass := range osClasses { |
| 531 | if os.Class == osClass { |
| 532 | supportedClass = true |
| 533 | } |
| 534 | } |
| 535 | if !supportedClass { |
| 536 | continue |
| 537 | } |
| 538 | |
| 539 | osTargets := mctx.Config().Targets[os] |
| 540 | if len(osTargets) == 0 { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 541 | continue |
| 542 | } |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 543 | |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 544 | // only the primary arch in the recovery partition |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 545 | if os == Android && module.InstallInRecovery() { |
| 546 | osTargets = []Target{osTargets[0]} |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Colin Cross | a9d8bee | 2018-10-02 13:59:46 -0700 | [diff] [blame] | 549 | prefer32 := false |
| 550 | if base.prefer32 != nil { |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 551 | prefer32 = base.prefer32(mctx, base, os.Class) |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 552 | } |
Colin Cross | a9d8bee | 2018-10-02 13:59:46 -0700 | [diff] [blame] | 553 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 554 | multilib, extraMultilib := decodeMultilib(base, os.Class) |
| 555 | targets, err := decodeMultilibTargets(multilib, osTargets, prefer32) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 556 | if err != nil { |
| 557 | mctx.ModuleErrorf("%s", err.Error()) |
| 558 | } |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 559 | |
| 560 | var multiTargets []Target |
| 561 | if extraMultilib != "" { |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 562 | multiTargets, err = decodeMultilibTargets(extraMultilib, osTargets, prefer32) |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 563 | if err != nil { |
| 564 | mctx.ModuleErrorf("%s", err.Error()) |
| 565 | } |
| 566 | } |
| 567 | |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 568 | if len(targets) > 0 { |
| 569 | primaryModules[len(moduleTargets)] = true |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 570 | moduleMultiTargets[len(moduleTargets)] = multiTargets |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 571 | moduleTargets = append(moduleTargets, targets...) |
| 572 | } |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 575 | if len(moduleTargets) == 0 { |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 576 | base.commonProperties.Enabled = boolPtr(false) |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 577 | return |
| 578 | } |
| 579 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 580 | targetNames := make([]string, len(moduleTargets)) |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 581 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 582 | for i, target := range moduleTargets { |
| 583 | targetNames[i] = target.String() |
| 584 | } |
| 585 | |
| 586 | modules := mctx.CreateVariations(targetNames...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 587 | for i, m := range modules { |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 588 | m.(Module).base().SetTarget(moduleTargets[i], moduleMultiTargets[i], primaryModules[i]) |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 589 | m.(Module).base().setArchProperties(mctx) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 590 | } |
| 591 | } |
| 592 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 593 | func decodeMultilib(base *ModuleBase, class OsClass) (multilib, extraMultilib string) { |
| 594 | switch class { |
| 595 | case Device: |
| 596 | multilib = String(base.commonProperties.Target.Android.Compile_multilib) |
| 597 | case Host, HostCross: |
| 598 | multilib = String(base.commonProperties.Target.Host.Compile_multilib) |
| 599 | } |
| 600 | if multilib == "" { |
| 601 | multilib = String(base.commonProperties.Compile_multilib) |
| 602 | } |
| 603 | if multilib == "" { |
| 604 | multilib = base.commonProperties.Default_multilib |
| 605 | } |
| 606 | |
| 607 | if base.commonProperties.UseTargetVariants { |
| 608 | return multilib, "" |
| 609 | } else { |
| 610 | // For app modules a single arch variant will be created per OS class which is expected to handle all the |
| 611 | // selected arches. Return the common-type as multilib and any Android.bp provided multilib as extraMultilib |
| 612 | if multilib == base.commonProperties.Default_multilib { |
| 613 | multilib = "first" |
| 614 | } |
| 615 | return base.commonProperties.Default_multilib, multilib |
| 616 | } |
| 617 | } |
| 618 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 619 | func filterArchStructFields(fields []reflect.StructField) (filteredFields []reflect.StructField, filtered bool) { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 620 | for _, field := range fields { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 621 | if !proptools.HasTag(field, "android", "arch_variant") { |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 622 | filtered = true |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 623 | continue |
| 624 | } |
| 625 | |
| 626 | // The arch_variant field isn't necessary past this point |
| 627 | // Instead of wasting space, just remove it. Go also has a |
| 628 | // 16-bit limit on structure name length. The name is constructed |
| 629 | // based on the Go source representation of the structure, so |
| 630 | // the tag names count towards that length. |
| 631 | // |
| 632 | // TODO: handle the uncommon case of other tags being involved |
| 633 | if field.Tag == `android:"arch_variant"` { |
| 634 | field.Tag = "" |
| 635 | } |
| 636 | |
| 637 | // Recurse into structs |
| 638 | switch field.Type.Kind() { |
| 639 | case reflect.Struct: |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 640 | var subFiltered bool |
| 641 | field.Type, subFiltered = filterArchStruct(field.Type) |
| 642 | filtered = filtered || subFiltered |
| 643 | if field.Type == nil { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 644 | continue |
| 645 | } |
| 646 | case reflect.Ptr: |
| 647 | if field.Type.Elem().Kind() == reflect.Struct { |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 648 | nestedType, subFiltered := filterArchStruct(field.Type.Elem()) |
| 649 | filtered = filtered || subFiltered |
| 650 | if nestedType == nil { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 651 | continue |
| 652 | } |
| 653 | field.Type = reflect.PtrTo(nestedType) |
| 654 | } |
| 655 | case reflect.Interface: |
| 656 | panic("Interfaces are not supported in arch_variant properties") |
| 657 | } |
| 658 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 659 | filteredFields = append(filteredFields, field) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 660 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 661 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 662 | return filteredFields, filtered |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 665 | // filterArchStruct takes a reflect.Type that is either a sturct or a pointer to a struct, and returns a reflect.Type |
| 666 | // that only contains the fields in the original type that have an `android:"arch_variant"` struct tag, and a bool |
| 667 | // that is true if the new struct type has fewer fields than the original type. If there are no fields in the |
| 668 | // original type with the struct tag it returns nil and true. |
| 669 | func filterArchStruct(prop reflect.Type) (filteredProp reflect.Type, filtered bool) { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 670 | var fields []reflect.StructField |
| 671 | |
| 672 | ptr := prop.Kind() == reflect.Ptr |
| 673 | if ptr { |
| 674 | prop = prop.Elem() |
| 675 | } |
| 676 | |
| 677 | for i := 0; i < prop.NumField(); i++ { |
| 678 | fields = append(fields, prop.Field(i)) |
| 679 | } |
| 680 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 681 | filteredFields, filtered := filterArchStructFields(fields) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 682 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 683 | if len(filteredFields) == 0 { |
| 684 | return nil, true |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 687 | if !filtered { |
| 688 | if ptr { |
| 689 | return reflect.PtrTo(prop), false |
| 690 | } |
| 691 | return prop, false |
| 692 | } |
| 693 | |
| 694 | ret := reflect.StructOf(filteredFields) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 695 | if ptr { |
| 696 | ret = reflect.PtrTo(ret) |
| 697 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 698 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 699 | return ret, true |
| 700 | } |
| 701 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 702 | // filterArchStruct takes a reflect.Type that is either a sturct or a pointer to a struct, and returns a list of |
| 703 | // reflect.Type that only contains the fields in the original type that have an `android:"arch_variant"` struct tag, |
| 704 | // and a bool that is true if the new struct type has fewer fields than the original type. If there are no fields in |
| 705 | // the original type with the struct tag it returns nil and true. Each returned struct type will have a maximum of |
| 706 | // 10 top level fields in it to attempt to avoid hitting the reflect.StructOf name length limit, although the limit |
| 707 | // can still be reached with a single struct field with many fields in it. |
| 708 | func filterArchStructSharded(prop reflect.Type) (filteredProp []reflect.Type, filtered bool) { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 709 | var fields []reflect.StructField |
| 710 | |
| 711 | ptr := prop.Kind() == reflect.Ptr |
| 712 | if ptr { |
| 713 | prop = prop.Elem() |
| 714 | } |
| 715 | |
| 716 | for i := 0; i < prop.NumField(); i++ { |
| 717 | fields = append(fields, prop.Field(i)) |
| 718 | } |
| 719 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 720 | fields, filtered = filterArchStructFields(fields) |
| 721 | if !filtered { |
| 722 | if ptr { |
| 723 | return []reflect.Type{reflect.PtrTo(prop)}, false |
| 724 | } |
| 725 | return []reflect.Type{prop}, false |
| 726 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 727 | |
| 728 | if len(fields) == 0 { |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 729 | return nil, true |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | shards := shardFields(fields, 10) |
| 733 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 734 | for _, shard := range shards { |
| 735 | s := reflect.StructOf(shard) |
| 736 | if ptr { |
| 737 | s = reflect.PtrTo(s) |
| 738 | } |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 739 | filteredProp = append(filteredProp, s) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 742 | return filteredProp, true |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | func shardFields(fields []reflect.StructField, shardSize int) [][]reflect.StructField { |
| 746 | ret := make([][]reflect.StructField, 0, (len(fields)+shardSize-1)/shardSize) |
| 747 | for len(fields) > shardSize { |
| 748 | ret = append(ret, fields[0:shardSize]) |
| 749 | fields = fields[shardSize:] |
| 750 | } |
| 751 | if len(fields) > 0 { |
| 752 | ret = append(ret, fields) |
| 753 | } |
| 754 | return ret |
| 755 | } |
| 756 | |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 757 | // createArchType takes a reflect.Type that is either a struct or a pointer to a struct, and returns a list of |
| 758 | // reflect.Type that contains the arch-variant properties inside structs for each architecture, os, target, multilib, |
| 759 | // etc. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 760 | func createArchType(props reflect.Type) []reflect.Type { |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 761 | propShards, _ := filterArchStructSharded(props) |
| 762 | if len(propShards) == 0 { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 763 | return nil |
| 764 | } |
| 765 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 766 | var ret []reflect.Type |
| 767 | for _, props := range propShards { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 768 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 769 | variantFields := func(names []string) []reflect.StructField { |
| 770 | ret := make([]reflect.StructField, len(names)) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 771 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 772 | for i, name := range names { |
| 773 | ret[i].Name = name |
| 774 | ret[i].Type = props |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 775 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 776 | |
| 777 | return ret |
| 778 | } |
| 779 | |
| 780 | archFields := make([]reflect.StructField, len(archTypeList)) |
| 781 | for i, arch := range archTypeList { |
| 782 | variants := []string{} |
| 783 | |
| 784 | for _, archVariant := range archVariants[arch] { |
| 785 | archVariant := variantReplacer.Replace(archVariant) |
| 786 | variants = append(variants, proptools.FieldNameForProperty(archVariant)) |
| 787 | } |
| 788 | for _, feature := range archFeatures[arch] { |
| 789 | feature := variantReplacer.Replace(feature) |
| 790 | variants = append(variants, proptools.FieldNameForProperty(feature)) |
| 791 | } |
| 792 | |
| 793 | fields := variantFields(variants) |
| 794 | |
| 795 | fields = append([]reflect.StructField{{ |
| 796 | Name: "BlueprintEmbed", |
| 797 | Type: props, |
| 798 | Anonymous: true, |
| 799 | }}, fields...) |
| 800 | |
| 801 | archFields[i] = reflect.StructField{ |
| 802 | Name: arch.Field, |
| 803 | Type: reflect.StructOf(fields), |
| 804 | } |
| 805 | } |
| 806 | archType := reflect.StructOf(archFields) |
| 807 | |
| 808 | multilibType := reflect.StructOf(variantFields([]string{"Lib32", "Lib64"})) |
| 809 | |
| 810 | targets := []string{ |
| 811 | "Host", |
| 812 | "Android64", |
| 813 | "Android32", |
| 814 | "Bionic", |
| 815 | "Linux", |
| 816 | "Not_windows", |
| 817 | "Arm_on_x86", |
| 818 | "Arm_on_x86_64", |
| 819 | } |
| 820 | for _, os := range osTypeList { |
| 821 | targets = append(targets, os.Field) |
| 822 | |
| 823 | for _, archType := range osArchTypeMap[os] { |
| 824 | targets = append(targets, os.Field+"_"+archType.Name) |
| 825 | |
| 826 | if os.Linux() { |
| 827 | target := "Linux_" + archType.Name |
| 828 | if !InList(target, targets) { |
| 829 | targets = append(targets, target) |
| 830 | } |
| 831 | } |
| 832 | if os.Bionic() { |
| 833 | target := "Bionic_" + archType.Name |
| 834 | if !InList(target, targets) { |
| 835 | targets = append(targets, target) |
| 836 | } |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 837 | } |
| 838 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 839 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 840 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 841 | targetType := reflect.StructOf(variantFields(targets)) |
| 842 | ret = append(ret, reflect.StructOf([]reflect.StructField{ |
| 843 | { |
| 844 | Name: "Arch", |
| 845 | Type: archType, |
| 846 | }, |
| 847 | { |
| 848 | Name: "Multilib", |
| 849 | Type: multilibType, |
| 850 | }, |
| 851 | { |
| 852 | Name: "Target", |
| 853 | Type: targetType, |
| 854 | }, |
| 855 | })) |
| 856 | } |
| 857 | return ret |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | var archPropTypeMap OncePer |
| 861 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 862 | func InitArchModule(m Module) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 863 | |
| 864 | base := m.base() |
| 865 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 866 | base.generalProperties = m.GetProperties() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 867 | |
| 868 | for _, properties := range base.generalProperties { |
| 869 | propertiesValue := reflect.ValueOf(properties) |
Colin Cross | 62496a0 | 2016-08-08 15:49:17 -0700 | [diff] [blame] | 870 | t := propertiesValue.Type() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 871 | if propertiesValue.Kind() != reflect.Ptr { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 872 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 873 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | propertiesValue = propertiesValue.Elem() |
| 877 | if propertiesValue.Kind() != reflect.Struct { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 878 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 879 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 880 | } |
| 881 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 882 | archPropTypes := archPropTypeMap.Once(t, func() interface{} { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 883 | return createArchType(t) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 884 | }).([]reflect.Type) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 885 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 886 | var archProperties []interface{} |
| 887 | for _, t := range archPropTypes { |
| 888 | archProperties = append(archProperties, reflect.New(t).Interface()) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 889 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 890 | base.archProperties = append(base.archProperties, archProperties) |
| 891 | m.AddProperties(archProperties...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 892 | } |
| 893 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 894 | base.customizableProperties = m.GetProperties() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 895 | } |
| 896 | |
Colin Cross | a716add | 2015-12-16 11:07:39 -0800 | [diff] [blame] | 897 | var variantReplacer = strings.NewReplacer("-", "_", ".", "_") |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 898 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 899 | func (a *ModuleBase) appendProperties(ctx BottomUpMutatorContext, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 900 | dst interface{}, src reflect.Value, field, srcPrefix string) reflect.Value { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 901 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 902 | src = src.FieldByName(field) |
| 903 | if !src.IsValid() { |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 904 | ctx.ModuleErrorf("field %q does not exist", srcPrefix) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 905 | return src |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 906 | } |
| 907 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 908 | ret := src |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 909 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 910 | if src.Kind() == reflect.Struct { |
| 911 | src = src.FieldByName("BlueprintEmbed") |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Colin Cross | 6ee75b6 | 2016-05-05 15:57:15 -0700 | [diff] [blame] | 914 | order := func(property string, |
| 915 | dstField, srcField reflect.StructField, |
| 916 | dstValue, srcValue interface{}) (proptools.Order, error) { |
| 917 | if proptools.HasTag(dstField, "android", "variant_prepend") { |
| 918 | return proptools.Prepend, nil |
| 919 | } else { |
| 920 | return proptools.Append, nil |
| 921 | } |
| 922 | } |
| 923 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 924 | err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, order) |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 925 | if err != nil { |
| 926 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
| 927 | ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
| 928 | } else { |
| 929 | panic(err) |
| 930 | } |
| 931 | } |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 932 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 933 | return ret |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 936 | // Rewrite the module's properties structs to contain arch-specific values. |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 937 | func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 938 | arch := a.Arch() |
| 939 | os := a.Os() |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 940 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 941 | for i := range a.generalProperties { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 942 | genProps := a.generalProperties[i] |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 943 | if a.archProperties[i] == nil { |
| 944 | continue |
| 945 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 946 | for _, archProperties := range a.archProperties[i] { |
| 947 | archPropValues := reflect.ValueOf(archProperties).Elem() |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 948 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 949 | archProp := archPropValues.FieldByName("Arch") |
| 950 | multilibProp := archPropValues.FieldByName("Multilib") |
| 951 | targetProp := archPropValues.FieldByName("Target") |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 952 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 953 | var field string |
| 954 | var prefix string |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 955 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 956 | // Handle arch-specific properties in the form: |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 957 | // arch: { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 958 | // arm64: { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 959 | // key: value, |
| 960 | // }, |
| 961 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 962 | t := arch.ArchType |
| 963 | |
| 964 | if arch.ArchType != Common { |
| 965 | field := proptools.FieldNameForProperty(t.Name) |
| 966 | prefix := "arch." + t.Name |
| 967 | archStruct := a.appendProperties(ctx, genProps, archProp, field, prefix) |
| 968 | |
| 969 | // Handle arch-variant-specific properties in the form: |
| 970 | // arch: { |
| 971 | // variant: { |
| 972 | // key: value, |
| 973 | // }, |
| 974 | // }, |
| 975 | v := variantReplacer.Replace(arch.ArchVariant) |
| 976 | if v != "" { |
| 977 | field := proptools.FieldNameForProperty(v) |
| 978 | prefix := "arch." + t.Name + "." + v |
| 979 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
| 980 | } |
| 981 | |
| 982 | // Handle cpu-variant-specific properties in the form: |
| 983 | // arch: { |
| 984 | // variant: { |
| 985 | // key: value, |
| 986 | // }, |
| 987 | // }, |
| 988 | if arch.CpuVariant != arch.ArchVariant { |
| 989 | c := variantReplacer.Replace(arch.CpuVariant) |
| 990 | if c != "" { |
| 991 | field := proptools.FieldNameForProperty(c) |
| 992 | prefix := "arch." + t.Name + "." + c |
| 993 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | // Handle arch-feature-specific properties in the form: |
| 998 | // arch: { |
| 999 | // feature: { |
| 1000 | // key: value, |
| 1001 | // }, |
| 1002 | // }, |
| 1003 | for _, feature := range arch.ArchFeatures { |
| 1004 | field := proptools.FieldNameForProperty(feature) |
| 1005 | prefix := "arch." + t.Name + "." + feature |
| 1006 | a.appendProperties(ctx, genProps, archStruct, field, prefix) |
| 1007 | } |
| 1008 | |
| 1009 | // Handle multilib-specific properties in the form: |
| 1010 | // multilib: { |
| 1011 | // lib32: { |
| 1012 | // key: value, |
| 1013 | // }, |
| 1014 | // }, |
| 1015 | field = proptools.FieldNameForProperty(t.Multilib) |
| 1016 | prefix = "multilib." + t.Multilib |
| 1017 | a.appendProperties(ctx, genProps, multilibProp, field, prefix) |
Colin Cross | 0801633 | 2016-12-20 09:53:14 -0800 | [diff] [blame] | 1018 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1019 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1020 | // Handle host-specific properties in the form: |
| 1021 | // target: { |
| 1022 | // host: { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1023 | // key: value, |
| 1024 | // }, |
| 1025 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1026 | if os.Class == Host || os.Class == HostCross { |
| 1027 | field = "Host" |
| 1028 | prefix = "target.host" |
| 1029 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1030 | } |
| 1031 | |
| 1032 | // Handle target OS generalities of the form: |
| 1033 | // target: { |
| 1034 | // bionic: { |
| 1035 | // key: value, |
| 1036 | // }, |
| 1037 | // bionic_x86: { |
| 1038 | // key: value, |
| 1039 | // }, |
| 1040 | // } |
| 1041 | if os.Linux() { |
| 1042 | field = "Linux" |
| 1043 | prefix = "target.linux" |
| 1044 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1045 | |
| 1046 | if arch.ArchType != Common { |
| 1047 | field = "Linux_" + arch.ArchType.Name |
| 1048 | prefix = "target.linux_" + arch.ArchType.Name |
| 1049 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1050 | } |
| 1051 | } |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1052 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1053 | if os.Bionic() { |
| 1054 | field = "Bionic" |
| 1055 | prefix = "target.bionic" |
| 1056 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1057 | |
| 1058 | if arch.ArchType != Common { |
| 1059 | field = "Bionic_" + t.Name |
| 1060 | prefix = "target.bionic_" + t.Name |
| 1061 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | // Handle target OS properties in the form: |
| 1066 | // target: { |
| 1067 | // linux_glibc: { |
| 1068 | // key: value, |
| 1069 | // }, |
| 1070 | // not_windows: { |
| 1071 | // key: value, |
| 1072 | // }, |
| 1073 | // linux_glibc_x86: { |
| 1074 | // key: value, |
| 1075 | // }, |
| 1076 | // linux_glibc_arm: { |
| 1077 | // key: value, |
| 1078 | // }, |
| 1079 | // android { |
| 1080 | // key: value, |
| 1081 | // }, |
| 1082 | // android_arm { |
| 1083 | // key: value, |
| 1084 | // }, |
| 1085 | // android_x86 { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1086 | // key: value, |
| 1087 | // }, |
| 1088 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1089 | field = os.Field |
| 1090 | prefix = "target." + os.Name |
| 1091 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1092 | |
| 1093 | if arch.ArchType != Common { |
| 1094 | field = os.Field + "_" + t.Name |
| 1095 | prefix = "target." + os.Name + "_" + t.Name |
| 1096 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1099 | if (os.Class == Host || os.Class == HostCross) && os != Windows { |
| 1100 | field := "Not_windows" |
| 1101 | prefix := "target.not_windows" |
| 1102 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1103 | } |
| 1104 | |
| 1105 | // Handle 64-bit device properties in the form: |
| 1106 | // target { |
| 1107 | // android64 { |
| 1108 | // key: value, |
| 1109 | // }, |
| 1110 | // android32 { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1111 | // key: value, |
| 1112 | // }, |
| 1113 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1114 | // WARNING: this is probably not what you want to use in your blueprints file, it selects |
| 1115 | // options for all targets on a device that supports 64-bit binaries, not just the targets |
| 1116 | // that are being compiled for 64-bit. Its expected use case is binaries like linker and |
| 1117 | // debuggerd that need to know when they are a 32-bit process running on a 64-bit device |
| 1118 | if os.Class == Device { |
| 1119 | if ctx.Config().Android64() { |
| 1120 | field := "Android64" |
| 1121 | prefix := "target.android64" |
| 1122 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1123 | } else { |
| 1124 | field := "Android32" |
| 1125 | prefix := "target.android32" |
| 1126 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1127 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1128 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1129 | if (arch.ArchType == X86 && (hasArmAbi(arch) || |
| 1130 | hasArmAndroidArch(ctx.Config().Targets[Android]))) || |
| 1131 | (arch.ArchType == Arm && |
| 1132 | hasX86AndroidArch(ctx.Config().Targets[Android])) { |
| 1133 | field := "Arm_on_x86" |
| 1134 | prefix := "target.arm_on_x86" |
| 1135 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1136 | } |
| 1137 | if (arch.ArchType == X86_64 && (hasArmAbi(arch) || |
| 1138 | hasArmAndroidArch(ctx.Config().Targets[Android]))) || |
| 1139 | (arch.ArchType == Arm && |
| 1140 | hasX8664AndroidArch(ctx.Config().Targets[Android])) { |
| 1141 | field := "Arm_on_x86_64" |
| 1142 | prefix := "target.arm_on_x86_64" |
| 1143 | a.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1144 | } |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 1145 | } |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1146 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | func forEachInterface(v reflect.Value, f func(reflect.Value)) { |
| 1151 | switch v.Kind() { |
| 1152 | case reflect.Interface: |
| 1153 | f(v) |
| 1154 | case reflect.Struct: |
| 1155 | for i := 0; i < v.NumField(); i++ { |
| 1156 | forEachInterface(v.Field(i), f) |
| 1157 | } |
| 1158 | case reflect.Ptr: |
| 1159 | forEachInterface(v.Elem(), f) |
| 1160 | default: |
| 1161 | panic(fmt.Errorf("Unsupported kind %s", v.Kind())) |
| 1162 | } |
| 1163 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1164 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1165 | // Convert the arch product variables into a list of targets for each os class structs |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1166 | func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1167 | variables := config.productVariables |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1168 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1169 | targets := make(map[OsType][]Target) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1170 | var targetErr error |
| 1171 | |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame^] | 1172 | addTarget := func(os OsType, archName string, archVariant, cpuVariant *string, abi []string) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1173 | if targetErr != nil { |
| 1174 | return |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1175 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1176 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1177 | arch, err := decodeArch(os, archName, archVariant, cpuVariant, abi) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1178 | if err != nil { |
| 1179 | targetErr = err |
| 1180 | return |
| 1181 | } |
| 1182 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1183 | targets[os] = append(targets[os], |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1184 | Target{ |
| 1185 | Os: os, |
| 1186 | Arch: arch, |
| 1187 | }) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1188 | } |
| 1189 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1190 | if variables.HostArch == nil { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1191 | return nil, fmt.Errorf("No host primary architecture set") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1194 | addTarget(BuildOs, *variables.HostArch, nil, nil, nil) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1195 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1196 | if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1197 | addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1198 | } |
| 1199 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1200 | if Bool(config.Host_bionic) { |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 1201 | addTarget(LinuxBionic, "x86_64", nil, nil, nil) |
| 1202 | } |
| 1203 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1204 | if String(variables.CrossHost) != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1205 | crossHostOs := osByName(*variables.CrossHost) |
| 1206 | if crossHostOs == NoOsType { |
| 1207 | return nil, fmt.Errorf("Unknown cross host OS %q", *variables.CrossHost) |
| 1208 | } |
| 1209 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1210 | if String(variables.CrossHostArch) == "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1211 | return nil, fmt.Errorf("No cross-host primary architecture set") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1212 | } |
| 1213 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1214 | addTarget(crossHostOs, *variables.CrossHostArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1215 | |
| 1216 | if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1217 | addTarget(crossHostOs, *variables.CrossHostSecondaryArch, nil, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1218 | } |
| 1219 | } |
| 1220 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1221 | if variables.DeviceArch != nil && *variables.DeviceArch != "" { |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 1222 | var target = Android |
| 1223 | if Bool(variables.Fuchsia) { |
| 1224 | target = Fuchsia |
| 1225 | } |
| 1226 | |
| 1227 | addTarget(target, *variables.DeviceArch, variables.DeviceArchVariant, |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1228 | variables.DeviceCpuVariant, variables.DeviceAbi) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1229 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1230 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" { |
| 1231 | addTarget(Android, *variables.DeviceSecondaryArch, |
| 1232 | variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant, |
| 1233 | variables.DeviceSecondaryAbi) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1234 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1235 | deviceArches := targets[Android] |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1236 | if deviceArches[0].Arch.ArchType.Multilib == deviceArches[1].Arch.ArchType.Multilib { |
| 1237 | deviceArches[1].Arch.Native = false |
| 1238 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1239 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1242 | if targetErr != nil { |
| 1243 | return nil, targetErr |
| 1244 | } |
| 1245 | |
| 1246 | return targets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1249 | // hasArmAbi returns true if arch has at least one arm ABI |
| 1250 | func hasArmAbi(arch Arch) bool { |
| 1251 | for _, abi := range arch.Abi { |
| 1252 | if strings.HasPrefix(abi, "arm") { |
| 1253 | return true |
| 1254 | } |
| 1255 | } |
| 1256 | return false |
| 1257 | } |
| 1258 | |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 1259 | // hasArmArch returns true if targets has at least arm Android arch |
| 1260 | func hasArmAndroidArch(targets []Target) bool { |
| 1261 | for _, target := range targets { |
| 1262 | if target.Os == Android && target.Arch.ArchType == Arm { |
| 1263 | return true |
| 1264 | } |
| 1265 | } |
| 1266 | return false |
| 1267 | } |
| 1268 | |
Victor Khimenko | 5eb8ec1 | 2018-03-21 20:30:54 +0100 | [diff] [blame] | 1269 | // hasX86Arch returns true if targets has at least x86 Android arch |
| 1270 | func hasX86AndroidArch(targets []Target) bool { |
| 1271 | for _, target := range targets { |
| 1272 | if target.Os == Android && target.Arch.ArchType == X86 { |
| 1273 | return true |
| 1274 | } |
| 1275 | } |
| 1276 | return false |
| 1277 | } |
| 1278 | |
| 1279 | // hasX8664Arch returns true if targets has at least x86_64 Android arch |
| 1280 | func hasX8664AndroidArch(targets []Target) bool { |
| 1281 | for _, target := range targets { |
| 1282 | if target.Os == Android && target.Arch.ArchType == X86_64 { |
| 1283 | return true |
| 1284 | } |
| 1285 | } |
| 1286 | return false |
| 1287 | } |
| 1288 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1289 | type archConfig struct { |
| 1290 | arch string |
| 1291 | archVariant string |
| 1292 | cpuVariant string |
| 1293 | abi []string |
| 1294 | } |
| 1295 | |
| 1296 | func getMegaDeviceConfig() []archConfig { |
| 1297 | return []archConfig{ |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 1298 | {"arm", "armv7-a-neon", "generic", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1299 | {"arm", "armv7-a-neon", "cortex-a7", []string{"armeabi-v7a"}}, |
| 1300 | {"arm", "armv7-a-neon", "cortex-a8", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 1301 | {"arm", "armv7-a-neon", "cortex-a9", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1302 | {"arm", "armv7-a-neon", "cortex-a15", []string{"armeabi-v7a"}}, |
| 1303 | {"arm", "armv7-a-neon", "cortex-a53", []string{"armeabi-v7a"}}, |
| 1304 | {"arm", "armv7-a-neon", "cortex-a53.a57", []string{"armeabi-v7a"}}, |
Richard Fung | eb37ed3 | 2018-09-24 16:33:45 -0700 | [diff] [blame] | 1305 | {"arm", "armv7-a-neon", "cortex-a72", []string{"armeabi-v7a"}}, |
Jake Weinstein | 6600a44 | 2017-05-15 18:27:12 -0400 | [diff] [blame] | 1306 | {"arm", "armv7-a-neon", "cortex-a73", []string{"armeabi-v7a"}}, |
Christopher Ferris | ba14a8f | 2018-04-23 18:15:25 -0700 | [diff] [blame] | 1307 | {"arm", "armv7-a-neon", "cortex-a75", []string{"armeabi-v7a"}}, |
Haibo Huang | a31e2bd | 2018-10-09 14:27:28 -0700 | [diff] [blame] | 1308 | {"arm", "armv7-a-neon", "cortex-a76", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1309 | {"arm", "armv7-a-neon", "krait", []string{"armeabi-v7a"}}, |
Alex Naidis | ae4fc18 | 2016-08-20 00:14:56 +0200 | [diff] [blame] | 1310 | {"arm", "armv7-a-neon", "kryo", []string{"armeabi-v7a"}}, |
Artem Serov | d3072b0 | 2018-11-15 15:21:51 +0000 | [diff] [blame] | 1311 | {"arm", "armv7-a-neon", "kryo385", []string{"armeabi-v7a"}}, |
Junmo Park | 8ea4959 | 2017-07-24 07:14:55 +0900 | [diff] [blame] | 1312 | {"arm", "armv7-a-neon", "exynos-m1", []string{"armeabi-v7a"}}, |
Junmo Park | d86c902 | 2017-07-21 09:07:47 +0900 | [diff] [blame] | 1313 | {"arm", "armv7-a-neon", "exynos-m2", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 1314 | {"arm64", "armv8-a", "cortex-a53", []string{"arm64-v8a"}}, |
Richard Fung | eb37ed3 | 2018-09-24 16:33:45 -0700 | [diff] [blame] | 1315 | {"arm64", "armv8-a", "cortex-a72", []string{"arm64-v8a"}}, |
Jake Weinstein | 6600a44 | 2017-05-15 18:27:12 -0400 | [diff] [blame] | 1316 | {"arm64", "armv8-a", "cortex-a73", []string{"arm64-v8a"}}, |
Alex Naidis | ac01ff5 | 2016-08-30 15:56:33 +0200 | [diff] [blame] | 1317 | {"arm64", "armv8-a", "kryo", []string{"arm64-v8a"}}, |
Junmo Park | 8ea4959 | 2017-07-24 07:14:55 +0900 | [diff] [blame] | 1318 | {"arm64", "armv8-a", "exynos-m1", []string{"arm64-v8a"}}, |
Junmo Park | d86c902 | 2017-07-21 09:07:47 +0900 | [diff] [blame] | 1319 | {"arm64", "armv8-a", "exynos-m2", []string{"arm64-v8a"}}, |
Christopher Ferris | ba14a8f | 2018-04-23 18:15:25 -0700 | [diff] [blame] | 1320 | {"arm64", "armv8-2a", "cortex-a75", []string{"arm64-v8a"}}, |
Haibo Huang | a31e2bd | 2018-10-09 14:27:28 -0700 | [diff] [blame] | 1321 | {"arm64", "armv8-2a", "cortex-a76", []string{"arm64-v8a"}}, |
Artem Serov | d3072b0 | 2018-11-15 15:21:51 +0000 | [diff] [blame] | 1322 | {"arm64", "armv8-2a", "kryo385", []string{"arm64-v8a"}}, |
Dan Willemsen | 468cc31 | 2016-01-13 23:25:19 -0800 | [diff] [blame] | 1323 | {"mips", "mips32-fp", "", []string{"mips"}}, |
| 1324 | {"mips", "mips32r2-fp", "", []string{"mips"}}, |
| 1325 | {"mips", "mips32r2-fp-xburst", "", []string{"mips"}}, |
Dan Willemsen | 65fb981 | 2016-07-19 21:37:28 -0700 | [diff] [blame] | 1326 | //{"mips", "mips32r6", "", []string{"mips"}}, |
Colin Cross | 1837b80 | 2017-04-26 19:10:34 -0700 | [diff] [blame] | 1327 | {"mips", "mips32r2dsp-fp", "", []string{"mips"}}, |
| 1328 | {"mips", "mips32r2dspr2-fp", "", []string{"mips"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1329 | // mips64r2 is mismatching 64r2 and 64r6 libraries during linking to libgcc |
| 1330 | //{"mips64", "mips64r2", "", []string{"mips64"}}, |
| 1331 | {"mips64", "mips64r6", "", []string{"mips64"}}, |
| 1332 | {"x86", "", "", []string{"x86"}}, |
| 1333 | {"x86", "atom", "", []string{"x86"}}, |
| 1334 | {"x86", "haswell", "", []string{"x86"}}, |
| 1335 | {"x86", "ivybridge", "", []string{"x86"}}, |
| 1336 | {"x86", "sandybridge", "", []string{"x86"}}, |
| 1337 | {"x86", "silvermont", "", []string{"x86"}}, |
Dan Willemsen | 8a35405 | 2016-05-10 14:30:51 -0700 | [diff] [blame] | 1338 | {"x86", "x86_64", "", []string{"x86"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1339 | {"x86_64", "", "", []string{"x86_64"}}, |
| 1340 | {"x86_64", "haswell", "", []string{"x86_64"}}, |
| 1341 | {"x86_64", "ivybridge", "", []string{"x86_64"}}, |
| 1342 | {"x86_64", "sandybridge", "", []string{"x86_64"}}, |
| 1343 | {"x86_64", "silvermont", "", []string{"x86_64"}}, |
| 1344 | } |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1345 | } |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1346 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1347 | func getNdkAbisConfig() []archConfig { |
| 1348 | return []archConfig{ |
Dan Willemsen | f4e0601 | 2019-01-23 22:31:26 -0800 | [diff] [blame] | 1349 | {"arm", "armv7-a-neon", "", []string{"armeabi"}}, |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1350 | {"arm64", "armv8-a", "", []string{"arm64-v8a"}}, |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1351 | {"x86", "", "", []string{"x86"}}, |
| 1352 | {"x86_64", "", "", []string{"x86_64"}}, |
| 1353 | } |
| 1354 | } |
| 1355 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1356 | func decodeArchSettings(os OsType, archConfigs []archConfig) ([]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1357 | var ret []Target |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1358 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1359 | for _, config := range archConfigs { |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1360 | arch, err := decodeArch(os, config.arch, &config.archVariant, |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame^] | 1361 | &config.cpuVariant, config.abi) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1362 | if err != nil { |
| 1363 | return nil, err |
| 1364 | } |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 1365 | arch.Native = false |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1366 | ret = append(ret, Target{ |
| 1367 | Os: Android, |
| 1368 | Arch: arch, |
| 1369 | }) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | return ret, nil |
| 1373 | } |
| 1374 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1375 | // Convert a set of strings from product variables into a single Arch struct |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame^] | 1376 | func decodeArch(os OsType, arch string, archVariant, cpuVariant *string, abi []string) (Arch, error) { |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1377 | stringPtr := func(p *string) string { |
| 1378 | if p != nil { |
| 1379 | return *p |
| 1380 | } |
| 1381 | return "" |
| 1382 | } |
| 1383 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1384 | archType, ok := archTypeMap[arch] |
| 1385 | if !ok { |
| 1386 | return Arch{}, fmt.Errorf("unknown arch %q", arch) |
| 1387 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1388 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1389 | a := Arch{ |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1390 | ArchType: archType, |
| 1391 | ArchVariant: stringPtr(archVariant), |
| 1392 | CpuVariant: stringPtr(cpuVariant), |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame^] | 1393 | Abi: abi, |
Dan Willemsen | 17f0526 | 2016-05-31 16:27:00 -0700 | [diff] [blame] | 1394 | Native: true, |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" { |
| 1398 | a.ArchVariant = "" |
| 1399 | } |
| 1400 | |
| 1401 | if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" { |
| 1402 | a.CpuVariant = "" |
| 1403 | } |
| 1404 | |
| 1405 | for i := 0; i < len(a.Abi); i++ { |
| 1406 | if a.Abi[i] == "" { |
| 1407 | a.Abi = append(a.Abi[:i], a.Abi[i+1:]...) |
| 1408 | i-- |
| 1409 | } |
| 1410 | } |
| 1411 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1412 | if a.ArchVariant == "" { |
| 1413 | if featureMap, ok := defaultArchFeatureMap[os]; ok { |
| 1414 | a.ArchFeatures = featureMap[archType] |
| 1415 | } |
| 1416 | } else { |
| 1417 | if featureMap, ok := archFeatureMap[archType]; ok { |
| 1418 | a.ArchFeatures = featureMap[a.ArchVariant] |
| 1419 | } |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1420 | } |
| 1421 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1422 | return a, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1425 | func filterMultilibTargets(targets []Target, multilib string) []Target { |
| 1426 | var ret []Target |
| 1427 | for _, t := range targets { |
| 1428 | if t.Arch.ArchType.Multilib == multilib { |
| 1429 | ret = append(ret, t) |
| 1430 | } |
| 1431 | } |
| 1432 | return ret |
| 1433 | } |
| 1434 | |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 1435 | func getCommonTargets(targets []Target) []Target { |
| 1436 | var ret []Target |
| 1437 | set := make(map[string]bool) |
| 1438 | |
| 1439 | for _, t := range targets { |
| 1440 | if _, found := set[t.Os.String()]; !found { |
| 1441 | set[t.Os.String()] = true |
| 1442 | ret = append(ret, commonTargetMap[t.Os.String()]) |
| 1443 | } |
| 1444 | } |
| 1445 | |
| 1446 | return ret |
| 1447 | } |
| 1448 | |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1449 | func firstTarget(targets []Target, filters ...string) []Target { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1450 | for _, filter := range filters { |
| 1451 | buildTargets := filterMultilibTargets(targets, filter) |
| 1452 | if len(buildTargets) > 0 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1453 | return buildTargets[:1] |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1454 | } |
| 1455 | } |
| 1456 | return nil |
| 1457 | } |
| 1458 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1459 | // Use the module multilib setting to select one or more targets from a target list |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 1460 | func decodeMultilibTargets(multilib string, targets []Target, prefer32 bool) ([]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1461 | buildTargets := []Target{} |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1462 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1463 | switch multilib { |
| 1464 | case "common": |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1465 | buildTargets = getCommonTargets(targets) |
| 1466 | case "common_first": |
| 1467 | buildTargets = getCommonTargets(targets) |
| 1468 | if prefer32 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1469 | buildTargets = append(buildTargets, firstTarget(targets, "lib32", "lib64")...) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1470 | } else { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1471 | buildTargets = append(buildTargets, firstTarget(targets, "lib64", "lib32")...) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1472 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1473 | case "both": |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 1474 | if prefer32 { |
| 1475 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) |
| 1476 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) |
| 1477 | } else { |
| 1478 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) |
| 1479 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) |
| 1480 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1481 | case "32": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1482 | buildTargets = filterMultilibTargets(targets, "lib32") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1483 | case "64": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1484 | buildTargets = filterMultilibTargets(targets, "lib64") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1485 | case "first": |
| 1486 | if prefer32 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1487 | buildTargets = firstTarget(targets, "lib32", "lib64") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1488 | } else { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1489 | buildTargets = firstTarget(targets, "lib64", "lib32") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1490 | } |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1491 | case "prefer32": |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1492 | buildTargets = filterMultilibTargets(targets, "lib32") |
| 1493 | if len(buildTargets) == 0 { |
| 1494 | buildTargets = filterMultilibTargets(targets, "lib64") |
| 1495 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1496 | default: |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1497 | return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", "64", or "prefer32" found %q`, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1498 | multilib) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1501 | return buildTargets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1502 | } |