Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 15 | package android |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 16 | |
| 17 | import ( |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 18 | "encoding" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 19 | "fmt" |
| 20 | "reflect" |
| 21 | "runtime" |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 22 | "strconv" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 23 | "strings" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 24 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 25 | "github.com/google/blueprint" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 26 | "github.com/google/blueprint/proptools" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 27 | ) |
| 28 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 29 | const COMMON_VARIANT = "common" |
| 30 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 31 | var ( |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 32 | archTypeList []ArchType |
| 33 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 34 | 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 Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 40 | |
| 41 | Common = ArchType{ |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 42 | Name: COMMON_VARIANT, |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 43 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 44 | ) |
| 45 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 46 | var archTypeMap = map[string]ArchType{ |
| 47 | "arm": Arm, |
| 48 | "arm64": Arm64, |
| 49 | "mips": Mips, |
Colin Cross | 3b336c2 | 2015-11-23 16:28:31 -0800 | [diff] [blame] | 50 | "mips64": Mips64, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 51 | "x86": X86, |
| 52 | "x86_64": X86_64, |
| 53 | } |
| 54 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 55 | /* |
| 56 | Example blueprints file containing all variant property groups, with comment listing what type |
| 57 | of variants get properties in that group: |
| 58 | |
| 59 | module { |
| 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 Willemsen | 5746bd4 | 2017-10-02 19:42:01 -0700 | [diff] [blame] | 95 | linux_glibc: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 96 | // 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 Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 110 | |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 111 | var archVariants = map[ArchType][]string{ |
| 112 | Arm: { |
Dan Albert | 8818f49 | 2019-02-19 13:53:01 -0800 | [diff] [blame] | 113 | "armv7-a", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 114 | "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 Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 161 | "amberlake", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 162 | "atom", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 163 | "broadwell", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 164 | "haswell", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 165 | "icelake", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 166 | "ivybridge", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 167 | "kabylake", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 168 | "sandybridge", |
| 169 | "silvermont", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 170 | "skylake", |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 171 | "stoneyridge", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 172 | "tigerlake", |
| 173 | "whiskeylake", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 174 | "x86_64", |
| 175 | }, |
| 176 | X86_64: { |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 177 | "amberlake", |
| 178 | "broadwell", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 179 | "haswell", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 180 | "icelake", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 181 | "ivybridge", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 182 | "kabylake", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 183 | "sandybridge", |
| 184 | "silvermont", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 185 | "skylake", |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 186 | "stoneyridge", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 187 | "tigerlake", |
| 188 | "whiskeylake", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 189 | }, |
| 190 | } |
| 191 | |
| 192 | var 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 Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 212 | "avx2", |
| 213 | "avx512", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 214 | "popcnt", |
| 215 | "movbe", |
| 216 | }, |
| 217 | X86_64: { |
| 218 | "ssse3", |
| 219 | "sse4", |
| 220 | "sse4_1", |
| 221 | "sse4_2", |
| 222 | "aes_ni", |
| 223 | "avx", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 224 | "avx2", |
| 225 | "avx512", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 226 | "popcnt", |
| 227 | }, |
| 228 | } |
| 229 | |
| 230 | var 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 Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 256 | "amberlake": { |
| 257 | "ssse3", |
| 258 | "sse4", |
| 259 | "sse4_1", |
| 260 | "sse4_2", |
| 261 | "avx", |
| 262 | "avx2", |
| 263 | "aes_ni", |
| 264 | "popcnt", |
| 265 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 266 | "atom": { |
| 267 | "ssse3", |
| 268 | "movbe", |
| 269 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 270 | "broadwell": { |
| 271 | "ssse3", |
| 272 | "sse4", |
| 273 | "sse4_1", |
| 274 | "sse4_2", |
| 275 | "avx", |
| 276 | "avx2", |
| 277 | "aes_ni", |
| 278 | "popcnt", |
| 279 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 280 | "haswell": { |
| 281 | "ssse3", |
| 282 | "sse4", |
| 283 | "sse4_1", |
| 284 | "sse4_2", |
| 285 | "aes_ni", |
| 286 | "avx", |
| 287 | "popcnt", |
| 288 | "movbe", |
| 289 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 290 | "icelake": { |
| 291 | "ssse3", |
| 292 | "sse4", |
| 293 | "sse4_1", |
| 294 | "sse4_2", |
| 295 | "avx", |
| 296 | "avx2", |
| 297 | "avx512", |
| 298 | "aes_ni", |
| 299 | "popcnt", |
| 300 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 301 | "ivybridge": { |
| 302 | "ssse3", |
| 303 | "sse4", |
| 304 | "sse4_1", |
| 305 | "sse4_2", |
| 306 | "aes_ni", |
| 307 | "avx", |
| 308 | "popcnt", |
| 309 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 310 | "kabylake": { |
| 311 | "ssse3", |
| 312 | "sse4", |
| 313 | "sse4_1", |
| 314 | "sse4_2", |
| 315 | "avx", |
| 316 | "avx2", |
| 317 | "aes_ni", |
| 318 | "popcnt", |
| 319 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 320 | "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 Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 336 | "skylake": { |
| 337 | "ssse3", |
| 338 | "sse4", |
| 339 | "sse4_1", |
| 340 | "sse4_2", |
| 341 | "avx", |
| 342 | "avx2", |
| 343 | "avx512", |
| 344 | "aes_ni", |
| 345 | "popcnt", |
| 346 | }, |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 347 | "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 Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 358 | "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 Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 380 | "x86_64": { |
| 381 | "ssse3", |
| 382 | "sse4", |
| 383 | "sse4_1", |
| 384 | "sse4_2", |
| 385 | "popcnt", |
| 386 | }, |
| 387 | }, |
| 388 | X86_64: { |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 389 | "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 Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 409 | "haswell": { |
| 410 | "ssse3", |
| 411 | "sse4", |
| 412 | "sse4_1", |
| 413 | "sse4_2", |
| 414 | "aes_ni", |
| 415 | "avx", |
| 416 | "popcnt", |
| 417 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 418 | "icelake": { |
| 419 | "ssse3", |
| 420 | "sse4", |
| 421 | "sse4_1", |
| 422 | "sse4_2", |
| 423 | "avx", |
| 424 | "avx2", |
| 425 | "avx512", |
| 426 | "aes_ni", |
| 427 | "popcnt", |
| 428 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 429 | "ivybridge": { |
| 430 | "ssse3", |
| 431 | "sse4", |
| 432 | "sse4_1", |
| 433 | "sse4_2", |
| 434 | "aes_ni", |
| 435 | "avx", |
| 436 | "popcnt", |
| 437 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 438 | "kabylake": { |
| 439 | "ssse3", |
| 440 | "sse4", |
| 441 | "sse4_1", |
| 442 | "sse4_2", |
| 443 | "avx", |
| 444 | "avx2", |
| 445 | "aes_ni", |
| 446 | "popcnt", |
| 447 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 448 | "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 Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 463 | "skylake": { |
| 464 | "ssse3", |
| 465 | "sse4", |
| 466 | "sse4_1", |
| 467 | "sse4_2", |
| 468 | "avx", |
| 469 | "avx2", |
| 470 | "avx512", |
| 471 | "aes_ni", |
| 472 | "popcnt", |
| 473 | }, |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 474 | "stoneyridge": { |
| 475 | "ssse3", |
| 476 | "sse4", |
| 477 | "sse4_1", |
| 478 | "sse4_2", |
| 479 | "aes_ni", |
| 480 | "avx", |
| 481 | "avx2", |
| 482 | "popcnt", |
| 483 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 484 | "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 Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 506 | }, |
| 507 | } |
| 508 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 509 | var defaultArchFeatureMap = map[OsType]map[ArchType][]string{} |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 510 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 511 | func 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 Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 526 | // An Arch indicates a single CPU architecture. |
| 527 | type Arch struct { |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 528 | ArchType ArchType |
| 529 | ArchVariant string |
| 530 | CpuVariant string |
| 531 | Abi []string |
| 532 | ArchFeatures []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | func (a Arch) String() string { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 536 | s := a.ArchType.String() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 537 | if a.ArchVariant != "" { |
| 538 | s += "_" + a.ArchVariant |
| 539 | } |
| 540 | if a.CpuVariant != "" { |
| 541 | s += "_" + a.CpuVariant |
| 542 | } |
| 543 | return s |
| 544 | } |
| 545 | |
| 546 | type ArchType struct { |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 547 | Name string |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 548 | Field string |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 549 | Multilib string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 550 | } |
| 551 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 552 | func newArch(name, multilib string) ArchType { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 553 | archType := ArchType{ |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 554 | Name: name, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 555 | Field: proptools.FieldNameForProperty(name), |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 556 | Multilib: multilib, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 557 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 558 | archTypeList = append(archTypeList, archType) |
| 559 | return archType |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 560 | } |
| 561 | |
Jaewoong Jung | 1ce9ac6 | 2019-08-13 14:11:33 -0700 | [diff] [blame] | 562 | func ArchTypeList() []ArchType { |
| 563 | return append([]ArchType(nil), archTypeList...) |
| 564 | } |
| 565 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 566 | func (a ArchType) String() string { |
| 567 | return a.Name |
| 568 | } |
| 569 | |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 570 | var _ encoding.TextMarshaler = ArchType{} |
| 571 | |
| 572 | func (a ArchType) MarshalText() ([]byte, error) { |
| 573 | return []byte(strconv.Quote(a.String())), nil |
| 574 | } |
| 575 | |
| 576 | var _ encoding.TextUnmarshaler = &ArchType{} |
| 577 | |
| 578 | func (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 Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 587 | var BuildOs = func() OsType { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 588 | 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 Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 596 | }() |
| 597 | |
| 598 | var ( |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 599 | osTypeList []OsType |
| 600 | commonTargetMap = make(map[string]Target) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 601 | |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 602 | NoOsType OsType |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 603 | Linux = NewOsType("linux_glibc", Host, false) |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 604 | Darwin = NewOsType("darwin", Host, false) |
Dan Willemsen | 9ff34c0 | 2018-10-10 17:58:19 -0700 | [diff] [blame] | 605 | LinuxBionic = NewOsType("linux_bionic", Host, false) |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 606 | Windows = NewOsType("windows", HostCross, true) |
| 607 | Android = NewOsType("android", Device, false) |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 608 | Fuchsia = NewOsType("fuchsia", Device, false) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 609 | |
| 610 | osArchTypeMap = map[OsType][]ArchType{ |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 611 | Linux: []ArchType{X86, X86_64}, |
| 612 | LinuxBionic: []ArchType{X86_64}, |
Dan Willemsen | e97e68a | 2018-08-28 17:12:56 -0700 | [diff] [blame] | 613 | Darwin: []ArchType{X86_64}, |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 614 | Windows: []ArchType{X86, X86_64}, |
| 615 | Android: []ArchType{Arm, Arm64, Mips, Mips64, X86, X86_64}, |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 616 | Fuchsia: []ArchType{Arm64, X86_64}, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 617 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 618 | ) |
| 619 | |
| 620 | type OsType struct { |
| 621 | Name, Field string |
| 622 | Class OsClass |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 623 | |
| 624 | DefaultDisabled bool |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 625 | } |
| 626 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 627 | type OsClass int |
| 628 | |
| 629 | const ( |
Dan Willemsen | 0e2d97b | 2016-11-28 17:50:06 -0800 | [diff] [blame] | 630 | Generic OsClass = iota |
| 631 | Device |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 632 | Host |
| 633 | HostCross |
| 634 | ) |
| 635 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 636 | func (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 Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 651 | func (os OsType) String() string { |
| 652 | return os.Name |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 653 | } |
| 654 | |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 655 | func (os OsType) Bionic() bool { |
| 656 | return os == Android || os == LinuxBionic |
| 657 | } |
| 658 | |
| 659 | func (os OsType) Linux() bool { |
| 660 | return os == Android || os == Linux || os == LinuxBionic |
| 661 | } |
| 662 | |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 663 | func NewOsType(name string, class OsClass, defDisabled bool) OsType { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 664 | os := OsType{ |
| 665 | Name: name, |
| 666 | Field: strings.Title(name), |
| 667 | Class: class, |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 668 | |
| 669 | DefaultDisabled: defDisabled, |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 670 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 671 | osTypeList = append(osTypeList, os) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 672 | |
| 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 Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 679 | return os |
| 680 | } |
| 681 | |
| 682 | func osByName(name string) OsType { |
| 683 | for _, os := range osTypeList { |
| 684 | if os.Name == name { |
| 685 | return os |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | return NoOsType |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 690 | } |
| 691 | |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 692 | type NativeBridgeSupport bool |
| 693 | |
| 694 | const ( |
| 695 | NativeBridgeDisabled NativeBridgeSupport = false |
| 696 | NativeBridgeEnabled NativeBridgeSupport = true |
| 697 | ) |
| 698 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 699 | type Target struct { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 700 | Os OsType |
| 701 | Arch Arch |
| 702 | NativeBridge NativeBridgeSupport |
| 703 | NativeBridgeHostArchName string |
| 704 | NativeBridgeRelativePath string |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 707 | func (target Target) String() string { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 708 | return target.OsVariation() + "_" + target.ArchVariation() |
| 709 | } |
| 710 | |
| 711 | func (target Target) OsVariation() string { |
| 712 | return target.Os.String() |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | func (target Target) ArchVariation() string { |
| 716 | var variation string |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 717 | if target.NativeBridge { |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 718 | variation = "native_bridge_" |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 719 | } |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 720 | variation += target.Arch.String() |
| 721 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 722 | return variation |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | func (target Target) Variations() []blueprint.Variation { |
| 726 | return []blueprint.Variation{ |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 727 | {Mutator: "os", Variation: target.OsVariation()}, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 728 | {Mutator: "arch", Variation: target.ArchVariation()}, |
| 729 | } |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 730 | } |
| 731 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 732 | func 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 Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 786 | // 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 Levillain | f5b635d | 2019-06-05 14:42:57 +0100 | [diff] [blame] | 792 | // If host is supported for the module, the Host and HostCross OsClasses are selected. If device is supported |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 793 | // for the module, the Device OsClass is selected. |
| 794 | // Within each selected OsClass, the multilib selection is determined by: |
Jaewoong Jung | 02b2d4d | 2019-06-06 15:19:57 -0700 | [diff] [blame] | 795 | // - The compile_multilib property if it set (which may be overridden by target.android.compile_multilib or |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 796 | // 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 Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 810 | func archMutator(mctx BottomUpMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 811 | var module Module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 812 | var ok bool |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 813 | if module, ok = mctx.Module().(Module); !ok { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 814 | return |
| 815 | } |
| 816 | |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 817 | base := module.base() |
| 818 | |
| 819 | if !base.ArchSpecific() { |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 820 | return |
| 821 | } |
| 822 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 823 | os := base.commonProperties.CompileOS |
| 824 | osTargets := mctx.Config().Targets[os] |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 825 | image := base.commonProperties.ImageVariation |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 826 | // Filter NativeBridge targets unless they are explicitly supported |
Colin Cross | 83bead4 | 2019-12-18 10:45:46 -0800 | [diff] [blame] | 827 | // Skip creating native bridge variants for vendor modules |
| 828 | if os == Android && |
| 829 | !(Bool(base.commonProperties.Native_bridge_supported) && image == CoreVariation) { |
| 830 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 831 | var targets []Target |
| 832 | for _, t := range osTargets { |
| 833 | if !t.NativeBridge { |
| 834 | targets = append(targets, t) |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 835 | } |
| 836 | } |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 837 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 838 | osTargets = targets |
| 839 | } |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 840 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 841 | // only the primary arch in the recovery partition |
| 842 | if os == Android && module.InstallInRecovery() { |
| 843 | osTargets = []Target{osTargets[0]} |
| 844 | } |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 845 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 846 | prefer32 := false |
| 847 | if base.prefer32 != nil { |
| 848 | prefer32 = base.prefer32(mctx, base, os.Class) |
| 849 | } |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 850 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 851 | 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 Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 856 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 857 | var multiTargets []Target |
| 858 | if extraMultilib != "" { |
| 859 | multiTargets, err = decodeMultilibTargets(extraMultilib, osTargets, prefer32) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 860 | if err != nil { |
| 861 | mctx.ModuleErrorf("%s", err.Error()) |
| 862 | } |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 865 | if image == RecoveryVariation { |
| 866 | primaryArch := mctx.Config().DevicePrimaryArchType() |
| 867 | targets = filterToArch(targets, primaryArch) |
| 868 | multiTargets = filterToArch(multiTargets, primaryArch) |
| 869 | } |
| 870 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 871 | if len(targets) == 0 { |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 872 | base.commonProperties.Enabled = boolPtr(false) |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 873 | return |
| 874 | } |
| 875 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 876 | targetNames := make([]string, len(targets)) |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 877 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 878 | for i, target := range targets { |
| 879 | targetNames[i] = target.ArchVariation() |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | modules := mctx.CreateVariations(targetNames...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 883 | for i, m := range modules { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 884 | 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 Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 889 | m.(Module).base().setArchProperties(mctx) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 893 | func 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 Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 919 | func 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 Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame^] | 929 | type archPropTypeDesc struct { |
| 930 | arch, multilib, target reflect.Type |
| 931 | } |
| 932 | |
| 933 | type 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. |
| 940 | func createArchPropTypeDesc(props reflect.Type) []archPropTypeDesc { |
Colin Cross | 7444910 | 2019-09-25 11:26:40 -0700 | [diff] [blame] | 941 | propShards, _ := proptools.FilterPropertyStructSharded(props, filterArchStruct) |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 942 | if len(propShards) == 0 { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 943 | return nil |
| 944 | } |
| 945 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame^] | 946 | var ret []archPropTypeDesc |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 947 | for _, props := range propShards { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 948 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 949 | variantFields := func(names []string) []reflect.StructField { |
| 950 | ret := make([]reflect.StructField, len(names)) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 951 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 952 | for i, name := range names { |
| 953 | ret[i].Name = name |
| 954 | ret[i].Type = props |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 955 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 956 | |
| 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 Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 1017 | } |
| 1018 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1019 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1020 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1021 | targetType := reflect.StructOf(variantFields(targets)) |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame^] | 1022 | |
| 1023 | ret = append(ret, archPropTypeDesc{ |
| 1024 | arch: reflect.PtrTo(archType), |
| 1025 | multilib: reflect.PtrTo(multilibType), |
| 1026 | target: reflect.PtrTo(targetType), |
| 1027 | }) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1028 | } |
| 1029 | return ret |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
Colin Cross | 7444910 | 2019-09-25 11:26:40 -0700 | [diff] [blame] | 1032 | func 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 Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1049 | var archPropTypeMap OncePer |
| 1050 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1051 | func InitArchModule(m Module) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1052 | |
| 1053 | base := m.base() |
| 1054 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1055 | base.generalProperties = m.GetProperties() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1056 | |
| 1057 | for _, properties := range base.generalProperties { |
| 1058 | propertiesValue := reflect.ValueOf(properties) |
Colin Cross | 62496a0 | 2016-08-08 15:49:17 -0700 | [diff] [blame] | 1059 | t := propertiesValue.Type() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1060 | if propertiesValue.Kind() != reflect.Ptr { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1061 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 1062 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | propertiesValue = propertiesValue.Elem() |
| 1066 | if propertiesValue.Kind() != reflect.Struct { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1067 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 1068 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1069 | } |
| 1070 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1071 | archPropTypes := archPropTypeMap.Once(NewCustomOnceKey(t), func() interface{} { |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame^] | 1072 | return createArchPropTypeDesc(t) |
| 1073 | }).([]archPropTypeDesc) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1074 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1075 | var archProperties []interface{} |
| 1076 | for _, t := range archPropTypes { |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame^] | 1077 | 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 Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1082 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1083 | base.archProperties = append(base.archProperties, archProperties) |
| 1084 | m.AddProperties(archProperties...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1085 | } |
| 1086 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1087 | base.customizableProperties = m.GetProperties() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1088 | } |
| 1089 | |
Colin Cross | a716add | 2015-12-16 11:07:39 -0800 | [diff] [blame] | 1090 | var variantReplacer = strings.NewReplacer("-", "_", ".", "_") |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 1091 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1092 | func (m *ModuleBase) appendProperties(ctx BottomUpMutatorContext, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1093 | dst interface{}, src reflect.Value, field, srcPrefix string) reflect.Value { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1094 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame^] | 1095 | if src.Kind() == reflect.Ptr { |
| 1096 | if src.IsNil() { |
| 1097 | return src |
| 1098 | } |
| 1099 | src = src.Elem() |
| 1100 | } |
| 1101 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1102 | src = src.FieldByName(field) |
| 1103 | if !src.IsValid() { |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1104 | ctx.ModuleErrorf("field %q does not exist", srcPrefix) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1105 | return src |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 1106 | } |
| 1107 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1108 | ret := src |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 1109 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1110 | if src.Kind() == reflect.Struct { |
| 1111 | src = src.FieldByName("BlueprintEmbed") |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Colin Cross | 6ee75b6 | 2016-05-05 15:57:15 -0700 | [diff] [blame] | 1114 | 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 Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1124 | err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, order) |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1125 | 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 Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 1132 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1133 | return ret |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1136 | // Rewrite the module's properties structs to contain os-specific values. |
| 1137 | func (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 Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame^] | 1148 | targetProp := archPropValues.FieldByName("Target").Elem() |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1149 | |
| 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 Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1230 | // Rewrite the module's properties structs to contain arch-specific values. |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1231 | func (m *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) { |
| 1232 | arch := m.Arch() |
| 1233 | os := m.Os() |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 1234 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1235 | for i := range m.generalProperties { |
| 1236 | genProps := m.generalProperties[i] |
| 1237 | if m.archProperties[i] == nil { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1238 | continue |
| 1239 | } |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1240 | for _, archProperties := range m.archProperties[i] { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1241 | archPropValues := reflect.ValueOf(archProperties).Elem() |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1242 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame^] | 1243 | archProp := archPropValues.FieldByName("Arch").Elem() |
| 1244 | multilibProp := archPropValues.FieldByName("Multilib").Elem() |
| 1245 | targetProp := archPropValues.FieldByName("Target").Elem() |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1246 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1247 | // Handle arch-specific properties in the form: |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1248 | // arch: { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1249 | // arm64: { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1250 | // key: value, |
| 1251 | // }, |
| 1252 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1253 | t := arch.ArchType |
| 1254 | |
| 1255 | if arch.ArchType != Common { |
| 1256 | field := proptools.FieldNameForProperty(t.Name) |
| 1257 | prefix := "arch." + t.Name |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1258 | archStruct := m.appendProperties(ctx, genProps, archProp, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1259 | |
| 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 Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1270 | m.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1271 | } |
| 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 Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1284 | m.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1285 | } |
| 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 Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1297 | m.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1298 | } |
| 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 Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1308 | m.appendProperties(ctx, genProps, multilibProp, field, prefix) |
Colin Cross | 0801633 | 2016-12-20 09:53:14 -0800 | [diff] [blame] | 1309 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1310 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1311 | // Handle combined OS-feature and arch specific properties in the form: |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1312 | // target: { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1313 | // bionic_x86: { |
| 1314 | // key: value, |
| 1315 | // }, |
| 1316 | // } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1317 | if os.Linux() && arch.ArchType != Common { |
| 1318 | field := "Linux_" + arch.ArchType.Name |
| 1319 | prefix := "target.linux_" + arch.ArchType.Name |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1320 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1321 | } |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1322 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1323 | if os.Bionic() && arch.ArchType != Common { |
| 1324 | field := "Bionic_" + t.Name |
| 1325 | prefix := "target.bionic_" + t.Name |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1326 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1329 | // Handle combined OS and arch specific properties in the form: |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1330 | // target: { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1331 | // linux_glibc_x86: { |
| 1332 | // key: value, |
| 1333 | // }, |
| 1334 | // linux_glibc_arm: { |
| 1335 | // key: value, |
| 1336 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1337 | // android_arm { |
| 1338 | // key: value, |
| 1339 | // }, |
| 1340 | // android_x86 { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1341 | // key: value, |
| 1342 | // }, |
| 1343 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1344 | if arch.ArchType != Common { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1345 | field := os.Field + "_" + t.Name |
| 1346 | prefix := "target." + os.Name + "_" + t.Name |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1347 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1350 | // Handle arm on x86 properties in the form: |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1351 | // target { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1352 | // arm_on_x86 { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1353 | // key: value, |
| 1354 | // }, |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1355 | // arm_on_x86_64 { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1356 | // key: value, |
| 1357 | // }, |
| 1358 | // }, |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1359 | // TODO(ccross): is this still necessary with native bridge? |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1360 | if os.Class == Device { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1361 | 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 Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1367 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1368 | } |
| 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 Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1375 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1376 | } |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 1377 | } |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1378 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | func 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 Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1396 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1397 | // Convert the arch product variables into a list of targets for each os class structs |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1398 | func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1399 | variables := config.productVariables |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1400 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1401 | targets := make(map[OsType][]Target) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1402 | var targetErr error |
| 1403 | |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1404 | addTarget := func(os OsType, archName string, archVariant, cpuVariant *string, abi []string, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1405 | nativeBridgeEnabled NativeBridgeSupport, nativeBridgeHostArchName *string, |
| 1406 | nativeBridgeRelativePath *string) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1407 | if targetErr != nil { |
| 1408 | return |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1409 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1410 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1411 | arch, err := decodeArch(os, archName, archVariant, cpuVariant, abi) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1412 | if err != nil { |
| 1413 | targetErr = err |
| 1414 | return |
| 1415 | } |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1416 | 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 Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1423 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1424 | targets[os] = append(targets[os], |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1425 | Target{ |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1426 | Os: os, |
| 1427 | Arch: arch, |
| 1428 | NativeBridge: nativeBridgeEnabled, |
| 1429 | NativeBridgeHostArchName: nativeBridgeHostArchNameStr, |
| 1430 | NativeBridgeRelativePath: nativeBridgeRelativePathStr, |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1431 | }) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1432 | } |
| 1433 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1434 | if variables.HostArch == nil { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1435 | return nil, fmt.Errorf("No host primary architecture set") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1438 | addTarget(BuildOs, *variables.HostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1439 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1440 | if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1441 | addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1442 | } |
| 1443 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1444 | if Bool(config.Host_bionic) { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1445 | addTarget(LinuxBionic, "x86_64", nil, nil, nil, NativeBridgeDisabled, nil, nil) |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1448 | if String(variables.CrossHost) != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1449 | crossHostOs := osByName(*variables.CrossHost) |
| 1450 | if crossHostOs == NoOsType { |
| 1451 | return nil, fmt.Errorf("Unknown cross host OS %q", *variables.CrossHost) |
| 1452 | } |
| 1453 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1454 | if String(variables.CrossHostArch) == "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1455 | return nil, fmt.Errorf("No cross-host primary architecture set") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1456 | } |
| 1457 | |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1458 | addTarget(crossHostOs, *variables.CrossHostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1459 | |
| 1460 | if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1461 | addTarget(crossHostOs, *variables.CrossHostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1462 | } |
| 1463 | } |
| 1464 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1465 | if variables.DeviceArch != nil && *variables.DeviceArch != "" { |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 1466 | var target = Android |
| 1467 | if Bool(variables.Fuchsia) { |
| 1468 | target = Fuchsia |
| 1469 | } |
| 1470 | |
| 1471 | addTarget(target, *variables.DeviceArch, variables.DeviceArchVariant, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1472 | variables.DeviceCpuVariant, variables.DeviceAbi, NativeBridgeDisabled, nil, nil) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1473 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1474 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" { |
| 1475 | addTarget(Android, *variables.DeviceSecondaryArch, |
| 1476 | variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1477 | variables.DeviceSecondaryAbi, NativeBridgeDisabled, nil, nil) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1478 | } |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1479 | |
| 1480 | if variables.NativeBridgeArch != nil && *variables.NativeBridgeArch != "" { |
| 1481 | addTarget(Android, *variables.NativeBridgeArch, |
| 1482 | variables.NativeBridgeArchVariant, variables.NativeBridgeCpuVariant, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1483 | variables.NativeBridgeAbi, NativeBridgeEnabled, variables.DeviceArch, |
| 1484 | variables.NativeBridgeRelativePath) |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1485 | } |
| 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, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1492 | variables.NativeBridgeSecondaryAbi, |
| 1493 | NativeBridgeEnabled, |
| 1494 | variables.DeviceSecondaryArch, |
| 1495 | variables.NativeBridgeSecondaryRelativePath) |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1496 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1499 | if targetErr != nil { |
| 1500 | return nil, targetErr |
| 1501 | } |
| 1502 | |
| 1503 | return targets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1504 | } |
| 1505 | |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1506 | // hasArmAbi returns true if arch has at least one arm ABI |
| 1507 | func 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 | |
dimitry | 628db6f | 2019-05-22 17:16:21 +0200 | [diff] [blame] | 1516 | // hasArmArch returns true if targets has at least non-native_bridge arm Android arch |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 1517 | func hasArmAndroidArch(targets []Target) bool { |
| 1518 | for _, target := range targets { |
dimitry | 628db6f | 2019-05-22 17:16:21 +0200 | [diff] [blame] | 1519 | if target.Os == Android && target.Arch.ArchType == Arm && target.NativeBridge == NativeBridgeDisabled { |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 1520 | return true |
| 1521 | } |
| 1522 | } |
| 1523 | return false |
| 1524 | } |
| 1525 | |
Victor Khimenko | 5eb8ec1 | 2018-03-21 20:30:54 +0100 | [diff] [blame] | 1526 | // hasX86Arch returns true if targets has at least x86 Android arch |
| 1527 | func 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 |
| 1537 | func 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 Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1546 | type archConfig struct { |
| 1547 | arch string |
| 1548 | archVariant string |
| 1549 | cpuVariant string |
| 1550 | abi []string |
| 1551 | } |
| 1552 | |
| 1553 | func getMegaDeviceConfig() []archConfig { |
| 1554 | return []archConfig{ |
Dan Albert | 8818f49 | 2019-02-19 13:53:01 -0800 | [diff] [blame] | 1555 | {"arm", "armv7-a", "generic", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 1556 | {"arm", "armv7-a-neon", "generic", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1557 | {"arm", "armv7-a-neon", "cortex-a7", []string{"armeabi-v7a"}}, |
| 1558 | {"arm", "armv7-a-neon", "cortex-a8", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 1559 | {"arm", "armv7-a-neon", "cortex-a9", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1560 | {"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 Fung | eb37ed3 | 2018-09-24 16:33:45 -0700 | [diff] [blame] | 1563 | {"arm", "armv7-a-neon", "cortex-a72", []string{"armeabi-v7a"}}, |
Jake Weinstein | 6600a44 | 2017-05-15 18:27:12 -0400 | [diff] [blame] | 1564 | {"arm", "armv7-a-neon", "cortex-a73", []string{"armeabi-v7a"}}, |
Christopher Ferris | ba14a8f | 2018-04-23 18:15:25 -0700 | [diff] [blame] | 1565 | {"arm", "armv7-a-neon", "cortex-a75", []string{"armeabi-v7a"}}, |
Haibo Huang | a31e2bd | 2018-10-09 14:27:28 -0700 | [diff] [blame] | 1566 | {"arm", "armv7-a-neon", "cortex-a76", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1567 | {"arm", "armv7-a-neon", "krait", []string{"armeabi-v7a"}}, |
Alex Naidis | ae4fc18 | 2016-08-20 00:14:56 +0200 | [diff] [blame] | 1568 | {"arm", "armv7-a-neon", "kryo", []string{"armeabi-v7a"}}, |
Artem Serov | d3072b0 | 2018-11-15 15:21:51 +0000 | [diff] [blame] | 1569 | {"arm", "armv7-a-neon", "kryo385", []string{"armeabi-v7a"}}, |
Junmo Park | 8ea4959 | 2017-07-24 07:14:55 +0900 | [diff] [blame] | 1570 | {"arm", "armv7-a-neon", "exynos-m1", []string{"armeabi-v7a"}}, |
Junmo Park | d86c902 | 2017-07-21 09:07:47 +0900 | [diff] [blame] | 1571 | {"arm", "armv7-a-neon", "exynos-m2", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 1572 | {"arm64", "armv8-a", "cortex-a53", []string{"arm64-v8a"}}, |
Richard Fung | eb37ed3 | 2018-09-24 16:33:45 -0700 | [diff] [blame] | 1573 | {"arm64", "armv8-a", "cortex-a72", []string{"arm64-v8a"}}, |
Jake Weinstein | 6600a44 | 2017-05-15 18:27:12 -0400 | [diff] [blame] | 1574 | {"arm64", "armv8-a", "cortex-a73", []string{"arm64-v8a"}}, |
Alex Naidis | ac01ff5 | 2016-08-30 15:56:33 +0200 | [diff] [blame] | 1575 | {"arm64", "armv8-a", "kryo", []string{"arm64-v8a"}}, |
Junmo Park | 8ea4959 | 2017-07-24 07:14:55 +0900 | [diff] [blame] | 1576 | {"arm64", "armv8-a", "exynos-m1", []string{"arm64-v8a"}}, |
Junmo Park | d86c902 | 2017-07-21 09:07:47 +0900 | [diff] [blame] | 1577 | {"arm64", "armv8-a", "exynos-m2", []string{"arm64-v8a"}}, |
Christopher Ferris | ba14a8f | 2018-04-23 18:15:25 -0700 | [diff] [blame] | 1578 | {"arm64", "armv8-2a", "cortex-a75", []string{"arm64-v8a"}}, |
Haibo Huang | a31e2bd | 2018-10-09 14:27:28 -0700 | [diff] [blame] | 1579 | {"arm64", "armv8-2a", "cortex-a76", []string{"arm64-v8a"}}, |
Artem Serov | d3072b0 | 2018-11-15 15:21:51 +0000 | [diff] [blame] | 1580 | {"arm64", "armv8-2a", "kryo385", []string{"arm64-v8a"}}, |
Dan Willemsen | 468cc31 | 2016-01-13 23:25:19 -0800 | [diff] [blame] | 1581 | {"mips", "mips32-fp", "", []string{"mips"}}, |
| 1582 | {"mips", "mips32r2-fp", "", []string{"mips"}}, |
| 1583 | {"mips", "mips32r2-fp-xburst", "", []string{"mips"}}, |
Dan Willemsen | 65fb981 | 2016-07-19 21:37:28 -0700 | [diff] [blame] | 1584 | //{"mips", "mips32r6", "", []string{"mips"}}, |
Colin Cross | 1837b80 | 2017-04-26 19:10:34 -0700 | [diff] [blame] | 1585 | {"mips", "mips32r2dsp-fp", "", []string{"mips"}}, |
| 1586 | {"mips", "mips32r2dspr2-fp", "", []string{"mips"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1587 | // 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 Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 1596 | {"x86", "stoneyridge", "", []string{"x86"}}, |
Dan Willemsen | 8a35405 | 2016-05-10 14:30:51 -0700 | [diff] [blame] | 1597 | {"x86", "x86_64", "", []string{"x86"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1598 | {"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 Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 1603 | {"x86_64", "stoneyridge", "", []string{"x86_64"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1604 | } |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1605 | } |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1606 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1607 | func getNdkAbisConfig() []archConfig { |
| 1608 | return []archConfig{ |
Dan Albert | 8818f49 | 2019-02-19 13:53:01 -0800 | [diff] [blame] | 1609 | {"arm", "armv7-a", "", []string{"armeabi"}}, |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1610 | {"arm64", "armv8-a", "", []string{"arm64-v8a"}}, |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1611 | {"x86", "", "", []string{"x86"}}, |
| 1612 | {"x86_64", "", "", []string{"x86_64"}}, |
| 1613 | } |
| 1614 | } |
| 1615 | |
Martin Stjernholm | c1ecc43 | 2019-11-15 15:00:31 +0000 | [diff] [blame] | 1616 | func 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 Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1625 | func decodeArchSettings(os OsType, archConfigs []archConfig) ([]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1626 | var ret []Target |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1627 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1628 | for _, config := range archConfigs { |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1629 | arch, err := decodeArch(os, config.arch, &config.archVariant, |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1630 | &config.cpuVariant, config.abi) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1631 | if err != nil { |
| 1632 | return nil, err |
| 1633 | } |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 1634 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1635 | ret = append(ret, Target{ |
| 1636 | Os: Android, |
| 1637 | Arch: arch, |
| 1638 | }) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | return ret, nil |
| 1642 | } |
| 1643 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1644 | // Convert a set of strings from product variables into a single Arch struct |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1645 | func decodeArch(os OsType, arch string, archVariant, cpuVariant *string, abi []string) (Arch, error) { |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1646 | stringPtr := func(p *string) string { |
| 1647 | if p != nil { |
| 1648 | return *p |
| 1649 | } |
| 1650 | return "" |
| 1651 | } |
| 1652 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1653 | archType, ok := archTypeMap[arch] |
| 1654 | if !ok { |
| 1655 | return Arch{}, fmt.Errorf("unknown arch %q", arch) |
| 1656 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1657 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1658 | a := Arch{ |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1659 | ArchType: archType, |
| 1660 | ArchVariant: stringPtr(archVariant), |
| 1661 | CpuVariant: stringPtr(cpuVariant), |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1662 | Abi: abi, |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1663 | } |
| 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 Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1680 | 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 Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1688 | } |
| 1689 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1690 | return a, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1693 | func 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 Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 1703 | func 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 Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1717 | func firstTarget(targets []Target, filters ...string) []Target { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1718 | for _, filter := range filters { |
| 1719 | buildTargets := filterMultilibTargets(targets, filter) |
| 1720 | if len(buildTargets) > 0 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1721 | return buildTargets[:1] |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1722 | } |
| 1723 | } |
| 1724 | return nil |
| 1725 | } |
| 1726 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1727 | // Use the module multilib setting to select one or more targets from a target list |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 1728 | func decodeMultilibTargets(multilib string, targets []Target, prefer32 bool) ([]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1729 | buildTargets := []Target{} |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1730 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1731 | switch multilib { |
| 1732 | case "common": |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1733 | buildTargets = getCommonTargets(targets) |
| 1734 | case "common_first": |
| 1735 | buildTargets = getCommonTargets(targets) |
| 1736 | if prefer32 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1737 | buildTargets = append(buildTargets, firstTarget(targets, "lib32", "lib64")...) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1738 | } else { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1739 | buildTargets = append(buildTargets, firstTarget(targets, "lib64", "lib32")...) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1740 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1741 | case "both": |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 1742 | 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 Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1749 | case "32": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1750 | buildTargets = filterMultilibTargets(targets, "lib32") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1751 | case "64": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1752 | buildTargets = filterMultilibTargets(targets, "lib64") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1753 | case "first": |
| 1754 | if prefer32 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1755 | buildTargets = firstTarget(targets, "lib32", "lib64") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1756 | } else { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1757 | buildTargets = firstTarget(targets, "lib64", "lib32") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1758 | } |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1759 | case "prefer32": |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1760 | buildTargets = filterMultilibTargets(targets, "lib32") |
| 1761 | if len(buildTargets) == 0 { |
| 1762 | buildTargets = filterMultilibTargets(targets, "lib64") |
| 1763 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1764 | default: |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1765 | return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", "64", or "prefer32" found %q`, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1766 | multilib) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1769 | return buildTargets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1770 | } |