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 | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame^] | 26 | "github.com/google/blueprint/bootstrap" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 28 | ) |
| 29 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 30 | const COMMON_VARIANT = "common" |
| 31 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 32 | var ( |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 33 | archTypeList []ArchType |
| 34 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 35 | Arm = newArch("arm", "lib32") |
| 36 | Arm64 = newArch("arm64", "lib64") |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 37 | X86 = newArch("x86", "lib32") |
| 38 | X86_64 = newArch("x86_64", "lib64") |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 39 | |
| 40 | Common = ArchType{ |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 41 | Name: COMMON_VARIANT, |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 42 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 43 | ) |
| 44 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 45 | var archTypeMap = map[string]ArchType{ |
| 46 | "arm": Arm, |
| 47 | "arm64": Arm64, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 48 | "x86": X86, |
| 49 | "x86_64": X86_64, |
| 50 | } |
| 51 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 52 | /* |
| 53 | Example blueprints file containing all variant property groups, with comment listing what type |
| 54 | of variants get properties in that group: |
| 55 | |
| 56 | module { |
| 57 | arch: { |
| 58 | arm: { |
| 59 | // Host or device variants with arm architecture |
| 60 | }, |
| 61 | arm64: { |
| 62 | // Host or device variants with arm64 architecture |
| 63 | }, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 64 | x86: { |
| 65 | // Host or device variants with x86 architecture |
| 66 | }, |
| 67 | x86_64: { |
| 68 | // Host or device variants with x86_64 architecture |
| 69 | }, |
| 70 | }, |
| 71 | multilib: { |
| 72 | lib32: { |
| 73 | // Host or device variants for 32-bit architectures |
| 74 | }, |
| 75 | lib64: { |
| 76 | // Host or device variants for 64-bit architectures |
| 77 | }, |
| 78 | }, |
| 79 | target: { |
| 80 | android: { |
| 81 | // Device variants |
| 82 | }, |
| 83 | host: { |
| 84 | // Host variants |
| 85 | }, |
Dan Willemsen | 5746bd4 | 2017-10-02 19:42:01 -0700 | [diff] [blame] | 86 | linux_glibc: { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 87 | // Linux host variants |
| 88 | }, |
| 89 | darwin: { |
| 90 | // Darwin host variants |
| 91 | }, |
| 92 | windows: { |
| 93 | // Windows host variants |
| 94 | }, |
| 95 | not_windows: { |
| 96 | // Non-windows host variants |
| 97 | }, |
| 98 | }, |
| 99 | } |
| 100 | */ |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 101 | |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 102 | var archVariants = map[ArchType][]string{ |
| 103 | Arm: { |
Dan Albert | 8818f49 | 2019-02-19 13:53:01 -0800 | [diff] [blame] | 104 | "armv7-a", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 105 | "armv7-a-neon", |
| 106 | "armv8-a", |
| 107 | "armv8-2a", |
| 108 | "cortex-a7", |
| 109 | "cortex-a8", |
| 110 | "cortex-a9", |
| 111 | "cortex-a15", |
| 112 | "cortex-a53", |
| 113 | "cortex-a53-a57", |
| 114 | "cortex-a55", |
| 115 | "cortex-a72", |
| 116 | "cortex-a73", |
| 117 | "cortex-a75", |
| 118 | "cortex-a76", |
| 119 | "krait", |
| 120 | "kryo", |
| 121 | "kryo385", |
| 122 | "exynos-m1", |
| 123 | "exynos-m2", |
| 124 | }, |
| 125 | Arm64: { |
| 126 | "armv8_a", |
| 127 | "armv8_2a", |
| 128 | "cortex-a53", |
| 129 | "cortex-a55", |
| 130 | "cortex-a72", |
| 131 | "cortex-a73", |
| 132 | "cortex-a75", |
| 133 | "cortex-a76", |
| 134 | "kryo", |
| 135 | "kryo385", |
| 136 | "exynos-m1", |
| 137 | "exynos-m2", |
| 138 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 139 | X86: { |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 140 | "amberlake", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 141 | "atom", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 142 | "broadwell", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 143 | "haswell", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 144 | "icelake", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 145 | "ivybridge", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 146 | "kabylake", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 147 | "sandybridge", |
| 148 | "silvermont", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 149 | "skylake", |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 150 | "stoneyridge", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 151 | "tigerlake", |
| 152 | "whiskeylake", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 153 | "x86_64", |
| 154 | }, |
| 155 | X86_64: { |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 156 | "amberlake", |
| 157 | "broadwell", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 158 | "haswell", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 159 | "icelake", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 160 | "ivybridge", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 161 | "kabylake", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 162 | "sandybridge", |
| 163 | "silvermont", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 164 | "skylake", |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 165 | "stoneyridge", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 166 | "tigerlake", |
| 167 | "whiskeylake", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 168 | }, |
| 169 | } |
| 170 | |
| 171 | var archFeatures = map[ArchType][]string{ |
| 172 | Arm: { |
| 173 | "neon", |
| 174 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 175 | X86: { |
| 176 | "ssse3", |
| 177 | "sse4", |
| 178 | "sse4_1", |
| 179 | "sse4_2", |
| 180 | "aes_ni", |
| 181 | "avx", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 182 | "avx2", |
| 183 | "avx512", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 184 | "popcnt", |
| 185 | "movbe", |
| 186 | }, |
| 187 | X86_64: { |
| 188 | "ssse3", |
| 189 | "sse4", |
| 190 | "sse4_1", |
| 191 | "sse4_2", |
| 192 | "aes_ni", |
| 193 | "avx", |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 194 | "avx2", |
| 195 | "avx512", |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 196 | "popcnt", |
| 197 | }, |
| 198 | } |
| 199 | |
| 200 | var archFeatureMap = map[ArchType]map[string][]string{ |
| 201 | Arm: { |
| 202 | "armv7-a-neon": { |
| 203 | "neon", |
| 204 | }, |
| 205 | "armv8-a": { |
| 206 | "neon", |
| 207 | }, |
| 208 | "armv8-2a": { |
| 209 | "neon", |
| 210 | }, |
| 211 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 212 | X86: { |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 213 | "amberlake": { |
| 214 | "ssse3", |
| 215 | "sse4", |
| 216 | "sse4_1", |
| 217 | "sse4_2", |
| 218 | "avx", |
| 219 | "avx2", |
| 220 | "aes_ni", |
| 221 | "popcnt", |
| 222 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 223 | "atom": { |
| 224 | "ssse3", |
| 225 | "movbe", |
| 226 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 227 | "broadwell": { |
| 228 | "ssse3", |
| 229 | "sse4", |
| 230 | "sse4_1", |
| 231 | "sse4_2", |
| 232 | "avx", |
| 233 | "avx2", |
| 234 | "aes_ni", |
| 235 | "popcnt", |
| 236 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 237 | "haswell": { |
| 238 | "ssse3", |
| 239 | "sse4", |
| 240 | "sse4_1", |
| 241 | "sse4_2", |
| 242 | "aes_ni", |
| 243 | "avx", |
| 244 | "popcnt", |
| 245 | "movbe", |
| 246 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 247 | "icelake": { |
| 248 | "ssse3", |
| 249 | "sse4", |
| 250 | "sse4_1", |
| 251 | "sse4_2", |
| 252 | "avx", |
| 253 | "avx2", |
| 254 | "avx512", |
| 255 | "aes_ni", |
| 256 | "popcnt", |
| 257 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 258 | "ivybridge": { |
| 259 | "ssse3", |
| 260 | "sse4", |
| 261 | "sse4_1", |
| 262 | "sse4_2", |
| 263 | "aes_ni", |
| 264 | "avx", |
| 265 | "popcnt", |
| 266 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 267 | "kabylake": { |
| 268 | "ssse3", |
| 269 | "sse4", |
| 270 | "sse4_1", |
| 271 | "sse4_2", |
| 272 | "avx", |
| 273 | "avx2", |
| 274 | "aes_ni", |
| 275 | "popcnt", |
| 276 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 277 | "sandybridge": { |
| 278 | "ssse3", |
| 279 | "sse4", |
| 280 | "sse4_1", |
| 281 | "sse4_2", |
| 282 | "popcnt", |
| 283 | }, |
| 284 | "silvermont": { |
| 285 | "ssse3", |
| 286 | "sse4", |
| 287 | "sse4_1", |
| 288 | "sse4_2", |
| 289 | "aes_ni", |
| 290 | "popcnt", |
| 291 | "movbe", |
| 292 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 293 | "skylake": { |
| 294 | "ssse3", |
| 295 | "sse4", |
| 296 | "sse4_1", |
| 297 | "sse4_2", |
| 298 | "avx", |
| 299 | "avx2", |
| 300 | "avx512", |
| 301 | "aes_ni", |
| 302 | "popcnt", |
| 303 | }, |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 304 | "stoneyridge": { |
| 305 | "ssse3", |
| 306 | "sse4", |
| 307 | "sse4_1", |
| 308 | "sse4_2", |
| 309 | "aes_ni", |
| 310 | "avx", |
| 311 | "avx2", |
| 312 | "popcnt", |
| 313 | "movbe", |
| 314 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 315 | "tigerlake": { |
| 316 | "ssse3", |
| 317 | "sse4", |
| 318 | "sse4_1", |
| 319 | "sse4_2", |
| 320 | "avx", |
| 321 | "avx2", |
| 322 | "avx512", |
| 323 | "aes_ni", |
| 324 | "popcnt", |
| 325 | }, |
| 326 | "whiskeylake": { |
| 327 | "ssse3", |
| 328 | "sse4", |
| 329 | "sse4_1", |
| 330 | "sse4_2", |
| 331 | "avx", |
| 332 | "avx2", |
| 333 | "avx512", |
| 334 | "aes_ni", |
| 335 | "popcnt", |
| 336 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 337 | "x86_64": { |
| 338 | "ssse3", |
| 339 | "sse4", |
| 340 | "sse4_1", |
| 341 | "sse4_2", |
| 342 | "popcnt", |
| 343 | }, |
| 344 | }, |
| 345 | X86_64: { |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 346 | "amberlake": { |
| 347 | "ssse3", |
| 348 | "sse4", |
| 349 | "sse4_1", |
| 350 | "sse4_2", |
| 351 | "avx", |
| 352 | "avx2", |
| 353 | "aes_ni", |
| 354 | "popcnt", |
| 355 | }, |
| 356 | "broadwell": { |
| 357 | "ssse3", |
| 358 | "sse4", |
| 359 | "sse4_1", |
| 360 | "sse4_2", |
| 361 | "avx", |
| 362 | "avx2", |
| 363 | "aes_ni", |
| 364 | "popcnt", |
| 365 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 366 | "haswell": { |
| 367 | "ssse3", |
| 368 | "sse4", |
| 369 | "sse4_1", |
| 370 | "sse4_2", |
| 371 | "aes_ni", |
| 372 | "avx", |
| 373 | "popcnt", |
| 374 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 375 | "icelake": { |
| 376 | "ssse3", |
| 377 | "sse4", |
| 378 | "sse4_1", |
| 379 | "sse4_2", |
| 380 | "avx", |
| 381 | "avx2", |
| 382 | "avx512", |
| 383 | "aes_ni", |
| 384 | "popcnt", |
| 385 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 386 | "ivybridge": { |
| 387 | "ssse3", |
| 388 | "sse4", |
| 389 | "sse4_1", |
| 390 | "sse4_2", |
| 391 | "aes_ni", |
| 392 | "avx", |
| 393 | "popcnt", |
| 394 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 395 | "kabylake": { |
| 396 | "ssse3", |
| 397 | "sse4", |
| 398 | "sse4_1", |
| 399 | "sse4_2", |
| 400 | "avx", |
| 401 | "avx2", |
| 402 | "aes_ni", |
| 403 | "popcnt", |
| 404 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 405 | "sandybridge": { |
| 406 | "ssse3", |
| 407 | "sse4", |
| 408 | "sse4_1", |
| 409 | "sse4_2", |
| 410 | "popcnt", |
| 411 | }, |
| 412 | "silvermont": { |
| 413 | "ssse3", |
| 414 | "sse4", |
| 415 | "sse4_1", |
| 416 | "sse4_2", |
| 417 | "aes_ni", |
| 418 | "popcnt", |
| 419 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 420 | "skylake": { |
| 421 | "ssse3", |
| 422 | "sse4", |
| 423 | "sse4_1", |
| 424 | "sse4_2", |
| 425 | "avx", |
| 426 | "avx2", |
| 427 | "avx512", |
| 428 | "aes_ni", |
| 429 | "popcnt", |
| 430 | }, |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 431 | "stoneyridge": { |
| 432 | "ssse3", |
| 433 | "sse4", |
| 434 | "sse4_1", |
| 435 | "sse4_2", |
| 436 | "aes_ni", |
| 437 | "avx", |
| 438 | "avx2", |
| 439 | "popcnt", |
| 440 | }, |
Shalini Salomi Bodapati | 4a0459d | 2019-01-22 10:00:15 +0530 | [diff] [blame] | 441 | "tigerlake": { |
| 442 | "ssse3", |
| 443 | "sse4", |
| 444 | "sse4_1", |
| 445 | "sse4_2", |
| 446 | "avx", |
| 447 | "avx2", |
| 448 | "avx512", |
| 449 | "aes_ni", |
| 450 | "popcnt", |
| 451 | }, |
| 452 | "whiskeylake": { |
| 453 | "ssse3", |
| 454 | "sse4", |
| 455 | "sse4_1", |
| 456 | "sse4_2", |
| 457 | "avx", |
| 458 | "avx2", |
| 459 | "avx512", |
| 460 | "aes_ni", |
| 461 | "popcnt", |
| 462 | }, |
Jaewoong Jung | e46114c | 2019-01-16 14:33:13 -0800 | [diff] [blame] | 463 | }, |
| 464 | } |
| 465 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 466 | var defaultArchFeatureMap = map[OsType]map[ArchType][]string{} |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 467 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 468 | func RegisterDefaultArchVariantFeatures(os OsType, arch ArchType, features ...string) { |
| 469 | checkCalledFromInit() |
| 470 | |
| 471 | for _, feature := range features { |
| 472 | if !InList(feature, archFeatures[arch]) { |
| 473 | panic(fmt.Errorf("Invalid feature %q for arch %q variant \"\"", feature, arch)) |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | if defaultArchFeatureMap[os] == nil { |
| 478 | defaultArchFeatureMap[os] = make(map[ArchType][]string) |
| 479 | } |
| 480 | defaultArchFeatureMap[os][arch] = features |
| 481 | } |
| 482 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 483 | // An Arch indicates a single CPU architecture. |
| 484 | type Arch struct { |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 485 | ArchType ArchType |
| 486 | ArchVariant string |
| 487 | CpuVariant string |
| 488 | Abi []string |
| 489 | ArchFeatures []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | func (a Arch) String() string { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 493 | s := a.ArchType.String() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 494 | if a.ArchVariant != "" { |
| 495 | s += "_" + a.ArchVariant |
| 496 | } |
| 497 | if a.CpuVariant != "" { |
| 498 | s += "_" + a.CpuVariant |
| 499 | } |
| 500 | return s |
| 501 | } |
| 502 | |
| 503 | type ArchType struct { |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 504 | Name string |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 505 | Field string |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 506 | Multilib string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 507 | } |
| 508 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 509 | func newArch(name, multilib string) ArchType { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 510 | archType := ArchType{ |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 511 | Name: name, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 512 | Field: proptools.FieldNameForProperty(name), |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 513 | Multilib: multilib, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 514 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 515 | archTypeList = append(archTypeList, archType) |
| 516 | return archType |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 517 | } |
| 518 | |
Jaewoong Jung | 1ce9ac6 | 2019-08-13 14:11:33 -0700 | [diff] [blame] | 519 | func ArchTypeList() []ArchType { |
| 520 | return append([]ArchType(nil), archTypeList...) |
| 521 | } |
| 522 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 523 | func (a ArchType) String() string { |
| 524 | return a.Name |
| 525 | } |
| 526 | |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 527 | var _ encoding.TextMarshaler = ArchType{} |
| 528 | |
| 529 | func (a ArchType) MarshalText() ([]byte, error) { |
| 530 | return []byte(strconv.Quote(a.String())), nil |
| 531 | } |
| 532 | |
| 533 | var _ encoding.TextUnmarshaler = &ArchType{} |
| 534 | |
| 535 | func (a *ArchType) UnmarshalText(text []byte) error { |
| 536 | if u, ok := archTypeMap[string(text)]; ok { |
| 537 | *a = u |
| 538 | return nil |
| 539 | } |
| 540 | |
| 541 | return fmt.Errorf("unknown ArchType %q", text) |
| 542 | } |
| 543 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 544 | var BuildOs = func() OsType { |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 545 | switch runtime.GOOS { |
| 546 | case "linux": |
| 547 | return Linux |
| 548 | case "darwin": |
| 549 | return Darwin |
| 550 | default: |
| 551 | panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS)) |
| 552 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 553 | }() |
| 554 | |
| 555 | var ( |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 556 | OsTypeList []OsType |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 557 | commonTargetMap = make(map[string]Target) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 558 | |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 559 | NoOsType OsType |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 560 | Linux = NewOsType("linux_glibc", Host, false) |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 561 | Darwin = NewOsType("darwin", Host, false) |
Dan Willemsen | 9ff34c0 | 2018-10-10 17:58:19 -0700 | [diff] [blame] | 562 | LinuxBionic = NewOsType("linux_bionic", Host, false) |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 563 | Windows = NewOsType("windows", HostCross, true) |
| 564 | Android = NewOsType("android", Device, false) |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 565 | Fuchsia = NewOsType("fuchsia", Device, false) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 566 | |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 567 | // A pseudo OSType for a common os variant, which is OSType agnostic and which |
| 568 | // has dependencies on all the OS variants. |
| 569 | CommonOS = NewOsType("common_os", Generic, false) |
| 570 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 571 | osArchTypeMap = map[OsType][]ArchType{ |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 572 | Linux: []ArchType{X86, X86_64}, |
| 573 | LinuxBionic: []ArchType{X86_64}, |
Dan Willemsen | e97e68a | 2018-08-28 17:12:56 -0700 | [diff] [blame] | 574 | Darwin: []ArchType{X86_64}, |
Dan Willemsen | 00fcbde | 2016-11-17 00:25:59 -0800 | [diff] [blame] | 575 | Windows: []ArchType{X86, X86_64}, |
Elliott Hughes | da3a071 | 2020-03-06 16:55:28 -0800 | [diff] [blame] | 576 | Android: []ArchType{Arm, Arm64, X86, X86_64}, |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 577 | Fuchsia: []ArchType{Arm64, X86_64}, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 578 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 579 | ) |
| 580 | |
| 581 | type OsType struct { |
| 582 | Name, Field string |
| 583 | Class OsClass |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 584 | |
| 585 | DefaultDisabled bool |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 586 | } |
| 587 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 588 | type OsClass int |
| 589 | |
| 590 | const ( |
Dan Willemsen | 0e2d97b | 2016-11-28 17:50:06 -0800 | [diff] [blame] | 591 | Generic OsClass = iota |
| 592 | Device |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 593 | Host |
| 594 | HostCross |
| 595 | ) |
| 596 | |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 597 | func (class OsClass) String() string { |
| 598 | switch class { |
| 599 | case Generic: |
| 600 | return "generic" |
| 601 | case Device: |
| 602 | return "device" |
| 603 | case Host: |
| 604 | return "host" |
| 605 | case HostCross: |
| 606 | return "host cross" |
| 607 | default: |
| 608 | panic(fmt.Errorf("unknown class %d", class)) |
| 609 | } |
| 610 | } |
| 611 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 612 | func (os OsType) String() string { |
| 613 | return os.Name |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 616 | func (os OsType) Bionic() bool { |
| 617 | return os == Android || os == LinuxBionic |
| 618 | } |
| 619 | |
| 620 | func (os OsType) Linux() bool { |
| 621 | return os == Android || os == Linux || os == LinuxBionic |
| 622 | } |
| 623 | |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 624 | func NewOsType(name string, class OsClass, defDisabled bool) OsType { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 625 | os := OsType{ |
| 626 | Name: name, |
| 627 | Field: strings.Title(name), |
| 628 | Class: class, |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 629 | |
| 630 | DefaultDisabled: defDisabled, |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 631 | } |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 632 | OsTypeList = append(OsTypeList, os) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 633 | |
| 634 | if _, found := commonTargetMap[name]; found { |
| 635 | panic(fmt.Errorf("Found Os type duplicate during OsType registration: %q", name)) |
| 636 | } else { |
| 637 | commonTargetMap[name] = Target{Os: os, Arch: Arch{ArchType: Common}} |
| 638 | } |
| 639 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 640 | return os |
| 641 | } |
| 642 | |
| 643 | func osByName(name string) OsType { |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 644 | for _, os := range OsTypeList { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 645 | if os.Name == name { |
| 646 | return os |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | return NoOsType |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 651 | } |
| 652 | |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 653 | type NativeBridgeSupport bool |
| 654 | |
| 655 | const ( |
| 656 | NativeBridgeDisabled NativeBridgeSupport = false |
| 657 | NativeBridgeEnabled NativeBridgeSupport = true |
| 658 | ) |
| 659 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 660 | type Target struct { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 661 | Os OsType |
| 662 | Arch Arch |
| 663 | NativeBridge NativeBridgeSupport |
| 664 | NativeBridgeHostArchName string |
| 665 | NativeBridgeRelativePath string |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 668 | func (target Target) String() string { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 669 | return target.OsVariation() + "_" + target.ArchVariation() |
| 670 | } |
| 671 | |
| 672 | func (target Target) OsVariation() string { |
| 673 | return target.Os.String() |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | func (target Target) ArchVariation() string { |
| 677 | var variation string |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 678 | if target.NativeBridge { |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 679 | variation = "native_bridge_" |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 680 | } |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 681 | variation += target.Arch.String() |
| 682 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 683 | return variation |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | func (target Target) Variations() []blueprint.Variation { |
| 687 | return []blueprint.Variation{ |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 688 | {Mutator: "os", Variation: target.OsVariation()}, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 689 | {Mutator: "arch", Variation: target.ArchVariation()}, |
| 690 | } |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 691 | } |
| 692 | |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame^] | 693 | func osMutator(bpctx blueprint.BottomUpMutatorContext) { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 694 | var module Module |
| 695 | var ok bool |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame^] | 696 | if module, ok = bpctx.Module().(Module); !ok { |
| 697 | if bootstrap.IsBootstrapModule(bpctx.Module()) { |
| 698 | // Bootstrap Go modules are always the build OS or linux bionic. |
| 699 | config := bpctx.Config().(Config) |
| 700 | osNames := []string{config.BuildOSTarget.OsVariation()} |
| 701 | for _, hostCrossTarget := range config.Targets[LinuxBionic] { |
| 702 | if hostCrossTarget.Arch.ArchType == config.BuildOSTarget.Arch.ArchType { |
| 703 | osNames = append(osNames, hostCrossTarget.OsVariation()) |
| 704 | } |
| 705 | } |
| 706 | osNames = FirstUniqueStrings(osNames) |
| 707 | bpctx.CreateVariations(osNames...) |
| 708 | } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 709 | return |
| 710 | } |
| 711 | |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame^] | 712 | // Bootstrap Go module support above requires this mutator to be a |
| 713 | // blueprint.BottomUpMutatorContext because android.BottomUpMutatorContext |
| 714 | // filters out non-Soong modules. Now that we've handled them, create a |
| 715 | // normal android.BottomUpMutatorContext. |
| 716 | mctx := bottomUpMutatorContextFactory(bpctx, module, false) |
| 717 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 718 | base := module.base() |
| 719 | |
| 720 | if !base.ArchSpecific() { |
| 721 | return |
| 722 | } |
| 723 | |
| 724 | osClasses := base.OsClassSupported() |
| 725 | |
| 726 | var moduleOSList []OsType |
| 727 | |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 728 | for _, os := range OsTypeList { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 729 | supportedClass := false |
| 730 | for _, osClass := range osClasses { |
| 731 | if os.Class == osClass { |
| 732 | supportedClass = true |
| 733 | } |
| 734 | } |
| 735 | if !supportedClass { |
| 736 | continue |
| 737 | } |
| 738 | |
| 739 | if len(mctx.Config().Targets[os]) == 0 { |
| 740 | continue |
| 741 | } |
| 742 | |
| 743 | moduleOSList = append(moduleOSList, os) |
| 744 | } |
| 745 | |
| 746 | if len(moduleOSList) == 0 { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 747 | base.Disable() |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 748 | return |
| 749 | } |
| 750 | |
| 751 | osNames := make([]string, len(moduleOSList)) |
| 752 | |
| 753 | for i, os := range moduleOSList { |
| 754 | osNames[i] = os.String() |
| 755 | } |
| 756 | |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 757 | createCommonOSVariant := base.commonProperties.CreateCommonOSVariant |
| 758 | if createCommonOSVariant { |
| 759 | // A CommonOS variant was requested so add it to the list of OS's variants to |
| 760 | // create. It needs to be added to the end because it needs to depend on the |
| 761 | // the other variants in the list returned by CreateVariations(...) and inter |
| 762 | // variant dependencies can only be created from a later variant in that list to |
| 763 | // an earlier one. That is because variants are always processed in the order in |
| 764 | // which they are returned from CreateVariations(...). |
| 765 | osNames = append(osNames, CommonOS.Name) |
| 766 | moduleOSList = append(moduleOSList, CommonOS) |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 767 | } |
| 768 | |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 769 | modules := mctx.CreateVariations(osNames...) |
| 770 | for i, m := range modules { |
| 771 | m.base().commonProperties.CompileOS = moduleOSList[i] |
| 772 | m.base().setOSProperties(mctx) |
| 773 | } |
| 774 | |
| 775 | if createCommonOSVariant { |
| 776 | // A CommonOS variant was requested so add dependencies from it (the last one in |
| 777 | // the list) to the OS type specific variants. |
| 778 | last := len(modules) - 1 |
| 779 | commonOSVariant := modules[last] |
| 780 | commonOSVariant.base().commonProperties.CommonOSVariant = true |
| 781 | for _, module := range modules[0:last] { |
| 782 | // Ignore modules that are enabled. Note, this will only avoid adding |
| 783 | // dependencies on OsType variants that are explicitly disabled in their |
| 784 | // properties. The CommonOS variant will still depend on disabled variants |
| 785 | // if they are disabled afterwards, e.g. in archMutator if |
| 786 | if module.Enabled() { |
| 787 | mctx.AddInterVariantDependency(commonOsToOsSpecificVariantTag, commonOSVariant, module) |
| 788 | } |
| 789 | } |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | // Identifies the dependency from CommonOS variant to the os specific variants. |
| 794 | type commonOSTag struct{ blueprint.BaseDependencyTag } |
| 795 | |
| 796 | var commonOsToOsSpecificVariantTag = commonOSTag{} |
| 797 | |
| 798 | // Get the OsType specific variants for the current CommonOS variant. |
| 799 | // |
| 800 | // The returned list will only contain enabled OsType specific variants of the |
| 801 | // module referenced in the supplied context. An empty list is returned if there |
| 802 | // are no enabled variants or the supplied context is not for an CommonOS |
| 803 | // variant. |
| 804 | func GetOsSpecificVariantsOfCommonOSVariant(mctx BaseModuleContext) []Module { |
| 805 | var variants []Module |
| 806 | mctx.VisitDirectDeps(func(m Module) { |
| 807 | if mctx.OtherModuleDependencyTag(m) == commonOsToOsSpecificVariantTag { |
| 808 | if m.Enabled() { |
| 809 | variants = append(variants, m) |
| 810 | } |
| 811 | } |
| 812 | }) |
| 813 | |
| 814 | return variants |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 817 | // archMutator splits a module into a variant for each Target requested by the module. Target selection |
| 818 | // for a module is in three levels, OsClass, mulitlib, and then Target. |
| 819 | // OsClass selection is determined by: |
| 820 | // - The HostOrDeviceSupported value passed in to InitAndroidArchModule by the module type factory, which selects |
| 821 | // whether the module type can compile for host, device or both. |
| 822 | // - The host_supported and device_supported properties on the module. |
Roland Levillain | f5b635d | 2019-06-05 14:42:57 +0100 | [diff] [blame] | 823 | // 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] | 824 | // for the module, the Device OsClass is selected. |
| 825 | // Within each selected OsClass, the multilib selection is determined by: |
Jaewoong Jung | 02b2d4d | 2019-06-06 15:19:57 -0700 | [diff] [blame] | 826 | // - 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] | 827 | // target.host.compile_multilib). |
| 828 | // - The default multilib passed to InitAndroidArchModule if compile_multilib was not set. |
| 829 | // Valid multilib values include: |
| 830 | // "both": compile for all Targets supported by the OsClass (generally x86_64 and x86, or arm64 and arm). |
| 831 | // "first": compile for only a single preferred Target supported by the OsClass. This is generally x86_64 or arm64, |
Elliott Hughes | 79ae341 | 2020-04-17 15:49:49 -0700 | [diff] [blame] | 832 | // but may be arm for a 32-bit only build. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 833 | // "32": compile for only a single 32-bit Target supported by the OsClass. |
| 834 | // "64": compile for only a single 64-bit Target supported by the OsClass. |
| 835 | // "common": compile a for a single Target that will work on all Targets suported by the OsClass (for example Java). |
| 836 | // |
| 837 | // Once the list of Targets is determined, the module is split into a variant for each Target. |
| 838 | // |
| 839 | // Modules can be initialized with InitAndroidMultiTargetsArchModule, in which case they will be split by OsClass, |
| 840 | // but will have a common Target that is expected to handle all other selected Targets via ctx.MultiTargets(). |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame^] | 841 | func archMutator(bpctx blueprint.BottomUpMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 842 | var module Module |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 843 | var ok bool |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame^] | 844 | if module, ok = bpctx.Module().(Module); !ok { |
| 845 | if bootstrap.IsBootstrapModule(bpctx.Module()) { |
| 846 | // Bootstrap Go modules are always the build architecture. |
| 847 | bpctx.CreateVariations(bpctx.Config().(Config).BuildOSTarget.ArchVariation()) |
| 848 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 849 | return |
| 850 | } |
| 851 | |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame^] | 852 | // Bootstrap Go module support above requires this mutator to be a |
| 853 | // blueprint.BottomUpMutatorContext because android.BottomUpMutatorContext |
| 854 | // filters out non-Soong modules. Now that we've handled them, create a |
| 855 | // normal android.BottomUpMutatorContext. |
| 856 | mctx := bottomUpMutatorContextFactory(bpctx, module, false) |
| 857 | |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 858 | base := module.base() |
| 859 | |
| 860 | if !base.ArchSpecific() { |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 861 | return |
| 862 | } |
| 863 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 864 | os := base.commonProperties.CompileOS |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 865 | if os == CommonOS { |
| 866 | // Make sure that the target related properties are initialized for the |
| 867 | // CommonOS variant. |
| 868 | addTargetProperties(module, commonTargetMap[os.Name], nil, true) |
| 869 | |
| 870 | // Do not create arch specific variants for the CommonOS variant. |
| 871 | return |
| 872 | } |
| 873 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 874 | osTargets := mctx.Config().Targets[os] |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 875 | image := base.commonProperties.ImageVariation |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 876 | // Filter NativeBridge targets unless they are explicitly supported |
Colin Cross | 83bead4 | 2019-12-18 10:45:46 -0800 | [diff] [blame] | 877 | // Skip creating native bridge variants for vendor modules |
| 878 | if os == Android && |
| 879 | !(Bool(base.commonProperties.Native_bridge_supported) && image == CoreVariation) { |
| 880 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 881 | var targets []Target |
| 882 | for _, t := range osTargets { |
| 883 | if !t.NativeBridge { |
| 884 | targets = append(targets, t) |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 885 | } |
| 886 | } |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 887 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 888 | osTargets = targets |
| 889 | } |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 890 | |
Yifan Hong | 1b3348d | 2020-01-21 15:53:22 -0800 | [diff] [blame] | 891 | // only the primary arch in the ramdisk / recovery partition |
| 892 | if os == Android && (module.InstallInRecovery() || module.InstallInRamdisk()) { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 893 | osTargets = []Target{osTargets[0]} |
| 894 | } |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 895 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 896 | prefer32 := false |
| 897 | if base.prefer32 != nil { |
| 898 | prefer32 = base.prefer32(mctx, base, os.Class) |
| 899 | } |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 900 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 901 | multilib, extraMultilib := decodeMultilib(base, os.Class) |
| 902 | targets, err := decodeMultilibTargets(multilib, osTargets, prefer32) |
| 903 | if err != nil { |
| 904 | mctx.ModuleErrorf("%s", err.Error()) |
| 905 | } |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 906 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 907 | var multiTargets []Target |
| 908 | if extraMultilib != "" { |
| 909 | multiTargets, err = decodeMultilibTargets(extraMultilib, osTargets, prefer32) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 910 | if err != nil { |
| 911 | mctx.ModuleErrorf("%s", err.Error()) |
| 912 | } |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 913 | } |
| 914 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 915 | if image == RecoveryVariation { |
| 916 | primaryArch := mctx.Config().DevicePrimaryArchType() |
| 917 | targets = filterToArch(targets, primaryArch) |
| 918 | multiTargets = filterToArch(multiTargets, primaryArch) |
| 919 | } |
| 920 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 921 | if len(targets) == 0 { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 922 | base.Disable() |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 923 | return |
| 924 | } |
| 925 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 926 | targetNames := make([]string, len(targets)) |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 927 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 928 | for i, target := range targets { |
| 929 | targetNames[i] = target.ArchVariation() |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | modules := mctx.CreateVariations(targetNames...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 933 | for i, m := range modules { |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 934 | addTargetProperties(m, targets[i], multiTargets, i == 0) |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame^] | 935 | m.base().setArchProperties(mctx) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 936 | } |
| 937 | } |
| 938 | |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 939 | func addTargetProperties(m Module, target Target, multiTargets []Target, primaryTarget bool) { |
| 940 | m.base().commonProperties.CompileTarget = target |
| 941 | m.base().commonProperties.CompileMultiTargets = multiTargets |
| 942 | m.base().commonProperties.CompilePrimary = primaryTarget |
| 943 | } |
| 944 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 945 | func decodeMultilib(base *ModuleBase, class OsClass) (multilib, extraMultilib string) { |
| 946 | switch class { |
| 947 | case Device: |
| 948 | multilib = String(base.commonProperties.Target.Android.Compile_multilib) |
| 949 | case Host, HostCross: |
| 950 | multilib = String(base.commonProperties.Target.Host.Compile_multilib) |
| 951 | } |
| 952 | if multilib == "" { |
| 953 | multilib = String(base.commonProperties.Compile_multilib) |
| 954 | } |
| 955 | if multilib == "" { |
| 956 | multilib = base.commonProperties.Default_multilib |
| 957 | } |
| 958 | |
| 959 | if base.commonProperties.UseTargetVariants { |
| 960 | return multilib, "" |
| 961 | } else { |
| 962 | // For app modules a single arch variant will be created per OS class which is expected to handle all the |
| 963 | // selected arches. Return the common-type as multilib and any Android.bp provided multilib as extraMultilib |
| 964 | if multilib == base.commonProperties.Default_multilib { |
| 965 | multilib = "first" |
| 966 | } |
| 967 | return base.commonProperties.Default_multilib, multilib |
| 968 | } |
| 969 | } |
| 970 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 971 | func filterToArch(targets []Target, arch ArchType) []Target { |
| 972 | for i := 0; i < len(targets); i++ { |
| 973 | if targets[i].Arch.ArchType != arch { |
| 974 | targets = append(targets[:i], targets[i+1:]...) |
| 975 | i-- |
| 976 | } |
| 977 | } |
| 978 | return targets |
| 979 | } |
| 980 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 981 | type archPropTypeDesc struct { |
| 982 | arch, multilib, target reflect.Type |
| 983 | } |
| 984 | |
| 985 | type archPropRoot struct { |
| 986 | Arch, Multilib, Target interface{} |
| 987 | } |
| 988 | |
| 989 | // createArchPropTypeDesc takes a reflect.Type that is either a struct or a pointer to a struct, and |
| 990 | // returns lists of reflect.Types that contains the arch-variant properties inside structs for each |
| 991 | // arch, multilib and target property. |
| 992 | func createArchPropTypeDesc(props reflect.Type) []archPropTypeDesc { |
Colin Cross | b1d8c99 | 2020-01-21 11:43:29 -0800 | [diff] [blame] | 993 | // Each property struct shard will be nested many times under the runtime generated arch struct, |
| 994 | // which can hit the limit of 64kB for the name of runtime generated structs. They are nested |
| 995 | // 97 times now, which may grow in the future, plus there is some overhead for the containing |
| 996 | // type. This number may need to be reduced if too many are added, but reducing it too far |
| 997 | // could cause problems if a single deeply nested property no longer fits in the name. |
| 998 | const maxArchTypeNameSize = 500 |
| 999 | |
| 1000 | propShards, _ := proptools.FilterPropertyStructSharded(props, maxArchTypeNameSize, filterArchStruct) |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 1001 | if len(propShards) == 0 { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1002 | return nil |
| 1003 | } |
| 1004 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1005 | var ret []archPropTypeDesc |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1006 | for _, props := range propShards { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1007 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1008 | variantFields := func(names []string) []reflect.StructField { |
| 1009 | ret := make([]reflect.StructField, len(names)) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1010 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1011 | for i, name := range names { |
| 1012 | ret[i].Name = name |
| 1013 | ret[i].Type = props |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 1014 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1015 | |
| 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", |
Victor Khimenko | c26fcf4 | 2020-05-07 22:16:33 +0200 | [diff] [blame] | 1058 | "Native_bridge", |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1059 | } |
Paul Duffin | a04c107 | 2020-03-02 10:16:35 +0000 | [diff] [blame] | 1060 | for _, os := range OsTypeList { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1061 | targets = append(targets, os.Field) |
| 1062 | |
| 1063 | for _, archType := range osArchTypeMap[os] { |
| 1064 | targets = append(targets, os.Field+"_"+archType.Name) |
| 1065 | |
| 1066 | if os.Linux() { |
| 1067 | target := "Linux_" + archType.Name |
| 1068 | if !InList(target, targets) { |
| 1069 | targets = append(targets, target) |
| 1070 | } |
| 1071 | } |
| 1072 | if os.Bionic() { |
| 1073 | target := "Bionic_" + archType.Name |
| 1074 | if !InList(target, targets) { |
| 1075 | targets = append(targets, target) |
| 1076 | } |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 1077 | } |
| 1078 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1079 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1080 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1081 | targetType := reflect.StructOf(variantFields(targets)) |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1082 | |
| 1083 | ret = append(ret, archPropTypeDesc{ |
| 1084 | arch: reflect.PtrTo(archType), |
| 1085 | multilib: reflect.PtrTo(multilibType), |
| 1086 | target: reflect.PtrTo(targetType), |
| 1087 | }) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1088 | } |
| 1089 | return ret |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Colin Cross | 7444910 | 2019-09-25 11:26:40 -0700 | [diff] [blame] | 1092 | func filterArchStruct(field reflect.StructField, prefix string) (bool, reflect.StructField) { |
| 1093 | if proptools.HasTag(field, "android", "arch_variant") { |
| 1094 | // The arch_variant field isn't necessary past this point |
| 1095 | // Instead of wasting space, just remove it. Go also has a |
| 1096 | // 16-bit limit on structure name length. The name is constructed |
| 1097 | // based on the Go source representation of the structure, so |
| 1098 | // the tag names count towards that length. |
Colin Cross | b4fecbf | 2020-01-21 11:38:47 -0800 | [diff] [blame] | 1099 | |
| 1100 | androidTag := field.Tag.Get("android") |
| 1101 | values := strings.Split(androidTag, ",") |
| 1102 | |
| 1103 | if string(field.Tag) != `android:"`+strings.Join(values, ",")+`"` { |
| 1104 | panic(fmt.Errorf("unexpected tag format %q", field.Tag)) |
Colin Cross | 7444910 | 2019-09-25 11:26:40 -0700 | [diff] [blame] | 1105 | } |
Colin Cross | b4fecbf | 2020-01-21 11:38:47 -0800 | [diff] [blame] | 1106 | // these tags don't need to be present in the runtime generated struct type. |
| 1107 | values = RemoveListFromList(values, []string{"arch_variant", "variant_prepend", "path"}) |
| 1108 | if len(values) > 0 { |
| 1109 | panic(fmt.Errorf("unknown tags %q in field %q", values, prefix+field.Name)) |
| 1110 | } |
| 1111 | |
| 1112 | field.Tag = "" |
Colin Cross | 7444910 | 2019-09-25 11:26:40 -0700 | [diff] [blame] | 1113 | return true, field |
| 1114 | } |
| 1115 | return false, field |
| 1116 | } |
| 1117 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1118 | var archPropTypeMap OncePer |
| 1119 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1120 | func InitArchModule(m Module) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1121 | |
| 1122 | base := m.base() |
| 1123 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1124 | base.generalProperties = m.GetProperties() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1125 | |
| 1126 | for _, properties := range base.generalProperties { |
| 1127 | propertiesValue := reflect.ValueOf(properties) |
Colin Cross | 62496a0 | 2016-08-08 15:49:17 -0700 | [diff] [blame] | 1128 | t := propertiesValue.Type() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1129 | if propertiesValue.Kind() != reflect.Ptr { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1130 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 1131 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | propertiesValue = propertiesValue.Elem() |
| 1135 | if propertiesValue.Kind() != reflect.Struct { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1136 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 1137 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1138 | } |
| 1139 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1140 | archPropTypes := archPropTypeMap.Once(NewCustomOnceKey(t), func() interface{} { |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1141 | return createArchPropTypeDesc(t) |
| 1142 | }).([]archPropTypeDesc) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1143 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1144 | var archProperties []interface{} |
| 1145 | for _, t := range archPropTypes { |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1146 | archProperties = append(archProperties, &archPropRoot{ |
| 1147 | Arch: reflect.Zero(t.arch).Interface(), |
| 1148 | Multilib: reflect.Zero(t.multilib).Interface(), |
| 1149 | Target: reflect.Zero(t.target).Interface(), |
| 1150 | }) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1151 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1152 | base.archProperties = append(base.archProperties, archProperties) |
| 1153 | m.AddProperties(archProperties...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1154 | } |
| 1155 | |
Colin Cross | 3624285 | 2017-06-23 15:06:31 -0700 | [diff] [blame] | 1156 | base.customizableProperties = m.GetProperties() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1157 | } |
| 1158 | |
Colin Cross | a716add | 2015-12-16 11:07:39 -0800 | [diff] [blame] | 1159 | var variantReplacer = strings.NewReplacer("-", "_", ".", "_") |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 1160 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1161 | func (m *ModuleBase) appendProperties(ctx BottomUpMutatorContext, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1162 | dst interface{}, src reflect.Value, field, srcPrefix string) reflect.Value { |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1163 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1164 | if src.Kind() == reflect.Ptr { |
| 1165 | if src.IsNil() { |
| 1166 | return src |
| 1167 | } |
| 1168 | src = src.Elem() |
| 1169 | } |
| 1170 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1171 | src = src.FieldByName(field) |
| 1172 | if !src.IsValid() { |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1173 | ctx.ModuleErrorf("field %q does not exist", srcPrefix) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1174 | return src |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 1175 | } |
| 1176 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1177 | ret := src |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 1178 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1179 | if src.Kind() == reflect.Struct { |
| 1180 | src = src.FieldByName("BlueprintEmbed") |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
Colin Cross | 6ee75b6 | 2016-05-05 15:57:15 -0700 | [diff] [blame] | 1183 | order := func(property string, |
| 1184 | dstField, srcField reflect.StructField, |
| 1185 | dstValue, srcValue interface{}) (proptools.Order, error) { |
| 1186 | if proptools.HasTag(dstField, "android", "variant_prepend") { |
| 1187 | return proptools.Prepend, nil |
| 1188 | } else { |
| 1189 | return proptools.Append, nil |
| 1190 | } |
| 1191 | } |
| 1192 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1193 | err := proptools.ExtendMatchingProperties([]interface{}{dst}, src.Interface(), nil, order) |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1194 | if err != nil { |
| 1195 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
| 1196 | ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
| 1197 | } else { |
| 1198 | panic(err) |
| 1199 | } |
| 1200 | } |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 1201 | |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1202 | return ret |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1205 | // Rewrite the module's properties structs to contain os-specific values. |
| 1206 | func (m *ModuleBase) setOSProperties(ctx BottomUpMutatorContext) { |
| 1207 | os := m.commonProperties.CompileOS |
| 1208 | |
| 1209 | for i := range m.generalProperties { |
| 1210 | genProps := m.generalProperties[i] |
| 1211 | if m.archProperties[i] == nil { |
| 1212 | continue |
| 1213 | } |
| 1214 | for _, archProperties := range m.archProperties[i] { |
| 1215 | archPropValues := reflect.ValueOf(archProperties).Elem() |
| 1216 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1217 | targetProp := archPropValues.FieldByName("Target").Elem() |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1218 | |
| 1219 | // Handle host-specific properties in the form: |
| 1220 | // target: { |
| 1221 | // host: { |
| 1222 | // key: value, |
| 1223 | // }, |
| 1224 | // }, |
| 1225 | if os.Class == Host || os.Class == HostCross { |
| 1226 | field := "Host" |
| 1227 | prefix := "target.host" |
| 1228 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1229 | } |
| 1230 | |
| 1231 | // Handle target OS generalities of the form: |
| 1232 | // target: { |
| 1233 | // bionic: { |
| 1234 | // key: value, |
| 1235 | // }, |
| 1236 | // } |
| 1237 | if os.Linux() { |
| 1238 | field := "Linux" |
| 1239 | prefix := "target.linux" |
| 1240 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1241 | } |
| 1242 | |
| 1243 | if os.Bionic() { |
| 1244 | field := "Bionic" |
| 1245 | prefix := "target.bionic" |
| 1246 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1247 | } |
| 1248 | |
| 1249 | // Handle target OS properties in the form: |
| 1250 | // target: { |
| 1251 | // linux_glibc: { |
| 1252 | // key: value, |
| 1253 | // }, |
| 1254 | // not_windows: { |
| 1255 | // key: value, |
| 1256 | // }, |
| 1257 | // android { |
| 1258 | // key: value, |
| 1259 | // }, |
| 1260 | // }, |
| 1261 | field := os.Field |
| 1262 | prefix := "target." + os.Name |
| 1263 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1264 | |
| 1265 | if (os.Class == Host || os.Class == HostCross) && os != Windows { |
| 1266 | field := "Not_windows" |
| 1267 | prefix := "target.not_windows" |
| 1268 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1269 | } |
| 1270 | |
| 1271 | // Handle 64-bit device properties in the form: |
| 1272 | // target { |
| 1273 | // android64 { |
| 1274 | // key: value, |
| 1275 | // }, |
| 1276 | // android32 { |
| 1277 | // key: value, |
| 1278 | // }, |
| 1279 | // }, |
| 1280 | // WARNING: this is probably not what you want to use in your blueprints file, it selects |
| 1281 | // options for all targets on a device that supports 64-bit binaries, not just the targets |
| 1282 | // that are being compiled for 64-bit. Its expected use case is binaries like linker and |
| 1283 | // debuggerd that need to know when they are a 32-bit process running on a 64-bit device |
| 1284 | if os.Class == Device { |
| 1285 | if ctx.Config().Android64() { |
| 1286 | field := "Android64" |
| 1287 | prefix := "target.android64" |
| 1288 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1289 | } else { |
| 1290 | field := "Android32" |
| 1291 | prefix := "target.android32" |
| 1292 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1293 | } |
| 1294 | } |
| 1295 | } |
| 1296 | } |
| 1297 | } |
| 1298 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1299 | // Rewrite the module's properties structs to contain arch-specific values. |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1300 | func (m *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) { |
| 1301 | arch := m.Arch() |
| 1302 | os := m.Os() |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 1303 | |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1304 | for i := range m.generalProperties { |
| 1305 | genProps := m.generalProperties[i] |
| 1306 | if m.archProperties[i] == nil { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1307 | continue |
| 1308 | } |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1309 | for _, archProperties := range m.archProperties[i] { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1310 | archPropValues := reflect.ValueOf(archProperties).Elem() |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1311 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1312 | archProp := archPropValues.FieldByName("Arch").Elem() |
| 1313 | multilibProp := archPropValues.FieldByName("Multilib").Elem() |
| 1314 | targetProp := archPropValues.FieldByName("Target").Elem() |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1315 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1316 | // Handle arch-specific properties in the form: |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1317 | // arch: { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1318 | // arm64: { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1319 | // key: value, |
| 1320 | // }, |
| 1321 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1322 | t := arch.ArchType |
| 1323 | |
| 1324 | if arch.ArchType != Common { |
| 1325 | field := proptools.FieldNameForProperty(t.Name) |
| 1326 | prefix := "arch." + t.Name |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1327 | archStruct := m.appendProperties(ctx, genProps, archProp, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1328 | |
| 1329 | // Handle arch-variant-specific properties in the form: |
| 1330 | // arch: { |
| 1331 | // variant: { |
| 1332 | // key: value, |
| 1333 | // }, |
| 1334 | // }, |
| 1335 | v := variantReplacer.Replace(arch.ArchVariant) |
| 1336 | if v != "" { |
| 1337 | field := proptools.FieldNameForProperty(v) |
| 1338 | prefix := "arch." + t.Name + "." + v |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1339 | m.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | // Handle cpu-variant-specific properties in the form: |
| 1343 | // arch: { |
| 1344 | // variant: { |
| 1345 | // key: value, |
| 1346 | // }, |
| 1347 | // }, |
| 1348 | if arch.CpuVariant != arch.ArchVariant { |
| 1349 | c := variantReplacer.Replace(arch.CpuVariant) |
| 1350 | if c != "" { |
| 1351 | field := proptools.FieldNameForProperty(c) |
| 1352 | prefix := "arch." + t.Name + "." + c |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1353 | m.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | // Handle arch-feature-specific properties in the form: |
| 1358 | // arch: { |
| 1359 | // feature: { |
| 1360 | // key: value, |
| 1361 | // }, |
| 1362 | // }, |
| 1363 | for _, feature := range arch.ArchFeatures { |
| 1364 | field := proptools.FieldNameForProperty(feature) |
| 1365 | prefix := "arch." + t.Name + "." + feature |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1366 | m.appendProperties(ctx, genProps, archStruct, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | // Handle multilib-specific properties in the form: |
| 1370 | // multilib: { |
| 1371 | // lib32: { |
| 1372 | // key: value, |
| 1373 | // }, |
| 1374 | // }, |
| 1375 | field = proptools.FieldNameForProperty(t.Multilib) |
| 1376 | prefix = "multilib." + t.Multilib |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1377 | m.appendProperties(ctx, genProps, multilibProp, field, prefix) |
Colin Cross | 0801633 | 2016-12-20 09:53:14 -0800 | [diff] [blame] | 1378 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1379 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1380 | // Handle combined OS-feature and arch specific properties in the form: |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1381 | // target: { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1382 | // bionic_x86: { |
| 1383 | // key: value, |
| 1384 | // }, |
| 1385 | // } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1386 | if os.Linux() && arch.ArchType != Common { |
| 1387 | field := "Linux_" + arch.ArchType.Name |
| 1388 | prefix := "target.linux_" + arch.ArchType.Name |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1389 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1390 | } |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1391 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1392 | if os.Bionic() && arch.ArchType != Common { |
| 1393 | field := "Bionic_" + t.Name |
| 1394 | prefix := "target.bionic_" + t.Name |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1395 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1398 | // Handle combined OS and arch specific properties in the form: |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1399 | // target: { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1400 | // linux_glibc_x86: { |
| 1401 | // key: value, |
| 1402 | // }, |
| 1403 | // linux_glibc_arm: { |
| 1404 | // key: value, |
| 1405 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1406 | // android_arm { |
| 1407 | // key: value, |
| 1408 | // }, |
| 1409 | // android_x86 { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1410 | // key: value, |
| 1411 | // }, |
| 1412 | // }, |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1413 | if arch.ArchType != Common { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1414 | field := os.Field + "_" + t.Name |
| 1415 | prefix := "target." + os.Name + "_" + t.Name |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1416 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1419 | // Handle arm on x86 properties in the form: |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1420 | // target { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1421 | // arm_on_x86 { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1422 | // key: value, |
| 1423 | // }, |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1424 | // arm_on_x86_64 { |
Colin Cross | d5934c8 | 2017-10-02 13:55:26 -0700 | [diff] [blame] | 1425 | // key: value, |
| 1426 | // }, |
| 1427 | // }, |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1428 | // TODO(ccross): is this still necessary with native bridge? |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1429 | if os.Class == Device { |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1430 | if (arch.ArchType == X86 && (hasArmAbi(arch) || |
| 1431 | hasArmAndroidArch(ctx.Config().Targets[Android]))) || |
| 1432 | (arch.ArchType == Arm && |
| 1433 | hasX86AndroidArch(ctx.Config().Targets[Android])) { |
| 1434 | field := "Arm_on_x86" |
| 1435 | prefix := "target.arm_on_x86" |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1436 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1437 | } |
| 1438 | if (arch.ArchType == X86_64 && (hasArmAbi(arch) || |
| 1439 | hasArmAndroidArch(ctx.Config().Targets[Android]))) || |
| 1440 | (arch.ArchType == Arm && |
| 1441 | hasX8664AndroidArch(ctx.Config().Targets[Android])) { |
| 1442 | field := "Arm_on_x86_64" |
| 1443 | prefix := "target.arm_on_x86_64" |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1444 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1445 | } |
Victor Khimenko | c26fcf4 | 2020-05-07 22:16:33 +0200 | [diff] [blame] | 1446 | if os == Android && m.Target().NativeBridge == NativeBridgeEnabled { |
| 1447 | field := "Native_bridge" |
| 1448 | prefix := "target.native_bridge" |
| 1449 | m.appendProperties(ctx, genProps, targetProp, field, prefix) |
| 1450 | } |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 1451 | } |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1452 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | func forEachInterface(v reflect.Value, f func(reflect.Value)) { |
| 1457 | switch v.Kind() { |
| 1458 | case reflect.Interface: |
| 1459 | f(v) |
| 1460 | case reflect.Struct: |
| 1461 | for i := 0; i < v.NumField(); i++ { |
| 1462 | forEachInterface(v.Field(i), f) |
| 1463 | } |
| 1464 | case reflect.Ptr: |
| 1465 | forEachInterface(v.Elem(), f) |
| 1466 | default: |
| 1467 | panic(fmt.Errorf("Unsupported kind %s", v.Kind())) |
| 1468 | } |
| 1469 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1470 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1471 | // 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] | 1472 | func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1473 | variables := config.productVariables |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1474 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1475 | targets := make(map[OsType][]Target) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1476 | var targetErr error |
| 1477 | |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1478 | addTarget := func(os OsType, archName string, archVariant, cpuVariant *string, abi []string, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1479 | nativeBridgeEnabled NativeBridgeSupport, nativeBridgeHostArchName *string, |
| 1480 | nativeBridgeRelativePath *string) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1481 | if targetErr != nil { |
| 1482 | return |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1483 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1484 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1485 | arch, err := decodeArch(os, archName, archVariant, cpuVariant, abi) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1486 | if err != nil { |
| 1487 | targetErr = err |
| 1488 | return |
| 1489 | } |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1490 | nativeBridgeRelativePathStr := String(nativeBridgeRelativePath) |
| 1491 | nativeBridgeHostArchNameStr := String(nativeBridgeHostArchName) |
| 1492 | |
| 1493 | // Use guest arch as relative install path by default |
| 1494 | if nativeBridgeEnabled && nativeBridgeRelativePathStr == "" { |
| 1495 | nativeBridgeRelativePathStr = arch.ArchType.String() |
| 1496 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1497 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1498 | targets[os] = append(targets[os], |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1499 | Target{ |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1500 | Os: os, |
| 1501 | Arch: arch, |
| 1502 | NativeBridge: nativeBridgeEnabled, |
| 1503 | NativeBridgeHostArchName: nativeBridgeHostArchNameStr, |
| 1504 | NativeBridgeRelativePath: nativeBridgeRelativePathStr, |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1505 | }) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1506 | } |
| 1507 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1508 | if variables.HostArch == nil { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1509 | return nil, fmt.Errorf("No host primary architecture set") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1512 | addTarget(BuildOs, *variables.HostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1513 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1514 | if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1515 | addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1516 | } |
| 1517 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1518 | if Bool(config.Host_bionic) { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1519 | addTarget(LinuxBionic, "x86_64", nil, nil, nil, NativeBridgeDisabled, nil, nil) |
Dan Willemsen | 01a405a | 2016-06-13 17:19:03 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1522 | if String(variables.CrossHost) != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1523 | crossHostOs := osByName(*variables.CrossHost) |
| 1524 | if crossHostOs == NoOsType { |
| 1525 | return nil, fmt.Errorf("Unknown cross host OS %q", *variables.CrossHost) |
| 1526 | } |
| 1527 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1528 | if String(variables.CrossHostArch) == "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1529 | return nil, fmt.Errorf("No cross-host primary architecture set") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1530 | } |
| 1531 | |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1532 | addTarget(crossHostOs, *variables.CrossHostArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1533 | |
| 1534 | if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1535 | addTarget(crossHostOs, *variables.CrossHostSecondaryArch, nil, nil, nil, NativeBridgeDisabled, nil, nil) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1536 | } |
| 1537 | } |
| 1538 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1539 | if variables.DeviceArch != nil && *variables.DeviceArch != "" { |
Doug Horn | 21b9427 | 2019-01-16 12:06:11 -0800 | [diff] [blame] | 1540 | var target = Android |
| 1541 | if Bool(variables.Fuchsia) { |
| 1542 | target = Fuchsia |
| 1543 | } |
| 1544 | |
| 1545 | addTarget(target, *variables.DeviceArch, variables.DeviceArchVariant, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1546 | variables.DeviceCpuVariant, variables.DeviceAbi, NativeBridgeDisabled, nil, nil) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1547 | |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1548 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" { |
| 1549 | addTarget(Android, *variables.DeviceSecondaryArch, |
| 1550 | variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1551 | variables.DeviceSecondaryAbi, NativeBridgeDisabled, nil, nil) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1552 | } |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1553 | |
| 1554 | if variables.NativeBridgeArch != nil && *variables.NativeBridgeArch != "" { |
| 1555 | addTarget(Android, *variables.NativeBridgeArch, |
| 1556 | variables.NativeBridgeArchVariant, variables.NativeBridgeCpuVariant, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1557 | variables.NativeBridgeAbi, NativeBridgeEnabled, variables.DeviceArch, |
| 1558 | variables.NativeBridgeRelativePath) |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" && |
| 1562 | variables.NativeBridgeSecondaryArch != nil && *variables.NativeBridgeSecondaryArch != "" { |
| 1563 | addTarget(Android, *variables.NativeBridgeSecondaryArch, |
| 1564 | variables.NativeBridgeSecondaryArchVariant, |
| 1565 | variables.NativeBridgeSecondaryCpuVariant, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1566 | variables.NativeBridgeSecondaryAbi, |
| 1567 | NativeBridgeEnabled, |
| 1568 | variables.DeviceSecondaryArch, |
| 1569 | variables.NativeBridgeSecondaryRelativePath) |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1570 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1571 | } |
| 1572 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1573 | if targetErr != nil { |
| 1574 | return nil, targetErr |
| 1575 | } |
| 1576 | |
| 1577 | return targets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1578 | } |
| 1579 | |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1580 | // hasArmAbi returns true if arch has at least one arm ABI |
| 1581 | func hasArmAbi(arch Arch) bool { |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 1582 | return PrefixInList(arch.Abi, "arm") |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1583 | } |
| 1584 | |
dimitry | 628db6f | 2019-05-22 17:16:21 +0200 | [diff] [blame] | 1585 | // 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] | 1586 | func hasArmAndroidArch(targets []Target) bool { |
| 1587 | for _, target := range targets { |
dimitry | 628db6f | 2019-05-22 17:16:21 +0200 | [diff] [blame] | 1588 | if target.Os == Android && target.Arch.ArchType == Arm && target.NativeBridge == NativeBridgeDisabled { |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 1589 | return true |
| 1590 | } |
| 1591 | } |
| 1592 | return false |
| 1593 | } |
| 1594 | |
Victor Khimenko | 5eb8ec1 | 2018-03-21 20:30:54 +0100 | [diff] [blame] | 1595 | // hasX86Arch returns true if targets has at least x86 Android arch |
| 1596 | func hasX86AndroidArch(targets []Target) bool { |
| 1597 | for _, target := range targets { |
| 1598 | if target.Os == Android && target.Arch.ArchType == X86 { |
| 1599 | return true |
| 1600 | } |
| 1601 | } |
| 1602 | return false |
| 1603 | } |
| 1604 | |
| 1605 | // hasX8664Arch returns true if targets has at least x86_64 Android arch |
| 1606 | func hasX8664AndroidArch(targets []Target) bool { |
| 1607 | for _, target := range targets { |
| 1608 | if target.Os == Android && target.Arch.ArchType == X86_64 { |
| 1609 | return true |
| 1610 | } |
| 1611 | } |
| 1612 | return false |
| 1613 | } |
| 1614 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1615 | type archConfig struct { |
| 1616 | arch string |
| 1617 | archVariant string |
| 1618 | cpuVariant string |
| 1619 | abi []string |
| 1620 | } |
| 1621 | |
| 1622 | func getMegaDeviceConfig() []archConfig { |
| 1623 | return []archConfig{ |
Dan Albert | 8818f49 | 2019-02-19 13:53:01 -0800 | [diff] [blame] | 1624 | {"arm", "armv7-a", "generic", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 1625 | {"arm", "armv7-a-neon", "generic", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1626 | {"arm", "armv7-a-neon", "cortex-a7", []string{"armeabi-v7a"}}, |
| 1627 | {"arm", "armv7-a-neon", "cortex-a8", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 1628 | {"arm", "armv7-a-neon", "cortex-a9", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1629 | {"arm", "armv7-a-neon", "cortex-a15", []string{"armeabi-v7a"}}, |
| 1630 | {"arm", "armv7-a-neon", "cortex-a53", []string{"armeabi-v7a"}}, |
| 1631 | {"arm", "armv7-a-neon", "cortex-a53.a57", []string{"armeabi-v7a"}}, |
Richard Fung | eb37ed3 | 2018-09-24 16:33:45 -0700 | [diff] [blame] | 1632 | {"arm", "armv7-a-neon", "cortex-a72", []string{"armeabi-v7a"}}, |
Jake Weinstein | 6600a44 | 2017-05-15 18:27:12 -0400 | [diff] [blame] | 1633 | {"arm", "armv7-a-neon", "cortex-a73", []string{"armeabi-v7a"}}, |
Christopher Ferris | ba14a8f | 2018-04-23 18:15:25 -0700 | [diff] [blame] | 1634 | {"arm", "armv7-a-neon", "cortex-a75", []string{"armeabi-v7a"}}, |
Haibo Huang | a31e2bd | 2018-10-09 14:27:28 -0700 | [diff] [blame] | 1635 | {"arm", "armv7-a-neon", "cortex-a76", []string{"armeabi-v7a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1636 | {"arm", "armv7-a-neon", "krait", []string{"armeabi-v7a"}}, |
Alex Naidis | ae4fc18 | 2016-08-20 00:14:56 +0200 | [diff] [blame] | 1637 | {"arm", "armv7-a-neon", "kryo", []string{"armeabi-v7a"}}, |
Artem Serov | d3072b0 | 2018-11-15 15:21:51 +0000 | [diff] [blame] | 1638 | {"arm", "armv7-a-neon", "kryo385", []string{"armeabi-v7a"}}, |
Junmo Park | 8ea4959 | 2017-07-24 07:14:55 +0900 | [diff] [blame] | 1639 | {"arm", "armv7-a-neon", "exynos-m1", []string{"armeabi-v7a"}}, |
Junmo Park | d86c902 | 2017-07-21 09:07:47 +0900 | [diff] [blame] | 1640 | {"arm", "armv7-a-neon", "exynos-m2", []string{"armeabi-v7a"}}, |
Dan Willemsen | 110a89d | 2016-01-14 15:17:19 -0800 | [diff] [blame] | 1641 | {"arm64", "armv8-a", "cortex-a53", []string{"arm64-v8a"}}, |
Richard Fung | eb37ed3 | 2018-09-24 16:33:45 -0700 | [diff] [blame] | 1642 | {"arm64", "armv8-a", "cortex-a72", []string{"arm64-v8a"}}, |
Jake Weinstein | 6600a44 | 2017-05-15 18:27:12 -0400 | [diff] [blame] | 1643 | {"arm64", "armv8-a", "cortex-a73", []string{"arm64-v8a"}}, |
Alex Naidis | ac01ff5 | 2016-08-30 15:56:33 +0200 | [diff] [blame] | 1644 | {"arm64", "armv8-a", "kryo", []string{"arm64-v8a"}}, |
Junmo Park | 8ea4959 | 2017-07-24 07:14:55 +0900 | [diff] [blame] | 1645 | {"arm64", "armv8-a", "exynos-m1", []string{"arm64-v8a"}}, |
Junmo Park | d86c902 | 2017-07-21 09:07:47 +0900 | [diff] [blame] | 1646 | {"arm64", "armv8-a", "exynos-m2", []string{"arm64-v8a"}}, |
Christopher Ferris | ba14a8f | 2018-04-23 18:15:25 -0700 | [diff] [blame] | 1647 | {"arm64", "armv8-2a", "cortex-a75", []string{"arm64-v8a"}}, |
Haibo Huang | a31e2bd | 2018-10-09 14:27:28 -0700 | [diff] [blame] | 1648 | {"arm64", "armv8-2a", "cortex-a76", []string{"arm64-v8a"}}, |
Artem Serov | d3072b0 | 2018-11-15 15:21:51 +0000 | [diff] [blame] | 1649 | {"arm64", "armv8-2a", "kryo385", []string{"arm64-v8a"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1650 | {"x86", "", "", []string{"x86"}}, |
| 1651 | {"x86", "atom", "", []string{"x86"}}, |
| 1652 | {"x86", "haswell", "", []string{"x86"}}, |
| 1653 | {"x86", "ivybridge", "", []string{"x86"}}, |
| 1654 | {"x86", "sandybridge", "", []string{"x86"}}, |
| 1655 | {"x86", "silvermont", "", []string{"x86"}}, |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 1656 | {"x86", "stoneyridge", "", []string{"x86"}}, |
Dan Willemsen | 8a35405 | 2016-05-10 14:30:51 -0700 | [diff] [blame] | 1657 | {"x86", "x86_64", "", []string{"x86"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1658 | {"x86_64", "", "", []string{"x86_64"}}, |
| 1659 | {"x86_64", "haswell", "", []string{"x86_64"}}, |
| 1660 | {"x86_64", "ivybridge", "", []string{"x86_64"}}, |
| 1661 | {"x86_64", "sandybridge", "", []string{"x86_64"}}, |
| 1662 | {"x86_64", "silvermont", "", []string{"x86_64"}}, |
Benjamin Gordon | 87e7f2f | 2019-02-14 10:59:48 -0700 | [diff] [blame] | 1663 | {"x86_64", "stoneyridge", "", []string{"x86_64"}}, |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1664 | } |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1665 | } |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1666 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1667 | func getNdkAbisConfig() []archConfig { |
| 1668 | return []archConfig{ |
Dan Albert | 6bba644 | 2020-01-30 15:16:49 -0800 | [diff] [blame] | 1669 | {"arm", "armv7-a", "", []string{"armeabi-v7a"}}, |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1670 | {"arm64", "armv8-a", "", []string{"arm64-v8a"}}, |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1671 | {"x86", "", "", []string{"x86"}}, |
| 1672 | {"x86_64", "", "", []string{"x86_64"}}, |
| 1673 | } |
| 1674 | } |
| 1675 | |
Martin Stjernholm | c1ecc43 | 2019-11-15 15:00:31 +0000 | [diff] [blame] | 1676 | func getAmlAbisConfig() []archConfig { |
| 1677 | return []archConfig{ |
| 1678 | {"arm", "armv7-a", "", []string{"armeabi-v7a"}}, |
| 1679 | {"arm64", "armv8-a", "", []string{"arm64-v8a"}}, |
| 1680 | {"x86", "", "", []string{"x86"}}, |
| 1681 | {"x86_64", "", "", []string{"x86_64"}}, |
| 1682 | } |
| 1683 | } |
| 1684 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1685 | func decodeArchSettings(os OsType, archConfigs []archConfig) ([]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1686 | var ret []Target |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1687 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1688 | for _, config := range archConfigs { |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1689 | arch, err := decodeArch(os, config.arch, &config.archVariant, |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1690 | &config.cpuVariant, config.abi) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1691 | if err != nil { |
| 1692 | return nil, err |
| 1693 | } |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 1694 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1695 | ret = append(ret, Target{ |
| 1696 | Os: Android, |
| 1697 | Arch: arch, |
| 1698 | }) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | return ret, nil |
| 1702 | } |
| 1703 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1704 | // 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] | 1705 | 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] | 1706 | stringPtr := func(p *string) string { |
| 1707 | if p != nil { |
| 1708 | return *p |
| 1709 | } |
| 1710 | return "" |
| 1711 | } |
| 1712 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1713 | archType, ok := archTypeMap[arch] |
| 1714 | if !ok { |
| 1715 | return Arch{}, fmt.Errorf("unknown arch %q", arch) |
| 1716 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1717 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1718 | a := Arch{ |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1719 | ArchType: archType, |
| 1720 | ArchVariant: stringPtr(archVariant), |
| 1721 | CpuVariant: stringPtr(cpuVariant), |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1722 | Abi: abi, |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" { |
| 1726 | a.ArchVariant = "" |
| 1727 | } |
| 1728 | |
| 1729 | if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" { |
| 1730 | a.CpuVariant = "" |
| 1731 | } |
| 1732 | |
| 1733 | for i := 0; i < len(a.Abi); i++ { |
| 1734 | if a.Abi[i] == "" { |
| 1735 | a.Abi = append(a.Abi[:i], a.Abi[i+1:]...) |
| 1736 | i-- |
| 1737 | } |
| 1738 | } |
| 1739 | |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1740 | if a.ArchVariant == "" { |
| 1741 | if featureMap, ok := defaultArchFeatureMap[os]; ok { |
| 1742 | a.ArchFeatures = featureMap[archType] |
| 1743 | } |
| 1744 | } else { |
| 1745 | if featureMap, ok := archFeatureMap[archType]; ok { |
| 1746 | a.ArchFeatures = featureMap[a.ArchVariant] |
| 1747 | } |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1748 | } |
| 1749 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1750 | return a, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1753 | func filterMultilibTargets(targets []Target, multilib string) []Target { |
| 1754 | var ret []Target |
| 1755 | for _, t := range targets { |
| 1756 | if t.Arch.ArchType.Multilib == multilib { |
| 1757 | ret = append(ret, t) |
| 1758 | } |
| 1759 | } |
| 1760 | return ret |
| 1761 | } |
| 1762 | |
Paul Duffin | ca7f0ef | 2020-02-25 15:50:49 +0000 | [diff] [blame] | 1763 | // Return the set of Os specific common architecture targets for each Os in a list of |
| 1764 | // targets. |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 1765 | func getCommonTargets(targets []Target) []Target { |
| 1766 | var ret []Target |
| 1767 | set := make(map[string]bool) |
| 1768 | |
| 1769 | for _, t := range targets { |
| 1770 | if _, found := set[t.Os.String()]; !found { |
| 1771 | set[t.Os.String()] = true |
| 1772 | ret = append(ret, commonTargetMap[t.Os.String()]) |
| 1773 | } |
| 1774 | } |
| 1775 | |
| 1776 | return ret |
| 1777 | } |
| 1778 | |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1779 | func firstTarget(targets []Target, filters ...string) []Target { |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1780 | for _, filter := range filters { |
| 1781 | buildTargets := filterMultilibTargets(targets, filter) |
| 1782 | if len(buildTargets) > 0 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1783 | return buildTargets[:1] |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1784 | } |
| 1785 | } |
| 1786 | return nil |
| 1787 | } |
| 1788 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1789 | // 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] | 1790 | func decodeMultilibTargets(multilib string, targets []Target, prefer32 bool) ([]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1791 | buildTargets := []Target{} |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1792 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1793 | switch multilib { |
| 1794 | case "common": |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1795 | buildTargets = getCommonTargets(targets) |
| 1796 | case "common_first": |
| 1797 | buildTargets = getCommonTargets(targets) |
| 1798 | if prefer32 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1799 | buildTargets = append(buildTargets, firstTarget(targets, "lib32", "lib64")...) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1800 | } else { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1801 | buildTargets = append(buildTargets, firstTarget(targets, "lib64", "lib32")...) |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1802 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1803 | case "both": |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 1804 | if prefer32 { |
| 1805 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) |
| 1806 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) |
| 1807 | } else { |
| 1808 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) |
| 1809 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) |
| 1810 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1811 | case "32": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1812 | buildTargets = filterMultilibTargets(targets, "lib32") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1813 | case "64": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1814 | buildTargets = filterMultilibTargets(targets, "lib64") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1815 | case "first": |
| 1816 | if prefer32 { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1817 | buildTargets = firstTarget(targets, "lib32", "lib64") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1818 | } else { |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1819 | buildTargets = firstTarget(targets, "lib64", "lib32") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1820 | } |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1821 | case "prefer32": |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1822 | buildTargets = filterMultilibTargets(targets, "lib32") |
| 1823 | if len(buildTargets) == 0 { |
| 1824 | buildTargets = filterMultilibTargets(targets, "lib64") |
| 1825 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1826 | default: |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1827 | 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] | 1828 | multilib) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1831 | return buildTargets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1832 | } |