blob: 907c58b820f302a23167c43db1da55bf5d976e70 [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 Crossf6566ed2015-03-24 11:13:38 -070025 "github.com/google/blueprint/proptools"
Colin Cross3f40fa42015-01-30 17:27:36 -080026)
27
28var (
Dan Willemsenb1957a52016-06-23 23:44:54 -070029 archTypeList []ArchType
30
Colin Crossec193632015-07-06 17:49:43 -070031 Arm = newArch("arm", "lib32")
32 Arm64 = newArch("arm64", "lib64")
33 Mips = newArch("mips", "lib32")
34 Mips64 = newArch("mips64", "lib64")
35 X86 = newArch("x86", "lib32")
36 X86_64 = newArch("x86_64", "lib64")
Colin Cross2fe66872015-03-30 17:20:39 -070037
38 Common = ArchType{
39 Name: "common",
40 }
Colin Cross3f40fa42015-01-30 17:27:36 -080041)
42
Colin Cross4225f652015-09-17 14:33:42 -070043var archTypeMap = map[string]ArchType{
44 "arm": Arm,
45 "arm64": Arm64,
46 "mips": Mips,
Colin Cross3b336c22015-11-23 16:28:31 -080047 "mips64": Mips64,
Colin Cross4225f652015-09-17 14:33:42 -070048 "x86": X86,
49 "x86_64": X86_64,
50}
51
Colin Cross3f40fa42015-01-30 17:27:36 -080052/*
53Example blueprints file containing all variant property groups, with comment listing what type
54of variants get properties in that group:
55
56module {
57 arch: {
58 arm: {
59 // Host or device variants with arm architecture
60 },
61 arm64: {
62 // Host or device variants with arm64 architecture
63 },
64 mips: {
65 // Host or device variants with mips architecture
66 },
67 mips64: {
68 // Host or device variants with mips64 architecture
69 },
70 x86: {
71 // Host or device variants with x86 architecture
72 },
73 x86_64: {
74 // Host or device variants with x86_64 architecture
75 },
76 },
77 multilib: {
78 lib32: {
79 // Host or device variants for 32-bit architectures
80 },
81 lib64: {
82 // Host or device variants for 64-bit architectures
83 },
84 },
85 target: {
86 android: {
87 // Device variants
88 },
89 host: {
90 // Host variants
91 },
Dan Willemsen5746bd42017-10-02 19:42:01 -070092 linux_glibc: {
Colin Cross3f40fa42015-01-30 17:27:36 -080093 // Linux host variants
94 },
95 darwin: {
96 // Darwin host variants
97 },
98 windows: {
99 // Windows host variants
100 },
101 not_windows: {
102 // Non-windows host variants
103 },
104 },
105}
106*/
Colin Cross7d5136f2015-05-11 13:39:40 -0700107
Jaewoong Junge46114c2019-01-16 14:33:13 -0800108var archVariants = map[ArchType][]string{
109 Arm: {
Dan Albert8818f492019-02-19 13:53:01 -0800110 "armv7-a",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800111 "armv7-a-neon",
112 "armv8-a",
113 "armv8-2a",
114 "cortex-a7",
115 "cortex-a8",
116 "cortex-a9",
117 "cortex-a15",
118 "cortex-a53",
119 "cortex-a53-a57",
120 "cortex-a55",
121 "cortex-a72",
122 "cortex-a73",
123 "cortex-a75",
124 "cortex-a76",
125 "krait",
126 "kryo",
127 "kryo385",
128 "exynos-m1",
129 "exynos-m2",
130 },
131 Arm64: {
132 "armv8_a",
133 "armv8_2a",
134 "cortex-a53",
135 "cortex-a55",
136 "cortex-a72",
137 "cortex-a73",
138 "cortex-a75",
139 "cortex-a76",
140 "kryo",
141 "kryo385",
142 "exynos-m1",
143 "exynos-m2",
144 },
145 Mips: {
146 "mips32_fp",
147 "mips32r2_fp",
148 "mips32r2_fp_xburst",
149 "mips32r2dsp_fp",
150 "mips32r2dspr2_fp",
151 "mips32r6",
152 },
153 Mips64: {
154 "mips64r2",
155 "mips64r6",
156 },
157 X86: {
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530158 "amberlake",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800159 "atom",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530160 "broadwell",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800161 "haswell",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530162 "icelake",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800163 "ivybridge",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530164 "kabylake",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800165 "sandybridge",
166 "silvermont",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530167 "skylake",
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -0700168 "stoneyridge",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530169 "tigerlake",
170 "whiskeylake",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800171 "x86_64",
172 },
173 X86_64: {
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530174 "amberlake",
175 "broadwell",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800176 "haswell",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530177 "icelake",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800178 "ivybridge",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530179 "kabylake",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800180 "sandybridge",
181 "silvermont",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530182 "skylake",
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -0700183 "stoneyridge",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530184 "tigerlake",
185 "whiskeylake",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800186 },
187}
188
189var archFeatures = map[ArchType][]string{
190 Arm: {
191 "neon",
192 },
193 Mips: {
194 "dspr2",
195 "rev6",
196 "msa",
197 },
198 Mips64: {
199 "rev6",
200 "msa",
201 },
202 X86: {
203 "ssse3",
204 "sse4",
205 "sse4_1",
206 "sse4_2",
207 "aes_ni",
208 "avx",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530209 "avx2",
210 "avx512",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800211 "popcnt",
212 "movbe",
213 },
214 X86_64: {
215 "ssse3",
216 "sse4",
217 "sse4_1",
218 "sse4_2",
219 "aes_ni",
220 "avx",
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530221 "avx2",
222 "avx512",
Jaewoong Junge46114c2019-01-16 14:33:13 -0800223 "popcnt",
224 },
225}
226
227var archFeatureMap = map[ArchType]map[string][]string{
228 Arm: {
229 "armv7-a-neon": {
230 "neon",
231 },
232 "armv8-a": {
233 "neon",
234 },
235 "armv8-2a": {
236 "neon",
237 },
238 },
239 Mips: {
240 "mips32r2dspr2_fp": {
241 "dspr2",
242 },
243 "mips32r6": {
244 "rev6",
245 },
246 },
247 Mips64: {
248 "mips64r6": {
249 "rev6",
250 },
251 },
252 X86: {
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530253 "amberlake": {
254 "ssse3",
255 "sse4",
256 "sse4_1",
257 "sse4_2",
258 "avx",
259 "avx2",
260 "aes_ni",
261 "popcnt",
262 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800263 "atom": {
264 "ssse3",
265 "movbe",
266 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530267 "broadwell": {
268 "ssse3",
269 "sse4",
270 "sse4_1",
271 "sse4_2",
272 "avx",
273 "avx2",
274 "aes_ni",
275 "popcnt",
276 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800277 "haswell": {
278 "ssse3",
279 "sse4",
280 "sse4_1",
281 "sse4_2",
282 "aes_ni",
283 "avx",
284 "popcnt",
285 "movbe",
286 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530287 "icelake": {
288 "ssse3",
289 "sse4",
290 "sse4_1",
291 "sse4_2",
292 "avx",
293 "avx2",
294 "avx512",
295 "aes_ni",
296 "popcnt",
297 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800298 "ivybridge": {
299 "ssse3",
300 "sse4",
301 "sse4_1",
302 "sse4_2",
303 "aes_ni",
304 "avx",
305 "popcnt",
306 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530307 "kabylake": {
308 "ssse3",
309 "sse4",
310 "sse4_1",
311 "sse4_2",
312 "avx",
313 "avx2",
314 "aes_ni",
315 "popcnt",
316 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800317 "sandybridge": {
318 "ssse3",
319 "sse4",
320 "sse4_1",
321 "sse4_2",
322 "popcnt",
323 },
324 "silvermont": {
325 "ssse3",
326 "sse4",
327 "sse4_1",
328 "sse4_2",
329 "aes_ni",
330 "popcnt",
331 "movbe",
332 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530333 "skylake": {
334 "ssse3",
335 "sse4",
336 "sse4_1",
337 "sse4_2",
338 "avx",
339 "avx2",
340 "avx512",
341 "aes_ni",
342 "popcnt",
343 },
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -0700344 "stoneyridge": {
345 "ssse3",
346 "sse4",
347 "sse4_1",
348 "sse4_2",
349 "aes_ni",
350 "avx",
351 "avx2",
352 "popcnt",
353 "movbe",
354 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530355 "tigerlake": {
356 "ssse3",
357 "sse4",
358 "sse4_1",
359 "sse4_2",
360 "avx",
361 "avx2",
362 "avx512",
363 "aes_ni",
364 "popcnt",
365 },
366 "whiskeylake": {
367 "ssse3",
368 "sse4",
369 "sse4_1",
370 "sse4_2",
371 "avx",
372 "avx2",
373 "avx512",
374 "aes_ni",
375 "popcnt",
376 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800377 "x86_64": {
378 "ssse3",
379 "sse4",
380 "sse4_1",
381 "sse4_2",
382 "popcnt",
383 },
384 },
385 X86_64: {
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530386 "amberlake": {
387 "ssse3",
388 "sse4",
389 "sse4_1",
390 "sse4_2",
391 "avx",
392 "avx2",
393 "aes_ni",
394 "popcnt",
395 },
396 "broadwell": {
397 "ssse3",
398 "sse4",
399 "sse4_1",
400 "sse4_2",
401 "avx",
402 "avx2",
403 "aes_ni",
404 "popcnt",
405 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800406 "haswell": {
407 "ssse3",
408 "sse4",
409 "sse4_1",
410 "sse4_2",
411 "aes_ni",
412 "avx",
413 "popcnt",
414 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530415 "icelake": {
416 "ssse3",
417 "sse4",
418 "sse4_1",
419 "sse4_2",
420 "avx",
421 "avx2",
422 "avx512",
423 "aes_ni",
424 "popcnt",
425 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800426 "ivybridge": {
427 "ssse3",
428 "sse4",
429 "sse4_1",
430 "sse4_2",
431 "aes_ni",
432 "avx",
433 "popcnt",
434 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530435 "kabylake": {
436 "ssse3",
437 "sse4",
438 "sse4_1",
439 "sse4_2",
440 "avx",
441 "avx2",
442 "aes_ni",
443 "popcnt",
444 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800445 "sandybridge": {
446 "ssse3",
447 "sse4",
448 "sse4_1",
449 "sse4_2",
450 "popcnt",
451 },
452 "silvermont": {
453 "ssse3",
454 "sse4",
455 "sse4_1",
456 "sse4_2",
457 "aes_ni",
458 "popcnt",
459 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530460 "skylake": {
461 "ssse3",
462 "sse4",
463 "sse4_1",
464 "sse4_2",
465 "avx",
466 "avx2",
467 "avx512",
468 "aes_ni",
469 "popcnt",
470 },
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -0700471 "stoneyridge": {
472 "ssse3",
473 "sse4",
474 "sse4_1",
475 "sse4_2",
476 "aes_ni",
477 "avx",
478 "avx2",
479 "popcnt",
480 },
Shalini Salomi Bodapati4a0459d2019-01-22 10:00:15 +0530481 "tigerlake": {
482 "ssse3",
483 "sse4",
484 "sse4_1",
485 "sse4_2",
486 "avx",
487 "avx2",
488 "avx512",
489 "aes_ni",
490 "popcnt",
491 },
492 "whiskeylake": {
493 "ssse3",
494 "sse4",
495 "sse4_1",
496 "sse4_2",
497 "avx",
498 "avx2",
499 "avx512",
500 "aes_ni",
501 "popcnt",
502 },
Jaewoong Junge46114c2019-01-16 14:33:13 -0800503 },
504}
505
Dan Willemsen01a3c252019-01-11 19:02:16 -0800506var defaultArchFeatureMap = map[OsType]map[ArchType][]string{}
Colin Crossc5c24ad2015-11-20 15:35:00 -0800507
Dan Willemsen01a3c252019-01-11 19:02:16 -0800508func RegisterDefaultArchVariantFeatures(os OsType, arch ArchType, features ...string) {
509 checkCalledFromInit()
510
511 for _, feature := range features {
512 if !InList(feature, archFeatures[arch]) {
513 panic(fmt.Errorf("Invalid feature %q for arch %q variant \"\"", feature, arch))
514 }
515 }
516
517 if defaultArchFeatureMap[os] == nil {
518 defaultArchFeatureMap[os] = make(map[ArchType][]string)
519 }
520 defaultArchFeatureMap[os][arch] = features
521}
522
Colin Cross3f40fa42015-01-30 17:27:36 -0800523// An Arch indicates a single CPU architecture.
524type Arch struct {
Colin Crossc5c24ad2015-11-20 15:35:00 -0800525 ArchType ArchType
526 ArchVariant string
527 CpuVariant string
528 Abi []string
529 ArchFeatures []string
Dan Willemsen17f05262016-05-31 16:27:00 -0700530 Native bool
Colin Cross3f40fa42015-01-30 17:27:36 -0800531}
532
533func (a Arch) String() string {
Colin Crossd3ba0392015-05-07 14:11:29 -0700534 s := a.ArchType.String()
Colin Cross3f40fa42015-01-30 17:27:36 -0800535 if a.ArchVariant != "" {
536 s += "_" + a.ArchVariant
537 }
538 if a.CpuVariant != "" {
539 s += "_" + a.CpuVariant
540 }
541 return s
542}
543
544type ArchType struct {
Colin Crossec193632015-07-06 17:49:43 -0700545 Name string
Dan Willemsenb1957a52016-06-23 23:44:54 -0700546 Field string
Colin Crossec193632015-07-06 17:49:43 -0700547 Multilib string
Colin Cross3f40fa42015-01-30 17:27:36 -0800548}
549
Colin Crossec193632015-07-06 17:49:43 -0700550func newArch(name, multilib string) ArchType {
Dan Willemsenb1957a52016-06-23 23:44:54 -0700551 archType := ArchType{
Colin Crossec193632015-07-06 17:49:43 -0700552 Name: name,
Dan Willemsenb1957a52016-06-23 23:44:54 -0700553 Field: proptools.FieldNameForProperty(name),
Colin Crossec193632015-07-06 17:49:43 -0700554 Multilib: multilib,
Colin Cross3f40fa42015-01-30 17:27:36 -0800555 }
Dan Willemsenb1957a52016-06-23 23:44:54 -0700556 archTypeList = append(archTypeList, archType)
557 return archType
Colin Cross3f40fa42015-01-30 17:27:36 -0800558}
559
Jaewoong Jung1ce9ac62019-08-13 14:11:33 -0700560func ArchTypeList() []ArchType {
561 return append([]ArchType(nil), archTypeList...)
562}
563
Colin Cross3f40fa42015-01-30 17:27:36 -0800564func (a ArchType) String() string {
565 return a.Name
566}
567
Colin Cross74ba9622019-02-11 15:11:14 -0800568var _ encoding.TextMarshaler = ArchType{}
569
570func (a ArchType) MarshalText() ([]byte, error) {
571 return []byte(strconv.Quote(a.String())), nil
572}
573
574var _ encoding.TextUnmarshaler = &ArchType{}
575
576func (a *ArchType) UnmarshalText(text []byte) error {
577 if u, ok := archTypeMap[string(text)]; ok {
578 *a = u
579 return nil
580 }
581
582 return fmt.Errorf("unknown ArchType %q", text)
583}
584
Colin Crossa1ad8d12016-06-01 17:09:44 -0700585var BuildOs = func() OsType {
Dan Willemsen490fd492015-11-24 17:53:15 -0800586 switch runtime.GOOS {
587 case "linux":
588 return Linux
589 case "darwin":
590 return Darwin
591 default:
592 panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS))
593 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700594}()
595
596var (
Nan Zhangdb0b9a32017-02-27 10:12:13 -0800597 osTypeList []OsType
598 commonTargetMap = make(map[string]Target)
Colin Crossa1ad8d12016-06-01 17:09:44 -0700599
Dan Willemsen00fcbde2016-11-17 00:25:59 -0800600 NoOsType OsType
Dan Willemsen866b5632017-09-22 12:28:24 -0700601 Linux = NewOsType("linux_glibc", Host, false)
Dan Willemsen00fcbde2016-11-17 00:25:59 -0800602 Darwin = NewOsType("darwin", Host, false)
Dan Willemsen9ff34c02018-10-10 17:58:19 -0700603 LinuxBionic = NewOsType("linux_bionic", Host, false)
Dan Willemsen00fcbde2016-11-17 00:25:59 -0800604 Windows = NewOsType("windows", HostCross, true)
605 Android = NewOsType("android", Device, false)
Doug Horn21b94272019-01-16 12:06:11 -0800606 Fuchsia = NewOsType("fuchsia", Device, false)
Dan Willemsenb1957a52016-06-23 23:44:54 -0700607
608 osArchTypeMap = map[OsType][]ArchType{
Dan Willemsen00fcbde2016-11-17 00:25:59 -0800609 Linux: []ArchType{X86, X86_64},
610 LinuxBionic: []ArchType{X86_64},
Dan Willemsene97e68a2018-08-28 17:12:56 -0700611 Darwin: []ArchType{X86_64},
Dan Willemsen00fcbde2016-11-17 00:25:59 -0800612 Windows: []ArchType{X86, X86_64},
613 Android: []ArchType{Arm, Arm64, Mips, Mips64, X86, X86_64},
Doug Horn21b94272019-01-16 12:06:11 -0800614 Fuchsia: []ArchType{Arm64, X86_64},
Dan Willemsenb1957a52016-06-23 23:44:54 -0700615 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700616)
617
618type OsType struct {
619 Name, Field string
620 Class OsClass
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800621
622 DefaultDisabled bool
Dan Willemsen490fd492015-11-24 17:53:15 -0800623}
624
Colin Crossa1ad8d12016-06-01 17:09:44 -0700625type OsClass int
626
627const (
Dan Willemsen0e2d97b2016-11-28 17:50:06 -0800628 Generic OsClass = iota
629 Device
Colin Crossa1ad8d12016-06-01 17:09:44 -0700630 Host
631 HostCross
632)
633
Colin Cross67a5c132017-05-09 13:45:28 -0700634func (class OsClass) String() string {
635 switch class {
636 case Generic:
637 return "generic"
638 case Device:
639 return "device"
640 case Host:
641 return "host"
642 case HostCross:
643 return "host cross"
644 default:
645 panic(fmt.Errorf("unknown class %d", class))
646 }
647}
648
Colin Crossa1ad8d12016-06-01 17:09:44 -0700649func (os OsType) String() string {
650 return os.Name
Colin Cross54c71122016-06-01 17:09:44 -0700651}
652
Dan Willemsen866b5632017-09-22 12:28:24 -0700653func (os OsType) Bionic() bool {
654 return os == Android || os == LinuxBionic
655}
656
657func (os OsType) Linux() bool {
658 return os == Android || os == Linux || os == LinuxBionic
659}
660
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800661func NewOsType(name string, class OsClass, defDisabled bool) OsType {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700662 os := OsType{
663 Name: name,
664 Field: strings.Title(name),
665 Class: class,
Dan Willemsen0a37a2a2016-11-13 10:16:05 -0800666
667 DefaultDisabled: defDisabled,
Colin Cross54c71122016-06-01 17:09:44 -0700668 }
Colin Crossa1ad8d12016-06-01 17:09:44 -0700669 osTypeList = append(osTypeList, os)
Nan Zhangdb0b9a32017-02-27 10:12:13 -0800670
671 if _, found := commonTargetMap[name]; found {
672 panic(fmt.Errorf("Found Os type duplicate during OsType registration: %q", name))
673 } else {
674 commonTargetMap[name] = Target{Os: os, Arch: Arch{ArchType: Common}}
675 }
676
Colin Crossa1ad8d12016-06-01 17:09:44 -0700677 return os
678}
679
680func osByName(name string) OsType {
681 for _, os := range osTypeList {
682 if os.Name == name {
683 return os
684 }
685 }
686
687 return NoOsType
Dan Willemsen490fd492015-11-24 17:53:15 -0800688}
689
dimitry1f33e402019-03-26 12:39:31 +0100690type NativeBridgeSupport bool
691
692const (
693 NativeBridgeDisabled NativeBridgeSupport = false
694 NativeBridgeEnabled NativeBridgeSupport = true
695)
696
Colin Crossa1ad8d12016-06-01 17:09:44 -0700697type Target struct {
dimitry8d6dde82019-07-11 10:23:53 +0200698 Os OsType
699 Arch Arch
700 NativeBridge NativeBridgeSupport
701 NativeBridgeHostArchName string
702 NativeBridgeRelativePath string
Colin Crossd3ba0392015-05-07 14:11:29 -0700703}
704
Colin Crossa1ad8d12016-06-01 17:09:44 -0700705func (target Target) String() string {
dimitry1f33e402019-03-26 12:39:31 +0100706 variant := ""
707 if target.NativeBridge {
708 variant = "native_bridge_"
709 }
710 return target.Os.String() + "_" + variant + target.Arch.String()
Dan Willemsen490fd492015-11-24 17:53:15 -0800711}
712
Colin Crossee0bc3b2018-10-02 22:01:37 -0700713// archMutator splits a module into a variant for each Target requested by the module. Target selection
714// for a module is in three levels, OsClass, mulitlib, and then Target.
715// OsClass selection is determined by:
716// - The HostOrDeviceSupported value passed in to InitAndroidArchModule by the module type factory, which selects
717// whether the module type can compile for host, device or both.
718// - The host_supported and device_supported properties on the module.
Roland Levillainf5b635d2019-06-05 14:42:57 +0100719// 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 -0700720// for the module, the Device OsClass is selected.
721// Within each selected OsClass, the multilib selection is determined by:
Jaewoong Jung02b2d4d2019-06-06 15:19:57 -0700722// - The compile_multilib property if it set (which may be overridden by target.android.compile_multilib or
Colin Crossee0bc3b2018-10-02 22:01:37 -0700723// target.host.compile_multilib).
724// - The default multilib passed to InitAndroidArchModule if compile_multilib was not set.
725// Valid multilib values include:
726// "both": compile for all Targets supported by the OsClass (generally x86_64 and x86, or arm64 and arm).
727// "first": compile for only a single preferred Target supported by the OsClass. This is generally x86_64 or arm64,
728// but may be arm for a 32-bit only build or a build with TARGET_PREFER_32_BIT=true set.
729// "32": compile for only a single 32-bit Target supported by the OsClass.
730// "64": compile for only a single 64-bit Target supported by the OsClass.
731// "common": compile a for a single Target that will work on all Targets suported by the OsClass (for example Java).
732//
733// Once the list of Targets is determined, the module is split into a variant for each Target.
734//
735// Modules can be initialized with InitAndroidMultiTargetsArchModule, in which case they will be split by OsClass,
736// 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 -0700737func archMutator(mctx BottomUpMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700738 var module Module
Colin Cross3f40fa42015-01-30 17:27:36 -0800739 var ok bool
Colin Cross635c3b02016-05-18 15:37:25 -0700740 if module, ok = mctx.Module().(Module); !ok {
Colin Cross3f40fa42015-01-30 17:27:36 -0800741 return
742 }
743
Colin Cross5eca7cb2018-10-02 14:02:10 -0700744 base := module.base()
745
746 if !base.ArchSpecific() {
Colin Crossb9db4802016-06-03 01:50:47 +0000747 return
748 }
749
Colin Crossa1ad8d12016-06-01 17:09:44 -0700750 var moduleTargets []Target
Colin Crossee0bc3b2018-10-02 22:01:37 -0700751 moduleMultiTargets := make(map[int][]Target)
Colin Cross8b74d172016-09-13 09:59:14 -0700752 primaryModules := make(map[int]bool)
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700753 osClasses := base.OsClassSupported()
Colin Crossa1ad8d12016-06-01 17:09:44 -0700754
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700755 for _, os := range osTypeList {
756 supportedClass := false
757 for _, osClass := range osClasses {
758 if os.Class == osClass {
759 supportedClass = true
760 }
761 }
762 if !supportedClass {
763 continue
764 }
765
766 osTargets := mctx.Config().Targets[os]
767 if len(osTargets) == 0 {
Colin Crossa1ad8d12016-06-01 17:09:44 -0700768 continue
769 }
Colin Crossee0bc3b2018-10-02 22:01:37 -0700770
dimitry1f33e402019-03-26 12:39:31 +0100771 // Filter NativeBridge targets unless they are explicitly supported
772 if os == Android && !Bool(base.commonProperties.Native_bridge_supported) {
773 var targets []Target
774 for _, t := range osTargets {
775 if !t.NativeBridge {
776 targets = append(targets, t)
777 }
778 }
779
780 osTargets = targets
781 }
782
Colin Cross5eca7cb2018-10-02 14:02:10 -0700783 // only the primary arch in the recovery partition
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700784 if os == Android && module.InstallInRecovery() {
785 osTargets = []Target{osTargets[0]}
Colin Cross5eca7cb2018-10-02 14:02:10 -0700786 }
787
Colin Crossa9d8bee2018-10-02 13:59:46 -0700788 prefer32 := false
789 if base.prefer32 != nil {
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700790 prefer32 = base.prefer32(mctx, base, os.Class)
Colin Cross8b74d172016-09-13 09:59:14 -0700791 }
Colin Crossa9d8bee2018-10-02 13:59:46 -0700792
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700793 multilib, extraMultilib := decodeMultilib(base, os.Class)
794 targets, err := decodeMultilibTargets(multilib, osTargets, prefer32)
Colin Crossa1ad8d12016-06-01 17:09:44 -0700795 if err != nil {
796 mctx.ModuleErrorf("%s", err.Error())
797 }
Colin Crossee0bc3b2018-10-02 22:01:37 -0700798
799 var multiTargets []Target
800 if extraMultilib != "" {
Dan Willemsen0ef639b2018-10-10 17:02:29 -0700801 multiTargets, err = decodeMultilibTargets(extraMultilib, osTargets, prefer32)
Colin Crossee0bc3b2018-10-02 22:01:37 -0700802 if err != nil {
803 mctx.ModuleErrorf("%s", err.Error())
804 }
805 }
806
Colin Cross8b74d172016-09-13 09:59:14 -0700807 if len(targets) > 0 {
808 primaryModules[len(moduleTargets)] = true
Colin Crossee0bc3b2018-10-02 22:01:37 -0700809 moduleMultiTargets[len(moduleTargets)] = multiTargets
Colin Cross8b74d172016-09-13 09:59:14 -0700810 moduleTargets = append(moduleTargets, targets...)
811 }
Colin Crossb9db4802016-06-03 01:50:47 +0000812 }
813
Dan Willemsen3f32f032016-07-11 14:36:48 -0700814 if len(moduleTargets) == 0 {
Colin Cross5eca7cb2018-10-02 14:02:10 -0700815 base.commonProperties.Enabled = boolPtr(false)
Dan Willemsen3f32f032016-07-11 14:36:48 -0700816 return
817 }
818
Colin Crossa1ad8d12016-06-01 17:09:44 -0700819 targetNames := make([]string, len(moduleTargets))
Colin Crossb9db4802016-06-03 01:50:47 +0000820
Colin Crossa1ad8d12016-06-01 17:09:44 -0700821 for i, target := range moduleTargets {
822 targetNames[i] = target.String()
823 }
824
825 modules := mctx.CreateVariations(targetNames...)
Colin Cross3f40fa42015-01-30 17:27:36 -0800826 for i, m := range modules {
Colin Crossee0bc3b2018-10-02 22:01:37 -0700827 m.(Module).base().SetTarget(moduleTargets[i], moduleMultiTargets[i], primaryModules[i])
Colin Cross635c3b02016-05-18 15:37:25 -0700828 m.(Module).base().setArchProperties(mctx)
Colin Cross3f40fa42015-01-30 17:27:36 -0800829 }
830}
831
Colin Crossee0bc3b2018-10-02 22:01:37 -0700832func decodeMultilib(base *ModuleBase, class OsClass) (multilib, extraMultilib string) {
833 switch class {
834 case Device:
835 multilib = String(base.commonProperties.Target.Android.Compile_multilib)
836 case Host, HostCross:
837 multilib = String(base.commonProperties.Target.Host.Compile_multilib)
838 }
839 if multilib == "" {
840 multilib = String(base.commonProperties.Compile_multilib)
841 }
842 if multilib == "" {
843 multilib = base.commonProperties.Default_multilib
844 }
845
846 if base.commonProperties.UseTargetVariants {
847 return multilib, ""
848 } else {
849 // For app modules a single arch variant will be created per OS class which is expected to handle all the
850 // selected arches. Return the common-type as multilib and any Android.bp provided multilib as extraMultilib
851 if multilib == base.commonProperties.Default_multilib {
852 multilib = "first"
853 }
854 return base.commonProperties.Default_multilib, multilib
855 }
856}
857
Colin Crosscb988072019-01-24 14:58:11 -0800858func filterArchStructFields(fields []reflect.StructField) (filteredFields []reflect.StructField, filtered bool) {
Colin Crossc17727d2018-10-24 12:42:09 -0700859 for _, field := range fields {
Dan Willemsenb1957a52016-06-23 23:44:54 -0700860 if !proptools.HasTag(field, "android", "arch_variant") {
Colin Crosscb988072019-01-24 14:58:11 -0800861 filtered = true
Dan Willemsenb1957a52016-06-23 23:44:54 -0700862 continue
863 }
864
865 // The arch_variant field isn't necessary past this point
866 // Instead of wasting space, just remove it. Go also has a
867 // 16-bit limit on structure name length. The name is constructed
868 // based on the Go source representation of the structure, so
869 // the tag names count towards that length.
870 //
871 // TODO: handle the uncommon case of other tags being involved
872 if field.Tag == `android:"arch_variant"` {
873 field.Tag = ""
874 }
875
876 // Recurse into structs
877 switch field.Type.Kind() {
878 case reflect.Struct:
Colin Crosscb988072019-01-24 14:58:11 -0800879 var subFiltered bool
880 field.Type, subFiltered = filterArchStruct(field.Type)
881 filtered = filtered || subFiltered
882 if field.Type == nil {
Dan Willemsenb1957a52016-06-23 23:44:54 -0700883 continue
884 }
885 case reflect.Ptr:
886 if field.Type.Elem().Kind() == reflect.Struct {
Colin Crosscb988072019-01-24 14:58:11 -0800887 nestedType, subFiltered := filterArchStruct(field.Type.Elem())
888 filtered = filtered || subFiltered
889 if nestedType == nil {
Dan Willemsenb1957a52016-06-23 23:44:54 -0700890 continue
891 }
892 field.Type = reflect.PtrTo(nestedType)
893 }
894 case reflect.Interface:
895 panic("Interfaces are not supported in arch_variant properties")
896 }
897
Colin Crosscb988072019-01-24 14:58:11 -0800898 filteredFields = append(filteredFields, field)
Dan Willemsenb1957a52016-06-23 23:44:54 -0700899 }
Colin Crossc17727d2018-10-24 12:42:09 -0700900
Colin Crosscb988072019-01-24 14:58:11 -0800901 return filteredFields, filtered
Colin Crossc17727d2018-10-24 12:42:09 -0700902}
903
Colin Crosscb988072019-01-24 14:58:11 -0800904// filterArchStruct takes a reflect.Type that is either a sturct or a pointer to a struct, and returns a reflect.Type
905// that only contains the fields in the original type that have an `android:"arch_variant"` struct tag, and a bool
906// that is true if the new struct type has fewer fields than the original type. If there are no fields in the
907// original type with the struct tag it returns nil and true.
908func filterArchStruct(prop reflect.Type) (filteredProp reflect.Type, filtered bool) {
Colin Crossc17727d2018-10-24 12:42:09 -0700909 var fields []reflect.StructField
910
911 ptr := prop.Kind() == reflect.Ptr
912 if ptr {
913 prop = prop.Elem()
914 }
915
916 for i := 0; i < prop.NumField(); i++ {
917 fields = append(fields, prop.Field(i))
918 }
919
Colin Crosscb988072019-01-24 14:58:11 -0800920 filteredFields, filtered := filterArchStructFields(fields)
Colin Crossc17727d2018-10-24 12:42:09 -0700921
Colin Crosscb988072019-01-24 14:58:11 -0800922 if len(filteredFields) == 0 {
923 return nil, true
Dan Willemsenb1957a52016-06-23 23:44:54 -0700924 }
925
Colin Crosscb988072019-01-24 14:58:11 -0800926 if !filtered {
927 if ptr {
928 return reflect.PtrTo(prop), false
929 }
930 return prop, false
931 }
932
933 ret := reflect.StructOf(filteredFields)
Dan Willemsenb1957a52016-06-23 23:44:54 -0700934 if ptr {
935 ret = reflect.PtrTo(ret)
936 }
Colin Crossc17727d2018-10-24 12:42:09 -0700937
Dan Willemsenb1957a52016-06-23 23:44:54 -0700938 return ret, true
939}
940
Colin Crosscb988072019-01-24 14:58:11 -0800941// filterArchStruct takes a reflect.Type that is either a sturct or a pointer to a struct, and returns a list of
942// reflect.Type that only contains the fields in the original type that have an `android:"arch_variant"` struct tag,
943// and a bool that is true if the new struct type has fewer fields than the original type. If there are no fields in
944// the original type with the struct tag it returns nil and true. Each returned struct type will have a maximum of
945// 10 top level fields in it to attempt to avoid hitting the reflect.StructOf name length limit, although the limit
946// can still be reached with a single struct field with many fields in it.
947func filterArchStructSharded(prop reflect.Type) (filteredProp []reflect.Type, filtered bool) {
Colin Crossc17727d2018-10-24 12:42:09 -0700948 var fields []reflect.StructField
949
950 ptr := prop.Kind() == reflect.Ptr
951 if ptr {
952 prop = prop.Elem()
953 }
954
955 for i := 0; i < prop.NumField(); i++ {
956 fields = append(fields, prop.Field(i))
957 }
958
Colin Crosscb988072019-01-24 14:58:11 -0800959 fields, filtered = filterArchStructFields(fields)
960 if !filtered {
961 if ptr {
962 return []reflect.Type{reflect.PtrTo(prop)}, false
963 }
964 return []reflect.Type{prop}, false
965 }
Colin Crossc17727d2018-10-24 12:42:09 -0700966
967 if len(fields) == 0 {
Colin Crosscb988072019-01-24 14:58:11 -0800968 return nil, true
Colin Crossc17727d2018-10-24 12:42:09 -0700969 }
970
971 shards := shardFields(fields, 10)
972
Colin Crossc17727d2018-10-24 12:42:09 -0700973 for _, shard := range shards {
974 s := reflect.StructOf(shard)
975 if ptr {
976 s = reflect.PtrTo(s)
977 }
Colin Crosscb988072019-01-24 14:58:11 -0800978 filteredProp = append(filteredProp, s)
Colin Crossc17727d2018-10-24 12:42:09 -0700979 }
980
Colin Crosscb988072019-01-24 14:58:11 -0800981 return filteredProp, true
Colin Crossc17727d2018-10-24 12:42:09 -0700982}
983
984func shardFields(fields []reflect.StructField, shardSize int) [][]reflect.StructField {
985 ret := make([][]reflect.StructField, 0, (len(fields)+shardSize-1)/shardSize)
986 for len(fields) > shardSize {
987 ret = append(ret, fields[0:shardSize])
988 fields = fields[shardSize:]
989 }
990 if len(fields) > 0 {
991 ret = append(ret, fields)
992 }
993 return ret
994}
995
Colin Crosscb988072019-01-24 14:58:11 -0800996// createArchType takes a reflect.Type that is either a struct or a pointer to a struct, and returns a list of
997// reflect.Type that contains the arch-variant properties inside structs for each architecture, os, target, multilib,
998// etc.
Colin Crossc17727d2018-10-24 12:42:09 -0700999func createArchType(props reflect.Type) []reflect.Type {
Colin Crosscb988072019-01-24 14:58:11 -08001000 propShards, _ := filterArchStructSharded(props)
1001 if len(propShards) == 0 {
Dan Willemsenb1957a52016-06-23 23:44:54 -07001002 return nil
1003 }
1004
Colin Crossc17727d2018-10-24 12:42:09 -07001005 var ret []reflect.Type
1006 for _, props := range propShards {
Dan Willemsenb1957a52016-06-23 23:44:54 -07001007
Colin Crossc17727d2018-10-24 12:42:09 -07001008 variantFields := func(names []string) []reflect.StructField {
1009 ret := make([]reflect.StructField, len(names))
Dan Willemsenb1957a52016-06-23 23:44:54 -07001010
Colin Crossc17727d2018-10-24 12:42:09 -07001011 for i, name := range names {
1012 ret[i].Name = name
1013 ret[i].Type = props
Dan Willemsen866b5632017-09-22 12:28:24 -07001014 }
Colin Crossc17727d2018-10-24 12:42:09 -07001015
1016 return ret
1017 }
1018
1019 archFields := make([]reflect.StructField, len(archTypeList))
1020 for i, arch := range archTypeList {
1021 variants := []string{}
1022
1023 for _, archVariant := range archVariants[arch] {
1024 archVariant := variantReplacer.Replace(archVariant)
1025 variants = append(variants, proptools.FieldNameForProperty(archVariant))
1026 }
1027 for _, feature := range archFeatures[arch] {
1028 feature := variantReplacer.Replace(feature)
1029 variants = append(variants, proptools.FieldNameForProperty(feature))
1030 }
1031
1032 fields := variantFields(variants)
1033
1034 fields = append([]reflect.StructField{{
1035 Name: "BlueprintEmbed",
1036 Type: props,
1037 Anonymous: true,
1038 }}, fields...)
1039
1040 archFields[i] = reflect.StructField{
1041 Name: arch.Field,
1042 Type: reflect.StructOf(fields),
1043 }
1044 }
1045 archType := reflect.StructOf(archFields)
1046
1047 multilibType := reflect.StructOf(variantFields([]string{"Lib32", "Lib64"}))
1048
1049 targets := []string{
1050 "Host",
1051 "Android64",
1052 "Android32",
1053 "Bionic",
1054 "Linux",
1055 "Not_windows",
1056 "Arm_on_x86",
1057 "Arm_on_x86_64",
1058 }
1059 for _, os := range osTypeList {
1060 targets = append(targets, os.Field)
1061
1062 for _, archType := range osArchTypeMap[os] {
1063 targets = append(targets, os.Field+"_"+archType.Name)
1064
1065 if os.Linux() {
1066 target := "Linux_" + archType.Name
1067 if !InList(target, targets) {
1068 targets = append(targets, target)
1069 }
1070 }
1071 if os.Bionic() {
1072 target := "Bionic_" + archType.Name
1073 if !InList(target, targets) {
1074 targets = append(targets, target)
1075 }
Dan Willemsen866b5632017-09-22 12:28:24 -07001076 }
1077 }
Dan Willemsenb1957a52016-06-23 23:44:54 -07001078 }
Dan Willemsenb1957a52016-06-23 23:44:54 -07001079
Colin Crossc17727d2018-10-24 12:42:09 -07001080 targetType := reflect.StructOf(variantFields(targets))
1081 ret = append(ret, reflect.StructOf([]reflect.StructField{
1082 {
1083 Name: "Arch",
1084 Type: archType,
1085 },
1086 {
1087 Name: "Multilib",
1088 Type: multilibType,
1089 },
1090 {
1091 Name: "Target",
1092 Type: targetType,
1093 },
1094 }))
1095 }
1096 return ret
Dan Willemsenb1957a52016-06-23 23:44:54 -07001097}
1098
1099var archPropTypeMap OncePer
1100
Colin Cross36242852017-06-23 15:06:31 -07001101func InitArchModule(m Module) {
Colin Cross3f40fa42015-01-30 17:27:36 -08001102
1103 base := m.base()
1104
Colin Cross36242852017-06-23 15:06:31 -07001105 base.generalProperties = m.GetProperties()
Colin Cross3f40fa42015-01-30 17:27:36 -08001106
1107 for _, properties := range base.generalProperties {
1108 propertiesValue := reflect.ValueOf(properties)
Colin Cross62496a02016-08-08 15:49:17 -07001109 t := propertiesValue.Type()
Colin Cross3f40fa42015-01-30 17:27:36 -08001110 if propertiesValue.Kind() != reflect.Ptr {
Colin Crossca860ac2016-01-04 14:34:37 -08001111 panic(fmt.Errorf("properties must be a pointer to a struct, got %T",
1112 propertiesValue.Interface()))
Colin Cross3f40fa42015-01-30 17:27:36 -08001113 }
1114
1115 propertiesValue = propertiesValue.Elem()
1116 if propertiesValue.Kind() != reflect.Struct {
Colin Crossca860ac2016-01-04 14:34:37 -08001117 panic(fmt.Errorf("properties must be a pointer to a struct, got %T",
1118 propertiesValue.Interface()))
Colin Cross3f40fa42015-01-30 17:27:36 -08001119 }
1120
Colin Cross571cccf2019-02-04 11:22:08 -08001121 archPropTypes := archPropTypeMap.Once(NewCustomOnceKey(t), func() interface{} {
Dan Willemsenb1957a52016-06-23 23:44:54 -07001122 return createArchType(t)
Colin Crossc17727d2018-10-24 12:42:09 -07001123 }).([]reflect.Type)
Colin Cross3f40fa42015-01-30 17:27:36 -08001124
Colin Crossc17727d2018-10-24 12:42:09 -07001125 var archProperties []interface{}
1126 for _, t := range archPropTypes {
1127 archProperties = append(archProperties, reflect.New(t).Interface())
Dan Willemsenb1957a52016-06-23 23:44:54 -07001128 }
Colin Crossc17727d2018-10-24 12:42:09 -07001129 base.archProperties = append(base.archProperties, archProperties)
1130 m.AddProperties(archProperties...)
Colin Cross3f40fa42015-01-30 17:27:36 -08001131 }
1132
Colin Cross36242852017-06-23 15:06:31 -07001133 base.customizableProperties = m.GetProperties()
Colin Cross3f40fa42015-01-30 17:27:36 -08001134}
1135
Colin Crossa716add2015-12-16 11:07:39 -08001136var variantReplacer = strings.NewReplacer("-", "_", ".", "_")
Colin Crossec193632015-07-06 17:49:43 -07001137
Colin Cross4157e882019-06-06 16:57:04 -07001138func (m *ModuleBase) appendProperties(ctx BottomUpMutatorContext,
Dan Willemsenb1957a52016-06-23 23:44:54 -07001139 dst interface{}, src reflect.Value, field, srcPrefix string) reflect.Value {
Colin Cross06a931b2015-10-28 17:23:31 -07001140
Dan Willemsenb1957a52016-06-23 23:44:54 -07001141 src = src.FieldByName(field)
1142 if !src.IsValid() {
Colin Crosseeabb892015-11-20 13:07:51 -08001143 ctx.ModuleErrorf("field %q does not exist", srcPrefix)
Dan Willemsenb1957a52016-06-23 23:44:54 -07001144 return src
Colin Cross85a88972015-11-23 13:29:51 -08001145 }
1146
Dan Willemsenb1957a52016-06-23 23:44:54 -07001147 ret := src
Colin Cross85a88972015-11-23 13:29:51 -08001148
Dan Willemsenb1957a52016-06-23 23:44:54 -07001149 if src.Kind() == reflect.Struct {
1150 src = src.FieldByName("BlueprintEmbed")
Colin Cross06a931b2015-10-28 17:23:31 -07001151 }
1152
Colin Cross6ee75b62016-05-05 15:57:15 -07001153 order := func(property string,
1154 dstField, srcField reflect.StructField,
1155 dstValue, srcValue interface{}) (proptools.Order, error) {
1156 if proptools.HasTag(dstField, "android", "variant_prepend") {
1157 return proptools.Prepend, nil
1158 } else {
1159 return proptools.Append, nil
1160 }
1161 }
1162
Dan Willemsenb1957a52016-06-23 23:44:54 -07001163 err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, order)
Colin Cross06a931b2015-10-28 17:23:31 -07001164 if err != nil {
1165 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
1166 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
1167 } else {
1168 panic(err)
1169 }
1170 }
Colin Cross85a88972015-11-23 13:29:51 -08001171
Dan Willemsenb1957a52016-06-23 23:44:54 -07001172 return ret
Colin Cross06a931b2015-10-28 17:23:31 -07001173}
1174
Colin Cross3f40fa42015-01-30 17:27:36 -08001175// Rewrite the module's properties structs to contain arch-specific values.
Colin Cross4157e882019-06-06 16:57:04 -07001176func (m *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
1177 arch := m.Arch()
1178 os := m.Os()
Colin Crossd3ba0392015-05-07 14:11:29 -07001179
Colin Cross4157e882019-06-06 16:57:04 -07001180 for i := range m.generalProperties {
1181 genProps := m.generalProperties[i]
1182 if m.archProperties[i] == nil {
Dan Willemsenb1957a52016-06-23 23:44:54 -07001183 continue
1184 }
Colin Cross4157e882019-06-06 16:57:04 -07001185 for _, archProperties := range m.archProperties[i] {
Colin Crossc17727d2018-10-24 12:42:09 -07001186 archPropValues := reflect.ValueOf(archProperties).Elem()
Dan Willemsenb1957a52016-06-23 23:44:54 -07001187
Colin Crossc17727d2018-10-24 12:42:09 -07001188 archProp := archPropValues.FieldByName("Arch")
1189 multilibProp := archPropValues.FieldByName("Multilib")
1190 targetProp := archPropValues.FieldByName("Target")
Dan Willemsenb1957a52016-06-23 23:44:54 -07001191
Colin Crossc17727d2018-10-24 12:42:09 -07001192 var field string
1193 var prefix string
Colin Crossd5934c82017-10-02 13:55:26 -07001194
Colin Crossc17727d2018-10-24 12:42:09 -07001195 // Handle arch-specific properties in the form:
Colin Crossd5934c82017-10-02 13:55:26 -07001196 // arch: {
Colin Crossc17727d2018-10-24 12:42:09 -07001197 // arm64: {
Colin Crossd5934c82017-10-02 13:55:26 -07001198 // key: value,
1199 // },
1200 // },
Colin Crossc17727d2018-10-24 12:42:09 -07001201 t := arch.ArchType
1202
1203 if arch.ArchType != Common {
1204 field := proptools.FieldNameForProperty(t.Name)
1205 prefix := "arch." + t.Name
Colin Cross4157e882019-06-06 16:57:04 -07001206 archStruct := m.appendProperties(ctx, genProps, archProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001207
1208 // Handle arch-variant-specific properties in the form:
1209 // arch: {
1210 // variant: {
1211 // key: value,
1212 // },
1213 // },
1214 v := variantReplacer.Replace(arch.ArchVariant)
1215 if v != "" {
1216 field := proptools.FieldNameForProperty(v)
1217 prefix := "arch." + t.Name + "." + v
Colin Cross4157e882019-06-06 16:57:04 -07001218 m.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001219 }
1220
1221 // Handle cpu-variant-specific properties in the form:
1222 // arch: {
1223 // variant: {
1224 // key: value,
1225 // },
1226 // },
1227 if arch.CpuVariant != arch.ArchVariant {
1228 c := variantReplacer.Replace(arch.CpuVariant)
1229 if c != "" {
1230 field := proptools.FieldNameForProperty(c)
1231 prefix := "arch." + t.Name + "." + c
Colin Cross4157e882019-06-06 16:57:04 -07001232 m.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001233 }
1234 }
1235
1236 // Handle arch-feature-specific properties in the form:
1237 // arch: {
1238 // feature: {
1239 // key: value,
1240 // },
1241 // },
1242 for _, feature := range arch.ArchFeatures {
1243 field := proptools.FieldNameForProperty(feature)
1244 prefix := "arch." + t.Name + "." + feature
Colin Cross4157e882019-06-06 16:57:04 -07001245 m.appendProperties(ctx, genProps, archStruct, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001246 }
1247
1248 // Handle multilib-specific properties in the form:
1249 // multilib: {
1250 // lib32: {
1251 // key: value,
1252 // },
1253 // },
1254 field = proptools.FieldNameForProperty(t.Multilib)
1255 prefix = "multilib." + t.Multilib
Colin Cross4157e882019-06-06 16:57:04 -07001256 m.appendProperties(ctx, genProps, multilibProp, field, prefix)
Colin Cross08016332016-12-20 09:53:14 -08001257 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001258
Colin Crossc17727d2018-10-24 12:42:09 -07001259 // Handle host-specific properties in the form:
1260 // target: {
1261 // host: {
Colin Crossd5934c82017-10-02 13:55:26 -07001262 // key: value,
1263 // },
1264 // },
Colin Crossc17727d2018-10-24 12:42:09 -07001265 if os.Class == Host || os.Class == HostCross {
1266 field = "Host"
1267 prefix = "target.host"
Colin Cross4157e882019-06-06 16:57:04 -07001268 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001269 }
1270
1271 // Handle target OS generalities of the form:
1272 // target: {
1273 // bionic: {
1274 // key: value,
1275 // },
1276 // bionic_x86: {
1277 // key: value,
1278 // },
1279 // }
1280 if os.Linux() {
1281 field = "Linux"
1282 prefix = "target.linux"
Colin Cross4157e882019-06-06 16:57:04 -07001283 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001284
1285 if arch.ArchType != Common {
1286 field = "Linux_" + arch.ArchType.Name
1287 prefix = "target.linux_" + arch.ArchType.Name
Colin Cross4157e882019-06-06 16:57:04 -07001288 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossd5934c82017-10-02 13:55:26 -07001289 }
1290 }
Colin Crossc5c24ad2015-11-20 15:35:00 -08001291
Colin Crossc17727d2018-10-24 12:42:09 -07001292 if os.Bionic() {
1293 field = "Bionic"
1294 prefix = "target.bionic"
Colin Cross4157e882019-06-06 16:57:04 -07001295 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001296
1297 if arch.ArchType != Common {
1298 field = "Bionic_" + t.Name
1299 prefix = "target.bionic_" + t.Name
Colin Cross4157e882019-06-06 16:57:04 -07001300 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001301 }
1302 }
1303
1304 // Handle target OS properties in the form:
1305 // target: {
1306 // linux_glibc: {
1307 // key: value,
1308 // },
1309 // not_windows: {
1310 // key: value,
1311 // },
1312 // linux_glibc_x86: {
1313 // key: value,
1314 // },
1315 // linux_glibc_arm: {
1316 // key: value,
1317 // },
1318 // android {
1319 // key: value,
1320 // },
1321 // android_arm {
1322 // key: value,
1323 // },
1324 // android_x86 {
Colin Crossd5934c82017-10-02 13:55:26 -07001325 // key: value,
1326 // },
1327 // },
Colin Crossc17727d2018-10-24 12:42:09 -07001328 field = os.Field
1329 prefix = "target." + os.Name
Colin Cross4157e882019-06-06 16:57:04 -07001330 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001331
1332 if arch.ArchType != Common {
1333 field = os.Field + "_" + t.Name
1334 prefix = "target." + os.Name + "_" + t.Name
Colin Cross4157e882019-06-06 16:57:04 -07001335 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossd5934c82017-10-02 13:55:26 -07001336 }
1337
Colin Crossc17727d2018-10-24 12:42:09 -07001338 if (os.Class == Host || os.Class == HostCross) && os != Windows {
1339 field := "Not_windows"
1340 prefix := "target.not_windows"
Colin Cross4157e882019-06-06 16:57:04 -07001341 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001342 }
1343
1344 // Handle 64-bit device properties in the form:
1345 // target {
1346 // android64 {
1347 // key: value,
1348 // },
1349 // android32 {
Colin Crossd5934c82017-10-02 13:55:26 -07001350 // key: value,
1351 // },
1352 // },
Colin Crossc17727d2018-10-24 12:42:09 -07001353 // WARNING: this is probably not what you want to use in your blueprints file, it selects
1354 // options for all targets on a device that supports 64-bit binaries, not just the targets
1355 // that are being compiled for 64-bit. Its expected use case is binaries like linker and
1356 // debuggerd that need to know when they are a 32-bit process running on a 64-bit device
1357 if os.Class == Device {
1358 if ctx.Config().Android64() {
1359 field := "Android64"
1360 prefix := "target.android64"
Colin Cross4157e882019-06-06 16:57:04 -07001361 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001362 } else {
1363 field := "Android32"
1364 prefix := "target.android32"
Colin Cross4157e882019-06-06 16:57:04 -07001365 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001366 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001367
Colin Crossc17727d2018-10-24 12:42:09 -07001368 if (arch.ArchType == X86 && (hasArmAbi(arch) ||
1369 hasArmAndroidArch(ctx.Config().Targets[Android]))) ||
1370 (arch.ArchType == Arm &&
1371 hasX86AndroidArch(ctx.Config().Targets[Android])) {
1372 field := "Arm_on_x86"
1373 prefix := "target.arm_on_x86"
Colin Cross4157e882019-06-06 16:57:04 -07001374 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001375 }
1376 if (arch.ArchType == X86_64 && (hasArmAbi(arch) ||
1377 hasArmAndroidArch(ctx.Config().Targets[Android]))) ||
1378 (arch.ArchType == Arm &&
1379 hasX8664AndroidArch(ctx.Config().Targets[Android])) {
1380 field := "Arm_on_x86_64"
1381 prefix := "target.arm_on_x86_64"
Colin Cross4157e882019-06-06 16:57:04 -07001382 m.appendProperties(ctx, genProps, targetProp, field, prefix)
Colin Crossc17727d2018-10-24 12:42:09 -07001383 }
Colin Cross4247f0d2017-04-13 16:56:14 -07001384 }
Colin Crossbb2e2b72016-12-08 17:23:53 -08001385 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001386 }
1387}
1388
1389func forEachInterface(v reflect.Value, f func(reflect.Value)) {
1390 switch v.Kind() {
1391 case reflect.Interface:
1392 f(v)
1393 case reflect.Struct:
1394 for i := 0; i < v.NumField(); i++ {
1395 forEachInterface(v.Field(i), f)
1396 }
1397 case reflect.Ptr:
1398 forEachInterface(v.Elem(), f)
1399 default:
1400 panic(fmt.Errorf("Unsupported kind %s", v.Kind()))
1401 }
1402}
Colin Cross4225f652015-09-17 14:33:42 -07001403
Colin Crossa1ad8d12016-06-01 17:09:44 -07001404// Convert the arch product variables into a list of targets for each os class structs
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001405func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) {
Dan Willemsen45133ac2018-03-09 21:22:06 -08001406 variables := config.productVariables
Dan Willemsen490fd492015-11-24 17:53:15 -08001407
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001408 targets := make(map[OsType][]Target)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001409 var targetErr error
1410
dimitry1f33e402019-03-26 12:39:31 +01001411 addTarget := func(os OsType, archName string, archVariant, cpuVariant *string, abi []string,
dimitry8d6dde82019-07-11 10:23:53 +02001412 nativeBridgeEnabled NativeBridgeSupport, nativeBridgeHostArchName *string,
1413 nativeBridgeRelativePath *string) {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001414 if targetErr != nil {
1415 return
Dan Willemsen490fd492015-11-24 17:53:15 -08001416 }
Colin Crossa1ad8d12016-06-01 17:09:44 -07001417
Dan Willemsen01a3c252019-01-11 19:02:16 -08001418 arch, err := decodeArch(os, archName, archVariant, cpuVariant, abi)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001419 if err != nil {
1420 targetErr = err
1421 return
1422 }
dimitry8d6dde82019-07-11 10:23:53 +02001423 nativeBridgeRelativePathStr := String(nativeBridgeRelativePath)
1424 nativeBridgeHostArchNameStr := String(nativeBridgeHostArchName)
1425
1426 // Use guest arch as relative install path by default
1427 if nativeBridgeEnabled && nativeBridgeRelativePathStr == "" {
1428 nativeBridgeRelativePathStr = arch.ArchType.String()
1429 }
Colin Crossa1ad8d12016-06-01 17:09:44 -07001430
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001431 targets[os] = append(targets[os],
Colin Crossa1ad8d12016-06-01 17:09:44 -07001432 Target{
dimitry8d6dde82019-07-11 10:23:53 +02001433 Os: os,
1434 Arch: arch,
1435 NativeBridge: nativeBridgeEnabled,
1436 NativeBridgeHostArchName: nativeBridgeHostArchNameStr,
1437 NativeBridgeRelativePath: nativeBridgeRelativePathStr,
Colin Crossa1ad8d12016-06-01 17:09:44 -07001438 })
Dan Willemsen490fd492015-11-24 17:53:15 -08001439 }
1440
Colin Cross4225f652015-09-17 14:33:42 -07001441 if variables.HostArch == nil {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001442 return nil, fmt.Errorf("No host primary architecture set")
Colin Cross4225f652015-09-17 14:33:42 -07001443 }
1444
dimitry8d6dde82019-07-11 10:23:53 +02001445 addTarget(BuildOs, *variables.HostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil)
Colin Cross4225f652015-09-17 14:33:42 -07001446
Colin Crosseeabb892015-11-20 13:07:51 -08001447 if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" {
dimitry8d6dde82019-07-11 10:23:53 +02001448 addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil)
Dan Willemsen490fd492015-11-24 17:53:15 -08001449 }
1450
Colin Crossff3ae9d2018-04-10 16:15:18 -07001451 if Bool(config.Host_bionic) {
dimitry8d6dde82019-07-11 10:23:53 +02001452 addTarget(LinuxBionic, "x86_64", nil, nil, nil, NativeBridgeDisabled, nil, nil)
Dan Willemsen01a405a2016-06-13 17:19:03 -07001453 }
1454
Colin Crossff3ae9d2018-04-10 16:15:18 -07001455 if String(variables.CrossHost) != "" {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001456 crossHostOs := osByName(*variables.CrossHost)
1457 if crossHostOs == NoOsType {
1458 return nil, fmt.Errorf("Unknown cross host OS %q", *variables.CrossHost)
1459 }
1460
Colin Crossff3ae9d2018-04-10 16:15:18 -07001461 if String(variables.CrossHostArch) == "" {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001462 return nil, fmt.Errorf("No cross-host primary architecture set")
Dan Willemsen490fd492015-11-24 17:53:15 -08001463 }
1464
dimitry8d6dde82019-07-11 10:23:53 +02001465 addTarget(crossHostOs, *variables.CrossHostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil)
Dan Willemsen490fd492015-11-24 17:53:15 -08001466
1467 if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" {
dimitry8d6dde82019-07-11 10:23:53 +02001468 addTarget(crossHostOs, *variables.CrossHostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil)
Dan Willemsen490fd492015-11-24 17:53:15 -08001469 }
1470 }
1471
Dan Willemsen3f32f032016-07-11 14:36:48 -07001472 if variables.DeviceArch != nil && *variables.DeviceArch != "" {
Doug Horn21b94272019-01-16 12:06:11 -08001473 var target = Android
1474 if Bool(variables.Fuchsia) {
1475 target = Fuchsia
1476 }
1477
1478 addTarget(target, *variables.DeviceArch, variables.DeviceArchVariant,
dimitry8d6dde82019-07-11 10:23:53 +02001479 variables.DeviceCpuVariant, variables.DeviceAbi, NativeBridgeDisabled, nil, nil)
Colin Cross4225f652015-09-17 14:33:42 -07001480
Dan Willemsen3f32f032016-07-11 14:36:48 -07001481 if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" {
1482 addTarget(Android, *variables.DeviceSecondaryArch,
1483 variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant,
dimitry8d6dde82019-07-11 10:23:53 +02001484 variables.DeviceSecondaryAbi, NativeBridgeDisabled, nil, nil)
Colin Cross4225f652015-09-17 14:33:42 -07001485
Dan Willemsen0ef639b2018-10-10 17:02:29 -07001486 deviceArches := targets[Android]
Dan Willemsen3f32f032016-07-11 14:36:48 -07001487 if deviceArches[0].Arch.ArchType.Multilib == deviceArches[1].Arch.ArchType.Multilib {
1488 deviceArches[1].Arch.Native = false
1489 }
Colin Cross4225f652015-09-17 14:33:42 -07001490 }
dimitry1f33e402019-03-26 12:39:31 +01001491
1492 if variables.NativeBridgeArch != nil && *variables.NativeBridgeArch != "" {
1493 addTarget(Android, *variables.NativeBridgeArch,
1494 variables.NativeBridgeArchVariant, variables.NativeBridgeCpuVariant,
dimitry8d6dde82019-07-11 10:23:53 +02001495 variables.NativeBridgeAbi, NativeBridgeEnabled, variables.DeviceArch,
1496 variables.NativeBridgeRelativePath)
dimitry1f33e402019-03-26 12:39:31 +01001497 }
1498
1499 if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" &&
1500 variables.NativeBridgeSecondaryArch != nil && *variables.NativeBridgeSecondaryArch != "" {
1501 addTarget(Android, *variables.NativeBridgeSecondaryArch,
1502 variables.NativeBridgeSecondaryArchVariant,
1503 variables.NativeBridgeSecondaryCpuVariant,
dimitry8d6dde82019-07-11 10:23:53 +02001504 variables.NativeBridgeSecondaryAbi,
1505 NativeBridgeEnabled,
1506 variables.DeviceSecondaryArch,
1507 variables.NativeBridgeSecondaryRelativePath)
dimitry1f33e402019-03-26 12:39:31 +01001508 }
Colin Cross4225f652015-09-17 14:33:42 -07001509 }
1510
Colin Crossa1ad8d12016-06-01 17:09:44 -07001511 if targetErr != nil {
1512 return nil, targetErr
1513 }
1514
1515 return targets, nil
Colin Cross4225f652015-09-17 14:33:42 -07001516}
1517
Colin Crossbb2e2b72016-12-08 17:23:53 -08001518// hasArmAbi returns true if arch has at least one arm ABI
1519func hasArmAbi(arch Arch) bool {
1520 for _, abi := range arch.Abi {
1521 if strings.HasPrefix(abi, "arm") {
1522 return true
1523 }
1524 }
1525 return false
1526}
1527
dimitry628db6f2019-05-22 17:16:21 +02001528// hasArmArch returns true if targets has at least non-native_bridge arm Android arch
Colin Cross4247f0d2017-04-13 16:56:14 -07001529func hasArmAndroidArch(targets []Target) bool {
1530 for _, target := range targets {
dimitry628db6f2019-05-22 17:16:21 +02001531 if target.Os == Android && target.Arch.ArchType == Arm && target.NativeBridge == NativeBridgeDisabled {
Colin Cross4247f0d2017-04-13 16:56:14 -07001532 return true
1533 }
1534 }
1535 return false
1536}
1537
Victor Khimenko5eb8ec12018-03-21 20:30:54 +01001538// hasX86Arch returns true if targets has at least x86 Android arch
1539func hasX86AndroidArch(targets []Target) bool {
1540 for _, target := range targets {
1541 if target.Os == Android && target.Arch.ArchType == X86 {
1542 return true
1543 }
1544 }
1545 return false
1546}
1547
1548// hasX8664Arch returns true if targets has at least x86_64 Android arch
1549func hasX8664AndroidArch(targets []Target) bool {
1550 for _, target := range targets {
1551 if target.Os == Android && target.Arch.ArchType == X86_64 {
1552 return true
1553 }
1554 }
1555 return false
1556}
1557
Dan Albert4098deb2016-10-19 14:04:41 -07001558type archConfig struct {
1559 arch string
1560 archVariant string
1561 cpuVariant string
1562 abi []string
1563}
1564
1565func getMegaDeviceConfig() []archConfig {
1566 return []archConfig{
Dan Albert8818f492019-02-19 13:53:01 -08001567 {"arm", "armv7-a", "generic", []string{"armeabi-v7a"}},
Dan Willemsen110a89d2016-01-14 15:17:19 -08001568 {"arm", "armv7-a-neon", "generic", []string{"armeabi-v7a"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -08001569 {"arm", "armv7-a-neon", "cortex-a7", []string{"armeabi-v7a"}},
1570 {"arm", "armv7-a-neon", "cortex-a8", []string{"armeabi-v7a"}},
Dan Willemsen110a89d2016-01-14 15:17:19 -08001571 {"arm", "armv7-a-neon", "cortex-a9", []string{"armeabi-v7a"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -08001572 {"arm", "armv7-a-neon", "cortex-a15", []string{"armeabi-v7a"}},
1573 {"arm", "armv7-a-neon", "cortex-a53", []string{"armeabi-v7a"}},
1574 {"arm", "armv7-a-neon", "cortex-a53.a57", []string{"armeabi-v7a"}},
Richard Fungeb37ed32018-09-24 16:33:45 -07001575 {"arm", "armv7-a-neon", "cortex-a72", []string{"armeabi-v7a"}},
Jake Weinstein6600a442017-05-15 18:27:12 -04001576 {"arm", "armv7-a-neon", "cortex-a73", []string{"armeabi-v7a"}},
Christopher Ferrisba14a8f2018-04-23 18:15:25 -07001577 {"arm", "armv7-a-neon", "cortex-a75", []string{"armeabi-v7a"}},
Haibo Huanga31e2bd2018-10-09 14:27:28 -07001578 {"arm", "armv7-a-neon", "cortex-a76", []string{"armeabi-v7a"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -08001579 {"arm", "armv7-a-neon", "krait", []string{"armeabi-v7a"}},
Alex Naidisae4fc182016-08-20 00:14:56 +02001580 {"arm", "armv7-a-neon", "kryo", []string{"armeabi-v7a"}},
Artem Serovd3072b02018-11-15 15:21:51 +00001581 {"arm", "armv7-a-neon", "kryo385", []string{"armeabi-v7a"}},
Junmo Park8ea49592017-07-24 07:14:55 +09001582 {"arm", "armv7-a-neon", "exynos-m1", []string{"armeabi-v7a"}},
Junmo Parkd86c9022017-07-21 09:07:47 +09001583 {"arm", "armv7-a-neon", "exynos-m2", []string{"armeabi-v7a"}},
Dan Willemsen110a89d2016-01-14 15:17:19 -08001584 {"arm64", "armv8-a", "cortex-a53", []string{"arm64-v8a"}},
Richard Fungeb37ed32018-09-24 16:33:45 -07001585 {"arm64", "armv8-a", "cortex-a72", []string{"arm64-v8a"}},
Jake Weinstein6600a442017-05-15 18:27:12 -04001586 {"arm64", "armv8-a", "cortex-a73", []string{"arm64-v8a"}},
Alex Naidisac01ff52016-08-30 15:56:33 +02001587 {"arm64", "armv8-a", "kryo", []string{"arm64-v8a"}},
Junmo Park8ea49592017-07-24 07:14:55 +09001588 {"arm64", "armv8-a", "exynos-m1", []string{"arm64-v8a"}},
Junmo Parkd86c9022017-07-21 09:07:47 +09001589 {"arm64", "armv8-a", "exynos-m2", []string{"arm64-v8a"}},
Christopher Ferrisba14a8f2018-04-23 18:15:25 -07001590 {"arm64", "armv8-2a", "cortex-a75", []string{"arm64-v8a"}},
Haibo Huanga31e2bd2018-10-09 14:27:28 -07001591 {"arm64", "armv8-2a", "cortex-a76", []string{"arm64-v8a"}},
Artem Serovd3072b02018-11-15 15:21:51 +00001592 {"arm64", "armv8-2a", "kryo385", []string{"arm64-v8a"}},
Dan Willemsen468cc312016-01-13 23:25:19 -08001593 {"mips", "mips32-fp", "", []string{"mips"}},
1594 {"mips", "mips32r2-fp", "", []string{"mips"}},
1595 {"mips", "mips32r2-fp-xburst", "", []string{"mips"}},
Dan Willemsen65fb9812016-07-19 21:37:28 -07001596 //{"mips", "mips32r6", "", []string{"mips"}},
Colin Cross1837b802017-04-26 19:10:34 -07001597 {"mips", "mips32r2dsp-fp", "", []string{"mips"}},
1598 {"mips", "mips32r2dspr2-fp", "", []string{"mips"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -08001599 // mips64r2 is mismatching 64r2 and 64r6 libraries during linking to libgcc
1600 //{"mips64", "mips64r2", "", []string{"mips64"}},
1601 {"mips64", "mips64r6", "", []string{"mips64"}},
1602 {"x86", "", "", []string{"x86"}},
1603 {"x86", "atom", "", []string{"x86"}},
1604 {"x86", "haswell", "", []string{"x86"}},
1605 {"x86", "ivybridge", "", []string{"x86"}},
1606 {"x86", "sandybridge", "", []string{"x86"}},
1607 {"x86", "silvermont", "", []string{"x86"}},
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -07001608 {"x86", "stoneyridge", "", []string{"x86"}},
Dan Willemsen8a354052016-05-10 14:30:51 -07001609 {"x86", "x86_64", "", []string{"x86"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -08001610 {"x86_64", "", "", []string{"x86_64"}},
1611 {"x86_64", "haswell", "", []string{"x86_64"}},
1612 {"x86_64", "ivybridge", "", []string{"x86_64"}},
1613 {"x86_64", "sandybridge", "", []string{"x86_64"}},
1614 {"x86_64", "silvermont", "", []string{"x86_64"}},
Benjamin Gordon87e7f2f2019-02-14 10:59:48 -07001615 {"x86_64", "stoneyridge", "", []string{"x86_64"}},
Dan Willemsen322acaf2016-01-12 23:07:05 -08001616 }
Dan Albert4098deb2016-10-19 14:04:41 -07001617}
Dan Willemsen322acaf2016-01-12 23:07:05 -08001618
Dan Albert4098deb2016-10-19 14:04:41 -07001619func getNdkAbisConfig() []archConfig {
1620 return []archConfig{
Dan Albert8818f492019-02-19 13:53:01 -08001621 {"arm", "armv7-a", "", []string{"armeabi"}},
Dan Albert4098deb2016-10-19 14:04:41 -07001622 {"arm64", "armv8-a", "", []string{"arm64-v8a"}},
Dan Albert4098deb2016-10-19 14:04:41 -07001623 {"x86", "", "", []string{"x86"}},
1624 {"x86_64", "", "", []string{"x86_64"}},
1625 }
1626}
1627
Dan Willemsen01a3c252019-01-11 19:02:16 -08001628func decodeArchSettings(os OsType, archConfigs []archConfig) ([]Target, error) {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001629 var ret []Target
Dan Willemsen322acaf2016-01-12 23:07:05 -08001630
Dan Albert4098deb2016-10-19 14:04:41 -07001631 for _, config := range archConfigs {
Dan Willemsen01a3c252019-01-11 19:02:16 -08001632 arch, err := decodeArch(os, config.arch, &config.archVariant,
Colin Crossa74ca042019-01-31 14:31:51 -08001633 &config.cpuVariant, config.abi)
Dan Willemsen322acaf2016-01-12 23:07:05 -08001634 if err != nil {
1635 return nil, err
1636 }
Dan Willemsen17f05262016-05-31 16:27:00 -07001637 arch.Native = false
Colin Crossa1ad8d12016-06-01 17:09:44 -07001638 ret = append(ret, Target{
1639 Os: Android,
1640 Arch: arch,
1641 })
Dan Willemsen322acaf2016-01-12 23:07:05 -08001642 }
1643
1644 return ret, nil
1645}
1646
Colin Cross4225f652015-09-17 14:33:42 -07001647// Convert a set of strings from product variables into a single Arch struct
Colin Crossa74ca042019-01-31 14:31:51 -08001648func decodeArch(os OsType, arch string, archVariant, cpuVariant *string, abi []string) (Arch, error) {
Colin Cross4225f652015-09-17 14:33:42 -07001649 stringPtr := func(p *string) string {
1650 if p != nil {
1651 return *p
1652 }
1653 return ""
1654 }
1655
Colin Crosseeabb892015-11-20 13:07:51 -08001656 archType, ok := archTypeMap[arch]
1657 if !ok {
1658 return Arch{}, fmt.Errorf("unknown arch %q", arch)
1659 }
Colin Cross4225f652015-09-17 14:33:42 -07001660
Colin Crosseeabb892015-11-20 13:07:51 -08001661 a := Arch{
Colin Cross4225f652015-09-17 14:33:42 -07001662 ArchType: archType,
1663 ArchVariant: stringPtr(archVariant),
1664 CpuVariant: stringPtr(cpuVariant),
Colin Crossa74ca042019-01-31 14:31:51 -08001665 Abi: abi,
Dan Willemsen17f05262016-05-31 16:27:00 -07001666 Native: true,
Colin Crosseeabb892015-11-20 13:07:51 -08001667 }
1668
1669 if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" {
1670 a.ArchVariant = ""
1671 }
1672
1673 if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" {
1674 a.CpuVariant = ""
1675 }
1676
1677 for i := 0; i < len(a.Abi); i++ {
1678 if a.Abi[i] == "" {
1679 a.Abi = append(a.Abi[:i], a.Abi[i+1:]...)
1680 i--
1681 }
1682 }
1683
Dan Willemsen01a3c252019-01-11 19:02:16 -08001684 if a.ArchVariant == "" {
1685 if featureMap, ok := defaultArchFeatureMap[os]; ok {
1686 a.ArchFeatures = featureMap[archType]
1687 }
1688 } else {
1689 if featureMap, ok := archFeatureMap[archType]; ok {
1690 a.ArchFeatures = featureMap[a.ArchVariant]
1691 }
Colin Crossc5c24ad2015-11-20 15:35:00 -08001692 }
1693
Colin Crosseeabb892015-11-20 13:07:51 -08001694 return a, nil
Colin Cross4225f652015-09-17 14:33:42 -07001695}
1696
Colin Cross69617d32016-09-06 10:39:07 -07001697func filterMultilibTargets(targets []Target, multilib string) []Target {
1698 var ret []Target
1699 for _, t := range targets {
1700 if t.Arch.ArchType.Multilib == multilib {
1701 ret = append(ret, t)
1702 }
1703 }
1704 return ret
1705}
1706
Nan Zhangdb0b9a32017-02-27 10:12:13 -08001707func getCommonTargets(targets []Target) []Target {
1708 var ret []Target
1709 set := make(map[string]bool)
1710
1711 for _, t := range targets {
1712 if _, found := set[t.Os.String()]; !found {
1713 set[t.Os.String()] = true
1714 ret = append(ret, commonTargetMap[t.Os.String()])
1715 }
1716 }
1717
1718 return ret
1719}
1720
Colin Cross3dceee32018-09-06 10:19:57 -07001721func firstTarget(targets []Target, filters ...string) []Target {
Colin Cross6b4a32d2017-12-05 13:42:45 -08001722 for _, filter := range filters {
1723 buildTargets := filterMultilibTargets(targets, filter)
1724 if len(buildTargets) > 0 {
Colin Cross3dceee32018-09-06 10:19:57 -07001725 return buildTargets[:1]
Colin Cross6b4a32d2017-12-05 13:42:45 -08001726 }
1727 }
1728 return nil
1729}
1730
Colin Crossa1ad8d12016-06-01 17:09:44 -07001731// Use the module multilib setting to select one or more targets from a target list
Colin Crossee0bc3b2018-10-02 22:01:37 -07001732func decodeMultilibTargets(multilib string, targets []Target, prefer32 bool) ([]Target, error) {
Colin Crossa1ad8d12016-06-01 17:09:44 -07001733 buildTargets := []Target{}
Colin Cross6b4a32d2017-12-05 13:42:45 -08001734
Colin Cross4225f652015-09-17 14:33:42 -07001735 switch multilib {
1736 case "common":
Colin Cross6b4a32d2017-12-05 13:42:45 -08001737 buildTargets = getCommonTargets(targets)
1738 case "common_first":
1739 buildTargets = getCommonTargets(targets)
1740 if prefer32 {
Colin Cross3dceee32018-09-06 10:19:57 -07001741 buildTargets = append(buildTargets, firstTarget(targets, "lib32", "lib64")...)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001742 } else {
Colin Cross3dceee32018-09-06 10:19:57 -07001743 buildTargets = append(buildTargets, firstTarget(targets, "lib64", "lib32")...)
Colin Cross6b4a32d2017-12-05 13:42:45 -08001744 }
Colin Cross4225f652015-09-17 14:33:42 -07001745 case "both":
Colin Cross8b74d172016-09-13 09:59:14 -07001746 if prefer32 {
1747 buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...)
1748 buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...)
1749 } else {
1750 buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...)
1751 buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...)
1752 }
Colin Cross4225f652015-09-17 14:33:42 -07001753 case "32":
Colin Cross69617d32016-09-06 10:39:07 -07001754 buildTargets = filterMultilibTargets(targets, "lib32")
Colin Cross4225f652015-09-17 14:33:42 -07001755 case "64":
Colin Cross69617d32016-09-06 10:39:07 -07001756 buildTargets = filterMultilibTargets(targets, "lib64")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001757 case "first":
1758 if prefer32 {
Colin Cross3dceee32018-09-06 10:19:57 -07001759 buildTargets = firstTarget(targets, "lib32", "lib64")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001760 } else {
Colin Cross3dceee32018-09-06 10:19:57 -07001761 buildTargets = firstTarget(targets, "lib64", "lib32")
Colin Cross6b4a32d2017-12-05 13:42:45 -08001762 }
Colin Cross69617d32016-09-06 10:39:07 -07001763 case "prefer32":
Colin Cross3dceee32018-09-06 10:19:57 -07001764 buildTargets = filterMultilibTargets(targets, "lib32")
1765 if len(buildTargets) == 0 {
1766 buildTargets = filterMultilibTargets(targets, "lib64")
1767 }
Colin Cross4225f652015-09-17 14:33:42 -07001768 default:
Colin Cross69617d32016-09-06 10:39:07 -07001769 return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", "64", or "prefer32" found %q`,
Colin Cross4225f652015-09-17 14:33:42 -07001770 multilib)
Colin Cross4225f652015-09-17 14:33:42 -07001771 }
1772
Colin Crossa1ad8d12016-06-01 17:09:44 -07001773 return buildTargets, nil
Colin Cross4225f652015-09-17 14:33:42 -07001774}