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" |
Ivan Lozano | 03b717d | 2024-07-18 15:13:50 +0000 | [diff] [blame] | 22 | "slices" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 23 | "strings" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 24 | |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 25 | "github.com/google/blueprint" |
Colin Cross | f6566ed | 2015-03-24 11:13:38 -0700 | [diff] [blame] | 26 | "github.com/google/blueprint/proptools" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 27 | ) |
| 28 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 29 | /* |
| 30 | Example blueprints file containing all variant property groups, with comment listing what type |
| 31 | of variants get properties in that group: |
| 32 | |
| 33 | module { |
| 34 | arch: { |
| 35 | arm: { |
| 36 | // Host or device variants with arm architecture |
| 37 | }, |
| 38 | arm64: { |
| 39 | // Host or device variants with arm64 architecture |
| 40 | }, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 41 | x86: { |
| 42 | // Host or device variants with x86 architecture |
| 43 | }, |
| 44 | x86_64: { |
| 45 | // Host or device variants with x86_64 architecture |
| 46 | }, |
| 47 | }, |
| 48 | multilib: { |
| 49 | lib32: { |
| 50 | // Host or device variants for 32-bit architectures |
| 51 | }, |
| 52 | lib64: { |
| 53 | // Host or device variants for 64-bit architectures |
| 54 | }, |
| 55 | }, |
| 56 | target: { |
| 57 | android: { |
Martin Stjernholm | e284b48 | 2020-09-23 21:03:27 +0100 | [diff] [blame] | 58 | // Device variants (implies Bionic) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 59 | }, |
| 60 | host: { |
| 61 | // Host variants |
| 62 | }, |
Martin Stjernholm | e284b48 | 2020-09-23 21:03:27 +0100 | [diff] [blame] | 63 | bionic: { |
| 64 | // Bionic (device and host) variants |
| 65 | }, |
| 66 | linux_bionic: { |
| 67 | // Bionic host variants |
| 68 | }, |
| 69 | linux: { |
| 70 | // Bionic (device and host) and Linux glibc variants |
| 71 | }, |
Dan Willemsen | 5746bd4 | 2017-10-02 19:42:01 -0700 | [diff] [blame] | 72 | linux_glibc: { |
Martin Stjernholm | e284b48 | 2020-09-23 21:03:27 +0100 | [diff] [blame] | 73 | // Linux host variants (using non-Bionic libc) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 74 | }, |
| 75 | darwin: { |
| 76 | // Darwin host variants |
| 77 | }, |
| 78 | windows: { |
| 79 | // Windows host variants |
| 80 | }, |
| 81 | not_windows: { |
| 82 | // Non-windows host variants |
| 83 | }, |
Martin Stjernholm | e284b48 | 2020-09-23 21:03:27 +0100 | [diff] [blame] | 84 | android_arm: { |
| 85 | // Any <os>_<arch> combination restricts to that os and arch |
| 86 | }, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 87 | }, |
| 88 | } |
| 89 | */ |
Colin Cross | 7d5136f | 2015-05-11 13:39:40 -0700 | [diff] [blame] | 90 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 91 | // An Arch indicates a single CPU architecture. |
| 92 | type Arch struct { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 93 | // The type of the architecture (arm, arm64, x86, or x86_64). |
| 94 | ArchType ArchType |
| 95 | |
| 96 | // The variant of the architecture, for example "armv7-a" or "armv7-a-neon" for arm. |
| 97 | ArchVariant string |
| 98 | |
| 99 | // The variant of the CPU, for example "cortex-a53" for arm64. |
| 100 | CpuVariant string |
| 101 | |
| 102 | // The list of Android app ABIs supported by the CPU architecture, for example "arm64-v8a". |
| 103 | Abi []string |
| 104 | |
| 105 | // The list of arch-specific features supported by the CPU architecture, for example "neon". |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 106 | ArchFeatures []string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 109 | // String returns the Arch as a string. The value is used as the name of the variant created |
| 110 | // by archMutator. |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 111 | func (a Arch) String() string { |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 112 | s := a.ArchType.String() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 113 | if a.ArchVariant != "" { |
| 114 | s += "_" + a.ArchVariant |
| 115 | } |
| 116 | if a.CpuVariant != "" { |
| 117 | s += "_" + a.CpuVariant |
| 118 | } |
| 119 | return s |
| 120 | } |
| 121 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 122 | // ArchType is used to define the 4 supported architecture types (arm, arm64, x86, x86_64), as |
| 123 | // well as the "common" architecture used for modules that support multiple architectures, for |
| 124 | // example Java modules. |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 125 | type ArchType struct { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 126 | // Name is the name of the architecture type, "arm", "arm64", "x86", or "x86_64". |
| 127 | Name string |
| 128 | |
| 129 | // Field is the name of the field used in properties that refer to the architecture, e.g. "Arm64". |
| 130 | Field string |
| 131 | |
| 132 | // Multilib is either "lib32" or "lib64" for 32-bit or 64-bit architectures. |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 133 | Multilib string |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 136 | // String returns the name of the ArchType. |
| 137 | func (a ArchType) String() string { |
| 138 | return a.Name |
| 139 | } |
| 140 | |
Spandan Das | d4530d6 | 2024-09-26 00:46:12 +0000 | [diff] [blame] | 141 | func (a ArchType) Bitness() string { |
| 142 | if a.Multilib == "lib32" { |
| 143 | return "32" |
| 144 | } |
Spandan Das | a8b7452 | 2024-09-28 04:41:57 +0000 | [diff] [blame] | 145 | if a.Multilib == "lib64" { |
| 146 | return "64" |
| 147 | } |
| 148 | panic("Bitness is not defined for the common variant") |
Spandan Das | d4530d6 | 2024-09-26 00:46:12 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 151 | const COMMON_VARIANT = "common" |
| 152 | |
| 153 | var ( |
| 154 | archTypeList []ArchType |
| 155 | |
Colin Cross | f05b0d3 | 2022-07-14 18:10:34 -0700 | [diff] [blame] | 156 | Arm = newArch("arm", "lib32") |
| 157 | Arm64 = newArch("arm64", "lib64") |
| 158 | Riscv64 = newArch("riscv64", "lib64") |
| 159 | X86 = newArch("x86", "lib32") |
| 160 | X86_64 = newArch("x86_64", "lib64") |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 161 | |
| 162 | Common = ArchType{ |
| 163 | Name: COMMON_VARIANT, |
| 164 | } |
| 165 | ) |
| 166 | |
| 167 | var archTypeMap = map[string]ArchType{} |
| 168 | |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 169 | func newArch(name, multilib string) ArchType { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 170 | archType := ArchType{ |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 171 | Name: name, |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 172 | Field: proptools.FieldNameForProperty(name), |
Colin Cross | ec19363 | 2015-07-06 17:49:43 -0700 | [diff] [blame] | 173 | Multilib: multilib, |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 174 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 175 | archTypeList = append(archTypeList, archType) |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 176 | archTypeMap[name] = archType |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 177 | return archType |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Usta | eabf0f3 | 2021-12-06 15:17:23 -0500 | [diff] [blame] | 180 | // ArchTypeList returns a slice copy of the 4 supported ArchTypes for arm, |
Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 181 | // arm64, x86 and x86_64. |
Jaewoong Jung | 1ce9ac6 | 2019-08-13 14:11:33 -0700 | [diff] [blame] | 182 | func ArchTypeList() []ArchType { |
| 183 | return append([]ArchType(nil), archTypeList...) |
| 184 | } |
| 185 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 186 | // MarshalText allows an ArchType to be serialized through any encoder that supports |
| 187 | // encoding.TextMarshaler. |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 188 | func (a ArchType) MarshalText() ([]byte, error) { |
Jeongik Cha | bec4d03 | 2021-04-15 08:55:38 +0900 | [diff] [blame] | 189 | return []byte(a.String()), nil |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 190 | } |
| 191 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 192 | var _ encoding.TextMarshaler = ArchType{} |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 193 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 194 | // UnmarshalText allows an ArchType to be deserialized through any decoder that supports |
| 195 | // encoding.TextUnmarshaler. |
Colin Cross | 74ba962 | 2019-02-11 15:11:14 -0800 | [diff] [blame] | 196 | func (a *ArchType) UnmarshalText(text []byte) error { |
| 197 | if u, ok := archTypeMap[string(text)]; ok { |
| 198 | *a = u |
| 199 | return nil |
| 200 | } |
| 201 | |
| 202 | return fmt.Errorf("unknown ArchType %q", text) |
| 203 | } |
| 204 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 205 | var _ encoding.TextUnmarshaler = &ArchType{} |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 206 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 207 | // OsClass is an enum that describes whether a variant of a module runs on the host, on the device, |
| 208 | // or is generic. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 209 | type OsClass int |
| 210 | |
| 211 | const ( |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 212 | // Generic is used for variants of modules that are not OS-specific. |
Dan Willemsen | 0e2d97b | 2016-11-28 17:50:06 -0800 | [diff] [blame] | 213 | Generic OsClass = iota |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 214 | // Device is used for variants of modules that run on the device. |
Dan Willemsen | 0e2d97b | 2016-11-28 17:50:06 -0800 | [diff] [blame] | 215 | Device |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 216 | // Host is used for variants of modules that run on the host. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 217 | Host |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 218 | ) |
| 219 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 220 | // String returns the OsClass as a string. |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 221 | func (class OsClass) String() string { |
| 222 | switch class { |
| 223 | case Generic: |
| 224 | return "generic" |
| 225 | case Device: |
| 226 | return "device" |
| 227 | case Host: |
| 228 | return "host" |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 229 | default: |
| 230 | panic(fmt.Errorf("unknown class %d", class)) |
| 231 | } |
| 232 | } |
| 233 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 234 | // OsType describes an OS variant of a module. |
| 235 | type OsType struct { |
| 236 | // Name is the name of the OS. It is also used as the name of the property in Android.bp |
| 237 | // files. |
| 238 | Name string |
| 239 | |
| 240 | // Field is the name of the OS converted to an exported field name, i.e. with the first |
| 241 | // character capitalized. |
| 242 | Field string |
| 243 | |
| 244 | // Class is the OsClass of the OS. |
| 245 | Class OsClass |
| 246 | |
| 247 | // DefaultDisabled is set when the module variants for the OS should not be created unless |
| 248 | // the module explicitly requests them. This is used to limit Windows cross compilation to |
| 249 | // only modules that need it. |
| 250 | DefaultDisabled bool |
| 251 | } |
| 252 | |
| 253 | // String returns the name of the OsType. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 254 | func (os OsType) String() string { |
| 255 | return os.Name |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 258 | // Bionic returns true if the OS uses the Bionic libc runtime, i.e. if the OS is Android or |
| 259 | // is Linux with Bionic. |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 260 | func (os OsType) Bionic() bool { |
| 261 | return os == Android || os == LinuxBionic |
| 262 | } |
| 263 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 264 | // Linux returns true if the OS uses the Linux kernel, i.e. if the OS is Android or is Linux |
| 265 | // with or without the Bionic libc runtime. |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 266 | func (os OsType) Linux() bool { |
Colin Cross | 528d67e | 2021-07-23 22:23:07 +0000 | [diff] [blame] | 267 | return os == Android || os == Linux || os == LinuxBionic || os == LinuxMusl |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 270 | // newOsType constructs an OsType and adds it to the global lists. |
| 271 | func newOsType(name string, class OsClass, defDisabled bool, archTypes ...ArchType) OsType { |
| 272 | checkCalledFromInit() |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 273 | os := OsType{ |
| 274 | Name: name, |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 275 | Field: proptools.FieldNameForProperty(name), |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 276 | Class: class, |
Dan Willemsen | 0a37a2a | 2016-11-13 10:16:05 -0800 | [diff] [blame] | 277 | |
| 278 | DefaultDisabled: defDisabled, |
Colin Cross | 54c7112 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 279 | } |
Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 280 | osTypeList = append(osTypeList, os) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 281 | |
| 282 | if _, found := commonTargetMap[name]; found { |
| 283 | panic(fmt.Errorf("Found Os type duplicate during OsType registration: %q", name)) |
| 284 | } else { |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 285 | commonTargetMap[name] = Target{Os: os, Arch: CommonArch} |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 286 | } |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 287 | osArchTypeMap[os] = archTypes |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 288 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 289 | return os |
| 290 | } |
| 291 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 292 | // osByName returns the OsType that has the given name, or NoOsType if none match. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 293 | func osByName(name string) OsType { |
Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 294 | for _, os := range osTypeList { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 295 | if os.Name == name { |
| 296 | return os |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | return NoOsType |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 301 | } |
| 302 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 303 | var ( |
Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 304 | // osTypeList contains a list of all the supported OsTypes, including ones not supported |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 305 | // by the current build host or the target device. |
Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 306 | osTypeList []OsType |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 307 | // commonTargetMap maps names of OsTypes to the corresponding common Target, i.e. the |
| 308 | // Target with the same OsType and the common ArchType. |
| 309 | commonTargetMap = make(map[string]Target) |
| 310 | // osArchTypeMap maps OsTypes to the list of supported ArchTypes for that OS. |
| 311 | osArchTypeMap = map[OsType][]ArchType{} |
| 312 | |
| 313 | // NoOsType is a placeholder for when no OS is needed. |
| 314 | NoOsType OsType |
| 315 | // Linux is the OS for the Linux kernel plus the glibc runtime. |
| 316 | Linux = newOsType("linux_glibc", Host, false, X86, X86_64) |
Colin Cross | 528d67e | 2021-07-23 22:23:07 +0000 | [diff] [blame] | 317 | // LinuxMusl is the OS for the Linux kernel plus the musl runtime. |
Colin Cross | a9b2aac | 2022-06-15 17:25:51 -0700 | [diff] [blame] | 318 | LinuxMusl = newOsType("linux_musl", Host, false, X86, X86_64, Arm64, Arm) |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 319 | // Darwin is the OS for MacOS/Darwin host machines. |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 320 | Darwin = newOsType("darwin", Host, false, Arm64, X86_64) |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 321 | // LinuxBionic is the OS for the Linux kernel plus the Bionic libc runtime, but without the |
| 322 | // rest of Android. |
| 323 | LinuxBionic = newOsType("linux_bionic", Host, false, Arm64, X86_64) |
| 324 | // Windows the OS for Windows host machines. |
| 325 | Windows = newOsType("windows", Host, true, X86, X86_64) |
| 326 | // Android is the OS for target devices that run all of Android, including the Linux kernel |
| 327 | // and the Bionic libc runtime. |
Colin Cross | f05b0d3 | 2022-07-14 18:10:34 -0700 | [diff] [blame] | 328 | Android = newOsType("android", Device, false, Arm, Arm64, Riscv64, X86, X86_64) |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 329 | |
| 330 | // CommonOS is a pseudo OSType for a common OS variant, which is OsType agnostic and which |
| 331 | // has dependencies on all the OS variants. |
| 332 | CommonOS = newOsType("common_os", Generic, false) |
Colin Cross | e9fe294 | 2020-11-10 18:12:15 -0800 | [diff] [blame] | 333 | |
| 334 | // CommonArch is the Arch for all modules that are os-specific but not arch specific, |
| 335 | // for example most Java modules. |
| 336 | CommonArch = Arch{ArchType: Common} |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 337 | ) |
| 338 | |
Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 339 | // OsTypeList returns a slice copy of the supported OsTypes. |
| 340 | func OsTypeList() []OsType { |
| 341 | return append([]OsType(nil), osTypeList...) |
| 342 | } |
| 343 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 344 | // Target specifies the OS and architecture that a module is being compiled for. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 345 | type Target struct { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 346 | // Os the OS that the module is being compiled for (e.g. "linux_glibc", "android"). |
| 347 | Os OsType |
| 348 | // Arch is the architecture that the module is being compiled for. |
| 349 | Arch Arch |
| 350 | // NativeBridge is NativeBridgeEnabled if the architecture is supported using NativeBridge |
| 351 | // (i.e. arm on x86) for this device. |
| 352 | NativeBridge NativeBridgeSupport |
| 353 | // NativeBridgeHostArchName is the name of the real architecture that is used to implement |
| 354 | // the NativeBridge architecture. For example, for arm on x86 this would be "x86". |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 355 | NativeBridgeHostArchName string |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 356 | // NativeBridgeRelativePath is the name of the subdirectory that will contain NativeBridge |
| 357 | // libraries and binaries. |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 358 | NativeBridgeRelativePath string |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 359 | |
| 360 | // HostCross is true when the target cannot run natively on the current build host. |
| 361 | // For example, linux_glibc_x86 returns true on a regular x86/i686/Linux machines, but returns false |
| 362 | // on Mac (different OS), or on 64-bit only i686/Linux machines (unsupported arch). |
| 363 | HostCross bool |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 366 | // NativeBridgeSupport is an enum that specifies if a Target supports NativeBridge. |
| 367 | type NativeBridgeSupport bool |
| 368 | |
| 369 | const ( |
| 370 | NativeBridgeDisabled NativeBridgeSupport = false |
| 371 | NativeBridgeEnabled NativeBridgeSupport = true |
| 372 | ) |
| 373 | |
| 374 | // String returns the OS and arch variations used for the Target. |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 375 | func (target Target) String() string { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 376 | return target.OsVariation() + "_" + target.ArchVariation() |
| 377 | } |
| 378 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 379 | // OsVariation returns the name of the variation used by the osMutator for the Target. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 380 | func (target Target) OsVariation() string { |
| 381 | return target.Os.String() |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 384 | // ArchVariation returns the name of the variation used by the archMutator for the Target. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 385 | func (target Target) ArchVariation() string { |
| 386 | var variation string |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 387 | if target.NativeBridge { |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 388 | variation = "native_bridge_" |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 389 | } |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 390 | variation += target.Arch.String() |
| 391 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 392 | return variation |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 395 | // Variations returns a list of blueprint.Variations for the osMutator and archMutator for the |
| 396 | // Target. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 397 | func (target Target) Variations() []blueprint.Variation { |
| 398 | return []blueprint.Variation{ |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 399 | {Mutator: "os", Variation: target.OsVariation()}, |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 400 | {Mutator: "arch", Variation: target.ArchVariation()}, |
| 401 | } |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 402 | } |
| 403 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 404 | // osMutator splits an arch-specific module into a variant for each OS that is enabled for the |
| 405 | // module. It uses the HostOrDevice value passed to InitAndroidArchModule and the |
| 406 | // device_supported and host_supported properties to determine which OsTypes are enabled for this |
| 407 | // module, then searches through the Targets to determine which have enabled Targets for this |
| 408 | // module. |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 409 | type osTransitionMutator struct{} |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 410 | |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 411 | type allOsInfo struct { |
| 412 | Os map[string]OsType |
| 413 | Variations []string |
| 414 | } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 415 | |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 416 | var allOsProvider = blueprint.NewMutatorProvider[*allOsInfo]("os_propagate") |
| 417 | |
| 418 | // moduleOSList collects a list of OSTypes supported by this module based on the HostOrDevice |
| 419 | // value passed to InitAndroidArchModule and the device_supported and host_supported properties. |
| 420 | func moduleOSList(ctx ConfigContext, base *ModuleBase) []OsType { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 421 | var moduleOSList []OsType |
Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 422 | for _, os := range osTypeList { |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 423 | for _, t := range ctx.Config().Targets[os] { |
Colin Cross | 08d6f8f | 2020-11-19 02:33:19 +0000 | [diff] [blame] | 424 | if base.supportsTarget(t) { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 425 | moduleOSList = append(moduleOSList, os) |
| 426 | break |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 431 | if base.commonProperties.CreateCommonOSVariant { |
| 432 | // A CommonOS variant was requested so add it to the list of OS variants to |
| 433 | // create. It needs to be added to the end because it needs to depend on the |
| 434 | // the other variants and inter variant dependencies can only be created from a |
| 435 | // later variant in that list to an earlier one. That is because variants are |
| 436 | // always processed in the order in which they are created. |
| 437 | moduleOSList = append(moduleOSList, CommonOS) |
| 438 | } |
| 439 | |
| 440 | return moduleOSList |
| 441 | } |
| 442 | |
| 443 | func (o *osTransitionMutator) Split(ctx BaseModuleContext) []string { |
| 444 | module := ctx.Module() |
| 445 | base := module.base() |
| 446 | |
| 447 | // Nothing to do for modules that are not architecture specific (e.g. a genrule). |
| 448 | if !base.ArchSpecific() { |
| 449 | return []string{""} |
| 450 | } |
| 451 | |
| 452 | moduleOSList := moduleOSList(ctx, base) |
Cole Faust | 8fc38f3 | 2023-12-12 17:14:22 -0800 | [diff] [blame] | 453 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 454 | // If there are no supported OSes then disable the module. |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 455 | if len(moduleOSList) == 0 { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 456 | base.Disable() |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 457 | return []string{""} |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 460 | // Convert the list of supported OsTypes to the variation names. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 461 | osNames := make([]string, len(moduleOSList)) |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 462 | osMapping := make(map[string]OsType, len(moduleOSList)) |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 463 | for i, os := range moduleOSList { |
| 464 | osNames[i] = os.String() |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 465 | osMapping[osNames[i]] = os |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 468 | SetProvider(ctx, allOsProvider, &allOsInfo{ |
| 469 | Os: osMapping, |
| 470 | Variations: osNames, |
| 471 | }) |
| 472 | |
| 473 | return osNames |
| 474 | } |
| 475 | |
| 476 | func (o *osTransitionMutator) OutgoingTransition(ctx OutgoingTransitionContext, sourceVariation string) string { |
| 477 | return sourceVariation |
| 478 | } |
| 479 | |
| 480 | func (o *osTransitionMutator) IncomingTransition(ctx IncomingTransitionContext, incomingVariation string) string { |
| 481 | module := ctx.Module() |
| 482 | base := module.base() |
| 483 | |
| 484 | if !base.ArchSpecific() { |
| 485 | return "" |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 488 | return incomingVariation |
| 489 | } |
| 490 | |
| 491 | func (o *osTransitionMutator) Mutate(ctx BottomUpMutatorContext, variation string) { |
| 492 | module := ctx.Module() |
| 493 | base := module.base() |
| 494 | |
| 495 | if variation == "" { |
| 496 | return |
| 497 | } |
| 498 | |
| 499 | allOsInfo, ok := ModuleProvider(ctx, allOsProvider) |
| 500 | if !ok { |
| 501 | panic(fmt.Errorf("missing allOsProvider")) |
| 502 | } |
| 503 | |
| 504 | // Annotate this variant with which OS it was created for, and |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 505 | // squash the appropriate OS-specific properties into the top level properties. |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 506 | base.commonProperties.CompileOS = allOsInfo.Os[variation] |
| 507 | base.setOSProperties(ctx) |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 508 | |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 509 | if variation == CommonOS.String() { |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 510 | // A CommonOS variant was requested so add dependencies from it (the last one in |
| 511 | // the list) to the OS type specific variants. |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 512 | osList := allOsInfo.Variations[:len(allOsInfo.Variations)-1] |
| 513 | for _, os := range osList { |
| 514 | variation := []blueprint.Variation{{"os", os}} |
| 515 | ctx.AddVariationDependencies(variation, commonOsToOsSpecificVariantTag, ctx.ModuleName()) |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | } |
| 519 | |
Colin Cross | c179ea6 | 2020-10-09 10:54:15 -0700 | [diff] [blame] | 520 | type archDepTag struct { |
| 521 | blueprint.BaseDependencyTag |
| 522 | name string |
| 523 | } |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 524 | |
Colin Cross | c179ea6 | 2020-10-09 10:54:15 -0700 | [diff] [blame] | 525 | // Identifies the dependency from CommonOS variant to the os specific variants. |
| 526 | var commonOsToOsSpecificVariantTag = archDepTag{name: "common os to os specific"} |
| 527 | |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 528 | // Get the OsType specific variants for the current CommonOS variant. |
| 529 | // |
| 530 | // The returned list will only contain enabled OsType specific variants of the |
| 531 | // module referenced in the supplied context. An empty list is returned if there |
| 532 | // are no enabled variants or the supplied context is not for an CommonOS |
| 533 | // variant. |
| 534 | func GetOsSpecificVariantsOfCommonOSVariant(mctx BaseModuleContext) []Module { |
| 535 | var variants []Module |
| 536 | mctx.VisitDirectDeps(func(m Module) { |
| 537 | if mctx.OtherModuleDependencyTag(m) == commonOsToOsSpecificVariantTag { |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 538 | if m.Enabled(mctx) { |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 539 | variants = append(variants, m) |
| 540 | } |
| 541 | } |
| 542 | }) |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 543 | return variants |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Dan Willemsen | 4745007 | 2021-10-19 20:24:49 -0700 | [diff] [blame] | 546 | var DarwinUniversalVariantTag = archDepTag{name: "darwin universal binary"} |
| 547 | |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 548 | // archTransitionMutator splits a module into a variant for each Target requested by the module. Target selection |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 549 | // for a module is in three levels, OsClass, multilib, and then Target. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 550 | // OsClass selection is determined by: |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 551 | // - The HostOrDeviceSupported value passed in to InitAndroidArchModule by the module type factory, which selects |
| 552 | // whether the module type can compile for host, device or both. |
| 553 | // - The host_supported and device_supported properties on the module. |
| 554 | // |
Roland Levillain | f5b635d | 2019-06-05 14:42:57 +0100 | [diff] [blame] | 555 | // 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] | 556 | // for the module, the Device OsClass is selected. |
| 557 | // Within each selected OsClass, the multilib selection is determined by: |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 558 | // - The compile_multilib property if it set (which may be overridden by target.android.compile_multilib or |
| 559 | // target.host.compile_multilib). |
| 560 | // - The default multilib passed to InitAndroidArchModule if compile_multilib was not set. |
| 561 | // |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 562 | // Valid multilib values include: |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 563 | // |
| 564 | // "both": compile for all Targets supported by the OsClass (generally x86_64 and x86, or arm64 and arm). |
| 565 | // "first": compile for only a single preferred Target supported by the OsClass. This is generally x86_64 or arm64, |
| 566 | // but may be arm for a 32-bit only build. |
| 567 | // "32": compile for only a single 32-bit Target supported by the OsClass. |
| 568 | // "64": compile for only a single 64-bit Target supported by the OsClass. |
| 569 | // "common": compile a for a single Target that will work on all Targets supported by the OsClass (for example Java). |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 570 | // |
| 571 | // Once the list of Targets is determined, the module is split into a variant for each Target. |
| 572 | // |
| 573 | // Modules can be initialized with InitAndroidMultiTargetsArchModule, in which case they will be split by OsClass, |
| 574 | // but will have a common Target that is expected to handle all other selected Targets via ctx.MultiTargets(). |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 575 | type archTransitionMutator struct{} |
| 576 | |
| 577 | type allArchInfo struct { |
| 578 | Targets map[string]Target |
| 579 | MultiTargets []Target |
| 580 | Primary string |
| 581 | Multilib string |
| 582 | } |
| 583 | |
| 584 | var allArchProvider = blueprint.NewMutatorProvider[*allArchInfo]("arch_propagate") |
| 585 | |
| 586 | func (a *archTransitionMutator) Split(ctx BaseModuleContext) []string { |
| 587 | module := ctx.Module() |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 588 | base := module.base() |
| 589 | |
| 590 | if !base.ArchSpecific() { |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 591 | return []string{""} |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 592 | } |
| 593 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 594 | os := base.commonProperties.CompileOS |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 595 | if os == CommonOS { |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 596 | // Do not create arch specific variants for the CommonOS variant. |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 597 | return []string{""} |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 598 | } |
| 599 | |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 600 | osTargets := ctx.Config().Targets[os] |
Ivan Lozano | c7eafa7 | 2024-07-16 17:55:33 +0000 | [diff] [blame] | 601 | |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 602 | image := base.commonProperties.ImageVariation |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 603 | // Filter NativeBridge targets unless they are explicitly supported. |
| 604 | // Skip creating native bridge variants for non-core modules. |
Paul Duffin | e3d1ae4 | 2021-09-03 17:47:17 +0100 | [diff] [blame] | 605 | if os == Android && !(base.IsNativeBridgeSupported() && image == CoreVariation) { |
Ivan Lozano | 03b717d | 2024-07-18 15:13:50 +0000 | [diff] [blame] | 606 | osTargets = slices.DeleteFunc(slices.Clone(osTargets), func(t Target) bool { |
| 607 | return bool(t.NativeBridge) |
| 608 | }) |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 609 | } |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 610 | |
Ivan Lozano | c7eafa7 | 2024-07-16 17:55:33 +0000 | [diff] [blame] | 611 | // Filter HostCross targets if disabled. |
| 612 | if base.HostSupported() && !base.HostCrossSupported() { |
Ivan Lozano | 03b717d | 2024-07-18 15:13:50 +0000 | [diff] [blame] | 613 | osTargets = slices.DeleteFunc(slices.Clone(osTargets), func(t Target) bool { |
| 614 | return t.HostCross |
| 615 | }) |
Ivan Lozano | c7eafa7 | 2024-07-16 17:55:33 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Yifan Hong | 60e0cfb | 2020-10-21 15:17:56 -0700 | [diff] [blame] | 618 | // only the primary arch in the ramdisk / vendor_ramdisk / recovery partition |
Inseob Kim | 08758f0 | 2021-04-08 21:13:22 +0900 | [diff] [blame] | 619 | if os == Android && (module.InstallInRecovery() || module.InstallInRamdisk() || module.InstallInVendorRamdisk() || module.InstallInDebugRamdisk()) { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 620 | osTargets = []Target{osTargets[0]} |
| 621 | } |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 622 | |
Jaewoong Jung | 003d808 | 2021-02-24 17:39:54 -0800 | [diff] [blame] | 623 | // Windows builds always prefer 32-bit |
| 624 | prefer32 := os == Windows |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 625 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 626 | // Determine the multilib selection for this module. |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 627 | multilib, extraMultilib := decodeMultilib(ctx, base) |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 628 | |
| 629 | // Convert the multilib selection into a list of Targets. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 630 | targets, err := decodeMultilibTargets(multilib, osTargets, prefer32) |
| 631 | if err != nil { |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 632 | ctx.ModuleErrorf("%s", err.Error()) |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 633 | } |
Colin Cross | 5eca7cb | 2018-10-02 14:02:10 -0700 | [diff] [blame] | 634 | |
Colin Cross | c0f0eb8 | 2022-07-19 14:41:11 -0700 | [diff] [blame] | 635 | // If there are no supported targets disable the module. |
| 636 | if len(targets) == 0 { |
| 637 | base.Disable() |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 638 | return []string{""} |
Colin Cross | c0f0eb8 | 2022-07-19 14:41:11 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 641 | // If the module is using extraMultilib, decode the extraMultilib selection into |
| 642 | // a separate list of Targets. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 643 | var multiTargets []Target |
| 644 | if extraMultilib != "" { |
| 645 | multiTargets, err = decodeMultilibTargets(extraMultilib, osTargets, prefer32) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 646 | if err != nil { |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 647 | ctx.ModuleErrorf("%s", err.Error()) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 648 | } |
Colin Cross | c0f0eb8 | 2022-07-19 14:41:11 -0700 | [diff] [blame] | 649 | multiTargets = filterHostCross(multiTargets, targets[0].HostCross) |
Colin Cross | b9db480 | 2016-06-03 01:50:47 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 652 | // Recovery is always the primary architecture, filter out any other architectures. |
Inseob Kim | 20fb5d4 | 2021-02-02 20:07:58 +0900 | [diff] [blame] | 653 | // Common arch is also allowed |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 654 | if image == RecoveryVariation { |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 655 | primaryArch := ctx.Config().DevicePrimaryArchType() |
Inseob Kim | 20fb5d4 | 2021-02-02 20:07:58 +0900 | [diff] [blame] | 656 | targets = filterToArch(targets, primaryArch, Common) |
| 657 | multiTargets = filterToArch(multiTargets, primaryArch, Common) |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 658 | } |
| 659 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 660 | // If there are no supported targets disable the module. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 661 | if len(targets) == 0 { |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 662 | base.Disable() |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 663 | return []string{""} |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 666 | // Convert the targets into a list of arch variation names. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 667 | targetNames := make([]string, len(targets)) |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 668 | targetMapping := make(map[string]Target, len(targets)) |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 669 | for i, target := range targets { |
| 670 | targetNames[i] = target.ArchVariation() |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 671 | targetMapping[targetNames[i]] = targets[i] |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 672 | } |
| 673 | |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 674 | SetProvider(ctx, allArchProvider, &allArchInfo{ |
| 675 | Targets: targetMapping, |
| 676 | MultiTargets: multiTargets, |
| 677 | Primary: targetNames[0], |
| 678 | Multilib: multilib, |
| 679 | }) |
| 680 | return targetNames |
| 681 | } |
Dan Willemsen | 8528f4e | 2021-10-19 00:22:06 -0700 | [diff] [blame] | 682 | |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 683 | func (a *archTransitionMutator) OutgoingTransition(ctx OutgoingTransitionContext, sourceVariation string) string { |
| 684 | return sourceVariation |
| 685 | } |
| 686 | |
| 687 | func (a *archTransitionMutator) IncomingTransition(ctx IncomingTransitionContext, incomingVariation string) string { |
| 688 | module := ctx.Module() |
| 689 | base := module.base() |
| 690 | |
| 691 | if !base.ArchSpecific() { |
| 692 | return "" |
| 693 | } |
| 694 | |
| 695 | os := base.commonProperties.CompileOS |
| 696 | if os == CommonOS { |
| 697 | // Do not create arch specific variants for the CommonOS variant. |
| 698 | return "" |
| 699 | } |
| 700 | |
Cole Faust | b9c67e2 | 2024-10-08 16:39:56 -0700 | [diff] [blame] | 701 | multilib, _ := decodeMultilib(ctx, base) |
| 702 | if multilib == "common" { |
| 703 | return "common" |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 704 | } |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 705 | return incomingVariation |
| 706 | } |
| 707 | |
| 708 | func (a *archTransitionMutator) Mutate(ctx BottomUpMutatorContext, variation string) { |
| 709 | module := ctx.Module() |
| 710 | base := module.base() |
| 711 | os := base.commonProperties.CompileOS |
| 712 | |
| 713 | if os == CommonOS { |
| 714 | // Make sure that the target related properties are initialized for the |
| 715 | // CommonOS variant. |
| 716 | addTargetProperties(module, commonTargetMap[os.Name], nil, true) |
| 717 | return |
| 718 | } |
| 719 | |
| 720 | if variation == "" { |
| 721 | return |
| 722 | } |
| 723 | |
| 724 | if !base.ArchSpecific() { |
| 725 | panic(fmt.Errorf("found variation %q for non arch specifc module", variation)) |
| 726 | } |
| 727 | |
| 728 | allArchInfo, ok := ModuleProvider(ctx, allArchProvider) |
| 729 | if !ok { |
| 730 | return |
| 731 | } |
| 732 | |
| 733 | target, ok := allArchInfo.Targets[variation] |
| 734 | if !ok { |
| 735 | panic(fmt.Errorf("missing Target for %q", variation)) |
| 736 | } |
| 737 | primary := variation == allArchInfo.Primary |
| 738 | multiTargets := allArchInfo.MultiTargets |
| 739 | |
| 740 | // Annotate the new variant with which Target it was created for, and |
| 741 | // squash the appropriate arch-specific properties into the top level properties. |
| 742 | addTargetProperties(ctx.Module(), target, multiTargets, primary) |
| 743 | base.setArchProperties(ctx) |
| 744 | |
| 745 | // Install support doesn't understand Darwin+Arm64 |
| 746 | if os == Darwin && target.HostCross { |
| 747 | base.commonProperties.SkipInstall = true |
| 748 | } |
Dan Willemsen | 4745007 | 2021-10-19 20:24:49 -0700 | [diff] [blame] | 749 | |
| 750 | // Create a dependency for Darwin Universal binaries from the primary to secondary |
| 751 | // architecture. The module itself will be responsible for calling lipo to merge the outputs. |
| 752 | if os == Darwin { |
Cole Faust | b9c67e2 | 2024-10-08 16:39:56 -0700 | [diff] [blame] | 753 | isUniversalBinary := allArchInfo.Multilib == "darwin_universal" && len(allArchInfo.Targets) == 2 |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 754 | isPrimary := variation == ctx.Config().BuildArch.String() |
| 755 | hasSecondaryConfigured := len(ctx.Config().Targets[Darwin]) > 1 |
| 756 | if isUniversalBinary && isPrimary && hasSecondaryConfigured { |
| 757 | secondaryArch := ctx.Config().Targets[Darwin][1].Arch.String() |
| 758 | variation := []blueprint.Variation{{"arch", secondaryArch}} |
| 759 | ctx.AddVariationDependencies(variation, DarwinUniversalVariantTag, ctx.ModuleName()) |
Dan Willemsen | 4745007 | 2021-10-19 20:24:49 -0700 | [diff] [blame] | 760 | } |
| 761 | } |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 762 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 763 | } |
| 764 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 765 | // addTargetProperties annotates a variant with the Target is is being compiled for, the list |
| 766 | // of additional Targets it is supporting (if any), and whether it is the primary Target for |
| 767 | // the module. |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 768 | func addTargetProperties(m Module, target Target, multiTargets []Target, primaryTarget bool) { |
| 769 | m.base().commonProperties.CompileTarget = target |
| 770 | m.base().commonProperties.CompileMultiTargets = multiTargets |
| 771 | m.base().commonProperties.CompilePrimary = primaryTarget |
Cole Faust | 0aa21cc | 2024-03-20 12:28:03 -0700 | [diff] [blame] | 772 | m.base().commonProperties.ArchReady = true |
Paul Duffin | 1356d8c | 2020-02-25 19:26:33 +0000 | [diff] [blame] | 773 | } |
| 774 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 775 | // decodeMultilib returns the appropriate compile_multilib property for the module, or the default |
| 776 | // multilib from the factory's call to InitAndroidArchModule if none was set. For modules that |
| 777 | // called InitAndroidMultiTargetsArchModule it always returns "common" for multilib, and returns |
| 778 | // the actual multilib in extraMultilib. |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 779 | func decodeMultilib(ctx ConfigContext, base *ModuleBase) (multilib, extraMultilib string) { |
| 780 | os := base.commonProperties.CompileOS |
| 781 | ignorePrefer32OnDevice := ctx.Config().IgnorePrefer32OnDevice() |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 782 | // First check the "android.compile_multilib" or "host.compile_multilib" properties. |
Dan Willemsen | 4745007 | 2021-10-19 20:24:49 -0700 | [diff] [blame] | 783 | switch os.Class { |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 784 | case Device: |
| 785 | multilib = String(base.commonProperties.Target.Android.Compile_multilib) |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 786 | case Host: |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 787 | multilib = String(base.commonProperties.Target.Host.Compile_multilib) |
| 788 | } |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 789 | |
| 790 | // If those aren't set, try the "compile_multilib" property. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 791 | if multilib == "" { |
| 792 | multilib = String(base.commonProperties.Compile_multilib) |
| 793 | } |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 794 | |
| 795 | // If that wasn't set, use the default multilib set by the factory. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 796 | if multilib == "" { |
| 797 | multilib = base.commonProperties.Default_multilib |
| 798 | } |
| 799 | |
Christopher Ferris | 98f1022 | 2022-07-13 23:16:52 -0700 | [diff] [blame] | 800 | // If a device is configured with multiple targets, this option |
| 801 | // force all device targets that prefer32 to be compiled only as |
| 802 | // the first target. |
| 803 | if ignorePrefer32OnDevice && os.Class == Device && (multilib == "prefer32" || multilib == "first_prefer32") { |
| 804 | multilib = "first" |
| 805 | } |
| 806 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 807 | if base.commonProperties.UseTargetVariants { |
Dan Willemsen | 4745007 | 2021-10-19 20:24:49 -0700 | [diff] [blame] | 808 | // Darwin has the concept of "universal binaries" which is implemented in Soong by |
| 809 | // building both x86_64 and arm64 variants, and having select module types know how to |
| 810 | // merge the outputs of their corresponding variants together into a final binary. Most |
| 811 | // module types don't need to understand this logic, as we only build a small portion |
| 812 | // of the tree for Darwin, and only module types writing macho files need to do the |
| 813 | // merging. |
| 814 | // |
| 815 | // This logic is not enabled for: |
| 816 | // "common", as it's not an arch-specific variant |
| 817 | // "32", as Darwin never has a 32-bit variant |
| 818 | // !UseTargetVariants, as the module has opted into handling the arch-specific logic on |
| 819 | // its own. |
| 820 | if os == Darwin && multilib != "common" && multilib != "32" { |
Cole Faust | b9c67e2 | 2024-10-08 16:39:56 -0700 | [diff] [blame] | 821 | multilib = "darwin_universal" |
Dan Willemsen | 4745007 | 2021-10-19 20:24:49 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 824 | return multilib, "" |
| 825 | } else { |
| 826 | // For app modules a single arch variant will be created per OS class which is expected to handle all the |
| 827 | // selected arches. Return the common-type as multilib and any Android.bp provided multilib as extraMultilib |
| 828 | if multilib == base.commonProperties.Default_multilib { |
| 829 | multilib = "first" |
| 830 | } |
| 831 | return base.commonProperties.Default_multilib, multilib |
| 832 | } |
| 833 | } |
| 834 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 835 | // filterToArch takes a list of Targets and an ArchType, and returns a modified list that contains |
Inseob Kim | 20fb5d4 | 2021-02-02 20:07:58 +0900 | [diff] [blame] | 836 | // only Targets that have the specified ArchTypes. |
| 837 | func filterToArch(targets []Target, archs ...ArchType) []Target { |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 838 | for i := 0; i < len(targets); i++ { |
Inseob Kim | 20fb5d4 | 2021-02-02 20:07:58 +0900 | [diff] [blame] | 839 | found := false |
| 840 | for _, arch := range archs { |
| 841 | if targets[i].Arch.ArchType == arch { |
| 842 | found = true |
| 843 | break |
| 844 | } |
| 845 | } |
| 846 | if !found { |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 847 | targets = append(targets[:i], targets[i+1:]...) |
| 848 | i-- |
| 849 | } |
| 850 | } |
| 851 | return targets |
| 852 | } |
| 853 | |
Colin Cross | c0f0eb8 | 2022-07-19 14:41:11 -0700 | [diff] [blame] | 854 | // filterHostCross takes a list of Targets and a hostCross value, and returns a modified list |
| 855 | // that contains only Targets that have the specified HostCross. |
| 856 | func filterHostCross(targets []Target, hostCross bool) []Target { |
| 857 | for i := 0; i < len(targets); i++ { |
| 858 | if targets[i].HostCross != hostCross { |
| 859 | targets = append(targets[:i], targets[i+1:]...) |
| 860 | i-- |
| 861 | } |
| 862 | } |
| 863 | return targets |
| 864 | } |
| 865 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 866 | // archPropRoot is a struct type used as the top level of the arch-specific properties. It |
| 867 | // contains the "arch", "multilib", and "target" property structs. It is used to split up the |
| 868 | // property structs to limit how much is allocated when a single arch-specific property group is |
| 869 | // used. The types are interface{} because they will hold instances of runtime-created types. |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 870 | type archPropRoot struct { |
| 871 | Arch, Multilib, Target interface{} |
| 872 | } |
| 873 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 874 | // archPropTypeDesc holds the runtime-created types for the property structs to instantiate to |
| 875 | // create an archPropRoot property struct. |
| 876 | type archPropTypeDesc struct { |
| 877 | arch, multilib, target reflect.Type |
| 878 | } |
| 879 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 880 | // createArchPropTypeDesc takes a reflect.Type that is either a struct or a pointer to a struct, and |
| 881 | // returns lists of reflect.Types that contains the arch-variant properties inside structs for each |
| 882 | // arch, multilib and target property. |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 883 | // |
| 884 | // This is a relatively expensive operation, so the results are cached in the global |
| 885 | // archPropTypeMap. It is constructed entirely based on compile-time data, so there is no need |
| 886 | // to isolate the results between multiple tests running in parallel. |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 887 | func createArchPropTypeDesc(props reflect.Type) []archPropTypeDesc { |
Colin Cross | b1d8c99 | 2020-01-21 11:43:29 -0800 | [diff] [blame] | 888 | // Each property struct shard will be nested many times under the runtime generated arch struct, |
| 889 | // which can hit the limit of 64kB for the name of runtime generated structs. They are nested |
| 890 | // 97 times now, which may grow in the future, plus there is some overhead for the containing |
| 891 | // type. This number may need to be reduced if too many are added, but reducing it too far |
| 892 | // could cause problems if a single deeply nested property no longer fits in the name. |
| 893 | const maxArchTypeNameSize = 500 |
| 894 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 895 | // Convert the type to a new set of types that contains only the arch-specific properties |
Usta Shrestha | 0b52d83 | 2022-02-04 21:37:39 -0500 | [diff] [blame] | 896 | // (those that are tagged with `android:"arch_variant"`), and sharded into multiple types |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 897 | // to keep the runtime-generated names under the limit. |
Colin Cross | b1d8c99 | 2020-01-21 11:43:29 -0800 | [diff] [blame] | 898 | propShards, _ := proptools.FilterPropertyStructSharded(props, maxArchTypeNameSize, filterArchStruct) |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 899 | |
| 900 | // If the type has no arch-specific properties there is nothing to do. |
Colin Cross | cb98807 | 2019-01-24 14:58:11 -0800 | [diff] [blame] | 901 | if len(propShards) == 0 { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 902 | return nil |
| 903 | } |
| 904 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 905 | var ret []archPropTypeDesc |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 906 | for _, props := range propShards { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 907 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 908 | // variantFields takes a list of variant property field names and returns a list the |
| 909 | // StructFields with the names and the type of the current shard. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 910 | variantFields := func(names []string) []reflect.StructField { |
| 911 | ret := make([]reflect.StructField, len(names)) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 912 | |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 913 | for i, name := range names { |
| 914 | ret[i].Name = name |
| 915 | ret[i].Type = props |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 916 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 917 | |
| 918 | return ret |
| 919 | } |
| 920 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 921 | // Create a type that contains the properties in this shard repeated for each |
| 922 | // architecture, architecture variant, and architecture feature. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 923 | archFields := make([]reflect.StructField, len(archTypeList)) |
| 924 | for i, arch := range archTypeList { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 925 | var variants []string |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 926 | |
| 927 | for _, archVariant := range archVariants[arch] { |
| 928 | archVariant := variantReplacer.Replace(archVariant) |
| 929 | variants = append(variants, proptools.FieldNameForProperty(archVariant)) |
| 930 | } |
Liz Kammer | 2c2afe2 | 2022-02-11 11:35:03 -0500 | [diff] [blame] | 931 | for _, cpuVariant := range cpuVariants[arch] { |
| 932 | cpuVariant := variantReplacer.Replace(cpuVariant) |
| 933 | variants = append(variants, proptools.FieldNameForProperty(cpuVariant)) |
| 934 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 935 | for _, feature := range archFeatures[arch] { |
| 936 | feature := variantReplacer.Replace(feature) |
| 937 | variants = append(variants, proptools.FieldNameForProperty(feature)) |
| 938 | } |
| 939 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 940 | // Create the StructFields for each architecture variant architecture feature |
| 941 | // (e.g. "arch.arm.cortex-a53" or "arch.arm.neon"). |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 942 | fields := variantFields(variants) |
| 943 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 944 | // Create the StructField for the architecture itself (e.g. "arch.arm"). The special |
| 945 | // "BlueprintEmbed" name is used by Blueprint to put the properties in the |
| 946 | // parent struct. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 947 | fields = append([]reflect.StructField{{ |
| 948 | Name: "BlueprintEmbed", |
| 949 | Type: props, |
| 950 | Anonymous: true, |
| 951 | }}, fields...) |
| 952 | |
| 953 | archFields[i] = reflect.StructField{ |
| 954 | Name: arch.Field, |
| 955 | Type: reflect.StructOf(fields), |
| 956 | } |
| 957 | } |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 958 | |
| 959 | // Create the type of the "arch" property struct for this shard. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 960 | archType := reflect.StructOf(archFields) |
| 961 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 962 | // Create the type for the "multilib" property struct for this shard, containing the |
| 963 | // "multilib.lib32" and "multilib.lib64" property structs. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 964 | multilibType := reflect.StructOf(variantFields([]string{"Lib32", "Lib64"})) |
| 965 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 966 | // Start with a list of the special targets |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 967 | targets := []string{ |
| 968 | "Host", |
| 969 | "Android64", |
| 970 | "Android32", |
| 971 | "Bionic", |
Colin Cross | 528d67e | 2021-07-23 22:23:07 +0000 | [diff] [blame] | 972 | "Glibc", |
| 973 | "Musl", |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 974 | "Linux", |
Colin Cross | a98d36d | 2022-03-07 14:39:49 -0800 | [diff] [blame] | 975 | "Host_linux", |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 976 | "Not_windows", |
| 977 | "Arm_on_x86", |
| 978 | "Arm_on_x86_64", |
Victor Khimenko | c26fcf4 | 2020-05-07 22:16:33 +0200 | [diff] [blame] | 979 | "Native_bridge", |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 980 | } |
Jingwen Chen | 2f6a21e | 2021-04-05 07:33:05 +0000 | [diff] [blame] | 981 | for _, os := range osTypeList { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 982 | // Add all the OSes. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 983 | targets = append(targets, os.Field) |
| 984 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 985 | // Add the OS/Arch combinations, e.g. "android_arm64". |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 986 | for _, archType := range osArchTypeMap[os] { |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 987 | targets = append(targets, GetCompoundTargetField(os, archType)) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 988 | |
Colin Cross | 1aa45b0 | 2022-02-10 10:33:10 -0800 | [diff] [blame] | 989 | // Also add the special "linux_<arch>", "bionic_<arch>" , "glibc_<arch>", and |
| 990 | // "musl_<arch>" property structs. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 991 | if os.Linux() { |
| 992 | target := "Linux_" + archType.Name |
| 993 | if !InList(target, targets) { |
| 994 | targets = append(targets, target) |
| 995 | } |
| 996 | } |
Colin Cross | a98d36d | 2022-03-07 14:39:49 -0800 | [diff] [blame] | 997 | if os.Linux() && os.Class == Host { |
| 998 | target := "Host_linux_" + archType.Name |
| 999 | if !InList(target, targets) { |
| 1000 | targets = append(targets, target) |
| 1001 | } |
| 1002 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1003 | if os.Bionic() { |
| 1004 | target := "Bionic_" + archType.Name |
| 1005 | if !InList(target, targets) { |
| 1006 | targets = append(targets, target) |
| 1007 | } |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 1008 | } |
Colin Cross | 1aa45b0 | 2022-02-10 10:33:10 -0800 | [diff] [blame] | 1009 | if os == Linux { |
| 1010 | target := "Glibc_" + archType.Name |
| 1011 | if !InList(target, targets) { |
| 1012 | targets = append(targets, target) |
| 1013 | } |
| 1014 | } |
| 1015 | if os == LinuxMusl { |
| 1016 | target := "Musl_" + archType.Name |
| 1017 | if !InList(target, targets) { |
| 1018 | targets = append(targets, target) |
| 1019 | } |
| 1020 | } |
Dan Willemsen | 866b563 | 2017-09-22 12:28:24 -0700 | [diff] [blame] | 1021 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1022 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1023 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1024 | // Create the type for the "target" property struct for this shard. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1025 | targetType := reflect.StructOf(variantFields(targets)) |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1026 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1027 | // Return a descriptor of the 3 runtime-created types. |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1028 | ret = append(ret, archPropTypeDesc{ |
| 1029 | arch: reflect.PtrTo(archType), |
| 1030 | multilib: reflect.PtrTo(multilibType), |
| 1031 | target: reflect.PtrTo(targetType), |
| 1032 | }) |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1033 | } |
| 1034 | return ret |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1037 | // variantReplacer converts architecture variant or architecture feature names into names that |
| 1038 | // are valid for an Android.bp file. |
| 1039 | var variantReplacer = strings.NewReplacer("-", "_", ".", "_") |
| 1040 | |
| 1041 | // filterArchStruct returns true if the given field is an architecture specific property. |
Colin Cross | 7444910 | 2019-09-25 11:26:40 -0700 | [diff] [blame] | 1042 | func filterArchStruct(field reflect.StructField, prefix string) (bool, reflect.StructField) { |
| 1043 | if proptools.HasTag(field, "android", "arch_variant") { |
| 1044 | // The arch_variant field isn't necessary past this point |
| 1045 | // Instead of wasting space, just remove it. Go also has a |
| 1046 | // 16-bit limit on structure name length. The name is constructed |
| 1047 | // based on the Go source representation of the structure, so |
| 1048 | // the tag names count towards that length. |
Colin Cross | b4fecbf | 2020-01-21 11:38:47 -0800 | [diff] [blame] | 1049 | |
| 1050 | androidTag := field.Tag.Get("android") |
| 1051 | values := strings.Split(androidTag, ",") |
| 1052 | |
| 1053 | if string(field.Tag) != `android:"`+strings.Join(values, ",")+`"` { |
| 1054 | panic(fmt.Errorf("unexpected tag format %q", field.Tag)) |
Colin Cross | 7444910 | 2019-09-25 11:26:40 -0700 | [diff] [blame] | 1055 | } |
Colin Cross | b4fecbf | 2020-01-21 11:38:47 -0800 | [diff] [blame] | 1056 | // these tags don't need to be present in the runtime generated struct type. |
Cole Faust | 5fda87b | 2024-04-24 11:21:14 -0700 | [diff] [blame] | 1057 | // However replace_instead_of_append does, because it's read by the blueprint |
| 1058 | // property extending util functions, which can operate on these generated arch |
| 1059 | // property structs. |
| 1060 | values = RemoveListFromList(values, []string{"arch_variant", "variant_prepend", "path"}) |
Liz Kammer | ff966b1 | 2022-07-29 10:49:16 -0400 | [diff] [blame] | 1061 | if len(values) > 0 { |
Cole Faust | 5fda87b | 2024-04-24 11:21:14 -0700 | [diff] [blame] | 1062 | if values[0] != "replace_instead_of_append" || len(values) > 1 { |
| 1063 | panic(fmt.Errorf("unknown tags %q in field %q", values, prefix+field.Name)) |
| 1064 | } |
| 1065 | field.Tag = `android:"replace_instead_of_append"` |
| 1066 | } else { |
| 1067 | field.Tag = `` |
Colin Cross | b4fecbf | 2020-01-21 11:38:47 -0800 | [diff] [blame] | 1068 | } |
Colin Cross | 7444910 | 2019-09-25 11:26:40 -0700 | [diff] [blame] | 1069 | return true, field |
| 1070 | } |
| 1071 | return false, field |
| 1072 | } |
| 1073 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1074 | // archPropTypeMap contains a cache of the results of createArchPropTypeDesc for each type. It is |
| 1075 | // shared across all Contexts, but is constructed based only on compile-time information so there |
| 1076 | // is no risk of contaminating one Context with data from another. |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1077 | var archPropTypeMap OncePer |
| 1078 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1079 | // initArchModule adds the architecture-specific property structs to a Module. |
| 1080 | func initArchModule(m Module) { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1081 | |
| 1082 | base := m.base() |
| 1083 | |
Usta | eabf0f3 | 2021-12-06 15:17:23 -0500 | [diff] [blame] | 1084 | if len(base.archProperties) != 0 { |
| 1085 | panic(fmt.Errorf("module %s already has archProperties", m.Name())) |
| 1086 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1087 | |
Usta | eabf0f3 | 2021-12-06 15:17:23 -0500 | [diff] [blame] | 1088 | getStructType := func(properties interface{}) reflect.Type { |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1089 | propertiesValue := reflect.ValueOf(properties) |
Colin Cross | 62496a0 | 2016-08-08 15:49:17 -0700 | [diff] [blame] | 1090 | t := propertiesValue.Type() |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1091 | if propertiesValue.Kind() != reflect.Ptr { |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1092 | panic(fmt.Errorf("properties must be a pointer to a struct, got %T", |
| 1093 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | propertiesValue = propertiesValue.Elem() |
| 1097 | if propertiesValue.Kind() != reflect.Struct { |
Usta | eabf0f3 | 2021-12-06 15:17:23 -0500 | [diff] [blame] | 1098 | panic(fmt.Errorf("properties must be a pointer to a struct, got a pointer to %T", |
Colin Cross | ca860ac | 2016-01-04 14:34:37 -0800 | [diff] [blame] | 1099 | propertiesValue.Interface())) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1100 | } |
Usta | eabf0f3 | 2021-12-06 15:17:23 -0500 | [diff] [blame] | 1101 | return t |
| 1102 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1103 | |
Usta | 851a327 | 2022-01-05 23:42:33 -0500 | [diff] [blame] | 1104 | for _, properties := range m.GetProperties() { |
Usta | eabf0f3 | 2021-12-06 15:17:23 -0500 | [diff] [blame] | 1105 | t := getStructType(properties) |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1106 | // Get or create the arch-specific property struct types for this property struct type. |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 1107 | archPropTypes := archPropTypeMap.Once(NewCustomOnceKey(t), func() interface{} { |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1108 | return createArchPropTypeDesc(t) |
| 1109 | }).([]archPropTypeDesc) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1110 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1111 | // Instantiate one of each arch-specific property struct type and add it to the |
| 1112 | // properties for the Module. |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1113 | var archProperties []interface{} |
| 1114 | for _, t := range archPropTypes { |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1115 | archProperties = append(archProperties, &archPropRoot{ |
| 1116 | Arch: reflect.Zero(t.arch).Interface(), |
| 1117 | Multilib: reflect.Zero(t.multilib).Interface(), |
| 1118 | Target: reflect.Zero(t.target).Interface(), |
| 1119 | }) |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1120 | } |
Colin Cross | c17727d | 2018-10-24 12:42:09 -0700 | [diff] [blame] | 1121 | base.archProperties = append(base.archProperties, archProperties) |
| 1122 | m.AddProperties(archProperties...) |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1123 | } |
| 1124 | |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1125 | } |
| 1126 | |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1127 | func maybeBlueprintEmbed(src reflect.Value) reflect.Value { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1128 | // If the value of the field is a struct (as opposed to a pointer to a struct) then step |
| 1129 | // into the BlueprintEmbed field. |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1130 | if src.Kind() == reflect.Struct { |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1131 | return src.FieldByName("BlueprintEmbed") |
| 1132 | } else { |
| 1133 | return src |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1134 | } |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | // Merges the property struct in srcValue into dst. |
Liz Kammer | b6dbc87 | 2021-05-14 15:14:40 -0400 | [diff] [blame] | 1138 | func mergePropertyStruct(ctx ArchVariantContext, dst interface{}, srcValue reflect.Value) { |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1139 | src := maybeBlueprintEmbed(srcValue).Interface() |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1140 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1141 | // order checks the `android:"variant_prepend"` tag to handle properties where the |
| 1142 | // arch-specific value needs to come before the generic value, for example for lists of |
| 1143 | // include directories. |
Colin Cross | 1e7e043 | 2024-02-02 10:59:50 -0800 | [diff] [blame] | 1144 | order := func(dstField, srcField reflect.StructField) (proptools.Order, error) { |
Colin Cross | 6ee75b6 | 2016-05-05 15:57:15 -0700 | [diff] [blame] | 1145 | if proptools.HasTag(dstField, "android", "variant_prepend") { |
| 1146 | return proptools.Prepend, nil |
| 1147 | } else { |
| 1148 | return proptools.Append, nil |
| 1149 | } |
| 1150 | } |
| 1151 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1152 | // Squash the located property struct into the destination property struct. |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1153 | err := proptools.ExtendMatchingProperties([]interface{}{dst}, src, nil, order) |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1154 | if err != nil { |
| 1155 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
| 1156 | ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
| 1157 | } else { |
| 1158 | panic(err) |
| 1159 | } |
| 1160 | } |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1161 | } |
Colin Cross | 85a8897 | 2015-11-23 13:29:51 -0800 | [diff] [blame] | 1162 | |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1163 | // Returns the immediate child of the input property struct that corresponds to |
| 1164 | // the sub-property "field". |
Liz Kammer | b6dbc87 | 2021-05-14 15:14:40 -0400 | [diff] [blame] | 1165 | func getChildPropertyStruct(ctx ArchVariantContext, |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1166 | src reflect.Value, field, userFriendlyField string) (reflect.Value, bool) { |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1167 | |
| 1168 | // Step into non-nil pointers to structs in the src value. |
| 1169 | if src.Kind() == reflect.Ptr { |
| 1170 | if src.IsNil() { |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1171 | return reflect.Value{}, false |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1172 | } |
| 1173 | src = src.Elem() |
| 1174 | } |
| 1175 | |
| 1176 | // Find the requested field in the src struct. |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1177 | child := src.FieldByName(proptools.FieldNameForProperty(field)) |
| 1178 | if !child.IsValid() { |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1179 | ctx.ModuleErrorf("field %q does not exist", userFriendlyField) |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1180 | return reflect.Value{}, false |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1181 | } |
| 1182 | |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1183 | if child.IsZero() { |
| 1184 | return reflect.Value{}, false |
| 1185 | } |
| 1186 | |
| 1187 | return child, true |
Colin Cross | 06a931b | 2015-10-28 17:23:31 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1190 | // Squash the appropriate OS-specific property structs into the matching top level property structs |
| 1191 | // based on the CompileOS value that was annotated on the variant. |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1192 | func (m *ModuleBase) setOSProperties(ctx BottomUpMutatorContext) { |
| 1193 | os := m.commonProperties.CompileOS |
| 1194 | |
Usta | dca0219 | 2021-12-20 12:56:46 -0500 | [diff] [blame] | 1195 | for i := range m.archProperties { |
Usta | 851a327 | 2022-01-05 23:42:33 -0500 | [diff] [blame] | 1196 | genProps := m.GetProperties()[i] |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1197 | if m.archProperties[i] == nil { |
| 1198 | continue |
| 1199 | } |
| 1200 | for _, archProperties := range m.archProperties[i] { |
| 1201 | archPropValues := reflect.ValueOf(archProperties).Elem() |
| 1202 | |
Colin Cross | cbbd13f | 2020-01-17 14:08:22 -0800 | [diff] [blame] | 1203 | targetProp := archPropValues.FieldByName("Target").Elem() |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1204 | |
| 1205 | // Handle host-specific properties in the form: |
| 1206 | // target: { |
| 1207 | // host: { |
| 1208 | // key: value, |
| 1209 | // }, |
| 1210 | // }, |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1211 | if os.Class == Host { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1212 | field := "Host" |
| 1213 | prefix := "target.host" |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1214 | if hostProperties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { |
| 1215 | mergePropertyStruct(ctx, genProps, hostProperties) |
| 1216 | } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | // Handle target OS generalities of the form: |
| 1220 | // target: { |
| 1221 | // bionic: { |
| 1222 | // key: value, |
| 1223 | // }, |
| 1224 | // } |
| 1225 | if os.Linux() { |
| 1226 | field := "Linux" |
| 1227 | prefix := "target.linux" |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1228 | if linuxProperties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { |
| 1229 | mergePropertyStruct(ctx, genProps, linuxProperties) |
| 1230 | } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
Colin Cross | a98d36d | 2022-03-07 14:39:49 -0800 | [diff] [blame] | 1233 | if os.Linux() && os.Class == Host { |
| 1234 | field := "Host_linux" |
| 1235 | prefix := "target.host_linux" |
| 1236 | if linuxProperties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { |
| 1237 | mergePropertyStruct(ctx, genProps, linuxProperties) |
| 1238 | } |
| 1239 | } |
| 1240 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1241 | if os.Bionic() { |
| 1242 | field := "Bionic" |
| 1243 | prefix := "target.bionic" |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1244 | if bionicProperties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { |
| 1245 | mergePropertyStruct(ctx, genProps, bionicProperties) |
| 1246 | } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
Colin Cross | 528d67e | 2021-07-23 22:23:07 +0000 | [diff] [blame] | 1249 | if os == Linux { |
| 1250 | field := "Glibc" |
| 1251 | prefix := "target.glibc" |
| 1252 | if bionicProperties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { |
| 1253 | mergePropertyStruct(ctx, genProps, bionicProperties) |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | if os == LinuxMusl { |
| 1258 | field := "Musl" |
| 1259 | prefix := "target.musl" |
| 1260 | if bionicProperties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { |
| 1261 | mergePropertyStruct(ctx, genProps, bionicProperties) |
| 1262 | } |
Colin Cross | 528d67e | 2021-07-23 22:23:07 +0000 | [diff] [blame] | 1263 | } |
| 1264 | |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1265 | // Handle target OS properties in the form: |
| 1266 | // target: { |
| 1267 | // linux_glibc: { |
| 1268 | // key: value, |
| 1269 | // }, |
| 1270 | // not_windows: { |
| 1271 | // key: value, |
| 1272 | // }, |
| 1273 | // android { |
| 1274 | // key: value, |
| 1275 | // }, |
| 1276 | // }, |
| 1277 | field := os.Field |
| 1278 | prefix := "target." + os.Name |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1279 | if osProperties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { |
| 1280 | mergePropertyStruct(ctx, genProps, osProperties) |
| 1281 | } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1282 | |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1283 | if os.Class == Host && os != Windows { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1284 | field := "Not_windows" |
| 1285 | prefix := "target.not_windows" |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1286 | if notWindowsProperties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { |
| 1287 | mergePropertyStruct(ctx, genProps, notWindowsProperties) |
| 1288 | } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | // Handle 64-bit device properties in the form: |
| 1292 | // target { |
| 1293 | // android64 { |
| 1294 | // key: value, |
| 1295 | // }, |
| 1296 | // android32 { |
| 1297 | // key: value, |
| 1298 | // }, |
| 1299 | // }, |
| 1300 | // WARNING: this is probably not what you want to use in your blueprints file, it selects |
| 1301 | // options for all targets on a device that supports 64-bit binaries, not just the targets |
| 1302 | // that are being compiled for 64-bit. Its expected use case is binaries like linker and |
| 1303 | // debuggerd that need to know when they are a 32-bit process running on a 64-bit device |
| 1304 | if os.Class == Device { |
| 1305 | if ctx.Config().Android64() { |
| 1306 | field := "Android64" |
| 1307 | prefix := "target.android64" |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1308 | if android64Properties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { |
| 1309 | mergePropertyStruct(ctx, genProps, android64Properties) |
| 1310 | } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1311 | } else { |
| 1312 | field := "Android32" |
| 1313 | prefix := "target.android32" |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1314 | if android32Properties, ok := getChildPropertyStruct(ctx, targetProp, field, prefix); ok { |
| 1315 | mergePropertyStruct(ctx, genProps, android32Properties) |
| 1316 | } |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 1317 | } |
| 1318 | } |
| 1319 | } |
| 1320 | } |
| 1321 | } |
| 1322 | |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1323 | // Returns the struct containing the properties specific to the given |
| 1324 | // architecture type. These look like this in Blueprint files: |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 1325 | // |
| 1326 | // arch: { |
| 1327 | // arm64: { |
| 1328 | // key: value, |
| 1329 | // }, |
| 1330 | // }, |
| 1331 | // |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1332 | // This struct will also contain sub-structs containing to the architecture/CPU |
| 1333 | // variants and features that themselves contain properties specific to those. |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1334 | func getArchTypeStruct(ctx ArchVariantContext, archProperties interface{}, archType ArchType) (reflect.Value, bool) { |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1335 | archPropValues := reflect.ValueOf(archProperties).Elem() |
| 1336 | archProp := archPropValues.FieldByName("Arch").Elem() |
| 1337 | prefix := "arch." + archType.Name |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1338 | return getChildPropertyStruct(ctx, archProp, archType.Name, prefix) |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | // Returns the struct containing the properties specific to a given multilib |
| 1342 | // value. These look like this in the Blueprint file: |
Colin Cross | d079e0b | 2022-08-16 10:27:33 -0700 | [diff] [blame] | 1343 | // |
| 1344 | // multilib: { |
| 1345 | // lib32: { |
| 1346 | // key: value, |
| 1347 | // }, |
| 1348 | // }, |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1349 | func getMultilibStruct(ctx ArchVariantContext, archProperties interface{}, archType ArchType) (reflect.Value, bool) { |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1350 | archPropValues := reflect.ValueOf(archProperties).Elem() |
| 1351 | multilibProp := archPropValues.FieldByName("Multilib").Elem() |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1352 | return getChildPropertyStruct(ctx, multilibProp, archType.Multilib, "multilib."+archType.Multilib) |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1353 | } |
| 1354 | |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 1355 | func GetCompoundTargetField(os OsType, arch ArchType) string { |
Rupert Shuttleworth | c194ffb | 2021-05-19 06:49:02 -0400 | [diff] [blame] | 1356 | return os.Field + "_" + arch.Name |
| 1357 | } |
| 1358 | |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1359 | // Returns the structs corresponding to the properties specific to the given |
| 1360 | // architecture and OS in archProperties. |
Colin Cross | b2388e3 | 2024-10-07 15:05:23 -0700 | [diff] [blame] | 1361 | func getArchProperties(ctx BaseModuleContext, archProperties interface{}, arch Arch, os OsType, nativeBridgeEnabled bool) []reflect.Value { |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1362 | result := make([]reflect.Value, 0) |
| 1363 | archPropValues := reflect.ValueOf(archProperties).Elem() |
| 1364 | |
| 1365 | targetProp := archPropValues.FieldByName("Target").Elem() |
| 1366 | |
| 1367 | archType := arch.ArchType |
| 1368 | |
| 1369 | if arch.ArchType != Common { |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1370 | archStruct, ok := getArchTypeStruct(ctx, archProperties, arch.ArchType) |
| 1371 | if ok { |
| 1372 | result = append(result, archStruct) |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1373 | |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1374 | // Handle arch-variant-specific properties in the form: |
| 1375 | // arch: { |
| 1376 | // arm: { |
| 1377 | // variant: { |
| 1378 | // key: value, |
| 1379 | // }, |
| 1380 | // }, |
| 1381 | // }, |
| 1382 | v := variantReplacer.Replace(arch.ArchVariant) |
| 1383 | if v != "" { |
| 1384 | prefix := "arch." + archType.Name + "." + v |
| 1385 | if variantProperties, ok := getChildPropertyStruct(ctx, archStruct, v, prefix); ok { |
| 1386 | result = append(result, variantProperties) |
| 1387 | } |
| 1388 | } |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1389 | |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1390 | // Handle cpu-variant-specific properties in the form: |
| 1391 | // arch: { |
| 1392 | // arm: { |
| 1393 | // variant: { |
| 1394 | // key: value, |
| 1395 | // }, |
| 1396 | // }, |
| 1397 | // }, |
| 1398 | if arch.CpuVariant != arch.ArchVariant { |
| 1399 | c := variantReplacer.Replace(arch.CpuVariant) |
| 1400 | if c != "" { |
| 1401 | prefix := "arch." + archType.Name + "." + c |
| 1402 | if cpuVariantProperties, ok := getChildPropertyStruct(ctx, archStruct, c, prefix); ok { |
| 1403 | result = append(result, cpuVariantProperties) |
| 1404 | } |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | // Handle arch-feature-specific properties in the form: |
| 1409 | // arch: { |
| 1410 | // arm: { |
| 1411 | // feature: { |
| 1412 | // key: value, |
| 1413 | // }, |
| 1414 | // }, |
| 1415 | // }, |
| 1416 | for _, feature := range arch.ArchFeatures { |
| 1417 | prefix := "arch." + archType.Name + "." + feature |
| 1418 | if featureProperties, ok := getChildPropertyStruct(ctx, archStruct, feature, prefix); ok { |
| 1419 | result = append(result, featureProperties) |
| 1420 | } |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1421 | } |
| 1422 | } |
| 1423 | |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1424 | if multilibProperties, ok := getMultilibStruct(ctx, archProperties, archType); ok { |
| 1425 | result = append(result, multilibProperties) |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1426 | } |
| 1427 | |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1428 | // Handle combined OS-feature and arch specific properties in the form: |
| 1429 | // target: { |
| 1430 | // bionic_x86: { |
| 1431 | // key: value, |
| 1432 | // }, |
| 1433 | // } |
| 1434 | if os.Linux() { |
| 1435 | field := "Linux_" + arch.ArchType.Name |
| 1436 | userFriendlyField := "target.linux_" + arch.ArchType.Name |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1437 | if linuxProperties, ok := getChildPropertyStruct(ctx, targetProp, field, userFriendlyField); ok { |
| 1438 | result = append(result, linuxProperties) |
| 1439 | } |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | if os.Bionic() { |
| 1443 | field := "Bionic_" + archType.Name |
| 1444 | userFriendlyField := "target.bionic_" + archType.Name |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1445 | if bionicProperties, ok := getChildPropertyStruct(ctx, targetProp, field, userFriendlyField); ok { |
| 1446 | result = append(result, bionicProperties) |
| 1447 | } |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | // Handle combined OS and arch specific properties in the form: |
| 1451 | // target: { |
| 1452 | // linux_glibc_x86: { |
| 1453 | // key: value, |
| 1454 | // }, |
| 1455 | // linux_glibc_arm: { |
| 1456 | // key: value, |
| 1457 | // }, |
| 1458 | // android_arm { |
| 1459 | // key: value, |
| 1460 | // }, |
| 1461 | // android_x86 { |
| 1462 | // key: value, |
| 1463 | // }, |
| 1464 | // }, |
Liz Kammer | 9abd62d | 2021-05-21 08:37:59 -0400 | [diff] [blame] | 1465 | field := GetCompoundTargetField(os, archType) |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1466 | userFriendlyField := "target." + os.Name + "_" + archType.Name |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1467 | if osArchProperties, ok := getChildPropertyStruct(ctx, targetProp, field, userFriendlyField); ok { |
| 1468 | result = append(result, osArchProperties) |
| 1469 | } |
Colin Cross | 528d67e | 2021-07-23 22:23:07 +0000 | [diff] [blame] | 1470 | |
Colin Cross | 1aa45b0 | 2022-02-10 10:33:10 -0800 | [diff] [blame] | 1471 | if os == Linux { |
| 1472 | field := "Glibc_" + archType.Name |
| 1473 | userFriendlyField := "target.glibc_" + "_" + archType.Name |
| 1474 | if osArchProperties, ok := getChildPropertyStruct(ctx, targetProp, field, userFriendlyField); ok { |
| 1475 | result = append(result, osArchProperties) |
| 1476 | } |
| 1477 | } |
| 1478 | |
Colin Cross | 528d67e | 2021-07-23 22:23:07 +0000 | [diff] [blame] | 1479 | if os == LinuxMusl { |
Colin Cross | 1aa45b0 | 2022-02-10 10:33:10 -0800 | [diff] [blame] | 1480 | field := "Musl_" + archType.Name |
| 1481 | userFriendlyField := "target.musl_" + "_" + archType.Name |
| 1482 | if osArchProperties, ok := getChildPropertyStruct(ctx, targetProp, field, userFriendlyField); ok { |
| 1483 | result = append(result, osArchProperties) |
| 1484 | } |
Colin Cross | 528d67e | 2021-07-23 22:23:07 +0000 | [diff] [blame] | 1485 | } |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | // Handle arm on x86 properties in the form: |
| 1489 | // target { |
| 1490 | // arm_on_x86 { |
| 1491 | // key: value, |
| 1492 | // }, |
| 1493 | // arm_on_x86_64 { |
| 1494 | // key: value, |
| 1495 | // }, |
| 1496 | // }, |
| 1497 | if os.Class == Device { |
| 1498 | if arch.ArchType == X86 && (hasArmAbi(arch) || |
| 1499 | hasArmAndroidArch(ctx.Config().Targets[Android])) { |
| 1500 | field := "Arm_on_x86" |
| 1501 | userFriendlyField := "target.arm_on_x86" |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1502 | if armOnX86Properties, ok := getChildPropertyStruct(ctx, targetProp, field, userFriendlyField); ok { |
| 1503 | result = append(result, armOnX86Properties) |
| 1504 | } |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1505 | } |
| 1506 | if arch.ArchType == X86_64 && (hasArmAbi(arch) || |
| 1507 | hasArmAndroidArch(ctx.Config().Targets[Android])) { |
| 1508 | field := "Arm_on_x86_64" |
| 1509 | userFriendlyField := "target.arm_on_x86_64" |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1510 | if armOnX8664Properties, ok := getChildPropertyStruct(ctx, targetProp, field, userFriendlyField); ok { |
| 1511 | result = append(result, armOnX8664Properties) |
| 1512 | } |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1513 | } |
| 1514 | if os == Android && nativeBridgeEnabled { |
| 1515 | userFriendlyField := "Native_bridge" |
| 1516 | prefix := "target.native_bridge" |
Lukacs T. Berki | 5f51839 | 2021-05-17 11:44:58 +0200 | [diff] [blame] | 1517 | if nativeBridgeProperties, ok := getChildPropertyStruct(ctx, targetProp, userFriendlyField, prefix); ok { |
| 1518 | result = append(result, nativeBridgeProperties) |
| 1519 | } |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | return result |
| 1524 | } |
| 1525 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1526 | // Squash the appropriate arch-specific property structs into the matching top level property |
| 1527 | // structs based on the CompileTarget value that was annotated on the variant. |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1528 | func (m *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) { |
| 1529 | arch := m.Arch() |
| 1530 | os := m.Os() |
Colin Cross | d3ba039 | 2015-05-07 14:11:29 -0700 | [diff] [blame] | 1531 | |
Usta | dca0219 | 2021-12-20 12:56:46 -0500 | [diff] [blame] | 1532 | for i := range m.archProperties { |
Usta | 851a327 | 2022-01-05 23:42:33 -0500 | [diff] [blame] | 1533 | genProps := m.GetProperties()[i] |
Colin Cross | 4157e88 | 2019-06-06 16:57:04 -0700 | [diff] [blame] | 1534 | if m.archProperties[i] == nil { |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1535 | continue |
| 1536 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1537 | |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1538 | propStructs := make([]reflect.Value, 0) |
| 1539 | for _, archProperty := range m.archProperties[i] { |
| 1540 | propStructShard := getArchProperties(ctx, archProperty, arch, os, m.Target().NativeBridge == NativeBridgeEnabled) |
| 1541 | propStructs = append(propStructs, propStructShard...) |
| 1542 | } |
Dan Willemsen | b1957a5 | 2016-06-23 23:44:54 -0700 | [diff] [blame] | 1543 | |
Lukacs T. Berki | 598dd00 | 2021-05-05 09:00:01 +0200 | [diff] [blame] | 1544 | for _, propStruct := range propStructs { |
| 1545 | mergePropertyStruct(ctx, genProps, propStruct) |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1546 | } |
Colin Cross | 3f40fa4 | 2015-01-30 17:27:36 -0800 | [diff] [blame] | 1547 | } |
| 1548 | } |
| 1549 | |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 1550 | // determineBuildOS stores the OS and architecture used for host targets used during the build into |
Colin Cross | 528d67e | 2021-07-23 22:23:07 +0000 | [diff] [blame] | 1551 | // config based on the runtime OS and architecture determined by Go and the product configuration. |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 1552 | func determineBuildOS(config *config) { |
| 1553 | config.BuildOS = func() OsType { |
| 1554 | switch runtime.GOOS { |
| 1555 | case "linux": |
Colin Cross | 528d67e | 2021-07-23 22:23:07 +0000 | [diff] [blame] | 1556 | if Bool(config.productVariables.HostMusl) { |
| 1557 | return LinuxMusl |
| 1558 | } |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame] | 1559 | return Linux |
| 1560 | case "darwin": |
| 1561 | return Darwin |
| 1562 | default: |
| 1563 | panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS)) |
| 1564 | } |
| 1565 | }() |
| 1566 | |
| 1567 | config.BuildArch = func() ArchType { |
| 1568 | switch runtime.GOARCH { |
| 1569 | case "amd64": |
| 1570 | return X86_64 |
| 1571 | default: |
| 1572 | panic(fmt.Sprintf("unsupported Arch: %s", runtime.GOARCH)) |
| 1573 | } |
| 1574 | }() |
| 1575 | |
| 1576 | } |
| 1577 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1578 | // Convert the arch product variables into a list of targets for each OsType. |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1579 | func decodeTargetProductVariables(config *config) (map[OsType][]Target, error) { |
Dan Willemsen | 45133ac | 2018-03-09 21:22:06 -0800 | [diff] [blame] | 1580 | variables := config.productVariables |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1581 | |
Dan Willemsen | 0ef639b | 2018-10-10 17:02:29 -0700 | [diff] [blame] | 1582 | targets := make(map[OsType][]Target) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1583 | var targetErr error |
| 1584 | |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1585 | type targetConfig struct { |
| 1586 | os OsType |
| 1587 | archName string |
| 1588 | archVariant *string |
| 1589 | cpuVariant *string |
| 1590 | abi []string |
| 1591 | nativeBridgeEnabled NativeBridgeSupport |
| 1592 | nativeBridgeHostArchName *string |
| 1593 | nativeBridgeRelativePath *string |
| 1594 | } |
| 1595 | |
| 1596 | addTarget := func(target targetConfig) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1597 | if targetErr != nil { |
| 1598 | return |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1599 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1600 | |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1601 | arch, err := decodeArch(target.os, target.archName, target.archVariant, target.cpuVariant, target.abi) |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1602 | if err != nil { |
| 1603 | targetErr = err |
| 1604 | return |
| 1605 | } |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1606 | nativeBridgeRelativePathStr := String(target.nativeBridgeRelativePath) |
| 1607 | nativeBridgeHostArchNameStr := String(target.nativeBridgeHostArchName) |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1608 | |
| 1609 | // Use guest arch as relative install path by default |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1610 | if target.nativeBridgeEnabled && nativeBridgeRelativePathStr == "" { |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1611 | nativeBridgeRelativePathStr = arch.ArchType.String() |
| 1612 | } |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1613 | |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1614 | // A target is considered as HostCross if it's a host target which can't run natively on |
| 1615 | // the currently configured build machine (either because the OS is different or because of |
| 1616 | // the unsupported arch) |
| 1617 | hostCross := false |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1618 | if target.os.Class == Host { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1619 | var osSupported bool |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1620 | if target.os == config.BuildOS { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1621 | osSupported = true |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1622 | } else if config.BuildOS.Linux() && target.os.Linux() { |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1623 | // LinuxBionic and Linux are compatible |
| 1624 | osSupported = true |
| 1625 | } else { |
| 1626 | osSupported = false |
| 1627 | } |
| 1628 | |
| 1629 | var archSupported bool |
| 1630 | if arch.ArchType == Common { |
| 1631 | archSupported = true |
| 1632 | } else if arch.ArchType.Name == *variables.HostArch { |
| 1633 | archSupported = true |
| 1634 | } else if variables.HostSecondaryArch != nil && arch.ArchType.Name == *variables.HostSecondaryArch { |
| 1635 | archSupported = true |
| 1636 | } else { |
| 1637 | archSupported = false |
| 1638 | } |
| 1639 | if !osSupported || !archSupported { |
| 1640 | hostCross = true |
| 1641 | } |
| 1642 | } |
| 1643 | |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1644 | targets[target.os] = append(targets[target.os], |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1645 | Target{ |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1646 | Os: target.os, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1647 | Arch: arch, |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1648 | NativeBridge: target.nativeBridgeEnabled, |
dimitry | 8d6dde8 | 2019-07-11 10:23:53 +0200 | [diff] [blame] | 1649 | NativeBridgeHostArchName: nativeBridgeHostArchNameStr, |
| 1650 | NativeBridgeRelativePath: nativeBridgeRelativePathStr, |
Jiyong Park | 1613e55 | 2020-09-14 19:43:17 +0900 | [diff] [blame] | 1651 | HostCross: hostCross, |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1652 | }) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1653 | } |
| 1654 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1655 | if variables.HostArch == nil { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1656 | return nil, fmt.Errorf("No host primary architecture set") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1659 | // The primary host target, which must always exist. |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1660 | addTarget(targetConfig{os: config.BuildOS, archName: *variables.HostArch, nativeBridgeEnabled: NativeBridgeDisabled}) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1661 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1662 | // An optional secondary host target. |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1663 | if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1664 | addTarget(targetConfig{os: config.BuildOS, archName: *variables.HostSecondaryArch, nativeBridgeEnabled: NativeBridgeDisabled}) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1665 | } |
| 1666 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1667 | // Optional cross-compiled host targets, generally Windows. |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1668 | if String(variables.CrossHost) != "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1669 | crossHostOs := osByName(*variables.CrossHost) |
| 1670 | if crossHostOs == NoOsType { |
| 1671 | return nil, fmt.Errorf("Unknown cross host OS %q", *variables.CrossHost) |
| 1672 | } |
| 1673 | |
Colin Cross | ff3ae9d | 2018-04-10 16:15:18 -0700 | [diff] [blame] | 1674 | if String(variables.CrossHostArch) == "" { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1675 | return nil, fmt.Errorf("No cross-host primary architecture set") |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1676 | } |
| 1677 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1678 | // The primary cross-compiled host target. |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1679 | addTarget(targetConfig{os: crossHostOs, archName: *variables.CrossHostArch, nativeBridgeEnabled: NativeBridgeDisabled}) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1680 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1681 | // An optional secondary cross-compiled host target. |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1682 | if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" { |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1683 | addTarget(targetConfig{os: crossHostOs, archName: *variables.CrossHostSecondaryArch, nativeBridgeEnabled: NativeBridgeDisabled}) |
Dan Willemsen | 490fd49 | 2015-11-24 17:53:15 -0800 | [diff] [blame] | 1684 | } |
| 1685 | } |
| 1686 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1687 | // Optional device targets |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1688 | if variables.DeviceArch != nil && *variables.DeviceArch != "" { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1689 | // The primary device target. |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1690 | addTarget(targetConfig{ |
| 1691 | os: Android, |
| 1692 | archName: *variables.DeviceArch, |
| 1693 | archVariant: variables.DeviceArchVariant, |
| 1694 | cpuVariant: variables.DeviceCpuVariant, |
| 1695 | abi: variables.DeviceAbi, |
| 1696 | nativeBridgeEnabled: NativeBridgeDisabled, |
| 1697 | }) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1698 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1699 | // An optional secondary device target. |
Dan Willemsen | 3f32f03 | 2016-07-11 14:36:48 -0700 | [diff] [blame] | 1700 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" { |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1701 | addTarget(targetConfig{ |
| 1702 | os: Android, |
| 1703 | archName: *variables.DeviceSecondaryArch, |
| 1704 | archVariant: variables.DeviceSecondaryArchVariant, |
| 1705 | cpuVariant: variables.DeviceSecondaryCpuVariant, |
| 1706 | abi: variables.DeviceSecondaryAbi, |
| 1707 | nativeBridgeEnabled: NativeBridgeDisabled, |
| 1708 | }) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1709 | } |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1710 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1711 | // An optional NativeBridge device target. |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1712 | if variables.NativeBridgeArch != nil && *variables.NativeBridgeArch != "" { |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1713 | addTarget(targetConfig{ |
| 1714 | os: Android, |
| 1715 | archName: *variables.NativeBridgeArch, |
| 1716 | archVariant: variables.NativeBridgeArchVariant, |
| 1717 | cpuVariant: variables.NativeBridgeCpuVariant, |
| 1718 | abi: variables.NativeBridgeAbi, |
| 1719 | nativeBridgeEnabled: NativeBridgeEnabled, |
| 1720 | nativeBridgeHostArchName: variables.DeviceArch, |
| 1721 | nativeBridgeRelativePath: variables.NativeBridgeRelativePath, |
| 1722 | }) |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1723 | } |
| 1724 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1725 | // An optional secondary NativeBridge device target. |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1726 | if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" && |
| 1727 | variables.NativeBridgeSecondaryArch != nil && *variables.NativeBridgeSecondaryArch != "" { |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1728 | addTarget(targetConfig{ |
| 1729 | os: Android, |
| 1730 | archName: *variables.NativeBridgeSecondaryArch, |
| 1731 | archVariant: variables.NativeBridgeSecondaryArchVariant, |
| 1732 | cpuVariant: variables.NativeBridgeSecondaryCpuVariant, |
| 1733 | abi: variables.NativeBridgeSecondaryAbi, |
| 1734 | nativeBridgeEnabled: NativeBridgeEnabled, |
| 1735 | nativeBridgeHostArchName: variables.DeviceSecondaryArch, |
| 1736 | nativeBridgeRelativePath: variables.NativeBridgeSecondaryRelativePath, |
| 1737 | }) |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 1738 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1741 | if targetErr != nil { |
| 1742 | return nil, targetErr |
| 1743 | } |
| 1744 | |
| 1745 | return targets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1748 | // hasArmAbi returns true if arch has at least one arm ABI |
| 1749 | func hasArmAbi(arch Arch) bool { |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 1750 | return PrefixInList(arch.Abi, "arm") |
Colin Cross | bb2e2b7 | 2016-12-08 17:23:53 -0800 | [diff] [blame] | 1751 | } |
| 1752 | |
Lev Rumyantsev | 3458121 | 2021-10-13 09:47:59 -0700 | [diff] [blame] | 1753 | // hasArmAndroidArch returns true if targets has at least |
| 1754 | // one arm Android arch (possibly native bridged) |
Colin Cross | 4247f0d | 2017-04-13 16:56:14 -0700 | [diff] [blame] | 1755 | func hasArmAndroidArch(targets []Target) bool { |
| 1756 | for _, target := range targets { |
Lev Rumyantsev | 3458121 | 2021-10-13 09:47:59 -0700 | [diff] [blame] | 1757 | if target.Os == Android && |
| 1758 | (target.Arch.ArchType == Arm || target.Arch.ArchType == Arm64) { |
Victor Khimenko | 5eb8ec1 | 2018-03-21 20:30:54 +0100 | [diff] [blame] | 1759 | return true |
| 1760 | } |
| 1761 | } |
| 1762 | return false |
| 1763 | } |
| 1764 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1765 | // archConfig describes a built-in configuration. |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1766 | type archConfig struct { |
Liz Kammer | 992918d | 2022-11-11 10:37:54 -0500 | [diff] [blame] | 1767 | Arch string `json:"arch"` |
| 1768 | ArchVariant string `json:"arch_variant"` |
| 1769 | CpuVariant string `json:"cpu_variant"` |
| 1770 | Abi []string `json:"abis"` |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
Elliott Hughes | c55b586 | 2022-10-27 23:46:22 +0000 | [diff] [blame] | 1773 | // getNdkAbisConfig returns the list of archConfigs that are used for building |
| 1774 | // the API stubs and static libraries that are included in the NDK. |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1775 | func getNdkAbisConfig() []archConfig { |
| 1776 | return []archConfig{ |
Tamas Petz | bca786d | 2021-01-20 18:56:33 +0100 | [diff] [blame] | 1777 | {"arm64", "armv8-a-branchprot", "", []string{"arm64-v8a"}}, |
Elliott Hughes | c55b586 | 2022-10-27 23:46:22 +0000 | [diff] [blame] | 1778 | {"arm", "armv7-a-neon", "", []string{"armeabi-v7a"}}, |
Elliott Hughes | f7d3109 | 2023-03-14 23:11:57 +0000 | [diff] [blame] | 1779 | {"riscv64", "", "", []string{"riscv64"}}, |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1780 | {"x86_64", "", "", []string{"x86_64"}}, |
Inseob Kim | 5219c0e | 2021-06-17 00:33:00 +0900 | [diff] [blame] | 1781 | {"x86", "", "", []string{"x86"}}, |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1782 | } |
| 1783 | } |
| 1784 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1785 | // getAmlAbisConfig returns a list of archConfigs for the ABIs supported by mainline modules. |
Martin Stjernholm | c1ecc43 | 2019-11-15 15:00:31 +0000 | [diff] [blame] | 1786 | func getAmlAbisConfig() []archConfig { |
| 1787 | return []archConfig{ |
Martin Stjernholm | c1ecc43 | 2019-11-15 15:00:31 +0000 | [diff] [blame] | 1788 | {"arm64", "armv8-a", "", []string{"arm64-v8a"}}, |
Inseob Kim | 5219c0e | 2021-06-17 00:33:00 +0900 | [diff] [blame] | 1789 | {"arm", "armv7-a-neon", "", []string{"armeabi-v7a"}}, |
Martin Stjernholm | c1ecc43 | 2019-11-15 15:00:31 +0000 | [diff] [blame] | 1790 | {"x86_64", "", "", []string{"x86_64"}}, |
Inseob Kim | 5219c0e | 2021-06-17 00:33:00 +0900 | [diff] [blame] | 1791 | {"x86", "", "", []string{"x86"}}, |
Martin Stjernholm | c1ecc43 | 2019-11-15 15:00:31 +0000 | [diff] [blame] | 1792 | } |
| 1793 | } |
| 1794 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1795 | // decodeArchSettings converts a list of archConfigs into a list of Targets for the given OsType. |
Liz Kammer | b7f3366 | 2022-02-28 14:16:16 -0500 | [diff] [blame] | 1796 | func decodeAndroidArchSettings(archConfigs []archConfig) ([]Target, error) { |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1797 | var ret []Target |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1798 | |
Dan Albert | 4098deb | 2016-10-19 14:04:41 -0700 | [diff] [blame] | 1799 | for _, config := range archConfigs { |
Liz Kammer | 992918d | 2022-11-11 10:37:54 -0500 | [diff] [blame] | 1800 | arch, err := decodeArch(Android, config.Arch, &config.ArchVariant, |
| 1801 | &config.CpuVariant, config.Abi) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1802 | if err != nil { |
| 1803 | return nil, err |
| 1804 | } |
Colin Cross | 3b19f5d | 2019-09-17 14:45:31 -0700 | [diff] [blame] | 1805 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1806 | ret = append(ret, Target{ |
| 1807 | Os: Android, |
| 1808 | Arch: arch, |
| 1809 | }) |
Dan Willemsen | 322acaf | 2016-01-12 23:07:05 -0800 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | return ret, nil |
| 1813 | } |
| 1814 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1815 | // decodeArch converts a set of strings from product variables into an Arch struct. |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1816 | func decodeArch(os OsType, arch string, archVariant, cpuVariant *string, abi []string) (Arch, error) { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1817 | // Verify the arch is valid |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1818 | archType, ok := archTypeMap[arch] |
| 1819 | if !ok { |
| 1820 | return Arch{}, fmt.Errorf("unknown arch %q", arch) |
| 1821 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1822 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1823 | a := Arch{ |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1824 | ArchType: archType, |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1825 | ArchVariant: String(archVariant), |
| 1826 | CpuVariant: String(cpuVariant), |
Colin Cross | a74ca04 | 2019-01-31 14:31:51 -0800 | [diff] [blame] | 1827 | Abi: abi, |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1828 | } |
| 1829 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1830 | // Convert generic arch variants into the empty string. |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1831 | if a.ArchVariant == a.ArchType.Name || a.ArchVariant == "generic" { |
| 1832 | a.ArchVariant = "" |
| 1833 | } |
| 1834 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1835 | // Convert generic CPU variants into the empty string. |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1836 | if a.CpuVariant == a.ArchType.Name || a.CpuVariant == "generic" { |
| 1837 | a.CpuVariant = "" |
| 1838 | } |
| 1839 | |
Liz Kammer | 2c2afe2 | 2022-02-11 11:35:03 -0500 | [diff] [blame] | 1840 | if a.ArchVariant != "" { |
| 1841 | if validArchVariants := archVariants[archType]; !InList(a.ArchVariant, validArchVariants) { |
| 1842 | return Arch{}, fmt.Errorf("[%q] unknown arch variant %q, support variants: %q", archType, a.ArchVariant, validArchVariants) |
| 1843 | } |
| 1844 | } |
| 1845 | |
| 1846 | if a.CpuVariant != "" { |
| 1847 | if validCpuVariants := cpuVariants[archType]; !InList(a.CpuVariant, validCpuVariants) { |
| 1848 | return Arch{}, fmt.Errorf("[%q] unknown cpu variant %q, support variants: %q", archType, a.CpuVariant, validCpuVariants) |
| 1849 | } |
| 1850 | } |
| 1851 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1852 | // Filter empty ABIs out of the list. |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1853 | for i := 0; i < len(a.Abi); i++ { |
| 1854 | if a.Abi[i] == "" { |
| 1855 | a.Abi = append(a.Abi[:i], a.Abi[i+1:]...) |
| 1856 | i-- |
| 1857 | } |
| 1858 | } |
| 1859 | |
Liz Kammer | e8303bd | 2022-02-16 09:02:48 -0500 | [diff] [blame] | 1860 | // Set ArchFeatures from the arch type. for Android OS, other os-es do not specify features |
| 1861 | if os == Android { |
| 1862 | if featureMap, ok := androidArchFeatureMap[archType]; ok { |
Dan Willemsen | 01a3c25 | 2019-01-11 19:02:16 -0800 | [diff] [blame] | 1863 | a.ArchFeatures = featureMap[a.ArchVariant] |
| 1864 | } |
Colin Cross | c5c24ad | 2015-11-20 15:35:00 -0800 | [diff] [blame] | 1865 | } |
| 1866 | |
Colin Cross | eeabb89 | 2015-11-20 13:07:51 -0800 | [diff] [blame] | 1867 | return a, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1870 | // filterMultilibTargets takes a list of Targets and a multilib value and returns a new list of |
| 1871 | // Targets containing only those that have the given multilib value. |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1872 | func filterMultilibTargets(targets []Target, multilib string) []Target { |
| 1873 | var ret []Target |
| 1874 | for _, t := range targets { |
| 1875 | if t.Arch.ArchType.Multilib == multilib { |
| 1876 | ret = append(ret, t) |
| 1877 | } |
| 1878 | } |
| 1879 | return ret |
| 1880 | } |
| 1881 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1882 | // getCommonTargets returns the set of Os specific common architecture targets for each Os in a list |
| 1883 | // of targets. |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 1884 | func getCommonTargets(targets []Target) []Target { |
| 1885 | var ret []Target |
| 1886 | set := make(map[string]bool) |
| 1887 | |
| 1888 | for _, t := range targets { |
| 1889 | if _, found := set[t.Os.String()]; !found { |
| 1890 | set[t.Os.String()] = true |
Colin Cross | 39a1814 | 2022-06-24 18:43:40 -0700 | [diff] [blame] | 1891 | common := commonTargetMap[t.Os.String()] |
| 1892 | common.HostCross = t.HostCross |
| 1893 | ret = append(ret, common) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 1894 | } |
| 1895 | } |
| 1896 | |
| 1897 | return ret |
| 1898 | } |
| 1899 | |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1900 | // FirstTarget takes a list of Targets and a list of multilib values and returns a list of Targets |
Colin Cross | c0f0eb8 | 2022-07-19 14:41:11 -0700 | [diff] [blame] | 1901 | // that contains zero or one Target for each OsType and HostCross, selecting the one that matches |
| 1902 | // the earliest filter. |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1903 | func FirstTarget(targets []Target, filters ...string) []Target { |
Jiyong Park | 2210198 | 2020-09-17 19:09:58 +0900 | [diff] [blame] | 1904 | // find the first target from each OS |
| 1905 | var ret []Target |
Colin Cross | c0f0eb8 | 2022-07-19 14:41:11 -0700 | [diff] [blame] | 1906 | type osHostCross struct { |
| 1907 | os OsType |
| 1908 | hostCross bool |
| 1909 | } |
| 1910 | set := make(map[osHostCross]bool) |
Jiyong Park | 2210198 | 2020-09-17 19:09:58 +0900 | [diff] [blame] | 1911 | |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1912 | for _, filter := range filters { |
| 1913 | buildTargets := filterMultilibTargets(targets, filter) |
Jiyong Park | 2210198 | 2020-09-17 19:09:58 +0900 | [diff] [blame] | 1914 | for _, t := range buildTargets { |
Colin Cross | c0f0eb8 | 2022-07-19 14:41:11 -0700 | [diff] [blame] | 1915 | key := osHostCross{t.Os, t.HostCross} |
| 1916 | if _, found := set[key]; !found { |
| 1917 | set[key] = true |
Jiyong Park | 2210198 | 2020-09-17 19:09:58 +0900 | [diff] [blame] | 1918 | ret = append(ret, t) |
| 1919 | } |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1920 | } |
| 1921 | } |
Jiyong Park | 2210198 | 2020-09-17 19:09:58 +0900 | [diff] [blame] | 1922 | return ret |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1923 | } |
| 1924 | |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1925 | // decodeMultilibTargets uses the module's multilib setting to select one or more targets from a |
| 1926 | // list of Targets. |
Colin Cross | ee0bc3b | 2018-10-02 22:01:37 -0700 | [diff] [blame] | 1927 | func decodeMultilibTargets(multilib string, targets []Target, prefer32 bool) ([]Target, error) { |
Colin Cross | a684540 | 2020-11-16 15:08:19 -0800 | [diff] [blame] | 1928 | var buildTargets []Target |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1929 | |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1930 | switch multilib { |
| 1931 | case "common": |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1932 | buildTargets = getCommonTargets(targets) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1933 | case "both": |
Colin Cross | 8b74d17 | 2016-09-13 09:59:14 -0700 | [diff] [blame] | 1934 | if prefer32 { |
| 1935 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) |
| 1936 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) |
| 1937 | } else { |
| 1938 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...) |
| 1939 | buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...) |
| 1940 | } |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1941 | case "32": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1942 | buildTargets = filterMultilibTargets(targets, "lib32") |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1943 | case "64": |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1944 | buildTargets = filterMultilibTargets(targets, "lib64") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1945 | case "first": |
| 1946 | if prefer32 { |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1947 | buildTargets = FirstTarget(targets, "lib32", "lib64") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1948 | } else { |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1949 | buildTargets = FirstTarget(targets, "lib64", "lib32") |
Colin Cross | 6b4a32d | 2017-12-05 13:42:45 -0800 | [diff] [blame] | 1950 | } |
Victor Chang | 9448e8f | 2020-09-14 15:34:16 +0100 | [diff] [blame] | 1951 | case "first_prefer32": |
Sam Delmerico | cc271e2 | 2022-06-01 15:45:02 +0000 | [diff] [blame] | 1952 | buildTargets = FirstTarget(targets, "lib32", "lib64") |
Colin Cross | 69617d3 | 2016-09-06 10:39:07 -0700 | [diff] [blame] | 1953 | case "prefer32": |
Colin Cross | 3dceee3 | 2018-09-06 10:19:57 -0700 | [diff] [blame] | 1954 | buildTargets = filterMultilibTargets(targets, "lib32") |
| 1955 | if len(buildTargets) == 0 { |
| 1956 | buildTargets = filterMultilibTargets(targets, "lib64") |
| 1957 | } |
Dan Willemsen | 4745007 | 2021-10-19 20:24:49 -0700 | [diff] [blame] | 1958 | case "darwin_universal": |
| 1959 | buildTargets = filterMultilibTargets(targets, "lib64") |
| 1960 | // Reverse the targets so that the first architecture can depend on the second |
| 1961 | // architecture module in order to merge the outputs. |
Colin Cross | b5e3f7d | 2023-07-06 15:37:53 -0700 | [diff] [blame] | 1962 | ReverseSliceInPlace(buildTargets) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1963 | default: |
Victor Chang | 9448e8f | 2020-09-14 15:34:16 +0100 | [diff] [blame] | 1964 | return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", "64", "prefer32" or "first_prefer32" found %q`, |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1965 | multilib) |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
Colin Cross | a1ad8d1 | 2016-06-01 17:09:44 -0700 | [diff] [blame] | 1968 | return buildTargets, nil |
Colin Cross | 4225f65 | 2015-09-17 14:33:42 -0700 | [diff] [blame] | 1969 | } |
Jingwen Chen | 5d86449 | 2021-02-24 07:20:12 -0500 | [diff] [blame] | 1970 | |
Liz Kammer | b6dbc87 | 2021-05-14 15:14:40 -0400 | [diff] [blame] | 1971 | // ArchVariantContext defines the limited context necessary to retrieve arch_variant properties. |
| 1972 | type ArchVariantContext interface { |
| 1973 | ModuleErrorf(fmt string, args ...interface{}) |
| 1974 | PropertyErrorf(property, fmt string, args ...interface{}) |
| 1975 | } |