blob: a79685cba849e8e6996ec2c8919cc6a6650226b3 [file] [log] [blame]
Colin Cross3f40fa42015-01-30 17:27:36 -08001// 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 Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross3f40fa42015-01-30 17:27:36 -080016
17import (
Colin Cross74ba9622019-02-11 15:11:14 -080018 "encoding"
Colin Cross3f40fa42015-01-30 17:27:36 -080019 "fmt"
20 "reflect"
21 "runtime"
Colin Cross74ba9622019-02-11 15:11:14 -080022 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080023 "strings"
Colin Crossf6566ed2015-03-24 11:13:38 -070024
Colin Cross0f7d2ef2019-10-16 11:03:10 -070025 "github.com/google/blueprint"
Colin Crossf6566ed2015-03-24 11:13:38 -070026 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080027)
28
Colin Cross0f7d2ef2019-10-16 11:03:10 -070029const COMMON_VARIANT = "common"
30
Colin Cross3f40fa42015-01-30 17:27:36 -080031var (
Dan Willemsenb1957a52016-06-23 23:44:54 -070032 archTypeList []ArchType
33
Colin Crossec193632015-07-06 17:49:43 -070034 Arm = newArch("arm", "lib32")
35 Arm64 = newArch("arm64", "lib64")
36 Mips = newArch("mips", "lib32")
37 Mips64 = newArch("mips64", "lib64")
38 X86 = newArch("x86", "lib32")
39 X86_64 = newArch("x86_64", "lib64")
Colin Cross2fe66872015-03-30 17:20:39 -070040
41 Common = ArchType{
Colin Cross0f7d2ef2019-10-16 11:03:10 -070042 Name: COMMON_VARIANT,
Colin Cross2fe66872015-03-30 17:20:39 -070043 }
Colin Cross3f40fa42015-01-30 17:27:36 -080044)
45
Colin Cross4225f652015-09-17 14:33:42 -070046var archTypeMap = map[string]ArchType{
47 "arm": Arm,
48 "arm64": Arm64,
49 "mips": Mips,
Colin Cross3b336c22015-11-23 16:28:31 -080050 "mips64": Mips64,
Colin Cross4225f652015-09-17 14:33:42 -070051 "x86": X86,
52 "x86_64": X86_64,
53}
54
Colin Cross3f40fa42015-01-30 17:27:36 -080055/*
56Example blueprints file containing all variant property groups, with comment listing what type
57of variants get properties in that group:
58
59module {
60 arch: {
61 arm: {
62 // Host or device variants with arm architecture
63 },
64 arm64: {
65 // Host or device variants with arm64 architecture
66 },
67 mips: {
68 // Host or device variants with mips architecture
69 },
70 mips64: {
71 // Host or device variants with mips64 architecture
72 },
73 x86: {
74 // Host or device variants with x86 architecture
75 },
76 x86_64: {
77 // Host or device variants with x86_64 architecture
78 },
79 },
80 multilib: {
81 lib32: {
82 // Host or device variants for 32-bit architectures
83 },
84 lib64: {
85 // Host or device variants for 64-bit architectures
86 },
87 },
88 target: {
89 android: {
90 // Device variants
91 },
92 host: {
93 // Host variants
94 },
Dan Willemsen5746bd42017-10-02 19:42:01 -070095 linux_glibc: {
Colin Cross3f40fa42015-01-30 17:27:36 -080096 // Linux host variants
97 },
98 darwin: {
99 // Darwin host variants
100 },
101 windows: {
102 // Windows host variants
103 },
104 not_windows: {
105 // Non-windows host variants
106 },
107 },
108}
109*/
Colin Cross7d5136f2015-05-11 13:39:40 -0700110
Jaewoong Junge46114c2019-01-16 14:33:13 -0800111var archVariants = map[ArchType][]string{
112 Arm: {
Dan Albert8818f492019-02-19 13:53:01 -0800113 "armv7-a",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800114 "armv7-a-neon",
115 "armv8-a",
116 "armv8-2a",
117 "cortex-a7",
118 "cortex-a8",
119 "cortex-a9",
120 "cortex-a15",
121 "cortex-a53",
122 "cortex-a53-a57",
123 "cortex-a55",
124 "cortex-a72",
125 "cortex-a73",
126 "cortex-a75",
127 "cortex-a76",
128 "krait",
129 "kryo",
130 "kryo385",
131 "exynos-m1",
132 "exynos-m2",
133 },
134 Arm64: {
135 "armv8_a",
136 "armv8_2a",
137 "cortex-a53",
138 "cortex-a55",
139 "cortex-a72",
140 "cortex-a73",
141 "cortex-a75",
142 "cortex-a76",
143 "kryo",
144 "kryo385",
145 "exynos-m1",
146 "exynos-m2",
147 },
148 Mips: {
149 "mips32_fp",
150 "mips32r2_fp",
151 "mips32r2_fp_xburst",
152 "mips32r2dsp_fp",
153 "mips32r2dspr2_fp",
154 "mips32r6",
155 },
156 Mips64: {
157 "mips64r2",
158 "mips64r6",
159 },
160 X86: {
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530161 "amberlake",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800162 "atom",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530163 "broadwell",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800164 "haswell",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530165 "icelake",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800166 "ivybridge",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530167 "kabylake",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800168 "sandybridge",
169 "silvermont",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530170 "skylake",
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -0700171 "stoneyridge",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530172 "tigerlake",
173 "whiskeylake",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800174 "x86_64",
175 },
176 X86_64: {
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530177 "amberlake",
178 "broadwell",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800179 "haswell",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530180 "icelake",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800181 "ivybridge",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530182 "kabylake",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800183 "sandybridge",
184 "silvermont",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530185 "skylake",
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -0700186 "stoneyridge",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530187 "tigerlake",
188 "whiskeylake",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800189 },
190}
191
192var archFeatures = map[ArchType][]string{
193 Arm: {
194 "neon",
195 },
196 Mips: {
197 "dspr2",
198 "rev6",
199 "msa",
200 },
201 Mips64: {
202 "rev6",
203 "msa",
204 },
205 X86: {
206 "ssse3",
207 "sse4",
208 "sse4_1",
209 "sse4_2",
210 "aes_ni",
211 "avx",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530212 "avx2",
213 "avx512",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800214 "popcnt",
215 "movbe",
216 },
217 X86_64: {
218 "ssse3",
219 "sse4",
220 "sse4_1",
221 "sse4_2",
222 "aes_ni",
223 "avx",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530224 "avx2",
225 "avx512",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800226 "popcnt",
227 },
228}
229
230var archFeatureMap = map[ArchType]map[string][]string{
231 Arm: {
232 "armv7-a-neon": {
233 "neon",
234 },
235 "armv8-a": {
236 "neon",
237 },
238 "armv8-2a": {
239 "neon",
240 },
241 },
242 Mips: {
243 "mips32r2dspr2_fp": {
244 "dspr2",
245 },
246 "mips32r6": {
247 "rev6",
248 },
249 },
250 Mips64: {
251 "mips64r6": {
252 "rev6",
253 },
254 },
255 X86: {
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530256 "amberlake": {
257 "ssse3",
258 "sse4",
259 "sse4_1",
260 "sse4_2",
261 "avx",
262 "avx2",
263 "aes_ni",
264 "popcnt",
265 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800266 "atom": {
267 "ssse3",
268 "movbe",
269 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530270 "broadwell": {
271 "ssse3",
272 "sse4",
273 "sse4_1",
274 "sse4_2",
275 "avx",
276 "avx2",
277 "aes_ni",
278 "popcnt",
279 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800280 "haswell": {
281 "ssse3",
282 "sse4",
283 "sse4_1",
284 "sse4_2",
285 "aes_ni",
286 "avx",
287 "popcnt",
288 "movbe",
289 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530290 "icelake": {
291 "ssse3",
292 "sse4",
293 "sse4_1",
294 "sse4_2",
295 "avx",
296 "avx2",
297 "avx512",
298 "aes_ni",
299 "popcnt",
300 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800301 "ivybridge": {
302 "ssse3",
303 "sse4",
304 "sse4_1",
305 "sse4_2",
306 "aes_ni",
307 "avx",
308 "popcnt",
309 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530310 "kabylake": {
311 "ssse3",
312 "sse4",
313 "sse4_1",
314 "sse4_2",
315 "avx",
316 "avx2",
317 "aes_ni",
318 "popcnt",
319 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800320 "sandybridge": {
321 "ssse3",
322 "sse4",
323 "sse4_1",
324 "sse4_2",
325 "popcnt",
326 },
327 "silvermont": {
328 "ssse3",
329 "sse4",
330 "sse4_1",
331 "sse4_2",
332 "aes_ni",
333 "popcnt",
334 "movbe",
335 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530336 "skylake": {
337 "ssse3",
338 "sse4",
339 "sse4_1",
340 "sse4_2",
341 "avx",
342 "avx2",
343 "avx512",
344 "aes_ni",
345 "popcnt",
346 },
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -0700347 "stoneyridge": {
348 "ssse3",
349 "sse4",
350 "sse4_1",
351 "sse4_2",
352 "aes_ni",
353 "avx",
354 "avx2",
355 "popcnt",
356 "movbe",
357 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530358 "tigerlake": {
359 "ssse3",
360 "sse4",
361 "sse4_1",
362 "sse4_2",
363 "avx",
364 "avx2",
365 "avx512",
366 "aes_ni",
367 "popcnt",
368 },
369 "whiskeylake": {
370 "ssse3",
371 "sse4",
372 "sse4_1",
373 "sse4_2",
374 "avx",
375 "avx2",
376 "avx512",
377 "aes_ni",
378 "popcnt",
379 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800380 "x86_64": {
381 "ssse3",
382 "sse4",
383 "sse4_1",
384 "sse4_2",
385 "popcnt",
386 },
387 },
388 X86_64: {
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530389 "amberlake": {
390 "ssse3",
391 "sse4",
392 "sse4_1",
393 "sse4_2",
394 "avx",
395 "avx2",
396 "aes_ni",
397 "popcnt",
398 },
399 "broadwell": {
400 "ssse3",
401 "sse4",
402 "sse4_1",
403 "sse4_2",
404 "avx",
405 "avx2",
406 "aes_ni",
407 "popcnt",
408 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800409 "haswell": {
410 "ssse3",
411 "sse4",
412 "sse4_1",
413 "sse4_2",
414 "aes_ni",
415 "avx",
416 "popcnt",
417 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530418 "icelake": {
419 "ssse3",
420 "sse4",
421 "sse4_1",
422 "sse4_2",
423 "avx",
424 "avx2",
425 "avx512",
426 "aes_ni",
427 "popcnt",
428 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800429 "ivybridge": {
430 "ssse3",
431 "sse4",
432 "sse4_1",
433 "sse4_2",
434 "aes_ni",
435 "avx",
436 "popcnt",
437 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530438 "kabylake": {
439 "ssse3",
440 "sse4",
441 "sse4_1",
442 "sse4_2",
443 "avx",
444 "avx2",
445 "aes_ni",
446 "popcnt",
447 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800448 "sandybridge": {
449 "ssse3",
450 "sse4",
451 "sse4_1",
452 "sse4_2",
453 "popcnt",
454 },
455 "silvermont": {
456 "ssse3",
457 "sse4",
458 "sse4_1",
459 "sse4_2",
460 "aes_ni",
461 "popcnt",
462 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530463 "skylake": {
464 "ssse3",
465 "sse4",
466 "sse4_1",
467 "sse4_2",
468 "avx",
469 "avx2",
470 "avx512",
471 "aes_ni",
472 "popcnt",
473 },
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -0700474 "stoneyridge": {
475 "ssse3",
476 "sse4",
477 "sse4_1",
478 "sse4_2",
479 "aes_ni",
480 "avx",
481 "avx2",
482 "popcnt",
483 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530484 "tigerlake": {
485 "ssse3",
486 "sse4",
487 "sse4_1",
488 "sse4_2",
489 "avx",
490 "avx2",
491 "avx512",
492 "aes_ni",
493 "popcnt",
494 },
495 "whiskeylake": {
496 "ssse3",
497 "sse4",
498 "sse4_1",
499 "sse4_2",
500 "avx",
501 "avx2",
502 "avx512",
503 "aes_ni",
504 "popcnt",
505 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800506 },
507}
508
Dan Willemsen01a3c252019-01-11 19:02:16 -0800509var defaultArchFeatureMap = map[OsType]map[ArchType][]string{}
Colin Crossc5c24ad2015-11-20 15:35:00 -0800510
Dan Willemsen01a3c252019-01-11 19:02:16 -0800511func RegisterDefaultArchVariantFeatures(os OsType, arch ArchType, features ...string) {
512 checkCalledFromInit()
513
514 for _, feature := range features {
515 if !InList(feature, archFeatures[arch]) {
516 panic(fmt.Errorf("Invalid feature %q for arch %q variant \"\"", feature, arch))
517 }
518 }
519
520 if defaultArchFeatureMap[os] == nil {
521 defaultArchFeatureMap[os] = make(map[ArchType][]string)
522 }
523 defaultArchFeatureMap[os][arch] = features
524}
525
Colin Cross3f40fa42015-01-30 17:27:36 -0800526// An Arch indicates a single CPU architecture.
527type Arch struct {
Colin Crossc5c24ad2015-11-20 15:35:00 -0800528 ArchType ArchType
529 ArchVariant string
530 CpuVariant string
531 Abi []string
532 ArchFeatures []string
Colin Cross3f40fa42015-01-30 17:27:36 -0800533}
534
535func (a Arch) String() string {
Colin Crossd3ba0392015-05-07 14:11:29 -0700536 s := a.ArchType.String()
Colin Cross3f40fa42015-01-30 17:27:36 -0800537 if a.ArchVariant != "" {
538 s += "_" + a.ArchVariant
539 }
540 if a.CpuVariant != "" {
541 s += "_" + a.CpuVariant
542 }
543 return s
544}
545
546type ArchType struct {
Colin Crossec193632015-07-06 17:49:43 -0700547 Name string
Dan Willemsenb1957a52016-06-23 23:44:54 -0700548 Field string
Colin Crossec193632015-07-06 17:49:43 -0700549 Multilib string
Colin Cross3f40fa42015-01-30 17:27:36 -0800550}
551
Colin Crossec193632015-07-06 17:49:43 -0700552func newArch(name, multilib string) ArchType {
Dan Willemsenb1957a52016-06-23 23:44:54 -0700553 archType := ArchType{
Colin Crossec193632015-07-06 17:49:43 -0700554 Name: name,
Dan Willemsenb1957a52016-06-23 23:44:54 -0700555 Field: proptools.FieldNameForProperty(name),
Colin Crossec193632015-07-06 17:49:43 -0700556 Multilib: multilib,
Colin Cross3f40fa42015-01-30 17:27:36 -0800557 }
Dan Willemsenb1957a52016-06-23 23:44:54 -0700558 archTypeList = append(archTypeList, archType)
559 return archType
Colin Cross3f40fa42015-01-30 17:27:36 -0800560}
561
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -0700562func ArchTypeList() []ArchType {
563 return append([]ArchType(nil), archTypeList...)
564}
565
Colin Cross3f40fa42015-01-30 17:27:36 -0800566func (a ArchType) String() string {
567 return a.Name
568}
569
Colin Cross74ba9622019-02-11 15:11:14 -0800570var _ encoding.TextMarshaler = ArchType{}
571
572func (a ArchType) MarshalText() ([]byte, error) {
573 return []byte(strconv.Quote(a.String())), nil
574}
575
576var _ encoding.TextUnmarshaler = &ArchType{}
577
578func (a *ArchType) UnmarshalText(text []byte) error {
579 if u, ok := archTypeMap[string(text)]; ok {
580 *a = u
581 return nil
582 }
583
584 return fmt.Errorf("unknown ArchType %q", text)
585}
586
Colin Crossa1ad8d12016-06-01 17:09:44 -0700587var BuildOs = func() OsType {
Dan Willemsen490fd492015-11-24 17:53:15 -0800588 switch runtime.GOOS {
589 case "linux":
590 return Linux
591 case "darwin":
592 return Darwin
593 default:
594 panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS))
595 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700596}()
597
598var (
Nan Zhangdb0b9a32017-02-27 10:12:13 -0800599 osTypeList []OsType
600 commonTargetMap = make(map[string]Target)
Colin Crossa1ad8d12016-06-01 17:09:44 -0700601
Dan Willemsen00fcbde2016-11-17 00:25:59 -0800602 NoOsType OsType
Dan Willemsen866b5632017-09-22 12:28:24 -0700603 Linux = NewOsType("linux_glibc", Host, false)
Dan Willemsen00fcbde2016-11-17 00:25:59 -0800604 Darwin = NewOsType("darwin", Host, false)
Dan Willemsen9ff34c02018-10-10 17:58:19 -0700605 LinuxBionic = NewOsType("linux_bionic", Host, false)
Dan Willemsen00fcbde2016-11-17 00:25:59 -0800606 Windows = NewOsType("windows", HostCross, true)
607 Android = NewOsType("android", Device, false)
Doug Horn21b94272019-01-16 12:06:11 -0800608 Fuchsia = NewOsType("fuchsia", Device, false)
Dan Willemsenb1957a52016-06-23 23:44:54 -0700609
610 osArchTypeMap = map[OsType][]ArchType{
Dan Willemsen00fcbde2016-11-17 00:25:59 -0800611 Linux: []ArchType{X86, X86_64},
612 LinuxBionic: []ArchType{X86_64},
Dan Willemsene97e68a2018-08-28 17:12:56 -0700613 Darwin: []ArchType{X86_64},
Dan Willemsen00fcbde2016-11-17 00:25:59 -0800614 Windows: []ArchType{X86, X86_64},
615 Android: []ArchType{Arm, Arm64, Mips, Mips64, X86, X86_64},
Doug Horn21b94272019-01-16 12:06:11 -0800616 Fuchsia: []ArchType{Arm64, X86_64},
Dan Willemsenb1957a52016-06-23 23:44:54 -0700617 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700618)
619
620type OsType struct {
621 Name, Field string
622 Class OsClass
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800623
624 DefaultDisabled bool
Dan Willemsen490fd492015-11-24 17:53:15 -0800625}
626
Colin Crossa1ad8d12016-06-01 17:09:44 -0700627type OsClass int
628
629const (
Dan Willemsen0e2d97b2016-11-28 17:50:06 -0800630 Generic OsClass = iota
631 Device
Colin Crossa1ad8d12016-06-01 17:09:44 -0700632 Host
633 HostCross
634)
635
Colin Cross67a5c132017-05-09 13:45:28 -0700636func (class OsClass) String() string {
637 switch class {
638 case Generic:
639 return "generic"
640 case Device:
641 return "device"
642 case Host:
643 return "host"
644 case HostCross:
645 return "host cross"
646 default:
647 panic(fmt.Errorf("unknown class %d", class))
648 }
649}
650
Colin Crossa1ad8d12016-06-01 17:09:44 -0700651func (os OsType) String() string {
652 return os.Name
Colin Cross54c71122016-06-01 17:09:44 -0700653}
654
Dan Willemsen866b5632017-09-22 12:28:24 -0700655func (os OsType) Bionic() bool {
656 return os == Android || os == LinuxBionic
657}
658
659func (os OsType) Linux() bool {
660 return os == Android || os == Linux || os == LinuxBionic
661}
662
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800663func NewOsType(name string, class OsClass, defDisabled bool) OsType {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700664 os := OsType{
665 Name: name,
666 Field: strings.Title(name),
667 Class: class,
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800668
669 DefaultDisabled: defDisabled,
Colin Cross54c71122016-06-01 17:09:44 -0700670 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700671 osTypeList = append(osTypeList, os)
Nan Zhangdb0b9a32017-02-27 10:12:13 -0800672
673 if _, found := commonTargetMap[name]; found {
674 panic(fmt.Errorf("Found Os type duplicate during OsType registration: %q", name))
675 } else {
676 commonTargetMap[name] = Target{Os: os, Arch: Arch{ArchType: Common}}
677 }
678
Colin Crossa1ad8d12016-06-01 17:09:44 -0700679 return os
680}
681
682func osByName(name string) OsType {
683 for _, os := range osTypeList {
684 if os.Name == name {
685 return os
686 }
687 }
688
689 return NoOsType
Dan Willemsen490fd492015-11-24 17:53:15 -0800690}
691
dimitry1f33e402019-03-26 12:39:31 +0100692type NativeBridgeSupport bool
693
694const (
695 NativeBridgeDisabled NativeBridgeSupport = false
696 NativeBridgeEnabled NativeBridgeSupport = true
697)
698
Colin Crossa1ad8d12016-06-01 17:09:44 -0700699type Target struct {
dimitry8d6dde82019-07-11 10:23:53 +0200700 Os OsType
701 Arch Arch
702 NativeBridge NativeBridgeSupport
703 NativeBridgeHostArchName string
704 NativeBridgeRelativePath string
Colin Crossd3ba0392015-05-07 14:11:29 -0700705}
706
Colin Crossa1ad8d12016-06-01 17:09:44 -0700707func (target Target) String() string {
Colin Crossa195f912019-10-16 11:07:20 -0700708 return target.OsVariation() + "_" + target.ArchVariation()
709}
710
711func (target Target) OsVariation() string {
712 return target.Os.String()
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700713}
714
715func (target Target) ArchVariation() string {
716 var variation string
dimitry1f33e402019-03-26 12:39:31 +0100717 if target.NativeBridge {
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700718 variation = "native_bridge_"
dimitry1f33e402019-03-26 12:39:31 +0100719 }
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700720 variation += target.Arch.String()
721
Colin Crossa195f912019-10-16 11:07:20 -0700722 return variation
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700723}
724
725func (target Target) Variations() []blueprint.Variation {
726 return []blueprint.Variation{
Colin Crossa195f912019-10-16 11:07:20 -0700727 {Mutator: "os", Variation: target.OsVariation()},
Colin Cross0f7d2ef2019-10-16 11:03:10 -0700728 {Mutator: "arch", Variation: target.ArchVariation()},
729 }
Dan Willemsen490fd492015-11-24 17:53:15 -0800730}
731
Colin Crossa195f912019-10-16 11:07:20 -0700732func osMutator(mctx BottomUpMutatorContext) {
733 var module Module
734 var ok bool
735 if module, ok = mctx.Module().(Module); !ok {
736 return
737 }
738
739 base := module.base()
740
741 if !base.ArchSpecific() {
742 return
743 }
744
745 osClasses := base.OsClassSupported()
746
747 var moduleOSList []OsType
748
749 for _, os := range osTypeList {
750 supportedClass := false
751 for _, osClass := range osClasses {
752 if os.Class == osClass {
753 supportedClass = true
754 }
755 }
756 if !supportedClass {
757 continue
758 }
759
760 if len(mctx.Config().Targets[os]) == 0 {
761 continue
762 }
763
764 moduleOSList = append(moduleOSList, os)
765 }
766
767 if len(moduleOSList) == 0 {
768 base.commonProperties.Enabled = boolPtr(false)
769 return
770 }
771
772 osNames := make([]string, len(moduleOSList))
773
774 for i, os := range moduleOSList {
775 osNames[i] = os.String()
776 }
777
778 modules := mctx.CreateVariations(osNames...)
779 for i, m := range modules {
780 m.(Module).base().commonProperties.CompileOS = moduleOSList[i]
781 m.(Module).base().setOSProperties(mctx)
782 }
783
784}
785
Colin Crossee0bc3b2018-10-02 22:01:37 -0700786// archMutator splits a module into a variant for each Target requested by the module. Target selection
787// for a module is in three levels, OsClass, mulitlib, and then Target.
788// OsClass selection is determined by:
789// - The HostOrDeviceSupported value passed in to InitAndroidArchModule by the module type factory, which selects
790// whether the module type can compile for host, device or both.
791// - The host_supported and device_supported properties on the module.
Roland Levillainf5b635d2019-06-05 14:42:57 +0100792// If host is supported for the module, the Host and HostCross OsClasses are selected. If device is supported
Colin Crossee0bc3b2018-10-02 22:01:37 -0700793// for the module, the Device OsClass is selected.
794// Within each selected OsClass, the multilib selection is determined by:
Jaewoong Jung02b2d4d2019-06-06 15:19:57 -0700795// - The compile_multilib property if it set (which may be overridden by target.android.compile_multilib or
Colin Crossee0bc3b2018-10-02 22:01:37 -0700796// target.host.compile_multilib).
797// - The default multilib passed to InitAndroidArchModule if compile_multilib was not set.
798// Valid multilib values include:
799// "both": compile for all Targets supported by the OsClass (generally x86_64 and x86, or arm64 and arm).
800// "first": compile for only a single preferred Target supported by the OsClass. This is generally x86_64 or arm64,
801// but may be arm for a 32-bit only build or a build with TARGET_PREFER_32_BIT=true set.
802// "32": compile for only a single 32-bit Target supported by the OsClass.
803// "64": compile for only a single 64-bit Target supported by the OsClass.
804// "common": compile a for a single Target that will work on all Targets suported by the OsClass (for example Java).
805//
806// Once the list of Targets is determined, the module is split into a variant for each Target.
807//
808// Modules can be initialized with InitAndroidMultiTargetsArchModule, in which case they will be split by OsClass,
809// but will have a common Target that is expected to handle all other selected Targets via ctx.MultiTargets().
Colin Cross1e676be2016-10-12 14:38:15 -0700810func archMutator(mctx BottomUpMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700811 var module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800812 var ok bool
Colin Cross635c3b02016-05-18 15:37:25 -0700813 if module, ok = mctx.Module().(Module); !ok {
Colin Cross3f40fa42015-01-30 17:27:36 -0800814 return
815 }
816
Colin Cross5eca7cb2018-10-02 14:02:10 -0700817 base := module.base()
818
819 if !base.ArchSpecific() {
Colin Crossb9db4802016-06-03 01:50:47 +0000820 return
821 }
822
Colin Crossa195f912019-10-16 11:07:20 -0700823 os := base.commonProperties.CompileOS
824 osTargets := mctx.Config().Targets[os]
Colin Crossfb0c16e2019-11-20 17:12:35 -0800825 image := base.commonProperties.ImageVariation
Colin Crossa195f912019-10-16 11:07:20 -0700826 // Filter NativeBridge targets unless they are explicitly supported
Colin Cross83bead42019-12-18 10:45:46 -0800827 // Skip creating native bridge variants for vendor modules
828 if os == Android &&
829 !(Bool(base.commonProperties.Native_bridge_supported) && image == CoreVariation) {
830
Colin Crossa195f912019-10-16 11:07:20 -0700831 var targets []Target
832 for _, t := range osTargets {
833 if !t.NativeBridge {
834 targets = append(targets, t)
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700835 }
836 }
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700837
Colin Crossa195f912019-10-16 11:07:20 -0700838 osTargets = targets
839 }
Colin Crossee0bc3b2018-10-02 22:01:37 -0700840
Colin Crossa195f912019-10-16 11:07:20 -0700841 // only the primary arch in the recovery partition
842 if os == Android && module.InstallInRecovery() {
843 osTargets = []Target{osTargets[0]}
844 }
dimitry1f33e402019-03-26 12:39:31 +0100845
Colin Crossa195f912019-10-16 11:07:20 -0700846 prefer32 := false
847 if base.prefer32 != nil {
848 prefer32 = base.prefer32(mctx, base, os.Class)
849 }
dimitry1f33e402019-03-26 12:39:31 +0100850
Colin Crossa195f912019-10-16 11:07:20 -0700851 multilib, extraMultilib := decodeMultilib(base, os.Class)
852 targets, err := decodeMultilibTargets(multilib, osTargets, prefer32)
853 if err != nil {
854 mctx.ModuleErrorf("%s", err.Error())
855 }
Colin Cross5eca7cb2018-10-02 14:02:10 -0700856
Colin Crossa195f912019-10-16 11:07:20 -0700857 var multiTargets []Target
858 if extraMultilib != "" {
859 multiTargets, err = decodeMultilibTargets(extraMultilib, osTargets, prefer32)
Colin Crossa1ad8d12016-06-01 17:09:44 -0700860 if err != nil {
861 mctx.ModuleErrorf("%s", err.Error())
862 }
Colin Crossb9db4802016-06-03 01:50:47 +0000863 }
864
Colin Crossfb0c16e2019-11-20 17:12:35 -0800865 if image == RecoveryVariation {
866 primaryArch := mctx.Config().DevicePrimaryArchType()
867 targets = filterToArch(targets, primaryArch)
868 multiTargets = filterToArch(multiTargets, primaryArch)
869 }
870
Colin Crossa195f912019-10-16 11:07:20 -0700871 if len(targets) == 0 {
Colin Cross5eca7cb2018-10-02 14:02:10 -0700872 base.commonProperties.Enabled = boolPtr(false)
Dan Willemsen3f32f032016-07-11 14:36:48 -0700873 return
874 }
875
Colin Crossa195f912019-10-16 11:07:20 -0700876 targetNames := make([]string, len(targets))
Colin Crossb9db4802016-06-03 01:50:47 +0000877
Colin Crossa195f912019-10-16 11:07:20 -0700878 for i, target := range targets {
879 targetNames[i] = target.ArchVariation()
Colin Crossa1ad8d12016-06-01 17:09:44 -0700880 }
881
882 modules := mctx.CreateVariations(targetNames...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800883 for i, m := range modules {
Colin Crossa195f912019-10-16 11:07:20 -0700884 m.(Module).base().commonProperties.CompileTarget = targets[i]
885 m.(Module).base().commonProperties.CompileMultiTargets = multiTargets
886 if i == 0 {
887 m.(Module).base().commonProperties.CompilePrimary = true
888 }
Colin Cross635c3b02016-05-18 15:37:25 -0700889 m.(Module).base().setArchProperties(mctx)
Colin Cross3f40fa42015-01-30 17:27:36 -0800890 }
891}
892
Colin Crossee0bc3b2018-10-02 22:01:37 -0700893func decodeMultilib(base *ModuleBase, class OsClass) (multilib, extraMultilib string) {
894 switch class {
895 case Device:
896 multilib = String(base.commonProperties.Target.Android.Compile_multilib)
897 case Host, HostCross:
898 multilib = String(base.commonProperties.Target.Host.Compile_multilib)
899 }
900 if multilib == "" {
901 multilib = String(base.commonProperties.Compile_multilib)
902 }
903 if multilib == "" {
904 multilib = base.commonProperties.Default_multilib
905 }
906
907 if base.commonProperties.UseTargetVariants {
908 return multilib, ""
909 } else {
910 // For app modules a single arch variant will be created per OS class which is expected to handle all the
911 // selected arches. Return the common-type as multilib and any Android.bp provided multilib as extraMultilib
912 if multilib == base.commonProperties.Default_multilib {
913 multilib = "first"
914 }
915 return base.commonProperties.Default_multilib, multilib
916 }
917}
918
Colin Crossfb0c16e2019-11-20 17:12:35 -0800919func filterToArch(targets []Target, arch ArchType) []Target {
920 for i := 0; i < len(targets); i++ {
921 if targets[i].Arch.ArchType != arch {
922 targets = append(targets[:i], targets[i+1:]...)
923 i--
924 }
925 }
926 return targets
927}
928
Colin Crosscbbd13f2020-01-17 14:08:22 -0800929type archPropTypeDesc struct {
930 arch, multilib, target reflect.Type
931}
932
933type archPropRoot struct {
934 Arch, Multilib, Target interface{}
935}
936
937// createArchPropTypeDesc takes a reflect.Type that is either a struct or a pointer to a struct, and
938// returns lists of reflect.Types that contains the arch-variant properties inside structs for each
939// arch, multilib and target property.
940func createArchPropTypeDesc(props reflect.Type) []archPropTypeDesc {
Colin Cross74449102019-09-25 11:26:40 -0700941 propShards, _ := proptools.FilterPropertyStructSharded(props, filterArchStruct)
Colin Crosscb988072019-01-24 14:58:11 -0800942 if len(propShards) == 0 {
Dan Willemsenb1957a52016-06-23 23:44:54 -0700943 return nil
944 }
945
Colin Crosscbbd13f2020-01-17 14:08:22 -0800946 var ret []archPropTypeDesc
Colin Crossc17727d2018-10-24 12:42:09 -0700947 for _, props := range propShards {
Dan Willemsenb1957a52016-06-23 23:44:54 -0700948
Colin Crossc17727d2018-10-24 12:42:09 -0700949 variantFields := func(names []string) []reflect.StructField {
950 ret := make([]reflect.StructField, len(names))
Dan Willemsenb1957a52016-06-23 23:44:54 -0700951
Colin Crossc17727d2018-10-24 12:42:09 -0700952 for i, name := range names {
953 ret[i].Name = name
954 ret[i].Type = props
Dan Willemsen866b5632017-09-22 12:28:24 -0700955 }
Colin Crossc17727d2018-10-24 12:42:09 -0700956
957 return ret
958 }
959
960 archFields := make([]reflect.StructField, len(archTypeList))
961 for i, arch := range archTypeList {
962 variants := []string{}
963
964 for _, archVariant := range archVariants[arch] {
965 archVariant := variantReplacer.Replace(archVariant)
966 variants = append(variants, proptools.FieldNameForProperty(archVariant))
967 }
968 for _, feature := range archFeatures[arch] {
969 feature := variantReplacer.Replace(feature)
970 variants = append(variants, proptools.FieldNameForProperty(feature))
971 }
972
973 fields := variantFields(variants)
974
975 fields = append([]reflect.StructField{{
976 Name: "BlueprintEmbed",
977 Type: props,
978 Anonymous: true,
979 }}, fields...)
980
981 archFields[i] = reflect.StructField{
982 Name: arch.Field,
983 Type: reflect.StructOf(fields),
984 }
985 }
986 archType := reflect.StructOf(archFields)
987
988 multilibType := reflect.StructOf(variantFields([]string{"Lib32", "Lib64"}))
989
990 targets := []string{
991 "Host",
992 "Android64",
993 "Android32",
994 "Bionic",
995 "Linux",
996 "Not_windows",
997 "Arm_on_x86",
998 "Arm_on_x86_64",
999 }
1000 for _, os := range osTypeList {
1001 targets = append(targets, os.Field)
1002
1003 for _, archType := range osArchTypeMap[os] {
1004 targets = append(targets, os.Field+"_"+archType.Name)
1005
1006 if os.Linux() {
1007 target := "Linux_" + archType.Name
1008 if !InList(target, targets) {
1009 targets = append(targets, target)
1010 }
1011 }
1012 if os.Bionic() {
1013 target := "Bionic_" + archType.Name
1014 if !InList(target, targets) {
1015 targets = append(targets, target)
1016 }
Dan Willemsen866b5632017-09-22 12:28:24 -07001017 }
1018 }
Dan Willemsenb1957a52016-06-23 23:44:54 -07001019 }
Dan Willemsenb1957a52016-06-23 23:44:54 -07001020
Colin Crossc17727d2018-10-24 12:42:09 -07001021 targetType := reflect.StructOf(variantFields(targets))
Colin Crosscbbd13f2020-01-17 14:08:22 -08001022
1023 ret = append(ret, archPropTypeDesc{
1024 arch: reflect.PtrTo(archType),
1025 multilib: reflect.PtrTo(multilibType),
1026 target: reflect.PtrTo(targetType),
1027 })
Colin Crossc17727d2018-10-24 12:42:09 -07001028 }
1029 return ret
Dan Willemsenb1957a52016-06-23 23:44:54 -07001030}
1031
Colin Cross74449102019-09-25 11:26:40 -07001032func filterArchStruct(field reflect.StructField, prefix string) (bool, reflect.StructField) {
1033 if proptools.HasTag(field, "android", "arch_variant") {
1034 // The arch_variant field isn't necessary past this point
1035 // Instead of wasting space, just remove it. Go also has a
1036 // 16-bit limit on structure name length. The name is constructed
1037 // based on the Go source representation of the structure, so
1038 // the tag names count towards that length.
1039 //
1040 // TODO: handle the uncommon case of other tags being involved
1041 if field.Tag == `android:"arch_variant"` {
1042 field.Tag = ""
1043 }
1044 return true, field
1045 }
1046 return false, field
1047}
1048
Dan Willemsenb1957a52016-06-23 23:44:54 -07001049var archPropTypeMap OncePer
1050
Colin Cross36242852017-06-23 15:06:31 -07001051func InitArchModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001052
1053 base := m.base()
1054
Colin Cross36242852017-06-23 15:06:31 -07001055 base.generalProperties = m.GetProperties()
Colin Cross3f40fa42015-01-30 17:27:36 -08001056
1057 for _, properties := range base.generalProperties {
1058 propertiesValue := reflect.ValueOf(properties)
Colin Cross62496a02016-08-08 15:49:17 -07001059 t := propertiesValue.Type()
Colin Cross3f40fa42015-01-30 17:27:36 -08001060 if propertiesValue.Kind() != reflect.Ptr {
Colin Crossca860ac2016-01-04 14:34:37 -08001061 panic(fmt.Errorf("properties must be a pointer to a struct, got %T",
1062 propertiesValue.Interface()))
Colin Cross3f40fa42015-01-30 17:27:36 -08001063 }
1064
1065 propertiesValue = propertiesValue.Elem()
1066 if propertiesValue.Kind() != reflect.Struct {
Colin Crossca860ac2016-01-04 14:34:37 -08001067 panic(fmt.Errorf("properties must be a pointer to a struct, got %T",
1068 propertiesValue.Interface()))
Colin Cross3f40fa42015-01-30 17:27:36 -08001069 }
1070
Colin Cross571cccf2019-02-04 11:22:08 -08001071 archPropTypes := archPropTypeMap.Once(NewCustomOnceKey(t), func() interface{} {
Colin Crosscbbd13f2020-01-17 14:08:22 -08001072 return createArchPropTypeDesc(t)
1073 }).([]archPropTypeDesc)
Colin Cross3f40fa42015-01-30 17:27:36 -08001074
Colin Crossc17727d2018-10-24 12:42:09 -07001075 var archProperties []interface{}
1076 for _, t := range archPropTypes {
Colin Crosscbbd13f2020-01-17 14:08:22 -08001077 archProperties = append(archProperties, &archPropRoot{
1078 Arch: reflect.Zero(t.arch).Interface(),
1079 Multilib: reflect.Zero(t.multilib).Interface(),
1080 Target: reflect.Zero(t.target).Interface(),
1081 })
Dan Willemsenb1957a52016-06-23 23:44:54 -07001082 }
Colin Crossc17727d2018-10-24 12:42:09 -07001083 base.archProperties = append(base.archProperties, archProperties)
1084 m.AddProperties(archProperties...)
Colin Cross3f40fa42015-01-30 17:27:36 -08001085 }
1086
Colin Cross36242852017-06-23 15:06:31 -07001087 base.customizableProperties = m.GetProperties()
Colin Cross3f40fa42015-01-30 17:27:36 -08001088}
1089
Colin Crossa716add2015-12-16 11:07:39 -08001090var variantReplacer = strings.NewReplacer("-", "_", ".", "_")
Colin Crossec193632015-07-06 17:49:43 -07001091
Colin Cross4157e882019-06-06 16:57:04 -07001092func (m *ModuleBase) appendProperties(ctx BottomUpMutatorContext,
Dan Willemsenb1957a52016-06-23 23:44:54 -07001093 dst interface{}, src reflect.Value, field, srcPrefix string) reflect.Value {
Colin Cross06a931b2015-10-28 17:23:31 -07001094
Colin Crosscbbd13f2020-01-17 14:08:22 -08001095 if src.Kind() == reflect.Ptr {
1096 if src.IsNil() {
1097 return src
1098 }
1099 src = src.Elem()
1100 }
1101
Dan Willemsenb1957a52016-06-23 23:44:54 -07001102 src = src.FieldByName(field)
1103 if !src.IsValid() {
Colin Crosseeabb892015-11-20 13:07:51 -08001104 ctx.ModuleErrorf("field %q does not exist", srcPrefix)
Dan Willemsenb1957a52016-06-23 23:44:54 -07001105 return src
Colin Cross85a88972015-11-23 13:29:51 -08001106 }
1107
Dan Willemsenb1957a52016-06-23 23:44:54 -07001108 ret := src
Colin Cross85a88972015-11-23 13:29:51 -08001109
Dan Willemsenb1957a52016-06-23 23:44:54 -07001110 if src.Kind() == reflect.Struct {
1111 src = src.FieldByName("BlueprintEmbed")
Colin Cross06a931b2015-10-28 17:23:31 -07001112 }
1113
Colin Cross6ee75b62016-05-05 15:57:15 -07001114 order := func(property string,
1115 dstField, srcField reflect.StructField,
1116 dstValue, srcValue interface{}) (proptools.Order, error) {
1117 if proptools.HasTag(dstField, "android", "variant_prepend") {
1118 return proptools.Prepend, nil
1119 } else {
1120 return proptools.Append, nil
1121 }
1122 }
1123
Dan Willemsenb1957a52016-06-23 23:44:54 -07001124 err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, order)
Colin Cross06a931b2015-10-28 17:23:31 -07001125 if err != nil {
1126 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
1127 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
1128 } else {
1129 panic(err)
1130 }
1131 }
Colin Cross85a88972015-11-23 13:29:51 -08001132
Dan Willemsenb1957a52016-06-23 23:44:54 -07001133 return ret
Colin Cross06a931b2015-10-28 17:23:31 -07001134}
1135
Colin Crossa195f912019-10-16 11:07:20 -07001136// Rewrite the module's properties structs to contain os-specific values.
1137func (m *ModuleBase) setOSProperties(ctx BottomUpMutatorContext) {
1138 os := m.commonProperties.CompileOS
1139
1140 for i := range m.generalProperties {
1141 genProps := m.generalProperties[i]
1142 if m.archProperties[i] == nil {
1143 continue
1144 }
1145 for _, archProperties := range m.archProperties[i] {
1146 archPropValues := reflect.ValueOf(archProperties).Elem()
1147
Colin Crosscbbd13f2020-01-17 14:08:22 -08001148 targetProp := archPropValues.FieldByName("Target").Elem()
Colin Crossa195f912019-10-16 11:07:20 -07001149
1150 // Handle host-specific properties in the form:
1151 // target: {
1152 // host: {
1153 // key: value,
1154 // },
1155 // },
1156 if os.Class == Host || os.Class == HostCross {
1157 field := "Host"
1158 prefix := "target.host"
1159 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1160 }
1161
1162 // Handle target OS generalities of the form:
1163 // target: {
1164 // bionic: {
1165 // key: value,
1166 // },
1167 // }
1168 if os.Linux() {
1169 field := "Linux"
1170 prefix := "target.linux"
1171 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1172 }
1173
1174 if os.Bionic() {
1175 field := "Bionic"
1176 prefix := "target.bionic"
1177 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1178 }
1179
1180 // Handle target OS properties in the form:
1181 // target: {
1182 // linux_glibc: {
1183 // key: value,
1184 // },
1185 // not_windows: {
1186 // key: value,
1187 // },
1188 // android {
1189 // key: value,
1190 // },
1191 // },
1192 field := os.Field
1193 prefix := "target." + os.Name
1194 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1195
1196 if (os.Class == Host || os.Class == HostCross) && os != Windows {
1197 field := "Not_windows"
1198 prefix := "target.not_windows"
1199 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1200 }
1201
1202 // Handle 64-bit device properties in the form:
1203 // target {
1204 // android64 {
1205 // key: value,
1206 // },
1207 // android32 {
1208 // key: value,
1209 // },
1210 // },
1211 // WARNING: this is probably not what you want to use in your blueprints file, it selects
1212 // options for all targets on a device that supports 64-bit binaries, not just the targets
1213 // that are being compiled for 64-bit. Its expected use case is binaries like linker and
1214 // debuggerd that need to know when they are a 32-bit process running on a 64-bit device
1215 if os.Class == Device {
1216 if ctx.Config().Android64() {
1217 field := "Android64"
1218 prefix := "target.android64"
1219 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1220 } else {
1221 field := "Android32"
1222 prefix := "target.android32"
1223 m.appendProperties(ctx, genProps, targetProp, field, prefix)
1224 }
1225 }
1226 }
1227 }
1228}
1229
Colin Cross3f40fa42015-01-30 17:27:36 -08001230// Rewrite the module's properties structs to contain arch-specific values.
Colin Cross4157e882019-06-06 16:57:04 -07001231func (m *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
1232 arch := m.Arch()
1233 os := m.Os()
Colin Crossd3ba0392015-05-07 14:11:29 -07001234
Colin Cross4157e882019-06-06 16:57:04 -07001235 for i := range m.generalProperties {
1236 genProps := m.generalProperties[i]
1237 if m.archProperties[i] == nil {
Dan Willemsenb1957a52016-06-23 23:44:54 -07001238 continue
1239 }
Colin Cross4157e882019-06-06 16:57:04 -07001240 for _, archProperties := range m.archProperties[i] {
Colin Crossc17727d2018-10-24 12:42:09 -07001241 archPropValues := reflect.ValueOf(archProperties).Elem()
Dan Willemsenb1957a52016-06-23 23:44:54 -07001242
Colin Crosscbbd13f2020-01-17 14:08:22 -08001243 archProp := archPropValues.FieldByName("Arch").Elem()
1244 multilibProp := archPropValues.FieldByName("Multilib").Elem()
1245 targetProp := archPropValues.FieldByName("Target").Elem()
Dan Willemsenb1957a52016-06-23 23:44:54 -07001246
Colin Crossc17727d2018-10-24 12:42:09 -07001247 // Handle arch-specific properties in the form:
Colin Crossd5934c82017-10-02 13:55:26 -07001248 // arch: {
Colin Crossc17727d2018-10-24 12:42:09 -07001249 // arm64: {
Colin Crossd5934c82017-10-02 13:55:26 -07001250 // key: value,
1251 // },
1252 // },
Colin Crossc17727d2018-10-24 12:42:09 -07001253 t := arch.ArchType
1254
1255 if arch.ArchType != Common {
1256 field := proptools.FieldNameForProperty(t.Name)
1257 prefix := "arch." + t.Name
Colin Cross4157e882019-06-06 16:57:04 -07001258 archStruct := m.appendProperties(ctx, genProps, archProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001259
1260 // Handle arch-variant-specific properties in the form:
1261 // arch: {
1262 // variant: {
1263 // key: value,
1264 // },
1265 // },
1266 v := variantReplacer.Replace(arch.ArchVariant)
1267 if v != "" {
1268 field := proptools.FieldNameForProperty(v)
1269 prefix := "arch." + t.Name + "." + v
Colin Cross4157e882019-06-06 16:57:04 -07001270 m.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001271 }
1272
1273 // Handle cpu-variant-specific properties in the form:
1274 // arch: {
1275 // variant: {
1276 // key: value,
1277 // },
1278 // },
1279 if arch.CpuVariant != arch.ArchVariant {
1280 c := variantReplacer.Replace(arch.CpuVariant)
1281 if c != "" {
1282 field := proptools.FieldNameForProperty(c)
1283 prefix := "arch." + t.Name + "." + c
Colin Cross4157e882019-06-06 16:57:04 -07001284 m.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001285 }
1286 }
1287
1288 // Handle arch-feature-specific properties in the form:
1289 // arch: {
1290 // feature: {
1291 // key: value,
1292 // },
1293 // },
1294 for _, feature := range arch.ArchFeatures {
1295 field := proptools.FieldNameForProperty(feature)
1296 prefix := "arch." + t.Name + "." + feature
Colin Cross4157e882019-06-06 16:57:04 -07001297 m.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001298 }
1299
1300 // Handle multilib-specific properties in the form:
1301 // multilib: {
1302 // lib32: {
1303 // key: value,
1304 // },
1305 // },
1306 field = proptools.FieldNameForProperty(t.Multilib)
1307 prefix = "multilib." + t.Multilib
Colin Cross4157e882019-06-06 16:57:04 -07001308 m.appendProperties(ctx, genProps, multilibProp, field, prefix)
Colin Cross08016332016-12-20 09:53:14 -08001309 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001310
Colin Crossa195f912019-10-16 11:07:20 -07001311 // Handle combined OS-feature and arch specific properties in the form:
Colin Crossc17727d2018-10-24 12:42:09 -07001312 // target: {
Colin Crossc17727d2018-10-24 12:42:09 -07001313 // bionic_x86: {
1314 // key: value,
1315 // },
1316 // }
Colin Crossa195f912019-10-16 11:07:20 -07001317 if os.Linux() && arch.ArchType != Common {
1318 field := "Linux_" + arch.ArchType.Name
1319 prefix := "target.linux_" + arch.ArchType.Name
Colin Cross4157e882019-06-06 16:57:04 -07001320 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossd5934c82017-10-02 13:55:26 -07001321 }
Colin Crossc5c24ad2015-11-20 15:35:00 -08001322
Colin Crossa195f912019-10-16 11:07:20 -07001323 if os.Bionic() && arch.ArchType != Common {
1324 field := "Bionic_" + t.Name
1325 prefix := "target.bionic_" + t.Name
Colin Cross4157e882019-06-06 16:57:04 -07001326 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001327 }
1328
Colin Crossa195f912019-10-16 11:07:20 -07001329 // Handle combined OS and arch specific properties in the form:
Colin Crossc17727d2018-10-24 12:42:09 -07001330 // target: {
Colin Crossc17727d2018-10-24 12:42:09 -07001331 // linux_glibc_x86: {
1332 // key: value,
1333 // },
1334 // linux_glibc_arm: {
1335 // key: value,
1336 // },
Colin Crossc17727d2018-10-24 12:42:09 -07001337 // android_arm {
1338 // key: value,
1339 // },
1340 // android_x86 {
Colin Crossd5934c82017-10-02 13:55:26 -07001341 // key: value,
1342 // },
1343 // },
Colin Crossc17727d2018-10-24 12:42:09 -07001344 if arch.ArchType != Common {
Colin Crossa195f912019-10-16 11:07:20 -07001345 field := os.Field + "_" + t.Name
1346 prefix := "target." + os.Name + "_" + t.Name
Colin Cross4157e882019-06-06 16:57:04 -07001347 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossd5934c82017-10-02 13:55:26 -07001348 }
1349
Colin Crossa195f912019-10-16 11:07:20 -07001350 // Handle arm on x86 properties in the form:
Colin Crossc17727d2018-10-24 12:42:09 -07001351 // target {
Colin Crossa195f912019-10-16 11:07:20 -07001352 // arm_on_x86 {
Colin Crossc17727d2018-10-24 12:42:09 -07001353 // key: value,
1354 // },
Colin Crossa195f912019-10-16 11:07:20 -07001355 // arm_on_x86_64 {
Colin Crossd5934c82017-10-02 13:55:26 -07001356 // key: value,
1357 // },
1358 // },
Colin Crossa195f912019-10-16 11:07:20 -07001359 // TODO(ccross): is this still necessary with native bridge?
Colin Crossc17727d2018-10-24 12:42:09 -07001360 if os.Class == Device {
Colin Crossc17727d2018-10-24 12:42:09 -07001361 if (arch.ArchType == X86 && (hasArmAbi(arch) ||
1362 hasArmAndroidArch(ctx.Config().Targets[Android]))) ||
1363 (arch.ArchType == Arm &&
1364 hasX86AndroidArch(ctx.Config().Targets[Android])) {
1365 field := "Arm_on_x86"
1366 prefix := "target.arm_on_x86"
Colin Cross4157e882019-06-06 16:57:04 -07001367 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001368 }
1369 if (arch.ArchType == X86_64 && (hasArmAbi(arch) ||
1370 hasArmAndroidArch(ctx.Config().Targets[Android]))) ||
1371 (arch.ArchType == Arm &&
1372 hasX8664AndroidArch(ctx.Config().Targets[Android])) {
1373 field := "Arm_on_x86_64"
1374 prefix := "target.arm_on_x86_64"
Colin Cross4157e882019-06-06 16:57:04 -07001375 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001376 }
Colin Cross4247f0d2017-04-13 16:56:14 -07001377 }
Colin Crossbb2e2b72016-12-08 17:23:53 -08001378 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001379 }
1380}
1381
1382func forEachInterface(v reflect.Value, f func(reflect.Value)) {
1383 switch v.Kind() {
1384 case reflect.Interface:
1385 f(v)
1386 case reflect.Struct:
1387 for i := 0; i < v.NumField(); i++ {
1388 forEachInterface(v.Field(i), f)
1389 }
1390 case reflect.Ptr:
1391 forEachInterface(v.Elem(), f)
1392 default:
1393 panic(fmt.Errorf("Unsupported kind %s", v.Kind()))
1394 }
1395}
Colin Cross4225f652015-09-17 14:33:42 -07001396
Colin Crossa1ad8d12016-06-01 17:09:44 -07001397// Convert the arch product variables into a list of targets for each os class structs
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001398func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001399 variables := config.productVariables
Dan Willemsen490fd492015-11-24 17:53:15 -08001400
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001401 targets := make(map[OsType][]Target)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001402 var targetErr error
1403
dimitry1f33e402019-03-26 12:39:31 +01001404 addTarget := func(os OsType, archName string, archVariant, cpuVariant *string, abi []string,
dimitry8d6dde82019-07-11 10:23:53 +02001405 nativeBridgeEnabled NativeBridgeSupport, nativeBridgeHostArchName *string,
1406 nativeBridgeRelativePath *string) {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001407 if targetErr != nil {
1408 return
Dan Willemsen490fd492015-11-24 17:53:15 -08001409 }
Colin Crossa1ad8d12016-06-01 17:09:44 -07001410
Dan Willemsen01a3c252019-01-11 19:02:16 -08001411 arch, err := decodeArch(os, archName, archVariant, cpuVariant, abi)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001412 if err != nil {
1413 targetErr = err
1414 return
1415 }
dimitry8d6dde82019-07-11 10:23:53 +02001416 nativeBridgeRelativePathStr := String(nativeBridgeRelativePath)
1417 nativeBridgeHostArchNameStr := String(nativeBridgeHostArchName)
1418
1419 // Use guest arch as relative install path by default
1420 if nativeBridgeEnabled && nativeBridgeRelativePathStr == "" {
1421 nativeBridgeRelativePathStr = arch.ArchType.String()
1422 }
Colin Crossa1ad8d12016-06-01 17:09:44 -07001423
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001424 targets[os] = append(targets[os],
Colin Crossa1ad8d12016-06-01 17:09:44 -07001425 Target{
dimitry8d6dde82019-07-11 10:23:53 +02001426 Os: os,
1427 Arch: arch,
1428 NativeBridge: nativeBridgeEnabled,
1429 NativeBridgeHostArchName: nativeBridgeHostArchNameStr,
1430 NativeBridgeRelativePath: nativeBridgeRelativePathStr,
Colin Crossa1ad8d12016-06-01 17:09:44 -07001431 })
Dan Willemsen490fd492015-11-24 17:53:15 -08001432 }
1433
Colin Cross4225f652015-09-17 14:33:42 -07001434 if variables.HostArch == nil {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001435 return nil, fmt.Errorf("No host primary architecture set")
Colin Cross4225f652015-09-17 14:33:42 -07001436 }
1437
dimitry8d6dde82019-07-11 10:23:53 +02001438 addTarget(BuildOs, *variables.HostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil)
Colin Cross4225f652015-09-17 14:33:42 -07001439
Colin Crosseeabb892015-11-20 13:07:51 -08001440 if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" {
dimitry8d6dde82019-07-11 10:23:53 +02001441 addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil)
Dan Willemsen490fd492015-11-24 17:53:15 -08001442 }
1443
Colin Crossff3ae9d2018-04-10 16:15:18 -07001444 if Bool(config.Host_bionic) {
dimitry8d6dde82019-07-11 10:23:53 +02001445 addTarget(LinuxBionic, "x86_64", nil, nil, nil, NativeBridgeDisabled, nil, nil)
Dan Willemsen01a405a2016-06-13 17:19:03 -07001446 }
1447
Colin Crossff3ae9d2018-04-10 16:15:18 -07001448 if String(variables.CrossHost) != "" {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001449 crossHostOs := osByName(*variables.CrossHost)
1450 if crossHostOs == NoOsType {
1451 return nil, fmt.Errorf("Unknown cross host OS %q", *variables.CrossHost)
1452 }
1453
Colin Crossff3ae9d2018-04-10 16:15:18 -07001454 if String(variables.CrossHostArch) == "" {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001455 return nil, fmt.Errorf("No cross-host primary architecture set")
Dan Willemsen490fd492015-11-24 17:53:15 -08001456 }
1457
dimitry8d6dde82019-07-11 10:23:53 +02001458 addTarget(crossHostOs, *variables.CrossHostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil)
Dan Willemsen490fd492015-11-24 17:53:15 -08001459
1460 if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" {
dimitry8d6dde82019-07-11 10:23:53 +02001461 addTarget(crossHostOs, *variables.CrossHostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil)
Dan Willemsen490fd492015-11-24 17:53:15 -08001462 }
1463 }
1464
Dan Willemsen3f32f032016-07-11 14:36:48 -07001465 if variables.DeviceArch != nil && *variables.DeviceArch != "" {
Doug Horn21b94272019-01-16 12:06:11 -08001466 var target = Android
1467 if Bool(variables.Fuchsia) {
1468 target = Fuchsia
1469 }
1470
1471 addTarget(target, *variables.DeviceArch, variables.DeviceArchVariant,
dimitry8d6dde82019-07-11 10:23:53 +02001472 variables.DeviceCpuVariant, variables.DeviceAbi, NativeBridgeDisabled, nil, nil)
Colin Cross4225f652015-09-17 14:33:42 -07001473
Dan Willemsen3f32f032016-07-11 14:36:48 -07001474 if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" {
1475 addTarget(Android, *variables.DeviceSecondaryArch,
1476 variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant,
dimitry8d6dde82019-07-11 10:23:53 +02001477 variables.DeviceSecondaryAbi, NativeBridgeDisabled, nil, nil)
Colin Cross4225f652015-09-17 14:33:42 -07001478 }
dimitry1f33e402019-03-26 12:39:31 +01001479
1480 if variables.NativeBridgeArch != nil && *variables.NativeBridgeArch != "" {
1481 addTarget(Android, *variables.NativeBridgeArch,
1482 variables.NativeBridgeArchVariant, variables.NativeBridgeCpuVariant,
dimitry8d6dde82019-07-11 10:23:53 +02001483 variables.NativeBridgeAbi, NativeBridgeEnabled, variables.DeviceArch,
1484 variables.NativeBridgeRelativePath)
dimitry1f33e402019-03-26 12:39:31 +01001485 }
1486
1487 if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" &&
1488 variables.NativeBridgeSecondaryArch != nil && *variables.NativeBridgeSecondaryArch != "" {
1489 addTarget(Android, *variables.NativeBridgeSecondaryArch,
1490 variables.NativeBridgeSecondaryArchVariant,
1491 variables.NativeBridgeSecondaryCpuVariant,
dimitry8d6dde82019-07-11 10:23:53 +02001492 variables.NativeBridgeSecondaryAbi,
1493 NativeBridgeEnabled,
1494 variables.DeviceSecondaryArch,
1495 variables.NativeBridgeSecondaryRelativePath)
dimitry1f33e402019-03-26 12:39:31 +01001496 }
Colin Cross4225f652015-09-17 14:33:42 -07001497 }
1498
Colin Crossa1ad8d12016-06-01 17:09:44 -07001499 if targetErr != nil {
1500 return nil, targetErr
1501 }
1502
1503 return targets, nil
Colin Cross4225f652015-09-17 14:33:42 -07001504}
1505
Colin Crossbb2e2b72016-12-08 17:23:53 -08001506// hasArmAbi returns true if arch has at least one arm ABI
1507func hasArmAbi(arch Arch) bool {
1508 for _, abi := range arch.Abi {
1509 if strings.HasPrefix(abi, "arm") {
1510 return true
1511 }
1512 }
1513 return false
1514}
1515
dimitry628db6f2019-05-22 17:16:21 +02001516// hasArmArch returns true if targets has at least non-native_bridge arm Android arch
Colin Cross4247f0d2017-04-13 16:56:14 -07001517func hasArmAndroidArch(targets []Target) bool {
1518 for _, target := range targets {
dimitry628db6f2019-05-22 17:16:21 +02001519 if target.Os == Android && target.Arch.ArchType == Arm && target.NativeBridge == NativeBridgeDisabled {
Colin Cross4247f0d2017-04-13 16:56:14 -07001520 return true
1521 }
1522 }
1523 return false
1524}
1525
Victor Khimenko5eb8ec12018-03-21 20:30:54 +01001526// hasX86Arch returns true if targets has at least x86 Android arch
1527func hasX86AndroidArch(targets []Target) bool {
1528 for _, target := range targets {
1529 if target.Os == Android && target.Arch.ArchType == X86 {
1530 return true
1531 }
1532 }
1533 return false
1534}
1535
1536// hasX8664Arch returns true if targets has at least x86_64 Android arch
1537func hasX8664AndroidArch(targets []Target) bool {
1538 for _, target := range targets {
1539 if target.Os == Android && target.Arch.ArchType == X86_64 {
1540 return true
1541 }
1542 }
1543 return false
1544}
1545
Dan Albert4098deb2016-10-19 14:04:41 -07001546type archConfig struct {
1547 arch string
1548 archVariant string
1549 cpuVariant string
1550 abi []string
1551}
1552
1553func getMegaDeviceConfig() []archConfig {
1554 return []archConfig{
Dan Albert8818f492019-02-19 13:53:01 -08001555 {"arm", "armv7-a", "generic", []string{"armeabi-v7a"}},
Dan Willemsen110a89d2016-01-14 15:17:19 -08001556 {"arm", "armv7-a-neon", "generic", []string{"armeabi-v7a"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -08001557 {"arm", "armv7-a-neon", "cortex-a7", []string{"armeabi-v7a"}},
1558 {"arm", "armv7-a-neon", "cortex-a8", []string{"armeabi-v7a"}},
Dan Willemsen110a89d2016-01-14 15:17:19 -08001559 {"arm", "armv7-a-neon", "cortex-a9", []string{"armeabi-v7a"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -08001560 {"arm", "armv7-a-neon", "cortex-a15", []string{"armeabi-v7a"}},
1561 {"arm", "armv7-a-neon", "cortex-a53", []string{"armeabi-v7a"}},
1562 {"arm", "armv7-a-neon", "cortex-a53.a57", []string{"armeabi-v7a"}},
Richard Fungeb37ed32018-09-24 16:33:45 -07001563 {"arm", "armv7-a-neon", "cortex-a72", []string{"armeabi-v7a"}},
Jake Weinstein6600a442017-05-15 18:27:12 -04001564 {"arm", "armv7-a-neon", "cortex-a73", []string{"armeabi-v7a"}},
Christopher Ferrisba14a8f2018-04-23 18:15:25 -07001565 {"arm", "armv7-a-neon", "cortex-a75", []string{"armeabi-v7a"}},
Haibo Huanga31e2bd2018-10-09 14:27:28 -07001566 {"arm", "armv7-a-neon", "cortex-a76", []string{"armeabi-v7a"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -08001567 {"arm", "armv7-a-neon", "krait", []string{"armeabi-v7a"}},
Alex Naidisae4fc182016-08-20 00:14:56 +02001568 {"arm", "armv7-a-neon", "kryo", []string{"armeabi-v7a"}},
Artem Serovd3072b02018-11-15 15:21:51 +00001569 {"arm", "armv7-a-neon", "kryo385", []string{"armeabi-v7a"}},
Junmo Park8ea49592017-07-24 07:14:55 +09001570 {"arm", "armv7-a-neon", "exynos-m1", []string{"armeabi-v7a"}},
Junmo Parkd86c9022017-07-21 09:07:47 +09001571 {"arm", "armv7-a-neon", "exynos-m2", []string{"armeabi-v7a"}},
Dan Willemsen110a89d2016-01-14 15:17:19 -08001572 {"arm64", "armv8-a", "cortex-a53", []string{"arm64-v8a"}},
Richard Fungeb37ed32018-09-24 16:33:45 -07001573 {"arm64", "armv8-a", "cortex-a72", []string{"arm64-v8a"}},
Jake Weinstein6600a442017-05-15 18:27:12 -04001574 {"arm64", "armv8-a", "cortex-a73", []string{"arm64-v8a"}},
Alex Naidisac01ff52016-08-30 15:56:33 +02001575 {"arm64", "armv8-a", "kryo", []string{"arm64-v8a"}},
Junmo Park8ea49592017-07-24 07:14:55 +09001576 {"arm64", "armv8-a", "exynos-m1", []string{"arm64-v8a"}},
Junmo Parkd86c9022017-07-21 09:07:47 +09001577 {"arm64", "armv8-a", "exynos-m2", []string{"arm64-v8a"}},
Christopher Ferrisba14a8f2018-04-23 18:15:25 -07001578 {"arm64", "armv8-2a", "cortex-a75", []string{"arm64-v8a"}},
Haibo Huanga31e2bd2018-10-09 14:27:28 -07001579 {"arm64", "armv8-2a", "cortex-a76", []string{"arm64-v8a"}},
Artem Serovd3072b02018-11-15 15:21:51 +00001580 {"arm64", "armv8-2a", "kryo385", []string{"arm64-v8a"}},
Dan Willemsen468cc312016-01-13 23:25:19 -08001581 {"mips", "mips32-fp", "", []string{"mips"}},
1582 {"mips", "mips32r2-fp", "", []string{"mips"}},
1583 {"mips", "mips32r2-fp-xburst", "", []string{"mips"}},
Dan Willemsen65fb9812016-07-19 21:37:28 -07001584 //{"mips", "mips32r6", "", []string{"mips"}},
Colin Cross1837b802017-04-26 19:10:34 -07001585 {"mips", "mips32r2dsp-fp", "", []string{"mips"}},
1586 {"mips", "mips32r2dspr2-fp", "", []string{"mips"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -08001587 // mips64r2 is mismatching 64r2 and 64r6 libraries during linking to libgcc
1588 //{"mips64", "mips64r2", "", []string{"mips64"}},
1589 {"mips64", "mips64r6", "", []string{"mips64"}},
1590 {"x86", "", "", []string{"x86"}},
1591 {"x86", "atom", "", []string{"x86"}},
1592 {"x86", "haswell", "", []string{"x86"}},
1593 {"x86", "ivybridge", "", []string{"x86"}},
1594 {"x86", "sandybridge", "", []string{"x86"}},
1595 {"x86", "silvermont", "", []string{"x86"}},
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -07001596 {"x86", "stoneyridge", "", []string{"x86"}},
Dan Willemsen8a354052016-05-10 14:30:51 -07001597 {"x86", "x86_64", "", []string{"x86"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -08001598 {"x86_64", "", "", []string{"x86_64"}},
1599 {"x86_64", "haswell", "", []string{"x86_64"}},
1600 {"x86_64", "ivybridge", "", []string{"x86_64"}},
1601 {"x86_64", "sandybridge", "", []string{"x86_64"}},
1602 {"x86_64", "silvermont", "", []string{"x86_64"}},
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -07001603 {"x86_64", "stoneyridge", "", []string{"x86_64"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -08001604 }
Dan Albert4098deb2016-10-19 14:04:41 -07001605}
Dan Willemsen322acaf2016-01-12 23:07:05 -08001606
Dan Albert4098deb2016-10-19 14:04:41 -07001607func getNdkAbisConfig() []archConfig {
1608 return []archConfig{
Dan Albert8818f492019-02-19 13:53:01 -08001609 {"arm", "armv7-a", "", []string{"armeabi"}},
Dan Albert4098deb2016-10-19 14:04:41 -07001610 {"arm64", "armv8-a", "", []string{"arm64-v8a"}},
Dan Albert4098deb2016-10-19 14:04:41 -07001611 {"x86", "", "", []string{"x86"}},
1612 {"x86_64", "", "", []string{"x86_64"}},
1613 }
1614}
1615
Martin Stjernholmc1ecc432019-11-15 15:00:31 +00001616func getAmlAbisConfig() []archConfig {
1617 return []archConfig{
1618 {"arm", "armv7-a", "", []string{"armeabi-v7a"}},
1619 {"arm64", "armv8-a", "", []string{"arm64-v8a"}},
1620 {"x86", "", "", []string{"x86"}},
1621 {"x86_64", "", "", []string{"x86_64"}},
1622 }
1623}
1624
Dan Willemsen01a3c252019-01-11 19:02:16 -08001625func decodeArchSettings(os OsType, archConfigs []archConfig) ([]Target, error) {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001626 var ret []Target
Dan Willemsen322acaf2016-01-12 23:07:05 -08001627
Dan Albert4098deb2016-10-19 14:04:41 -07001628 for _, config := range archConfigs {
Dan Willemsen01a3c252019-01-11 19:02:16 -08001629 arch, err := decodeArch(os, config.arch, &config.archVariant,
Colin Crossa74ca042019-01-31 14:31:51 -08001630 &config.cpuVariant, config.abi)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001631 if err != nil {
1632 return nil, err
1633 }
Colin Cross3b19f5d2019-09-17 14:45:31 -07001634
Colin Crossa1ad8d12016-06-01 17:09:44 -07001635 ret = append(ret, Target{
1636 Os: Android,
1637 Arch: arch,
1638 })
Dan Willemsen322acaf2016-01-12 23:07:05 -08001639 }
1640
1641 return ret, nil
1642}
1643
Colin Cross4225f652015-09-17 14:33:42 -07001644// Convert a set of strings from product variables into a single Arch struct
Colin Crossa74ca042019-01-31 14:31:51 -08001645func decodeArch(os OsType, arch string, archVariant, cpuVariant *string, abi []string) (Arch, error) {
Colin Cross4225f652015-09-17 14:33:42 -07001646 stringPtr := func(p *string) string {
1647 if p != nil {
1648 return *p
1649 }
1650 return ""
1651 }
1652
Colin Crosseeabb892015-11-20 13:07:51 -08001653 archType, ok := archTypeMap[arch]
1654 if !ok {
1655 return Arch{}, fmt.Errorf("unknown arch %q", arch)
1656 }
Colin Cross4225f652015-09-17 14:33:42 -07001657
Colin Crosseeabb892015-11-20 13:07:51 -08001658 a := Arch{
Colin Cross4225f652015-09-17 14:33:42 -07001659 ArchType: archType,
1660 ArchVariant: stringPtr(archVariant),
1661 CpuVariant: stringPtr(cpuVariant),
Colin Crossa74ca042019-01-31 14:31:51 -08001662 Abi: abi,
Colin Crosseeabb892015-11-20 13:07:51 -08001663 }
1664
1665 if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" {
1666 a.ArchVariant = ""
1667 }
1668
1669 if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" {
1670 a.CpuVariant = ""
1671 }
1672
1673 for i := 0; i < len(a.Abi); i++ {
1674 if a.Abi[i] == "" {
1675 a.Abi = append(a.Abi[:i], a.Abi[i+1:]...)
1676 i--
1677 }
1678 }
1679
Dan Willemsen01a3c252019-01-11 19:02:16 -08001680 if a.ArchVariant == "" {
1681 if featureMap, ok := defaultArchFeatureMap[os]; ok {
1682 a.ArchFeatures = featureMap[archType]
1683 }
1684 } else {
1685 if featureMap, ok := archFeatureMap[archType]; ok {
1686 a.ArchFeatures = featureMap[a.ArchVariant]
1687 }
Colin Crossc5c24ad2015-11-20 15:35:00 -08001688 }
1689
Colin Crosseeabb892015-11-20 13:07:51 -08001690 return a, nil
Colin Cross4225f652015-09-17 14:33:42 -07001691}
1692
Colin Cross69617d32016-09-06 10:39:07 -07001693func filterMultilibTargets(targets []Target, multilib string) []Target {
1694 var ret []Target
1695 for _, t := range targets {
1696 if t.Arch.ArchType.Multilib == multilib {
1697 ret = append(ret, t)
1698 }
1699 }
1700 return ret
1701}
1702
Nan Zhangdb0b9a32017-02-27 10:12:13 -08001703func getCommonTargets(targets []Target) []Target {
1704 var ret []Target
1705 set := make(map[string]bool)
1706
1707 for _, t := range targets {
1708 if _, found := set[t.Os.String()]; !found {
1709 set[t.Os.String()] = true
1710 ret = append(ret, commonTargetMap[t.Os.String()])
1711 }
1712 }
1713
1714 return ret
1715}
1716
Colin Cross3dceee32018-09-06 10:19:57 -07001717func firstTarget(targets []Target, filters ...string) []Target {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001718 for _, filter := range filters {
1719 buildTargets := filterMultilibTargets(targets, filter)
1720 if len(buildTargets) > 0 {
Colin Cross3dceee32018-09-06 10:19:57 -07001721 return buildTargets[:1]
Colin Cross6b4a32d2017-12-05 13:42:45 -08001722 }
1723 }
1724 return nil
1725}
1726
Colin Crossa1ad8d12016-06-01 17:09:44 -07001727// Use the module multilib setting to select one or more targets from a target list
Colin Crossee0bc3b2018-10-02 22:01:37 -07001728func decodeMultilibTargets(multilib string, targets []Target, prefer32 bool) ([]Target, error) {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001729 buildTargets := []Target{}
Colin Cross6b4a32d2017-12-05 13:42:45 -08001730
Colin Cross4225f652015-09-17 14:33:42 -07001731 switch multilib {
1732 case "common":
Colin Cross6b4a32d2017-12-05 13:42:45 -08001733 buildTargets = getCommonTargets(targets)
1734 case "common_first":
1735 buildTargets = getCommonTargets(targets)
1736 if prefer32 {
Colin Cross3dceee32018-09-06 10:19:57 -07001737 buildTargets = append(buildTargets, firstTarget(targets, "lib32", "lib64")...)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001738 } else {
Colin Cross3dceee32018-09-06 10:19:57 -07001739 buildTargets = append(buildTargets, firstTarget(targets, "lib64", "lib32")...)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001740 }
Colin Cross4225f652015-09-17 14:33:42 -07001741 case "both":
Colin Cross8b74d172016-09-13 09:59:14 -07001742 if prefer32 {
1743 buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...)
1744 buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...)
1745 } else {
1746 buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...)
1747 buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...)
1748 }
Colin Cross4225f652015-09-17 14:33:42 -07001749 case "32":
Colin Cross69617d32016-09-06 10:39:07 -07001750 buildTargets = filterMultilibTargets(targets, "lib32")
Colin Cross4225f652015-09-17 14:33:42 -07001751 case "64":
Colin Cross69617d32016-09-06 10:39:07 -07001752 buildTargets = filterMultilibTargets(targets, "lib64")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001753 case "first":
1754 if prefer32 {
Colin Cross3dceee32018-09-06 10:19:57 -07001755 buildTargets = firstTarget(targets, "lib32", "lib64")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001756 } else {
Colin Cross3dceee32018-09-06 10:19:57 -07001757 buildTargets = firstTarget(targets, "lib64", "lib32")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001758 }
Colin Cross69617d32016-09-06 10:39:07 -07001759 case "prefer32":
Colin Cross3dceee32018-09-06 10:19:57 -07001760 buildTargets = filterMultilibTargets(targets, "lib32")
1761 if len(buildTargets) == 0 {
1762 buildTargets = filterMultilibTargets(targets, "lib64")
1763 }
Colin Cross4225f652015-09-17 14:33:42 -07001764 default:
Colin Cross69617d32016-09-06 10:39:07 -07001765 return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", "64", or "prefer32" found %q`,
Colin Cross4225f652015-09-17 14:33:42 -07001766 multilib)
Colin Cross4225f652015-09-17 14:33:42 -07001767 }
1768
Colin Crossa1ad8d12016-06-01 17:09:44 -07001769 return buildTargets, nil
Colin Cross4225f652015-09-17 14:33:42 -07001770}