Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Android Open Source Project |
| 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 | |
| 15 | package rust |
| 16 | |
| 17 | import ( |
Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 18 | "fmt" |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 19 | "strconv" |
Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 20 | "strings" |
| 21 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 22 | "android/soong/bloaty" |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 23 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 24 | "github.com/google/blueprint" |
Colin Cross | a14fb6a | 2024-10-23 16:57:06 -0700 | [diff] [blame] | 25 | "github.com/google/blueprint/depset" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 26 | "github.com/google/blueprint/proptools" |
| 27 | |
| 28 | "android/soong/android" |
| 29 | "android/soong/cc" |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 30 | cc_config "android/soong/cc/config" |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 31 | "android/soong/fuzz" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 32 | "android/soong/rust/config" |
| 33 | ) |
| 34 | |
| 35 | var pctx = android.NewPackageContext("android/soong/rust") |
| 36 | |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 37 | type LibraryInfo struct { |
| 38 | Rlib bool |
| 39 | Dylib bool |
| 40 | } |
| 41 | |
| 42 | type CompilerInfo struct { |
| 43 | StdLinkageForDevice RustLinkage |
| 44 | StdLinkageForNonDevice RustLinkage |
| 45 | NoStdlibs bool |
| 46 | LibraryInfo *LibraryInfo |
| 47 | } |
| 48 | |
| 49 | type ProtobufDecoratorInfo struct{} |
| 50 | |
| 51 | type SourceProviderInfo struct { |
Yu Liu | 727204c | 2025-01-23 20:58:32 +0000 | [diff] [blame] | 52 | Srcs android.Paths |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 53 | ProtobufDecoratorInfo *ProtobufDecoratorInfo |
| 54 | } |
| 55 | |
| 56 | type RustInfo struct { |
| 57 | AndroidMkSuffix string |
| 58 | RustSubName string |
| 59 | TransitiveAndroidMkSharedLibs depset.DepSet[string] |
| 60 | CompilerInfo *CompilerInfo |
| 61 | SnapshotInfo *cc.SnapshotInfo |
| 62 | SourceProviderInfo *SourceProviderInfo |
| 63 | } |
| 64 | |
| 65 | var RustInfoProvider = blueprint.NewProvider[*RustInfo]() |
| 66 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 67 | func init() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 68 | android.RegisterModuleType("rust_defaults", defaultsFactory) |
Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 69 | android.PreDepsMutators(registerPreDepsMutators) |
| 70 | android.PostDepsMutators(registerPostDepsMutators) |
Inseob Kim | 3b24406 | 2023-07-11 13:31:36 +0900 | [diff] [blame] | 71 | pctx.Import("android/soong/android") |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 72 | pctx.Import("android/soong/rust/config") |
Thiébaud Weksteen | 682c9d7 | 2020-08-31 10:06:16 +0200 | [diff] [blame] | 73 | pctx.ImportAs("cc_config", "android/soong/cc/config") |
LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 74 | android.InitRegistrationContext.RegisterParallelSingletonType("kythe_rust_extract", kytheExtractRustFactory) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 77 | func registerPreDepsMutators(ctx android.RegisterMutatorsContext) { |
| 78 | ctx.Transition("rust_libraries", &libraryTransitionMutator{}) |
| 79 | ctx.Transition("rust_stdlinkage", &libstdTransitionMutator{}) |
Colin Cross | 8a96280 | 2024-10-09 15:29:27 -0700 | [diff] [blame] | 80 | ctx.BottomUp("rust_begin", BeginMutator) |
Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | func registerPostDepsMutators(ctx android.RegisterMutatorsContext) { |
Colin Cross | 8a96280 | 2024-10-09 15:29:27 -0700 | [diff] [blame] | 84 | ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator) |
Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 87 | type Flags struct { |
Ivan Lozano | 8a23fa4 | 2020-06-16 10:26:57 -0400 | [diff] [blame] | 88 | GlobalRustFlags []string // Flags that apply globally to rust |
| 89 | GlobalLinkFlags []string // Flags that apply globally to linker |
| 90 | RustFlags []string // Flags that apply to rust |
| 91 | LinkFlags []string // Flags that apply to linker |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 92 | ClippyFlags []string // Flags that apply to clippy-driver, during the linting |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 93 | RustdocFlags []string // Flags that apply to rustdoc |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 94 | Toolchain config.Toolchain |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 95 | Coverage bool |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 96 | Clippy bool |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 97 | EmitXrefs bool // If true, emit rules to aid cross-referencing |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | type BaseProperties struct { |
Liz Kammer | 884fe9e | 2023-02-28 14:29:13 -0500 | [diff] [blame] | 101 | AndroidMkRlibs []string `blueprint:"mutated"` |
| 102 | AndroidMkDylibs []string `blueprint:"mutated"` |
| 103 | AndroidMkProcMacroLibs []string `blueprint:"mutated"` |
Liz Kammer | 884fe9e | 2023-02-28 14:29:13 -0500 | [diff] [blame] | 104 | AndroidMkStaticLibs []string `blueprint:"mutated"` |
Ivan Lozano | 1dbfa14 | 2024-03-29 14:48:11 +0000 | [diff] [blame] | 105 | AndroidMkHeaderLibs []string `blueprint:"mutated"` |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 106 | |
Kiyoung Kim | b5fdb2e | 2024-01-03 14:24:34 +0900 | [diff] [blame] | 107 | ImageVariation string `blueprint:"mutated"` |
| 108 | VndkVersion string `blueprint:"mutated"` |
| 109 | SubName string `blueprint:"mutated"` |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 110 | |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 111 | // SubName is used by CC for tracking image variants / SDK versions. RustSubName is used for Rust-specific |
| 112 | // subnaming which shouldn't be visible to CC modules (such as the rlib stdlinkage subname). This should be |
| 113 | // appended before SubName. |
| 114 | RustSubName string `blueprint:"mutated"` |
| 115 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 116 | // Set by imageMutator |
Jihoon Kang | 47e9184 | 2024-06-19 00:51:16 +0000 | [diff] [blame] | 117 | ProductVariantNeeded bool `blueprint:"mutated"` |
| 118 | VendorVariantNeeded bool `blueprint:"mutated"` |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 119 | CoreVariantNeeded bool `blueprint:"mutated"` |
| 120 | VendorRamdiskVariantNeeded bool `blueprint:"mutated"` |
Matthew Maurer | c686838 | 2021-07-13 14:12:37 -0700 | [diff] [blame] | 121 | RamdiskVariantNeeded bool `blueprint:"mutated"` |
Matthew Maurer | 460ee94 | 2021-02-11 12:31:46 -0800 | [diff] [blame] | 122 | RecoveryVariantNeeded bool `blueprint:"mutated"` |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 123 | ExtraVariants []string `blueprint:"mutated"` |
| 124 | |
Ivan Lozano | a226863 | 2021-07-22 10:52:06 -0400 | [diff] [blame] | 125 | // Allows this module to use non-APEX version of libraries. Useful |
| 126 | // for building binaries that are started before APEXes are activated. |
| 127 | Bootstrap *bool |
| 128 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 129 | // Used by vendor snapshot to record dependencies from snapshot modules. |
| 130 | SnapshotSharedLibs []string `blueprint:"mutated"` |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 131 | SnapshotStaticLibs []string `blueprint:"mutated"` |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 132 | SnapshotRlibs []string `blueprint:"mutated"` |
| 133 | SnapshotDylibs []string `blueprint:"mutated"` |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 134 | |
Matthew Maurer | c686838 | 2021-07-13 14:12:37 -0700 | [diff] [blame] | 135 | // Make this module available when building for ramdisk. |
| 136 | // On device without a dedicated recovery partition, the module is only |
| 137 | // available after switching root into |
| 138 | // /first_stage_ramdisk. To expose the module before switching root, install |
| 139 | // the recovery variant instead. |
| 140 | Ramdisk_available *bool |
| 141 | |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 142 | // Make this module available when building for vendor ramdisk. |
| 143 | // On device without a dedicated recovery partition, the module is only |
| 144 | // available after switching root into |
| 145 | // /first_stage_ramdisk. To expose the module before switching root, install |
Matthew Maurer | 460ee94 | 2021-02-11 12:31:46 -0800 | [diff] [blame] | 146 | // the recovery variant instead |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 147 | Vendor_ramdisk_available *bool |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 148 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 149 | // Normally Soong uses the directory structure to decide which modules |
| 150 | // should be included (framework) or excluded (non-framework) from the |
| 151 | // different snapshots (vendor, recovery, etc.), but this property |
| 152 | // allows a partner to exclude a module normally thought of as a |
| 153 | // framework module from the vendor snapshot. |
| 154 | Exclude_from_vendor_snapshot *bool |
| 155 | |
| 156 | // Normally Soong uses the directory structure to decide which modules |
| 157 | // should be included (framework) or excluded (non-framework) from the |
| 158 | // different snapshots (vendor, recovery, etc.), but this property |
| 159 | // allows a partner to exclude a module normally thought of as a |
| 160 | // framework module from the recovery snapshot. |
| 161 | Exclude_from_recovery_snapshot *bool |
| 162 | |
Matthew Maurer | 460ee94 | 2021-02-11 12:31:46 -0800 | [diff] [blame] | 163 | // Make this module available when building for recovery |
| 164 | Recovery_available *bool |
| 165 | |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 166 | // The API level that this module is built against. The APIs of this API level will be |
| 167 | // visible at build time, but use of any APIs newer than min_sdk_version will render the |
| 168 | // module unloadable on older devices. In the future it will be possible to weakly-link new |
| 169 | // APIs, making the behavior match Java: such modules will load on older devices, but |
| 170 | // calling new APIs on devices that do not support them will result in a crash. |
| 171 | // |
| 172 | // This property has the same behavior as sdk_version does for Java modules. For those |
| 173 | // familiar with Android Gradle, the property behaves similarly to how compileSdkVersion |
| 174 | // does for Java code. |
| 175 | // |
| 176 | // In addition, setting this property causes two variants to be built, one for the platform |
| 177 | // and one for apps. |
| 178 | Sdk_version *string |
| 179 | |
| 180 | // Minimum OS API level supported by this C or C++ module. This property becomes the value |
| 181 | // of the __ANDROID_API__ macro. When the C or C++ module is included in an APEX or an APK, |
| 182 | // this property is also used to ensure that the min_sdk_version of the containing module is |
| 183 | // not older (i.e. less) than this module's min_sdk_version. When not set, this property |
| 184 | // defaults to the value of sdk_version. When this is set to "apex_inherit", this tracks |
| 185 | // min_sdk_version of the containing APEX. When the module |
| 186 | // is not built for an APEX, "apex_inherit" defaults to sdk_version. |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 187 | Min_sdk_version *string |
| 188 | |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 189 | // Variant is an SDK variant created by sdkMutator |
| 190 | IsSdkVariant bool `blueprint:"mutated"` |
| 191 | |
| 192 | // Set by factories of module types that can only be referenced from variants compiled against |
| 193 | // the SDK. |
| 194 | AlwaysSdk bool `blueprint:"mutated"` |
| 195 | |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 196 | HideFromMake bool `blueprint:"mutated"` |
| 197 | PreventInstall bool `blueprint:"mutated"` |
| 198 | |
| 199 | Installable *bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | type Module struct { |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 203 | fuzz.FuzzModule |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 204 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 205 | VendorProperties cc.VendorProperties |
| 206 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 207 | Properties BaseProperties |
| 208 | |
Aditya Choudhary | 87b2ab2 | 2023-11-17 15:27:06 +0000 | [diff] [blame] | 209 | hod android.HostOrDeviceSupported |
| 210 | multilib android.Multilib |
| 211 | testModule bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 212 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 213 | makeLinkType string |
| 214 | |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 215 | afdo *afdo |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 216 | compiler compiler |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 217 | coverage *coverage |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 218 | clippy *clippy |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 219 | sanitize *sanitize |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 220 | cachedToolchain config.Toolchain |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 221 | sourceProvider SourceProvider |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 222 | subAndroidMkOnce map[SubAndroidMkProvider]bool |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 223 | |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 224 | exportedLinkDirs []string |
| 225 | |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 226 | // Output file to be installed, may be stripped or unstripped. |
| 227 | outputFile android.OptionalPath |
| 228 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 229 | // Cross-reference input file |
| 230 | kytheFiles android.Paths |
| 231 | |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 232 | docTimestampFile android.OptionalPath |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 233 | |
| 234 | hideApexVariantFromMake bool |
Ivan Lozano | e950cda | 2021-11-09 11:26:04 -0500 | [diff] [blame] | 235 | |
| 236 | // For apex variants, this is set as apex.min_sdk_version |
| 237 | apexSdkVersion android.ApiLevel |
Cole Faust | b6e6f99 | 2023-08-17 17:42:26 -0700 | [diff] [blame] | 238 | |
Colin Cross | a14fb6a | 2024-10-23 16:57:06 -0700 | [diff] [blame] | 239 | transitiveAndroidMkSharedLibs depset.DepSet[string] |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 240 | |
| 241 | // Shared flags among stubs build rules of this module |
| 242 | sharedFlags cc.SharedFlags |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 245 | func (mod *Module) Header() bool { |
| 246 | //TODO: If Rust libraries provide header variants, this needs to be updated. |
| 247 | return false |
| 248 | } |
| 249 | |
| 250 | func (mod *Module) SetPreventInstall() { |
| 251 | mod.Properties.PreventInstall = true |
| 252 | } |
| 253 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 254 | func (mod *Module) SetHideFromMake() { |
| 255 | mod.Properties.HideFromMake = true |
| 256 | } |
| 257 | |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 258 | func (mod *Module) HiddenFromMake() bool { |
| 259 | return mod.Properties.HideFromMake |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 260 | } |
| 261 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 262 | func (mod *Module) SanitizePropDefined() bool { |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 263 | // Because compiler is not set for some Rust modules where sanitize might be set, check that compiler is also not |
| 264 | // nil since we need compiler to actually sanitize. |
| 265 | return mod.sanitize != nil && mod.compiler != nil |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 266 | } |
| 267 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 268 | func (mod *Module) IsPrebuilt() bool { |
| 269 | if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok { |
| 270 | return true |
| 271 | } |
| 272 | return false |
| 273 | } |
| 274 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 275 | func (mod *Module) SelectedStl() string { |
| 276 | return "" |
| 277 | } |
| 278 | |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 279 | func (mod *Module) NonCcVariants() bool { |
| 280 | if mod.compiler != nil { |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 281 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 282 | return library.buildRlib() || library.buildDylib() |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName())) |
| 286 | } |
| 287 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 288 | func (mod *Module) Static() bool { |
| 289 | if mod.compiler != nil { |
| 290 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 291 | return library.static() |
| 292 | } |
| 293 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 294 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | func (mod *Module) Shared() bool { |
| 298 | if mod.compiler != nil { |
| 299 | if library, ok := mod.compiler.(libraryInterface); ok { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 300 | return library.shared() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 301 | } |
| 302 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 303 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 306 | func (mod *Module) Dylib() bool { |
| 307 | if mod.compiler != nil { |
| 308 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 309 | return library.dylib() |
| 310 | } |
| 311 | } |
| 312 | return false |
| 313 | } |
| 314 | |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 315 | func (mod *Module) Source() bool { |
| 316 | if mod.compiler != nil { |
| 317 | if library, ok := mod.compiler.(libraryInterface); ok && mod.sourceProvider != nil { |
| 318 | return library.source() |
| 319 | } |
| 320 | } |
| 321 | return false |
| 322 | } |
| 323 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 324 | func (mod *Module) RlibStd() bool { |
| 325 | if mod.compiler != nil { |
| 326 | if library, ok := mod.compiler.(libraryInterface); ok && library.rlib() { |
| 327 | return library.rlibStd() |
| 328 | } |
| 329 | } |
| 330 | panic(fmt.Errorf("RlibStd() called on non-rlib module: %q", mod.BaseModuleName())) |
| 331 | } |
| 332 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 333 | func (mod *Module) Rlib() bool { |
| 334 | if mod.compiler != nil { |
| 335 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 336 | return library.rlib() |
| 337 | } |
| 338 | } |
| 339 | return false |
| 340 | } |
| 341 | |
| 342 | func (mod *Module) Binary() bool { |
Ivan Lozano | 21fa0a5 | 2021-11-01 09:19:45 -0400 | [diff] [blame] | 343 | if binary, ok := mod.compiler.(binaryInterface); ok { |
| 344 | return binary.binary() |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 345 | } |
| 346 | return false |
| 347 | } |
| 348 | |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 349 | func (mod *Module) StaticExecutable() bool { |
| 350 | if !mod.Binary() { |
| 351 | return false |
| 352 | } |
Ivan Lozano | 21fa0a5 | 2021-11-01 09:19:45 -0400 | [diff] [blame] | 353 | return mod.StaticallyLinked() |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 354 | } |
| 355 | |
Ashutosh Agarwal | 46e4fad | 2024-08-27 17:13:12 +0000 | [diff] [blame] | 356 | func (mod *Module) ApexExclude() bool { |
| 357 | if mod.compiler != nil { |
| 358 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 359 | return library.apexExclude() |
| 360 | } |
| 361 | } |
| 362 | return false |
| 363 | } |
| 364 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 365 | func (mod *Module) Object() bool { |
| 366 | // Rust has no modules which produce only object files. |
| 367 | return false |
| 368 | } |
| 369 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 370 | func (mod *Module) Toc() android.OptionalPath { |
| 371 | if mod.compiler != nil { |
Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 372 | if lib, ok := mod.compiler.(libraryInterface); ok { |
| 373 | return lib.toc() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName())) |
| 377 | } |
| 378 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 379 | func (mod *Module) UseSdk() bool { |
| 380 | return false |
| 381 | } |
| 382 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 383 | func (mod *Module) RelativeInstallPath() string { |
| 384 | if mod.compiler != nil { |
| 385 | return mod.compiler.relativeInstallPath() |
| 386 | } |
| 387 | return "" |
| 388 | } |
| 389 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 390 | func (mod *Module) UseVndk() bool { |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 391 | return mod.Properties.VndkVersion != "" |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 394 | func (mod *Module) Bootstrap() bool { |
Ivan Lozano | a226863 | 2021-07-22 10:52:06 -0400 | [diff] [blame] | 395 | return Bool(mod.Properties.Bootstrap) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 396 | } |
| 397 | |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 398 | func (mod *Module) SubName() string { |
| 399 | return mod.Properties.SubName |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Ivan Lozano | f1868af | 2022-04-12 13:08:36 -0400 | [diff] [blame] | 402 | func (mod *Module) IsVndkPrebuiltLibrary() bool { |
| 403 | // Rust modules do not provide VNDK prebuilts |
| 404 | return false |
| 405 | } |
| 406 | |
| 407 | func (mod *Module) IsVendorPublicLibrary() bool { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 408 | // Rust modules do not currently support vendor_public_library |
| 409 | return false |
Ivan Lozano | f1868af | 2022-04-12 13:08:36 -0400 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | func (mod *Module) SdkAndPlatformVariantVisibleToMake() bool { |
| 413 | // Rust modules to not provide Sdk variants |
| 414 | return false |
| 415 | } |
| 416 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 417 | func (c *Module) IsVndkPrivate() bool { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 418 | // Rust modules do not currently support VNDK variants |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 419 | return false |
| 420 | } |
| 421 | |
| 422 | func (c *Module) IsLlndk() bool { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 423 | // Rust modules do not currently support LLNDK variants |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 424 | return false |
| 425 | } |
| 426 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 427 | func (mod *Module) KernelHeadersDecorator() bool { |
| 428 | return false |
| 429 | } |
| 430 | |
Colin Cross | 1f3f130 | 2021-04-26 18:37:44 -0700 | [diff] [blame] | 431 | func (m *Module) NeedsLlndkVariants() bool { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 432 | // Rust modules do not currently support LLNDK variants |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 433 | return false |
| 434 | } |
| 435 | |
Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 436 | func (m *Module) NeedsVendorPublicLibraryVariants() bool { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 437 | // Rust modules do not currently support vendor_public_library |
Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 438 | return false |
| 439 | } |
| 440 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 441 | func (mod *Module) HasLlndkStubs() bool { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 442 | // Rust modules do not currently support LLNDK stubs |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 443 | return false |
| 444 | } |
| 445 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 446 | func (mod *Module) SdkVersion() string { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 447 | return String(mod.Properties.Sdk_version) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 450 | func (mod *Module) AlwaysSdk() bool { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 451 | return mod.Properties.AlwaysSdk |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Jiyong Park | 2286afd | 2020-06-16 21:58:53 +0900 | [diff] [blame] | 454 | func (mod *Module) IsSdkVariant() bool { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 455 | return mod.Properties.IsSdkVariant |
Jiyong Park | 2286afd | 2020-06-16 21:58:53 +0900 | [diff] [blame] | 456 | } |
| 457 | |
Colin Cross | 1348ce3 | 2020-10-01 13:37:16 -0700 | [diff] [blame] | 458 | func (mod *Module) SplitPerApiLevel() bool { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 459 | return cc.CanUseSdk(mod) && mod.IsCrt() |
Colin Cross | 1348ce3 | 2020-10-01 13:37:16 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 462 | func (mod *Module) XrefRustFiles() android.Paths { |
| 463 | return mod.kytheFiles |
| 464 | } |
| 465 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 466 | type Deps struct { |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 467 | Dylibs []string |
| 468 | Rlibs []string |
| 469 | Rustlibs []string |
| 470 | Stdlibs []string |
| 471 | ProcMacros []string |
| 472 | SharedLibs []string |
| 473 | StaticLibs []string |
| 474 | WholeStaticLibs []string |
| 475 | HeaderLibs []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 476 | |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 477 | // Used for data dependencies adjacent to tests |
| 478 | DataLibs []string |
| 479 | DataBins []string |
| 480 | |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 481 | CrtBegin, CrtEnd []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | type PathDeps struct { |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 485 | DyLibs RustLibraries |
| 486 | RLibs RustLibraries |
| 487 | SharedLibs android.Paths |
| 488 | SharedLibDeps android.Paths |
| 489 | StaticLibs android.Paths |
| 490 | ProcMacros RustLibraries |
| 491 | AfdoProfiles android.Paths |
Ivan Lozano | f458901 | 2024-11-20 22:18:11 +0000 | [diff] [blame] | 492 | LinkerDeps android.Paths |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 493 | |
| 494 | // depFlags and depLinkFlags are rustc and linker (clang) flags. |
| 495 | depFlags []string |
| 496 | depLinkFlags []string |
| 497 | |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 498 | // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 499 | // Both of these are exported and propagate to dependencies. |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 500 | linkDirs []string |
| 501 | rustLibObjects []string |
| 502 | staticLibObjects []string |
| 503 | wholeStaticLibObjects []string |
| 504 | sharedLibObjects []string |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 505 | |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 506 | // exportedLinkDirs are exported linkDirs for direct rlib dependencies to |
| 507 | // cc_library_static dependants of rlibs. |
| 508 | // Track them separately from linkDirs so superfluous -L flags don't get emitted. |
| 509 | exportedLinkDirs []string |
| 510 | |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 511 | // Used by bindgen modules which call clang |
| 512 | depClangFlags []string |
| 513 | depIncludePaths android.Paths |
Ivan Lozano | ddd0bdb | 2020-08-28 17:00:26 -0400 | [diff] [blame] | 514 | depGeneratedHeaders android.Paths |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 515 | depSystemIncludePaths android.Paths |
| 516 | |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 517 | CrtBegin android.Paths |
| 518 | CrtEnd android.Paths |
Chih-Hung Hsieh | bbd25ae | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 519 | |
| 520 | // Paths to generated source files |
Ivan Lozano | 9d74a52 | 2020-12-01 09:25:22 -0500 | [diff] [blame] | 521 | SrcDeps android.Paths |
| 522 | srcProviderFiles android.Paths |
Colin Cross | b614cd4 | 2024-10-11 12:52:21 -0700 | [diff] [blame] | 523 | |
| 524 | directImplementationDeps android.Paths |
| 525 | transitiveImplementationDeps []depset.DepSet[android.Path] |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | type RustLibraries []RustLibrary |
| 529 | |
| 530 | type RustLibrary struct { |
| 531 | Path android.Path |
| 532 | CrateName string |
| 533 | } |
| 534 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 535 | type exportedFlagsProducer interface { |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 536 | exportLinkDirs(...string) |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 537 | exportRustLibs(...string) |
| 538 | exportStaticLibs(...string) |
| 539 | exportWholeStaticLibs(...string) |
| 540 | exportSharedLibs(...string) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 543 | type xref interface { |
| 544 | XrefRustFiles() android.Paths |
| 545 | } |
| 546 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 547 | type flagExporter struct { |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 548 | linkDirs []string |
| 549 | ccLinkDirs []string |
| 550 | rustLibPaths []string |
| 551 | staticLibObjects []string |
| 552 | sharedLibObjects []string |
| 553 | wholeStaticLibObjects []string |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 556 | func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) { |
| 557 | flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...)) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 560 | func (flagExporter *flagExporter) exportRustLibs(flags ...string) { |
| 561 | flagExporter.rustLibPaths = android.FirstUniqueStrings(append(flagExporter.rustLibPaths, flags...)) |
| 562 | } |
| 563 | |
| 564 | func (flagExporter *flagExporter) exportStaticLibs(flags ...string) { |
| 565 | flagExporter.staticLibObjects = android.FirstUniqueStrings(append(flagExporter.staticLibObjects, flags...)) |
| 566 | } |
| 567 | |
| 568 | func (flagExporter *flagExporter) exportSharedLibs(flags ...string) { |
| 569 | flagExporter.sharedLibObjects = android.FirstUniqueStrings(append(flagExporter.sharedLibObjects, flags...)) |
| 570 | } |
| 571 | |
| 572 | func (flagExporter *flagExporter) exportWholeStaticLibs(flags ...string) { |
| 573 | flagExporter.wholeStaticLibObjects = android.FirstUniqueStrings(append(flagExporter.wholeStaticLibObjects, flags...)) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 574 | } |
| 575 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 576 | func (flagExporter *flagExporter) setProvider(ctx ModuleContext) { |
Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 577 | android.SetProvider(ctx, FlagExporterInfoProvider, FlagExporterInfo{ |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 578 | LinkDirs: flagExporter.linkDirs, |
| 579 | RustLibObjects: flagExporter.rustLibPaths, |
| 580 | StaticLibObjects: flagExporter.staticLibObjects, |
| 581 | WholeStaticLibObjects: flagExporter.wholeStaticLibObjects, |
| 582 | SharedLibPaths: flagExporter.sharedLibObjects, |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 583 | }) |
| 584 | } |
| 585 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 586 | var _ exportedFlagsProducer = (*flagExporter)(nil) |
| 587 | |
| 588 | func NewFlagExporter() *flagExporter { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 589 | return &flagExporter{} |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 592 | type FlagExporterInfo struct { |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 593 | Flags []string |
| 594 | LinkDirs []string |
| 595 | RustLibObjects []string |
| 596 | StaticLibObjects []string |
| 597 | WholeStaticLibObjects []string |
| 598 | SharedLibPaths []string |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Colin Cross | bc7d76c | 2023-12-12 16:39:03 -0800 | [diff] [blame] | 601 | var FlagExporterInfoProvider = blueprint.NewProvider[FlagExporterInfo]() |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 602 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 603 | func (mod *Module) isCoverageVariant() bool { |
| 604 | return mod.coverage.Properties.IsCoverageVariant |
| 605 | } |
| 606 | |
| 607 | var _ cc.Coverage = (*Module)(nil) |
| 608 | |
Colin Cross | e1a8555 | 2024-06-14 12:17:37 -0700 | [diff] [blame] | 609 | func (mod *Module) IsNativeCoverageNeeded(ctx cc.IsNativeCoverageNeededContext) bool { |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 610 | return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant |
| 611 | } |
| 612 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 613 | func (mod *Module) VndkVersion() string { |
| 614 | return mod.Properties.VndkVersion |
| 615 | } |
| 616 | |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 617 | func (mod *Module) ExportedCrateLinkDirs() []string { |
| 618 | return mod.exportedLinkDirs |
| 619 | } |
| 620 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 621 | func (mod *Module) PreventInstall() bool { |
| 622 | return mod.Properties.PreventInstall |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 623 | } |
Ivan Lozano | 9eaacc8 | 2024-10-30 14:28:17 +0000 | [diff] [blame] | 624 | func (c *Module) ForceDisableSanitizers() { |
| 625 | c.sanitize.Properties.ForceDisable = true |
| 626 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 627 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 628 | func (mod *Module) MarkAsCoverageVariant(coverage bool) { |
| 629 | mod.coverage.Properties.IsCoverageVariant = coverage |
| 630 | } |
| 631 | |
| 632 | func (mod *Module) EnableCoverageIfNeeded() { |
| 633 | mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | func defaultsFactory() android.Module { |
| 637 | return DefaultsFactory() |
| 638 | } |
| 639 | |
| 640 | type Defaults struct { |
| 641 | android.ModuleBase |
| 642 | android.DefaultsModuleBase |
| 643 | } |
| 644 | |
| 645 | func DefaultsFactory(props ...interface{}) android.Module { |
| 646 | module := &Defaults{} |
| 647 | |
| 648 | module.AddProperties(props...) |
| 649 | module.AddProperties( |
| 650 | &BaseProperties{}, |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 651 | &cc.AfdoProperties{}, |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 652 | &cc.VendorProperties{}, |
Jakub Kotur | 1d640d0 | 2021-01-06 12:40:43 +0100 | [diff] [blame] | 653 | &BenchmarkProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 654 | &BindgenProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 655 | &BaseCompilerProperties{}, |
| 656 | &BinaryCompilerProperties{}, |
| 657 | &LibraryCompilerProperties{}, |
| 658 | &ProcMacroCompilerProperties{}, |
| 659 | &PrebuiltProperties{}, |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 660 | &SourceProviderProperties{}, |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 661 | &TestProperties{}, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 662 | &cc.CoverageProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 663 | &cc.RustBindgenClangProperties{}, |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 664 | &ClippyProperties{}, |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 665 | &SanitizeProperties{}, |
Pawan Wagh | ccb7558 | 2023-08-16 23:58:25 +0000 | [diff] [blame] | 666 | &fuzz.FuzzProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 667 | ) |
| 668 | |
| 669 | android.InitDefaultsModule(module) |
| 670 | return module |
| 671 | } |
| 672 | |
| 673 | func (mod *Module) CrateName() string { |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 674 | return mod.compiler.crateName() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 677 | func (mod *Module) CcLibrary() bool { |
| 678 | if mod.compiler != nil { |
Ivan Lozano | 45e0e5b | 2021-11-13 07:42:36 -0500 | [diff] [blame] | 679 | if _, ok := mod.compiler.(libraryInterface); ok { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 680 | return true |
| 681 | } |
| 682 | } |
| 683 | return false |
| 684 | } |
| 685 | |
| 686 | func (mod *Module) CcLibraryInterface() bool { |
| 687 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 688 | // use build{Static,Shared}() instead of {static,shared}() here because this might be called before |
| 689 | // VariantIs{Static,Shared} is set. |
Ivan Lozano | 806efd3 | 2024-12-11 21:38:53 +0000 | [diff] [blame] | 690 | if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic() || lib.buildRlib()) { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 691 | return true |
| 692 | } |
| 693 | } |
| 694 | return false |
| 695 | } |
| 696 | |
Ivan Lozano | 61c02cc | 2023-06-09 14:06:44 -0400 | [diff] [blame] | 697 | func (mod *Module) RustLibraryInterface() bool { |
| 698 | if mod.compiler != nil { |
| 699 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 700 | return true |
| 701 | } |
| 702 | } |
| 703 | return false |
| 704 | } |
| 705 | |
Ivan Lozano | 0f9963e | 2023-02-06 13:31:02 -0500 | [diff] [blame] | 706 | func (mod *Module) IsFuzzModule() bool { |
| 707 | if _, ok := mod.compiler.(*fuzzDecorator); ok { |
| 708 | return true |
| 709 | } |
| 710 | return false |
| 711 | } |
| 712 | |
| 713 | func (mod *Module) FuzzModuleStruct() fuzz.FuzzModule { |
| 714 | return mod.FuzzModule |
| 715 | } |
| 716 | |
| 717 | func (mod *Module) FuzzPackagedModule() fuzz.FuzzPackagedModule { |
| 718 | if fuzzer, ok := mod.compiler.(*fuzzDecorator); ok { |
| 719 | return fuzzer.fuzzPackagedModule |
| 720 | } |
| 721 | panic(fmt.Errorf("FuzzPackagedModule called on non-fuzz module: %q", mod.BaseModuleName())) |
| 722 | } |
| 723 | |
Hamzeh Zawawy | 3891749 | 2023-04-05 22:08:46 +0000 | [diff] [blame] | 724 | func (mod *Module) FuzzSharedLibraries() android.RuleBuilderInstalls { |
Ivan Lozano | 0f9963e | 2023-02-06 13:31:02 -0500 | [diff] [blame] | 725 | if fuzzer, ok := mod.compiler.(*fuzzDecorator); ok { |
| 726 | return fuzzer.sharedLibraries |
| 727 | } |
| 728 | panic(fmt.Errorf("FuzzSharedLibraries called on non-fuzz module: %q", mod.BaseModuleName())) |
| 729 | } |
| 730 | |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 731 | func (mod *Module) UnstrippedOutputFile() android.Path { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 732 | if mod.compiler != nil { |
| 733 | return mod.compiler.unstrippedOutputFilePath() |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 734 | } |
| 735 | return nil |
| 736 | } |
| 737 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 738 | func (mod *Module) SetStatic() { |
| 739 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 740 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 741 | library.setStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 742 | return |
| 743 | } |
| 744 | } |
| 745 | panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName())) |
| 746 | } |
| 747 | |
| 748 | func (mod *Module) SetShared() { |
| 749 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 750 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 751 | library.setShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 752 | return |
| 753 | } |
| 754 | } |
| 755 | panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName())) |
| 756 | } |
| 757 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 758 | func (mod *Module) BuildStaticVariant() bool { |
| 759 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 760 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 761 | return library.buildStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName())) |
| 765 | } |
| 766 | |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 767 | func (mod *Module) BuildRlibVariant() bool { |
| 768 | if mod.compiler != nil { |
| 769 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 770 | return library.buildRlib() |
| 771 | } |
| 772 | } |
| 773 | panic(fmt.Errorf("BuildRlibVariant called on non-library module: %q", mod.BaseModuleName())) |
| 774 | } |
| 775 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 776 | func (mod *Module) BuildSharedVariant() bool { |
| 777 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 778 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 779 | return library.buildShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName())) |
| 783 | } |
| 784 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 785 | func (mod *Module) Module() android.Module { |
| 786 | return mod |
| 787 | } |
| 788 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 789 | func (mod *Module) OutputFile() android.OptionalPath { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 790 | return mod.outputFile |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 793 | func (mod *Module) CoverageFiles() android.Paths { |
| 794 | if mod.compiler != nil { |
Joel Galenson | fa04938 | 2021-01-14 16:03:18 -0800 | [diff] [blame] | 795 | return android.Paths{} |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 796 | } |
| 797 | panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName())) |
| 798 | } |
| 799 | |
Ivan Lozano | 7f67c2a | 2022-06-27 16:00:26 -0400 | [diff] [blame] | 800 | // Rust does not produce gcno files, and therefore does not produce a coverage archive. |
| 801 | func (mod *Module) CoverageOutputFile() android.OptionalPath { |
| 802 | return android.OptionalPath{} |
| 803 | } |
| 804 | |
| 805 | func (mod *Module) IsNdk(config android.Config) bool { |
| 806 | return false |
| 807 | } |
| 808 | |
Ivan Lozano | 9eaacc8 | 2024-10-30 14:28:17 +0000 | [diff] [blame] | 809 | func (mod *Module) IsStubs() bool { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 810 | if lib, ok := mod.compiler.(libraryInterface); ok { |
| 811 | return lib.BuildStubs() |
| 812 | } |
Ivan Lozano | 9eaacc8 | 2024-10-30 14:28:17 +0000 | [diff] [blame] | 813 | return false |
| 814 | } |
| 815 | |
Spandan Das | 10c4136 | 2024-12-03 01:33:09 +0000 | [diff] [blame] | 816 | func (mod *Module) HasStubsVariants() bool { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 817 | if lib, ok := mod.compiler.(libraryInterface); ok { |
| 818 | return lib.HasStubsVariants() |
| 819 | } |
Spandan Das | 10c4136 | 2024-12-03 01:33:09 +0000 | [diff] [blame] | 820 | return false |
| 821 | } |
| 822 | |
Ivan Lozano | 9eaacc8 | 2024-10-30 14:28:17 +0000 | [diff] [blame] | 823 | func (mod *Module) ApexSdkVersion() android.ApiLevel { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 824 | return mod.apexSdkVersion |
| 825 | } |
| 826 | |
| 827 | func (mod *Module) RustApexExclude() bool { |
| 828 | return mod.ApexExclude() |
| 829 | } |
| 830 | |
| 831 | func (mod *Module) getSharedFlags() *cc.SharedFlags { |
| 832 | shared := &mod.sharedFlags |
| 833 | if shared.FlagsMap == nil { |
| 834 | shared.NumSharedFlags = 0 |
| 835 | shared.FlagsMap = make(map[string]string) |
| 836 | } |
| 837 | return shared |
Ivan Lozano | 9eaacc8 | 2024-10-30 14:28:17 +0000 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | func (mod *Module) ImplementationModuleNameForMake(ctx android.BaseModuleContext) string { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 841 | name := mod.BaseModuleName() |
| 842 | if versioned, ok := mod.compiler.(cc.VersionedInterface); ok { |
| 843 | name = versioned.ImplementationModuleName(name) |
| 844 | } |
| 845 | return name |
Ivan Lozano | 9eaacc8 | 2024-10-30 14:28:17 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | func (mod *Module) Multilib() string { |
| 849 | return mod.Arch().ArchType.Multilib |
| 850 | } |
| 851 | |
| 852 | func (mod *Module) IsCrt() bool { |
| 853 | // Rust does not currently provide any crt modules. |
Ivan Lozano | 7f67c2a | 2022-06-27 16:00:26 -0400 | [diff] [blame] | 854 | return false |
| 855 | } |
| 856 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 857 | func (mod *Module) installable(apexInfo android.ApexInfo) bool { |
Jiyong Park | 2811e07 | 2021-09-30 17:25:21 +0900 | [diff] [blame] | 858 | if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) { |
Jiyong Park | bf8147a | 2021-05-17 13:19:33 +0900 | [diff] [blame] | 859 | return false |
| 860 | } |
| 861 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 862 | // The apex variant is not installable because it is included in the APEX and won't appear |
| 863 | // in the system partition as a standalone file. |
| 864 | if !apexInfo.IsForPlatform() { |
| 865 | return false |
| 866 | } |
| 867 | |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 868 | return mod.OutputFile().Valid() && !mod.Properties.PreventInstall |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 869 | } |
| 870 | |
Ivan Lozano | e950cda | 2021-11-09 11:26:04 -0500 | [diff] [blame] | 871 | func (ctx moduleContext) apexVariationName() string { |
Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 872 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) |
| 873 | return apexInfo.ApexVariationName |
Ivan Lozano | e950cda | 2021-11-09 11:26:04 -0500 | [diff] [blame] | 874 | } |
| 875 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 876 | var _ cc.LinkableInterface = (*Module)(nil) |
Ivan Lozano | 9eaacc8 | 2024-10-30 14:28:17 +0000 | [diff] [blame] | 877 | var _ cc.VersionedLinkableInterface = (*Module)(nil) |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 878 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 879 | func (mod *Module) Init() android.Module { |
| 880 | mod.AddProperties(&mod.Properties) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 881 | mod.AddProperties(&mod.VendorProperties) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 882 | |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 883 | if mod.afdo != nil { |
| 884 | mod.AddProperties(mod.afdo.props()...) |
| 885 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 886 | if mod.compiler != nil { |
| 887 | mod.AddProperties(mod.compiler.compilerProps()...) |
| 888 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 889 | if mod.coverage != nil { |
| 890 | mod.AddProperties(mod.coverage.props()...) |
| 891 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 892 | if mod.clippy != nil { |
| 893 | mod.AddProperties(mod.clippy.props()...) |
| 894 | } |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 895 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 896 | mod.AddProperties(mod.sourceProvider.SourceProviderProps()...) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 897 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 898 | if mod.sanitize != nil { |
| 899 | mod.AddProperties(mod.sanitize.props()...) |
| 900 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 901 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 902 | android.InitAndroidArchModule(mod, mod.hod, mod.multilib) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 903 | android.InitApexModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 904 | |
| 905 | android.InitDefaultableModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 906 | return mod |
| 907 | } |
| 908 | |
| 909 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 910 | return &Module{ |
| 911 | hod: hod, |
| 912 | multilib: multilib, |
| 913 | } |
| 914 | } |
| 915 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 916 | module := newBaseModule(hod, multilib) |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 917 | module.afdo = &afdo{} |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 918 | module.coverage = &coverage{} |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 919 | module.clippy = &clippy{} |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 920 | module.sanitize = &sanitize{} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 921 | return module |
| 922 | } |
| 923 | |
| 924 | type ModuleContext interface { |
| 925 | android.ModuleContext |
| 926 | ModuleContextIntf |
| 927 | } |
| 928 | |
| 929 | type BaseModuleContext interface { |
| 930 | android.BaseModuleContext |
| 931 | ModuleContextIntf |
| 932 | } |
| 933 | |
| 934 | type DepsContext interface { |
| 935 | android.BottomUpMutatorContext |
| 936 | ModuleContextIntf |
| 937 | } |
| 938 | |
| 939 | type ModuleContextIntf interface { |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 940 | RustModule() *Module |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 941 | toolchain() config.Toolchain |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | type depsContext struct { |
| 945 | android.BottomUpMutatorContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | type moduleContext struct { |
| 949 | android.ModuleContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 950 | } |
| 951 | |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 952 | type baseModuleContext struct { |
| 953 | android.BaseModuleContext |
| 954 | } |
| 955 | |
| 956 | func (ctx *moduleContext) RustModule() *Module { |
| 957 | return ctx.Module().(*Module) |
| 958 | } |
| 959 | |
| 960 | func (ctx *moduleContext) toolchain() config.Toolchain { |
| 961 | return ctx.RustModule().toolchain(ctx) |
| 962 | } |
| 963 | |
| 964 | func (ctx *depsContext) RustModule() *Module { |
| 965 | return ctx.Module().(*Module) |
| 966 | } |
| 967 | |
| 968 | func (ctx *depsContext) toolchain() config.Toolchain { |
| 969 | return ctx.RustModule().toolchain(ctx) |
| 970 | } |
| 971 | |
| 972 | func (ctx *baseModuleContext) RustModule() *Module { |
| 973 | return ctx.Module().(*Module) |
| 974 | } |
| 975 | |
| 976 | func (ctx *baseModuleContext) toolchain() config.Toolchain { |
| 977 | return ctx.RustModule().toolchain(ctx) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | func (mod *Module) nativeCoverage() bool { |
Matthew Maurer | a61e31f | 2021-05-27 11:09:11 -0700 | [diff] [blame] | 981 | // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage |
| 982 | if mod.Target().NativeBridge == android.NativeBridgeEnabled { |
| 983 | return false |
| 984 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 985 | return mod.compiler != nil && mod.compiler.nativeCoverage() |
| 986 | } |
| 987 | |
Ivan Lozano | 9eaacc8 | 2024-10-30 14:28:17 +0000 | [diff] [blame] | 988 | func (mod *Module) SetStl(s string) { |
| 989 | // STL is a CC concept; do nothing for Rust |
| 990 | } |
| 991 | |
| 992 | func (mod *Module) SetSdkVersion(s string) { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 993 | mod.Properties.Sdk_version = StringPtr(s) |
Ivan Lozano | 9eaacc8 | 2024-10-30 14:28:17 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | func (mod *Module) SetMinSdkVersion(s string) { |
| 997 | mod.Properties.Min_sdk_version = StringPtr(s) |
| 998 | } |
| 999 | |
| 1000 | func (mod *Module) VersionedInterface() cc.VersionedInterface { |
| 1001 | if _, ok := mod.compiler.(cc.VersionedInterface); ok { |
| 1002 | return mod.compiler.(cc.VersionedInterface) |
| 1003 | } |
| 1004 | return nil |
| 1005 | } |
| 1006 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 1007 | func (mod *Module) EverInstallable() bool { |
| 1008 | return mod.compiler != nil && |
| 1009 | // Check to see whether the module is actually ever installable. |
| 1010 | mod.compiler.everInstallable() |
| 1011 | } |
| 1012 | |
| 1013 | func (mod *Module) Installable() *bool { |
| 1014 | return mod.Properties.Installable |
| 1015 | } |
| 1016 | |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1017 | func (mod *Module) ProcMacro() bool { |
| 1018 | if pm, ok := mod.compiler.(procMacroInterface); ok { |
| 1019 | return pm.ProcMacro() |
| 1020 | } |
| 1021 | return false |
| 1022 | } |
| 1023 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1024 | func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain { |
| 1025 | if mod.cachedToolchain == nil { |
| 1026 | mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 1027 | } |
| 1028 | return mod.cachedToolchain |
| 1029 | } |
| 1030 | |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 1031 | func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain { |
| 1032 | return cc_config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 1033 | } |
| 1034 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1035 | func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1036 | } |
| 1037 | |
| 1038 | func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
| 1039 | ctx := &moduleContext{ |
| 1040 | ModuleContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1041 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1042 | |
Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 1043 | apexInfo, _ := android.ModuleProvider(actx, android.ApexInfoProvider) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1044 | if !apexInfo.IsForPlatform() { |
| 1045 | mod.hideApexVariantFromMake = true |
| 1046 | } |
| 1047 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1048 | toolchain := mod.toolchain(ctx) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 1049 | mod.makeLinkType = cc.GetMakeLinkType(actx, mod) |
| 1050 | |
Ivan Lozano | f1868af | 2022-04-12 13:08:36 -0400 | [diff] [blame] | 1051 | mod.Properties.SubName = cc.GetSubnameProperty(actx, mod) |
Matthew Maurer | a61e31f | 2021-05-27 11:09:11 -0700 | [diff] [blame] | 1052 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1053 | if !toolchain.Supported() { |
| 1054 | // This toolchain's unsupported, there's nothing to do for this mod. |
| 1055 | return |
| 1056 | } |
| 1057 | |
| 1058 | deps := mod.depsToPaths(ctx) |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 1059 | // Export linkDirs for CC rust generatedlibs |
| 1060 | mod.exportedLinkDirs = append(mod.exportedLinkDirs, deps.exportedLinkDirs...) |
| 1061 | mod.exportedLinkDirs = append(mod.exportedLinkDirs, deps.linkDirs...) |
| 1062 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1063 | flags := Flags{ |
| 1064 | Toolchain: toolchain, |
| 1065 | } |
| 1066 | |
Ivan Lozano | 67eada3 | 2021-09-23 11:50:33 -0400 | [diff] [blame] | 1067 | // Calculate rustc flags |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 1068 | if mod.afdo != nil { |
Vinh Tran | cde1016 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 1069 | flags, deps = mod.afdo.flags(actx, flags, deps) |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 1070 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1071 | if mod.compiler != nil { |
| 1072 | flags = mod.compiler.compilerFlags(ctx, flags) |
Ivan Lozano | 67eada3 | 2021-09-23 11:50:33 -0400 | [diff] [blame] | 1073 | flags = mod.compiler.cfgFlags(ctx, flags) |
Jihoon Kang | 091ffd8 | 2024-10-03 01:13:24 +0000 | [diff] [blame] | 1074 | flags = mod.compiler.featureFlags(ctx, mod, flags) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1075 | } |
| 1076 | if mod.coverage != nil { |
| 1077 | flags, deps = mod.coverage.flags(ctx, flags, deps) |
| 1078 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 1079 | if mod.clippy != nil { |
| 1080 | flags, deps = mod.clippy.flags(ctx, flags, deps) |
| 1081 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 1082 | if mod.sanitize != nil { |
| 1083 | flags, deps = mod.sanitize.flags(ctx, flags, deps) |
| 1084 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1085 | |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1086 | // SourceProvider needs to call GenerateSource() before compiler calls |
| 1087 | // compile() so it can provide the source. A SourceProvider has |
| 1088 | // multiple variants (e.g. source, rlib, dylib). Only the "source" |
| 1089 | // variant is responsible for effectively generating the source. The |
| 1090 | // remaining variants relies on the "source" variant output. |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 1091 | if mod.sourceProvider != nil { |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1092 | if mod.compiler.(libraryInterface).source() { |
| 1093 | mod.sourceProvider.GenerateSource(ctx, deps) |
| 1094 | mod.sourceProvider.setSubName(ctx.ModuleSubDir()) |
| 1095 | } else { |
Yu Liu | 727204c | 2025-01-23 20:58:32 +0000 | [diff] [blame] | 1096 | sourceMod := actx.GetDirectDepProxyWithTag(mod.Name(), sourceDepTag) |
| 1097 | sourceLib := android.OtherModuleProviderOrDefault(ctx, sourceMod, RustInfoProvider).SourceProviderInfo |
| 1098 | mod.sourceProvider.setOutputFiles(sourceLib.Srcs) |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1099 | } |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 1100 | ctx.CheckbuildFile(mod.sourceProvider.Srcs()...) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | if mod.compiler != nil && !mod.compiler.Disabled() { |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame] | 1104 | mod.compiler.initialize(ctx) |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 1105 | buildOutput := mod.compiler.compile(ctx, flags, deps) |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 1106 | if ctx.Failed() { |
| 1107 | return |
| 1108 | } |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 1109 | mod.outputFile = android.OptionalPathForPath(buildOutput.outputFile) |
Colin Cross | a6182ab | 2024-08-21 10:47:44 -0700 | [diff] [blame] | 1110 | ctx.CheckbuildFile(buildOutput.outputFile) |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 1111 | if buildOutput.kytheFile != nil { |
| 1112 | mod.kytheFiles = append(mod.kytheFiles, buildOutput.kytheFile) |
| 1113 | } |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 1114 | bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), android.OptionalPathForPath(mod.compiler.unstrippedOutputFilePath())) |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 1115 | |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 1116 | mod.docTimestampFile = mod.compiler.rustdoc(ctx, flags, deps) |
| 1117 | |
Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 1118 | apexInfo, _ := android.ModuleProvider(actx, android.ApexInfoProvider) |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1119 | if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) && !mod.ProcMacro() { |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 1120 | // If the module has been specifically configure to not be installed then |
| 1121 | // hide from make as otherwise it will break when running inside make as the |
| 1122 | // output path to install will not be specified. Not all uninstallable |
| 1123 | // modules can be hidden from make as some are needed for resolving make |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1124 | // side dependencies. In particular, proc-macros need to be captured in the |
| 1125 | // host snapshot. |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 1126 | mod.HideFromMake() |
Spandan Das | 034af2c | 2024-10-30 21:45:09 +0000 | [diff] [blame] | 1127 | mod.SkipInstall() |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 1128 | } else if !mod.installable(apexInfo) { |
| 1129 | mod.SkipInstall() |
| 1130 | } |
| 1131 | |
| 1132 | // Still call install though, the installs will be stored as PackageSpecs to allow |
| 1133 | // using the outputs in a genrule. |
| 1134 | if mod.OutputFile().Valid() { |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 1135 | mod.compiler.install(ctx) |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 1136 | if ctx.Failed() { |
| 1137 | return |
| 1138 | } |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 1139 | // Export your own directory as a linkDir |
| 1140 | mod.exportedLinkDirs = append(mod.exportedLinkDirs, linkPathFromFilePath(mod.OutputFile().Path())) |
| 1141 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1142 | } |
Chris Wailes | 74be764 | 2021-07-22 16:20:28 -0700 | [diff] [blame] | 1143 | |
Colin Cross | b614cd4 | 2024-10-11 12:52:21 -0700 | [diff] [blame] | 1144 | android.SetProvider(ctx, cc.ImplementationDepInfoProvider, &cc.ImplementationDepInfo{ |
| 1145 | ImplementationDeps: depset.New(depset.PREORDER, deps.directImplementationDeps, deps.transitiveImplementationDeps), |
| 1146 | }) |
| 1147 | |
Chris Wailes | 74be764 | 2021-07-22 16:20:28 -0700 | [diff] [blame] | 1148 | ctx.Phony("rust", ctx.RustModule().OutputFile().Path()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1149 | } |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 1150 | |
Yu Liu | f6f8549 | 2025-01-13 21:02:36 +0000 | [diff] [blame] | 1151 | linkableInfo := cc.CreateCommonLinkableInfo(ctx, mod) |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1152 | linkableInfo.Static = mod.Static() |
| 1153 | linkableInfo.Shared = mod.Shared() |
| 1154 | linkableInfo.CrateName = mod.CrateName() |
| 1155 | linkableInfo.ExportedCrateLinkDirs = mod.ExportedCrateLinkDirs() |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 1156 | if lib, ok := mod.compiler.(cc.VersionedInterface); ok { |
| 1157 | linkableInfo.StubsVersion = lib.StubsVersion() |
| 1158 | } |
| 1159 | |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1160 | android.SetProvider(ctx, cc.LinkableInfoProvider, linkableInfo) |
| 1161 | |
| 1162 | rustInfo := &RustInfo{ |
| 1163 | AndroidMkSuffix: mod.AndroidMkSuffix(), |
| 1164 | RustSubName: mod.Properties.RustSubName, |
| 1165 | TransitiveAndroidMkSharedLibs: mod.transitiveAndroidMkSharedLibs, |
| 1166 | } |
| 1167 | if mod.compiler != nil { |
| 1168 | rustInfo.CompilerInfo = &CompilerInfo{ |
| 1169 | NoStdlibs: mod.compiler.noStdlibs(), |
| 1170 | StdLinkageForDevice: mod.compiler.stdLinkage(true), |
| 1171 | StdLinkageForNonDevice: mod.compiler.stdLinkage(false), |
| 1172 | } |
| 1173 | if lib, ok := mod.compiler.(libraryInterface); ok { |
| 1174 | rustInfo.CompilerInfo.LibraryInfo = &LibraryInfo{ |
| 1175 | Dylib: lib.dylib(), |
| 1176 | Rlib: lib.rlib(), |
| 1177 | } |
| 1178 | } |
| 1179 | if lib, ok := mod.compiler.(cc.SnapshotInterface); ok { |
| 1180 | rustInfo.SnapshotInfo = &cc.SnapshotInfo{ |
| 1181 | SnapshotAndroidMkSuffix: lib.SnapshotAndroidMkSuffix(), |
| 1182 | } |
| 1183 | } |
| 1184 | } |
| 1185 | if mod.sourceProvider != nil { |
Yu Liu | 727204c | 2025-01-23 20:58:32 +0000 | [diff] [blame] | 1186 | rustInfo.SourceProviderInfo = &SourceProviderInfo{ |
| 1187 | Srcs: mod.sourceProvider.Srcs(), |
| 1188 | } |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1189 | if _, ok := mod.sourceProvider.(*protobufDecorator); ok { |
Yu Liu | 727204c | 2025-01-23 20:58:32 +0000 | [diff] [blame] | 1190 | rustInfo.SourceProviderInfo.ProtobufDecoratorInfo = &ProtobufDecoratorInfo{} |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | android.SetProvider(ctx, RustInfoProvider, rustInfo) |
Yu Liu | 986d98c | 2024-11-12 00:28:11 +0000 | [diff] [blame] | 1194 | |
Ivan Lozano | 9eaacc8 | 2024-10-30 14:28:17 +0000 | [diff] [blame] | 1195 | ccInfo := &cc.CcInfo{ |
| 1196 | IsPrebuilt: mod.IsPrebuilt(), |
| 1197 | } |
| 1198 | |
Ivan Lozano | 9587f45 | 2025-01-08 03:17:19 +0000 | [diff] [blame] | 1199 | // Define the linker info if compiler != nil because Rust currently |
| 1200 | // does compilation and linking in one step. If this changes in the future, |
| 1201 | // move this as appropriate. |
Cole Faust | c9b88c9 | 2025-02-06 17:58:26 -0800 | [diff] [blame] | 1202 | baseCompilerProps := mod.compiler.baseCompilerProps() |
Ivan Lozano | 9587f45 | 2025-01-08 03:17:19 +0000 | [diff] [blame] | 1203 | ccInfo.LinkerInfo = &cc.LinkerInfo{ |
Cole Faust | c9b88c9 | 2025-02-06 17:58:26 -0800 | [diff] [blame] | 1204 | WholeStaticLibs: baseCompilerProps.Whole_static_libs.GetOrDefault(ctx, nil), |
| 1205 | StaticLibs: baseCompilerProps.Static_libs.GetOrDefault(ctx, nil), |
| 1206 | SharedLibs: baseCompilerProps.Shared_libs.GetOrDefault(ctx, nil), |
Ivan Lozano | 9587f45 | 2025-01-08 03:17:19 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
Ivan Lozano | 9eaacc8 | 2024-10-30 14:28:17 +0000 | [diff] [blame] | 1209 | android.SetProvider(ctx, cc.CcInfoProvider, ccInfo) |
| 1210 | |
mrziwang | 0cbd3b0 | 2024-06-20 16:39:25 -0700 | [diff] [blame] | 1211 | mod.setOutputFiles(ctx) |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 1212 | |
| 1213 | buildComplianceMetadataInfo(ctx, mod, deps) |
Cole Faust | 58eef4f | 2025-01-29 15:14:17 -0800 | [diff] [blame] | 1214 | |
| 1215 | moduleInfoJSON := ctx.ModuleInfoJSON() |
| 1216 | if mod.compiler != nil { |
| 1217 | mod.compiler.moduleInfoJSON(ctx, moduleInfoJSON) |
| 1218 | } |
mrziwang | 0cbd3b0 | 2024-06-20 16:39:25 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | func (mod *Module) setOutputFiles(ctx ModuleContext) { |
| 1222 | if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) { |
| 1223 | ctx.SetOutputFiles(mod.sourceProvider.Srcs(), "") |
| 1224 | } else if mod.OutputFile().Valid() { |
| 1225 | ctx.SetOutputFiles(android.Paths{mod.OutputFile().Path()}, "") |
| 1226 | } else { |
| 1227 | ctx.SetOutputFiles(android.Paths{}, "") |
| 1228 | } |
| 1229 | if mod.compiler != nil { |
| 1230 | ctx.SetOutputFiles(android.PathsIfNonNil(mod.compiler.unstrippedOutputFilePath()), "unstripped") |
| 1231 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 1234 | func buildComplianceMetadataInfo(ctx *moduleContext, mod *Module, deps PathDeps) { |
| 1235 | // Dump metadata that can not be done in android/compliance-metadata.go |
| 1236 | metadataInfo := ctx.ComplianceMetadataInfo() |
| 1237 | metadataInfo.SetStringValue(android.ComplianceMetadataProp.IS_STATIC_LIB, strconv.FormatBool(mod.Static())) |
| 1238 | metadataInfo.SetStringValue(android.ComplianceMetadataProp.BUILT_FILES, mod.outputFile.String()) |
| 1239 | |
| 1240 | // Static libs |
Yu Liu | 727204c | 2025-01-23 20:58:32 +0000 | [diff] [blame] | 1241 | staticDeps := ctx.GetDirectDepsProxyWithTag(rlibDepTag) |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 1242 | staticDepNames := make([]string, 0, len(staticDeps)) |
| 1243 | for _, dep := range staticDeps { |
| 1244 | staticDepNames = append(staticDepNames, dep.Name()) |
| 1245 | } |
Yu Liu | 727204c | 2025-01-23 20:58:32 +0000 | [diff] [blame] | 1246 | ccStaticDeps := ctx.GetDirectDepsProxyWithTag(cc.StaticDepTag(false)) |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 1247 | for _, dep := range ccStaticDeps { |
| 1248 | staticDepNames = append(staticDepNames, dep.Name()) |
| 1249 | } |
| 1250 | |
| 1251 | staticDepPaths := make([]string, 0, len(deps.StaticLibs)+len(deps.RLibs)) |
| 1252 | // C static libraries |
| 1253 | for _, dep := range deps.StaticLibs { |
| 1254 | staticDepPaths = append(staticDepPaths, dep.String()) |
| 1255 | } |
| 1256 | // Rust static libraries |
| 1257 | for _, dep := range deps.RLibs { |
| 1258 | staticDepPaths = append(staticDepPaths, dep.Path.String()) |
| 1259 | } |
| 1260 | metadataInfo.SetListValue(android.ComplianceMetadataProp.STATIC_DEPS, android.FirstUniqueStrings(staticDepNames)) |
| 1261 | metadataInfo.SetListValue(android.ComplianceMetadataProp.STATIC_DEP_FILES, android.FirstUniqueStrings(staticDepPaths)) |
| 1262 | |
| 1263 | // C Whole static libs |
Yu Liu | 727204c | 2025-01-23 20:58:32 +0000 | [diff] [blame] | 1264 | ccWholeStaticDeps := ctx.GetDirectDepsProxyWithTag(cc.StaticDepTag(true)) |
Wei Li | a1aa297 | 2024-06-21 13:08:51 -0700 | [diff] [blame] | 1265 | wholeStaticDepNames := make([]string, 0, len(ccWholeStaticDeps)) |
| 1266 | for _, dep := range ccStaticDeps { |
| 1267 | wholeStaticDepNames = append(wholeStaticDepNames, dep.Name()) |
| 1268 | } |
| 1269 | metadataInfo.SetListValue(android.ComplianceMetadataProp.STATIC_DEPS, android.FirstUniqueStrings(staticDepNames)) |
| 1270 | } |
| 1271 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1272 | func (mod *Module) deps(ctx DepsContext) Deps { |
| 1273 | deps := Deps{} |
| 1274 | |
| 1275 | if mod.compiler != nil { |
| 1276 | deps = mod.compiler.compilerDeps(ctx, deps) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 1277 | } |
| 1278 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 1279 | deps = mod.sourceProvider.SourceProviderDeps(ctx, deps) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1282 | if mod.coverage != nil { |
| 1283 | deps = mod.coverage.deps(ctx, deps) |
| 1284 | } |
| 1285 | |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 1286 | if mod.sanitize != nil { |
| 1287 | deps = mod.sanitize.deps(ctx, deps) |
| 1288 | } |
| 1289 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1290 | deps.Rlibs = android.LastUniqueStrings(deps.Rlibs) |
| 1291 | deps.Dylibs = android.LastUniqueStrings(deps.Dylibs) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1292 | deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1293 | deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros) |
| 1294 | deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) |
| 1295 | deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) |
Andrew Walbran | 797e4be | 2022-03-07 15:41:53 +0000 | [diff] [blame] | 1296 | deps.Stdlibs = android.LastUniqueStrings(deps.Stdlibs) |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1297 | deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1298 | return deps |
| 1299 | |
| 1300 | } |
| 1301 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1302 | type dependencyTag struct { |
| 1303 | blueprint.BaseDependencyTag |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1304 | name string |
| 1305 | library bool |
| 1306 | procMacro bool |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1307 | dynamic bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 1310 | // InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive |
| 1311 | // dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary. |
| 1312 | func (d dependencyTag) InstallDepNeeded() bool { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1313 | return d.library || d.procMacro |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | var _ android.InstallNeededDependencyTag = dependencyTag{} |
| 1317 | |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1318 | func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation { |
| 1319 | if d.library && d.dynamic { |
| 1320 | return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency} |
| 1321 | } |
| 1322 | return nil |
| 1323 | } |
| 1324 | |
Yu Liu | c888460 | 2024-03-15 18:48:38 +0000 | [diff] [blame] | 1325 | func (d dependencyTag) PropagateAconfigValidation() bool { |
| 1326 | return d == rlibDepTag || d == sourceDepTag |
| 1327 | } |
| 1328 | |
| 1329 | var _ android.PropagateAconfigValidationDependencyTag = dependencyTag{} |
| 1330 | |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1331 | var _ android.LicenseAnnotationsDependencyTag = dependencyTag{} |
| 1332 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1333 | var ( |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1334 | customBindgenDepTag = dependencyTag{name: "customBindgenTag"} |
| 1335 | rlibDepTag = dependencyTag{name: "rlibTag", library: true} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1336 | dylibDepTag = dependencyTag{name: "dylib", library: true, dynamic: true} |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1337 | procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true} |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1338 | sourceDepTag = dependencyTag{name: "source"} |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 1339 | dataLibDepTag = dependencyTag{name: "data lib"} |
| 1340 | dataBinDepTag = dependencyTag{name: "data bin"} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1341 | ) |
| 1342 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1343 | func IsDylibDepTag(depTag blueprint.DependencyTag) bool { |
| 1344 | tag, ok := depTag.(dependencyTag) |
| 1345 | return ok && tag == dylibDepTag |
| 1346 | } |
| 1347 | |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 1348 | func IsRlibDepTag(depTag blueprint.DependencyTag) bool { |
| 1349 | tag, ok := depTag.(dependencyTag) |
| 1350 | return ok && tag == rlibDepTag |
| 1351 | } |
| 1352 | |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1353 | type autoDep struct { |
| 1354 | variation string |
| 1355 | depTag dependencyTag |
| 1356 | } |
| 1357 | |
| 1358 | var ( |
Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 1359 | sourceVariation = "source" |
| 1360 | rlibVariation = "rlib" |
| 1361 | dylibVariation = "dylib" |
| 1362 | rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag} |
| 1363 | dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag} |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1364 | ) |
| 1365 | |
| 1366 | type autoDeppable interface { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 1367 | autoDep(ctx android.BottomUpMutatorContext) autoDep |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1370 | func (mod *Module) begin(ctx BaseModuleContext) { |
| 1371 | if mod.coverage != nil { |
| 1372 | mod.coverage.begin(ctx) |
| 1373 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 1374 | if mod.sanitize != nil { |
| 1375 | mod.sanitize.begin(ctx) |
| 1376 | } |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 1377 | |
| 1378 | if mod.UseSdk() && mod.IsSdkVariant() { |
| 1379 | sdkVersion := "" |
| 1380 | if ctx.Device() { |
| 1381 | sdkVersion = mod.SdkVersion() |
| 1382 | } |
| 1383 | version, err := cc.NativeApiLevelFromUser(ctx, sdkVersion) |
| 1384 | if err != nil { |
| 1385 | ctx.PropertyErrorf("sdk_version", err.Error()) |
| 1386 | mod.Properties.Sdk_version = nil |
| 1387 | } else { |
| 1388 | mod.Properties.Sdk_version = StringPtr(version.String()) |
| 1389 | } |
| 1390 | } |
| 1391 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1392 | } |
| 1393 | |
Ivan Lozano | fba2aa2 | 2021-11-11 09:29:07 -0500 | [diff] [blame] | 1394 | func (mod *Module) Prebuilt() *android.Prebuilt { |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1395 | if p, ok := mod.compiler.(rustPrebuilt); ok { |
Ivan Lozano | fba2aa2 | 2021-11-11 09:29:07 -0500 | [diff] [blame] | 1396 | return p.prebuilt() |
| 1397 | } |
| 1398 | return nil |
| 1399 | } |
| 1400 | |
Kiyoung Kim | 37693d0 | 2024-04-04 09:56:15 +0900 | [diff] [blame] | 1401 | func (mod *Module) Symlinks() []string { |
| 1402 | // TODO update this to return the list of symlinks when Rust supports defining symlinks |
| 1403 | return nil |
| 1404 | } |
| 1405 | |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1406 | func rustMakeLibName(rustInfo *RustInfo, linkableInfo *cc.LinkableInfo, commonInfo *android.CommonModuleInfo, depName string) string { |
| 1407 | if rustInfo != nil { |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 1408 | // Use base module name for snapshots when exporting to Makefile. |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1409 | if rustInfo.SnapshotInfo != nil { |
| 1410 | baseName := linkableInfo.BaseModuleName |
| 1411 | return baseName + rustInfo.SnapshotInfo.SnapshotAndroidMkSuffix + rustInfo.AndroidMkSuffix |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 1412 | } |
| 1413 | } |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1414 | return cc.MakeLibName(nil, linkableInfo, commonInfo, depName) |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 1415 | } |
| 1416 | |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1417 | func collectIncludedProtos(mod *Module, rustInfo *RustInfo, linkableInfo *cc.LinkableInfo) { |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1418 | if protoMod, ok := mod.sourceProvider.(*protobufDecorator); ok { |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1419 | if rustInfo.SourceProviderInfo.ProtobufDecoratorInfo != nil { |
| 1420 | protoMod.additionalCrates = append(protoMod.additionalCrates, linkableInfo.CrateName) |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1421 | } |
| 1422 | } |
| 1423 | } |
Andrew Walbran | 5253323 | 2024-03-19 11:36:04 +0000 | [diff] [blame] | 1424 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1425 | func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
| 1426 | var depPaths PathDeps |
| 1427 | |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1428 | directRlibDeps := []*cc.LinkableInfo{} |
| 1429 | directDylibDeps := []*cc.LinkableInfo{} |
| 1430 | directProcMacroDeps := []*cc.LinkableInfo{} |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1431 | directSharedLibDeps := []cc.SharedLibraryInfo{} |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1432 | directStaticLibDeps := [](*cc.LinkableInfo){} |
| 1433 | directSrcProvidersDeps := []*android.ModuleProxy{} |
| 1434 | directSrcDeps := []android.SourceFilesInfo{} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1435 | |
Ivan Lozano | e950cda | 2021-11-09 11:26:04 -0500 | [diff] [blame] | 1436 | // For the dependency from platform to apex, use the latest stubs |
| 1437 | mod.apexSdkVersion = android.FutureApiLevel |
Colin Cross | ff694a8 | 2023-12-13 15:54:49 -0800 | [diff] [blame] | 1438 | apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) |
Ivan Lozano | e950cda | 2021-11-09 11:26:04 -0500 | [diff] [blame] | 1439 | if !apexInfo.IsForPlatform() { |
| 1440 | mod.apexSdkVersion = apexInfo.MinSdkVersion |
| 1441 | } |
| 1442 | |
| 1443 | if android.InList("hwaddress", ctx.Config().SanitizeDevice()) { |
| 1444 | // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000) |
| 1445 | // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)). |
| 1446 | // (b/144430859) |
| 1447 | mod.apexSdkVersion = android.FutureApiLevel |
| 1448 | } |
| 1449 | |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1450 | skipModuleList := map[string]bool{} |
| 1451 | |
Colin Cross | a14fb6a | 2024-10-23 16:57:06 -0700 | [diff] [blame] | 1452 | var transitiveAndroidMkSharedLibs []depset.DepSet[string] |
Cole Faust | b6e6f99 | 2023-08-17 17:42:26 -0700 | [diff] [blame] | 1453 | var directAndroidMkSharedLibs []string |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1454 | |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1455 | ctx.VisitDirectDepsProxy(func(dep android.ModuleProxy) { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1456 | depName := ctx.OtherModuleName(dep) |
| 1457 | depTag := ctx.OtherModuleDependencyTag(dep) |
Ivan Lozano | 806efd3 | 2024-12-11 21:38:53 +0000 | [diff] [blame] | 1458 | modStdLinkage := mod.compiler.stdLinkage(ctx.Device()) |
| 1459 | |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1460 | if _, exists := skipModuleList[depName]; exists { |
| 1461 | return |
| 1462 | } |
A. Cody Schuffelen | c183e3a | 2023-08-14 21:09:47 -0700 | [diff] [blame] | 1463 | |
| 1464 | if depTag == android.DarwinUniversalVariantTag { |
| 1465 | return |
| 1466 | } |
| 1467 | |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1468 | rustInfo, hasRustInfo := android.OtherModuleProvider(ctx, dep, RustInfoProvider) |
| 1469 | ccInfo, _ := android.OtherModuleProvider(ctx, dep, cc.CcInfoProvider) |
| 1470 | linkableInfo, hasLinkableInfo := android.OtherModuleProvider(ctx, dep, cc.LinkableInfoProvider) |
| 1471 | commonInfo := android.OtherModuleProviderOrDefault(ctx, dep, android.CommonModuleInfoKey) |
| 1472 | if hasRustInfo && !linkableInfo.Static && !linkableInfo.Shared { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1473 | //Handle Rust Modules |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1474 | makeLibName := rustMakeLibName(rustInfo, linkableInfo, &commonInfo, depName+rustInfo.RustSubName) |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 1475 | |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 1476 | switch { |
| 1477 | case depTag == dylibDepTag: |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1478 | dylib := rustInfo.CompilerInfo.LibraryInfo |
| 1479 | if dylib == nil || !dylib.Dylib { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1480 | ctx.ModuleErrorf("mod %q not an dylib library", depName) |
| 1481 | return |
| 1482 | } |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1483 | directDylibDeps = append(directDylibDeps, linkableInfo) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1484 | mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1485 | mod.Properties.SnapshotDylibs = append(mod.Properties.SnapshotDylibs, cc.BaseLibName(depName)) |
| 1486 | |
Colin Cross | b614cd4 | 2024-10-11 12:52:21 -0700 | [diff] [blame] | 1487 | depPaths.directImplementationDeps = append(depPaths.directImplementationDeps, android.OutputFileForModule(ctx, dep, "")) |
| 1488 | if info, ok := android.OtherModuleProvider(ctx, dep, cc.ImplementationDepInfoProvider); ok { |
| 1489 | depPaths.transitiveImplementationDeps = append(depPaths.transitiveImplementationDeps, info.ImplementationDeps) |
| 1490 | } |
| 1491 | |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1492 | if !rustInfo.CompilerInfo.NoStdlibs { |
| 1493 | rustDepStdLinkage := rustInfo.CompilerInfo.StdLinkageForNonDevice |
| 1494 | if ctx.Device() { |
| 1495 | rustDepStdLinkage = rustInfo.CompilerInfo.StdLinkageForDevice |
| 1496 | } |
Ivan Lozano | 806efd3 | 2024-12-11 21:38:53 +0000 | [diff] [blame] | 1497 | if rustDepStdLinkage != modStdLinkage { |
| 1498 | ctx.ModuleErrorf("Rust dependency %q has the wrong StdLinkage; expected %#v, got %#v", depName, modStdLinkage, rustDepStdLinkage) |
| 1499 | return |
| 1500 | } |
| 1501 | } |
| 1502 | |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 1503 | case depTag == rlibDepTag: |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1504 | rlib := rustInfo.CompilerInfo.LibraryInfo |
| 1505 | if rlib == nil || !rlib.Rlib { |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1506 | ctx.ModuleErrorf("mod %q not an rlib library", makeLibName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1507 | return |
| 1508 | } |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1509 | directRlibDeps = append(directRlibDeps, linkableInfo) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1510 | mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1511 | mod.Properties.SnapshotRlibs = append(mod.Properties.SnapshotRlibs, cc.BaseLibName(depName)) |
| 1512 | |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 1513 | // rust_ffi rlibs may export include dirs, so collect those here. |
| 1514 | exportedInfo, _ := android.OtherModuleProvider(ctx, dep, cc.FlagExporterInfoProvider) |
| 1515 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1516 | depPaths.exportedLinkDirs = append(depPaths.exportedLinkDirs, linkPathFromFilePath(linkableInfo.OutputFile.Path())) |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 1517 | |
Colin Cross | b614cd4 | 2024-10-11 12:52:21 -0700 | [diff] [blame] | 1518 | // rlibs are not installed, so don't add the output file to directImplementationDeps |
| 1519 | if info, ok := android.OtherModuleProvider(ctx, dep, cc.ImplementationDepInfoProvider); ok { |
| 1520 | depPaths.transitiveImplementationDeps = append(depPaths.transitiveImplementationDeps, info.ImplementationDeps) |
| 1521 | } |
| 1522 | |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1523 | if !rustInfo.CompilerInfo.NoStdlibs { |
| 1524 | rustDepStdLinkage := rustInfo.CompilerInfo.StdLinkageForNonDevice |
| 1525 | if ctx.Device() { |
| 1526 | rustDepStdLinkage = rustInfo.CompilerInfo.StdLinkageForDevice |
| 1527 | } |
Ivan Lozano | 806efd3 | 2024-12-11 21:38:53 +0000 | [diff] [blame] | 1528 | if rustDepStdLinkage != modStdLinkage { |
| 1529 | ctx.ModuleErrorf("Rust dependency %q has the wrong StdLinkage; expected %#v, got %#v", depName, modStdLinkage, rustDepStdLinkage) |
| 1530 | return |
| 1531 | } |
| 1532 | } |
| 1533 | |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 1534 | case depTag == procMacroDepTag: |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1535 | directProcMacroDeps = append(directProcMacroDeps, linkableInfo) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1536 | mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName) |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 1537 | // proc_macro link dirs need to be exported, so collect those here. |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1538 | depPaths.exportedLinkDirs = append(depPaths.exportedLinkDirs, linkPathFromFilePath(linkableInfo.OutputFile.Path())) |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1539 | |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 1540 | case depTag == sourceDepTag: |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1541 | if _, ok := mod.sourceProvider.(*protobufDecorator); ok { |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1542 | collectIncludedProtos(mod, rustInfo, linkableInfo) |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1543 | } |
Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 1544 | case cc.IsStaticDepTag(depTag): |
| 1545 | // Rust FFI rlibs should not be declared in a Rust modules |
| 1546 | // "static_libs" list as we can't handle them properly at the |
| 1547 | // moment (for example, they only produce an rlib-std variant). |
| 1548 | // Instead, a normal rust_library variant should be used. |
| 1549 | ctx.PropertyErrorf("static_libs", |
| 1550 | "found '%s' in static_libs; use a rust_library module in rustlibs instead of a rust_ffi module in static_libs", |
| 1551 | depName) |
| 1552 | |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 1553 | } |
| 1554 | |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1555 | transitiveAndroidMkSharedLibs = append(transitiveAndroidMkSharedLibs, rustInfo.TransitiveAndroidMkSharedLibs) |
Cole Faust | b6e6f99 | 2023-08-17 17:42:26 -0700 | [diff] [blame] | 1556 | |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 1557 | if android.IsSourceDepTagWithOutputTag(depTag, "") { |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1558 | // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct |
| 1559 | // OS/Arch variant is used. |
| 1560 | var helper string |
| 1561 | if ctx.Host() { |
| 1562 | helper = "missing 'host_supported'?" |
| 1563 | } else { |
| 1564 | helper = "device module defined?" |
| 1565 | } |
| 1566 | |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1567 | if commonInfo.Target.Os != ctx.Os() { |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1568 | ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper) |
| 1569 | return |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1570 | } else if commonInfo.Target.Arch.ArchType != ctx.Arch().ArchType { |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1571 | ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper) |
| 1572 | return |
| 1573 | } |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1574 | directSrcProvidersDeps = append(directSrcProvidersDeps, &dep) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 1577 | exportedInfo, _ := android.OtherModuleProvider(ctx, dep, FlagExporterInfoProvider) |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 1578 | |
| 1579 | //Append the dependencies exported objects, except for proc-macros which target a different arch/OS |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1580 | if depTag != procMacroDepTag { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1581 | depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...) |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 1582 | depPaths.rustLibObjects = append(depPaths.rustLibObjects, exportedInfo.RustLibObjects...) |
| 1583 | depPaths.sharedLibObjects = append(depPaths.sharedLibObjects, exportedInfo.SharedLibPaths...) |
| 1584 | depPaths.staticLibObjects = append(depPaths.staticLibObjects, exportedInfo.StaticLibObjects...) |
| 1585 | depPaths.wholeStaticLibObjects = append(depPaths.wholeStaticLibObjects, exportedInfo.WholeStaticLibObjects...) |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 1586 | depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1589 | if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag { |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1590 | linkFile := linkableInfo.UnstrippedOutputFile |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1591 | linkDir := linkPathFromFilePath(linkFile) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 1592 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok { |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1593 | lib.exportLinkDirs(linkDir) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1594 | } |
| 1595 | } |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 1596 | |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1597 | if depTag == sourceDepTag { |
| 1598 | if _, ok := mod.sourceProvider.(*protobufDecorator); ok && mod.Source() { |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1599 | if rustInfo.SourceProviderInfo.ProtobufDecoratorInfo != nil { |
Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 1600 | exportedInfo, _ := android.OtherModuleProvider(ctx, dep, cc.FlagExporterInfoProvider) |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1601 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1602 | } |
| 1603 | } |
| 1604 | } |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1605 | } else if hasLinkableInfo { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1606 | //Handle C dependencies |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1607 | makeLibName := cc.MakeLibName(ccInfo, linkableInfo, &commonInfo, depName) |
| 1608 | if !hasRustInfo { |
| 1609 | if commonInfo.Target.Os != ctx.Os() { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1610 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) |
| 1611 | return |
| 1612 | } |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1613 | if commonInfo.Target.Arch.ArchType != ctx.Arch().ArchType { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1614 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) |
| 1615 | return |
| 1616 | } |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 1617 | } |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 1618 | ccLibPath := linkableInfo.OutputFile |
| 1619 | if !ccLibPath.Valid() { |
Colin Cross | a86ea0e | 2023-08-01 09:57:22 -0700 | [diff] [blame] | 1620 | if !ctx.Config().AllowMissingDependencies() { |
| 1621 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) |
| 1622 | } else { |
| 1623 | ctx.AddMissingDependencies([]string{depName}) |
| 1624 | } |
| 1625 | return |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 1628 | linkPath := linkPathFromFilePath(ccLibPath.Path()) |
Colin Cross | a86ea0e | 2023-08-01 09:57:22 -0700 | [diff] [blame] | 1629 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1630 | exportDep := false |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1631 | switch { |
| 1632 | case cc.IsStaticDepTag(depTag): |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1633 | if cc.IsWholeStaticLib(depTag) { |
| 1634 | // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail |
| 1635 | // if the library is not prefixed by "lib". |
Ivan Lozano | fdadcd7 | 2021-11-01 09:04:23 -0400 | [diff] [blame] | 1636 | if mod.Binary() { |
Ivan Lozano | fdadcd7 | 2021-11-01 09:04:23 -0400 | [diff] [blame] | 1637 | // Since binaries don't need to 'rebundle' these like libraries and only use these for the |
| 1638 | // final linkage, pass the args directly to the linker to handle these cases. |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 1639 | depPaths.depLinkFlags = append(depPaths.depLinkFlags, []string{"-Wl,--whole-archive", ccLibPath.Path().String(), "-Wl,--no-whole-archive"}...) |
| 1640 | } else if libName, ok := libNameFromFilePath(ccLibPath.Path()); ok { |
| 1641 | depPaths.depFlags = append(depPaths.depFlags, "-lstatic:+whole-archive="+libName) |
| 1642 | depPaths.depLinkFlags = append(depPaths.depLinkFlags, ccLibPath.Path().String()) |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1643 | } else { |
| 1644 | ctx.ModuleErrorf("'%q' cannot be listed as a whole_static_library in Rust modules unless the output is prefixed by 'lib'", depName, ctx.ModuleName()) |
Ivan Lozano | fb6f36f | 2021-02-05 12:27:08 -0500 | [diff] [blame] | 1645 | } |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1646 | } |
| 1647 | |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 1648 | if cc.IsWholeStaticLib(depTag) { |
| 1649 | // Add whole staticlibs to wholeStaticLibObjects to propagate to Rust all dependents. |
| 1650 | depPaths.wholeStaticLibObjects = append(depPaths.wholeStaticLibObjects, ccLibPath.String()) |
| 1651 | } else { |
| 1652 | // Otherwise add to staticLibObjects, which only propagate through rlibs to their dependents. |
| 1653 | depPaths.staticLibObjects = append(depPaths.staticLibObjects, ccLibPath.String()) |
| 1654 | |
| 1655 | } |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1656 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
| 1657 | |
Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 1658 | exportedInfo, _ := android.OtherModuleProvider(ctx, dep, cc.FlagExporterInfoProvider) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1659 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1660 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1661 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 1662 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1663 | directStaticLibDeps = append(directStaticLibDeps, linkableInfo) |
Justin Yun | 2b3ed64 | 2022-02-16 08:15:07 +0900 | [diff] [blame] | 1664 | |
| 1665 | // Record baseLibName for snapshots. |
| 1666 | mod.Properties.SnapshotStaticLibs = append(mod.Properties.SnapshotStaticLibs, cc.BaseLibName(depName)) |
| 1667 | |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1668 | mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, makeLibName) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1669 | case cc.IsSharedDepTag(depTag): |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1670 | // For the shared lib dependencies, we may link to the stub variant |
| 1671 | // of the dependency depending on the context (e.g. if this |
| 1672 | // dependency crosses the APEX boundaries). |
| 1673 | sharedLibraryInfo, exportedInfo := cc.ChooseStubOrImpl(ctx, dep) |
| 1674 | |
Colin Cross | b614cd4 | 2024-10-11 12:52:21 -0700 | [diff] [blame] | 1675 | if !sharedLibraryInfo.IsStubs { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 1676 | // TODO(b/362509506): remove this additional check once all apex_exclude uses are switched to stubs. |
| 1677 | if !linkableInfo.RustApexExclude { |
| 1678 | depPaths.directImplementationDeps = append(depPaths.directImplementationDeps, android.OutputFileForModule(ctx, dep, "")) |
| 1679 | if info, ok := android.OtherModuleProvider(ctx, dep, cc.ImplementationDepInfoProvider); ok { |
| 1680 | depPaths.transitiveImplementationDeps = append(depPaths.transitiveImplementationDeps, info.ImplementationDeps) |
| 1681 | } |
Colin Cross | b614cd4 | 2024-10-11 12:52:21 -0700 | [diff] [blame] | 1682 | } |
| 1683 | } |
| 1684 | |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1685 | // Re-get linkObject as ChooseStubOrImpl actually tells us which |
| 1686 | // object (either from stub or non-stub) to use. |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 1687 | ccLibPath = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary) |
| 1688 | if !ccLibPath.Valid() { |
Colin Cross | a86ea0e | 2023-08-01 09:57:22 -0700 | [diff] [blame] | 1689 | if !ctx.Config().AllowMissingDependencies() { |
| 1690 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) |
| 1691 | } else { |
| 1692 | ctx.AddMissingDependencies([]string{depName}) |
| 1693 | } |
| 1694 | return |
| 1695 | } |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 1696 | linkPath = linkPathFromFilePath(ccLibPath.Path()) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1697 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1698 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 1699 | depPaths.sharedLibObjects = append(depPaths.sharedLibObjects, ccLibPath.String()) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1700 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1701 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1702 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 1703 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1704 | directSharedLibDeps = append(directSharedLibDeps, sharedLibraryInfo) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1705 | |
| 1706 | // Record baseLibName for snapshots. |
| 1707 | mod.Properties.SnapshotSharedLibs = append(mod.Properties.SnapshotSharedLibs, cc.BaseLibName(depName)) |
| 1708 | |
Cole Faust | b6e6f99 | 2023-08-17 17:42:26 -0700 | [diff] [blame] | 1709 | directAndroidMkSharedLibs = append(directAndroidMkSharedLibs, makeLibName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1710 | exportDep = true |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 1711 | case cc.IsHeaderDepTag(depTag): |
Colin Cross | 313aa54 | 2023-12-13 13:47:44 -0800 | [diff] [blame] | 1712 | exportedInfo, _ := android.OtherModuleProvider(ctx, dep, cc.FlagExporterInfoProvider) |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 1713 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1714 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1715 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Ivan Lozano | 1dbfa14 | 2024-03-29 14:48:11 +0000 | [diff] [blame] | 1716 | mod.Properties.AndroidMkHeaderLibs = append(mod.Properties.AndroidMkHeaderLibs, makeLibName) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1717 | case depTag == cc.CrtBeginDepTag: |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 1718 | depPaths.CrtBegin = append(depPaths.CrtBegin, ccLibPath.Path()) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1719 | case depTag == cc.CrtEndDepTag: |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 1720 | depPaths.CrtEnd = append(depPaths.CrtEnd, ccLibPath.Path()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 1723 | // Make sure shared dependencies are propagated |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 1724 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep { |
| 1725 | lib.exportLinkDirs(linkPath) |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 1726 | lib.exportSharedLibs(ccLibPath.String()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1727 | } |
Colin Cross | 018cbeb | 2022-01-24 17:22:45 -0800 | [diff] [blame] | 1728 | } else { |
| 1729 | switch { |
| 1730 | case depTag == cc.CrtBeginDepTag: |
| 1731 | depPaths.CrtBegin = append(depPaths.CrtBegin, android.OutputFileForModule(ctx, dep, "")) |
| 1732 | case depTag == cc.CrtEndDepTag: |
| 1733 | depPaths.CrtEnd = append(depPaths.CrtEnd, android.OutputFileForModule(ctx, dep, "")) |
| 1734 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1735 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1736 | |
Yu Liu | c41eae5 | 2025-01-14 01:03:08 +0000 | [diff] [blame] | 1737 | if srcDep, ok := android.OtherModuleProvider(ctx, dep, android.SourceFilesInfoProvider); ok { |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 1738 | if android.IsSourceDepTagWithOutputTag(depTag, "") { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1739 | // These are usually genrules which don't have per-target variants. |
| 1740 | directSrcDeps = append(directSrcDeps, srcDep) |
| 1741 | } |
| 1742 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1743 | }) |
| 1744 | |
Colin Cross | a14fb6a | 2024-10-23 16:57:06 -0700 | [diff] [blame] | 1745 | mod.transitiveAndroidMkSharedLibs = depset.New[string](depset.PREORDER, directAndroidMkSharedLibs, transitiveAndroidMkSharedLibs) |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1746 | |
| 1747 | var rlibDepFiles RustLibraries |
Andrew Walbran | 5253323 | 2024-03-19 11:36:04 +0000 | [diff] [blame] | 1748 | aliases := mod.compiler.Aliases() |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1749 | for _, dep := range directRlibDeps { |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1750 | crateName := dep.CrateName |
Andrew Walbran | 5253323 | 2024-03-19 11:36:04 +0000 | [diff] [blame] | 1751 | if alias, aliased := aliases[crateName]; aliased { |
| 1752 | crateName = alias |
| 1753 | } |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1754 | rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile, CrateName: crateName}) |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1755 | } |
| 1756 | var dylibDepFiles RustLibraries |
| 1757 | for _, dep := range directDylibDeps { |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1758 | crateName := dep.CrateName |
Andrew Walbran | 5253323 | 2024-03-19 11:36:04 +0000 | [diff] [blame] | 1759 | if alias, aliased := aliases[crateName]; aliased { |
| 1760 | crateName = alias |
| 1761 | } |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1762 | dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile, CrateName: crateName}) |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1763 | } |
| 1764 | var procMacroDepFiles RustLibraries |
| 1765 | for _, dep := range directProcMacroDeps { |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1766 | crateName := dep.CrateName |
Andrew Walbran | 5253323 | 2024-03-19 11:36:04 +0000 | [diff] [blame] | 1767 | if alias, aliased := aliases[crateName]; aliased { |
| 1768 | crateName = alias |
| 1769 | } |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1770 | procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile, CrateName: crateName}) |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1773 | var staticLibDepFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1774 | for _, dep := range directStaticLibDeps { |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1775 | staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile.Path()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1776 | } |
| 1777 | |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1778 | var sharedLibFiles android.Paths |
| 1779 | var sharedLibDepFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1780 | for _, dep := range directSharedLibDeps { |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1781 | sharedLibFiles = append(sharedLibFiles, dep.SharedLibrary) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1782 | if dep.TableOfContents.Valid() { |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1783 | sharedLibDepFiles = append(sharedLibDepFiles, dep.TableOfContents.Path()) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1784 | } else { |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1785 | sharedLibDepFiles = append(sharedLibDepFiles, dep.SharedLibrary) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1786 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1789 | var srcProviderDepFiles android.Paths |
| 1790 | for _, dep := range directSrcProvidersDeps { |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1791 | srcs := android.OutputFilesForModule(ctx, *dep, "") |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1792 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 1793 | } |
| 1794 | for _, dep := range directSrcDeps { |
Yu Liu | 8024b92 | 2024-12-20 23:31:32 +0000 | [diff] [blame] | 1795 | srcs := dep.Srcs |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1796 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 1797 | } |
| 1798 | |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1799 | depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...) |
| 1800 | depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...) |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1801 | depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibFiles...) |
| 1802 | depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, sharedLibDepFiles...) |
| 1803 | depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...) |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1804 | depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...) |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1805 | depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1806 | |
| 1807 | // Dedup exported flags from dependencies |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1808 | depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs) |
Ivan Lozano | 1f10f68 | 2024-11-08 16:16:50 +0000 | [diff] [blame] | 1809 | depPaths.rustLibObjects = android.FirstUniqueStrings(depPaths.rustLibObjects) |
| 1810 | depPaths.staticLibObjects = android.FirstUniqueStrings(depPaths.staticLibObjects) |
| 1811 | depPaths.wholeStaticLibObjects = android.FirstUniqueStrings(depPaths.wholeStaticLibObjects) |
| 1812 | depPaths.sharedLibObjects = android.FirstUniqueStrings(depPaths.sharedLibObjects) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1813 | depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags) |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 1814 | depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags) |
| 1815 | depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths) |
| 1816 | depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths) |
Ivan Lozano | ad7ba59 | 2025-01-23 01:23:43 +0000 | [diff] [blame] | 1817 | depPaths.depLinkFlags = android.FirstUniqueStrings(depPaths.depLinkFlags) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1818 | |
| 1819 | return depPaths |
| 1820 | } |
| 1821 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 1822 | func (mod *Module) InstallInData() bool { |
| 1823 | if mod.compiler == nil { |
| 1824 | return false |
| 1825 | } |
| 1826 | return mod.compiler.inData() |
| 1827 | } |
| 1828 | |
Matthew Maurer | 9f59e8d | 2021-08-19 13:10:05 -0700 | [diff] [blame] | 1829 | func (mod *Module) InstallInRamdisk() bool { |
| 1830 | return mod.InRamdisk() |
| 1831 | } |
| 1832 | |
| 1833 | func (mod *Module) InstallInVendorRamdisk() bool { |
| 1834 | return mod.InVendorRamdisk() |
| 1835 | } |
| 1836 | |
| 1837 | func (mod *Module) InstallInRecovery() bool { |
| 1838 | return mod.InRecovery() |
| 1839 | } |
| 1840 | |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1841 | func linkPathFromFilePath(filepath android.Path) string { |
| 1842 | return strings.Split(filepath.String(), filepath.Base())[0] |
| 1843 | } |
| 1844 | |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1845 | // usePublicApi returns true if the rust variant should link against NDK (publicapi) |
| 1846 | func (r *Module) usePublicApi() bool { |
| 1847 | return r.Device() && r.UseSdk() |
| 1848 | } |
| 1849 | |
| 1850 | // useVendorApi returns true if the rust variant should link against LLNDK (vendorapi) |
| 1851 | func (r *Module) useVendorApi() bool { |
| 1852 | return r.Device() && (r.InVendor() || r.InProduct()) |
| 1853 | } |
| 1854 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1855 | func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { |
| 1856 | ctx := &depsContext{ |
| 1857 | BottomUpMutatorContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1858 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1859 | |
| 1860 | deps := mod.deps(ctx) |
Colin Cross | 3146c5c | 2020-09-30 15:34:40 -0700 | [diff] [blame] | 1861 | var commonDepVariations []blueprint.Variation |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1862 | |
| 1863 | if ctx.Os() == android.Android { |
Kiyoung Kim | 37693d0 | 2024-04-04 09:56:15 +0900 | [diff] [blame] | 1864 | deps.SharedLibs, _ = cc.FilterNdkLibs(mod, ctx.Config(), deps.SharedLibs) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1865 | } |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1866 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1867 | stdLinkage := "dylib-std" |
Ivan Lozano | 806efd3 | 2024-12-11 21:38:53 +0000 | [diff] [blame] | 1868 | if mod.compiler.stdLinkage(ctx.Device()) == RlibLinkage { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1869 | stdLinkage = "rlib-std" |
| 1870 | } |
| 1871 | |
| 1872 | rlibDepVariations := commonDepVariations |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1873 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1874 | if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() { |
| 1875 | rlibDepVariations = append(rlibDepVariations, |
| 1876 | blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage}) |
| 1877 | } |
| 1878 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1879 | // rlibs |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1880 | rlibDepVariations = append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: rlibVariation}) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1881 | for _, lib := range deps.Rlibs { |
| 1882 | depTag := rlibDepTag |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1883 | actx.AddVariationDependencies(rlibDepVariations, depTag, lib) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1884 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1885 | |
| 1886 | // dylibs |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1887 | dylibDepVariations := append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: dylibVariation}) |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 1888 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1889 | for _, lib := range deps.Dylibs { |
Kiyoung Kim | 37693d0 | 2024-04-04 09:56:15 +0900 | [diff] [blame] | 1890 | actx.AddVariationDependencies(dylibDepVariations, dylibDepTag, lib) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1891 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1892 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1893 | // rustlibs |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1894 | if deps.Rustlibs != nil { |
| 1895 | if !mod.compiler.Disabled() { |
| 1896 | for _, lib := range deps.Rustlibs { |
| 1897 | autoDep := mod.compiler.(autoDeppable).autoDep(ctx) |
| 1898 | if autoDep.depTag == rlibDepTag { |
| 1899 | // Handle the rlib deptag case |
Kiyoung Kim | 37693d0 | 2024-04-04 09:56:15 +0900 | [diff] [blame] | 1900 | actx.AddVariationDependencies(rlibDepVariations, rlibDepTag, lib) |
| 1901 | |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1902 | } else { |
| 1903 | // autoDep.depTag is a dylib depTag. Not all rustlibs may be available as a dylib however. |
| 1904 | // Check for the existence of the dylib deptag variant. Select it if available, |
| 1905 | // otherwise select the rlib variant. |
| 1906 | autoDepVariations := append(commonDepVariations, |
| 1907 | blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}) |
Kiyoung Kim | 37693d0 | 2024-04-04 09:56:15 +0900 | [diff] [blame] | 1908 | if actx.OtherModuleDependencyVariantExists(autoDepVariations, lib) { |
| 1909 | actx.AddVariationDependencies(autoDepVariations, autoDep.depTag, lib) |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1910 | |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1911 | } else { |
| 1912 | // If there's no dylib dependency available, try to add the rlib dependency instead. |
Kiyoung Kim | 37693d0 | 2024-04-04 09:56:15 +0900 | [diff] [blame] | 1913 | actx.AddVariationDependencies(rlibDepVariations, rlibDepTag, lib) |
| 1914 | |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1915 | } |
| 1916 | } |
| 1917 | } |
| 1918 | } else if _, ok := mod.sourceProvider.(*protobufDecorator); ok { |
| 1919 | for _, lib := range deps.Rustlibs { |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1920 | srcProviderVariations := append(commonDepVariations, |
Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 1921 | blueprint.Variation{Mutator: "rust_libraries", Variation: sourceVariation}) |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1922 | |
Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 1923 | // Only add rustlib dependencies if they're source providers themselves. |
| 1924 | // This is used to track which crate names need to be added to the source generated |
| 1925 | // in the rust_protobuf mod.rs. |
Kiyoung Kim | 37693d0 | 2024-04-04 09:56:15 +0900 | [diff] [blame] | 1926 | if actx.OtherModuleDependencyVariantExists(srcProviderVariations, lib) { |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1927 | actx.AddVariationDependencies(srcProviderVariations, sourceDepTag, lib) |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1928 | } |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1929 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1930 | } |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1931 | } |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1932 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1933 | // stdlibs |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1934 | if deps.Stdlibs != nil { |
Ivan Lozano | 806efd3 | 2024-12-11 21:38:53 +0000 | [diff] [blame] | 1935 | if mod.compiler.stdLinkage(ctx.Device()) == RlibLinkage { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1936 | for _, lib := range deps.Stdlibs { |
Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 1937 | actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...), |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1938 | rlibDepTag, lib) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1939 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1940 | } else { |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1941 | for _, lib := range deps.Stdlibs { |
Kiyoung Kim | 37693d0 | 2024-04-04 09:56:15 +0900 | [diff] [blame] | 1942 | actx.AddVariationDependencies(dylibDepVariations, dylibDepTag, lib) |
| 1943 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1944 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1945 | } |
| 1946 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1947 | |
| 1948 | for _, lib := range deps.SharedLibs { |
Colin Cross | 8acea3e | 2024-12-12 14:53:30 -0800 | [diff] [blame] | 1949 | depTag := cc.SharedDepTag() |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1950 | name, version := cc.StubsLibNameAndVersion(lib) |
| 1951 | |
| 1952 | variations := []blueprint.Variation{ |
| 1953 | {Mutator: "link", Variation: "shared"}, |
| 1954 | } |
Spandan Das | ff66518 | 2024-09-11 18:48:44 +0000 | [diff] [blame] | 1955 | cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, name, version, false) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | for _, lib := range deps.WholeStaticLibs { |
| 1959 | depTag := cc.StaticDepTag(true) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1960 | |
| 1961 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1962 | {Mutator: "link", Variation: "static"}, |
| 1963 | }, depTag, lib) |
| 1964 | } |
| 1965 | |
| 1966 | for _, lib := range deps.StaticLibs { |
| 1967 | depTag := cc.StaticDepTag(false) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1968 | |
| 1969 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1970 | {Mutator: "link", Variation: "static"}, |
| 1971 | }, depTag, lib) |
| 1972 | } |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1973 | |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 1974 | actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...) |
| 1975 | |
Colin Cross | 565cafd | 2020-09-25 18:47:38 -0700 | [diff] [blame] | 1976 | crtVariations := cc.GetCrtVariations(ctx, mod) |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 1977 | for _, crt := range deps.CrtBegin { |
Kiyoung Kim | 37693d0 | 2024-04-04 09:56:15 +0900 | [diff] [blame] | 1978 | actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, crt) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1979 | } |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 1980 | for _, crt := range deps.CrtEnd { |
Kiyoung Kim | 37693d0 | 2024-04-04 09:56:15 +0900 | [diff] [blame] | 1981 | actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, crt) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1984 | if mod.sourceProvider != nil { |
| 1985 | if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok && |
| 1986 | bindgen.Properties.Custom_bindgen != "" { |
| 1987 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag, |
| 1988 | bindgen.Properties.Custom_bindgen) |
| 1989 | } |
| 1990 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1991 | |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 1992 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1993 | {Mutator: "link", Variation: "shared"}, |
| 1994 | }, dataLibDepTag, deps.DataLibs...) |
| 1995 | |
| 1996 | actx.AddVariationDependencies(nil, dataBinDepTag, deps.DataBins...) |
| 1997 | |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1998 | // proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy. |
Colin Cross | 0f7d2ef | 2019-10-16 11:03:10 -0700 | [diff] [blame] | 1999 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...) |
Vinh Tran | cde1016 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 2000 | |
| 2001 | mod.afdo.addDep(ctx, actx) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 2004 | func BeginMutator(ctx android.BottomUpMutatorContext) { |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 2005 | if mod, ok := ctx.Module().(*Module); ok && mod.Enabled(ctx) { |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 2006 | mod.beginMutator(ctx) |
| 2007 | } |
| 2008 | } |
| 2009 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 2010 | func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) { |
| 2011 | ctx := &baseModuleContext{ |
| 2012 | BaseModuleContext: actx, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 2013 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 2014 | |
| 2015 | mod.begin(ctx) |
| 2016 | } |
| 2017 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 2018 | func (mod *Module) Name() string { |
| 2019 | name := mod.ModuleBase.Name() |
| 2020 | if p, ok := mod.compiler.(interface { |
| 2021 | Name(string) string |
| 2022 | }); ok { |
| 2023 | name = p.Name(name) |
| 2024 | } |
| 2025 | return name |
| 2026 | } |
| 2027 | |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 2028 | func (mod *Module) disableClippy() { |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 2029 | if mod.clippy != nil { |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 2030 | mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none") |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 2031 | } |
| 2032 | } |
| 2033 | |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 2034 | var _ android.HostToolProvider = (*Module)(nil) |
| 2035 | |
| 2036 | func (mod *Module) HostToolPath() android.OptionalPath { |
| 2037 | if !mod.Host() { |
| 2038 | return android.OptionalPath{} |
| 2039 | } |
Chih-Hung Hsieh | a756270 | 2020-08-10 21:50:43 -0700 | [diff] [blame] | 2040 | if binary, ok := mod.compiler.(*binaryDecorator); ok { |
| 2041 | return android.OptionalPathForPath(binary.baseCompiler.path) |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 2042 | } else if pm, ok := mod.compiler.(*procMacroDecorator); ok { |
| 2043 | // Even though proc-macros aren't strictly "tools", since they target the compiler |
| 2044 | // and act as compiler plugins, we treat them similarly. |
| 2045 | return android.OptionalPathForPath(pm.baseCompiler.path) |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 2046 | } |
| 2047 | return android.OptionalPath{} |
| 2048 | } |
| 2049 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 2050 | var _ android.ApexModule = (*Module)(nil) |
| 2051 | |
Ivan Lozano | 24cf036 | 2024-10-04 16:02:38 +0000 | [diff] [blame] | 2052 | // If a module is marked for exclusion from apexes, don't provide apex variants. |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 2053 | // TODO(b/362509506): remove this once all apex_exclude usages are removed. |
Ivan Lozano | 24cf036 | 2024-10-04 16:02:38 +0000 | [diff] [blame] | 2054 | func (m *Module) CanHaveApexVariants() bool { |
| 2055 | if m.ApexExclude() { |
| 2056 | return false |
| 2057 | } else { |
| 2058 | return m.ApexModuleBase.CanHaveApexVariants() |
| 2059 | } |
| 2060 | } |
| 2061 | |
Ivan Lozano | a91ba25 | 2022-01-11 12:02:06 -0500 | [diff] [blame] | 2062 | func (mod *Module) MinSdkVersion() string { |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 2063 | return String(mod.Properties.Min_sdk_version) |
| 2064 | } |
| 2065 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2066 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 2067 | func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { |
Ivan Lozano | a91ba25 | 2022-01-11 12:02:06 -0500 | [diff] [blame] | 2068 | minSdkVersion := mod.MinSdkVersion() |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 2069 | if minSdkVersion == "apex_inherit" { |
| 2070 | return nil |
| 2071 | } |
| 2072 | if minSdkVersion == "" { |
| 2073 | return fmt.Errorf("min_sdk_version is not specificed") |
| 2074 | } |
| 2075 | |
| 2076 | // Not using nativeApiLevelFromUser because the context here is not |
| 2077 | // necessarily a native context. |
| 2078 | ver, err := android.ApiLevelFromUser(ctx, minSdkVersion) |
| 2079 | if err != nil { |
| 2080 | return err |
| 2081 | } |
| 2082 | |
| 2083 | if ver.GreaterThan(sdkVersion) { |
| 2084 | return fmt.Errorf("newer SDK(%v)", ver) |
| 2085 | } |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 2086 | return nil |
| 2087 | } |
| 2088 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 2089 | // Implements android.ApexModule |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 2090 | func (mod *Module) AlwaysRequiresPlatformApexVariant() bool { |
| 2091 | // stub libraries and native bridge libraries are always available to platform |
| 2092 | // TODO(b/362509506): remove the ApexExclude() check once all apex_exclude uses are switched to stubs. |
| 2093 | return mod.IsStubs() || mod.Target().NativeBridge == android.NativeBridgeEnabled || mod.ApexExclude() |
| 2094 | } |
| 2095 | |
| 2096 | // Implements android.ApexModule |
Colin Cross | f7bbd2f | 2024-12-05 13:57:10 -0800 | [diff] [blame] | 2097 | func (mod *Module) OutgoingDepIsInSameApex(depTag blueprint.DependencyTag) bool { |
Matthew Maurer | 581b6d8 | 2022-09-29 16:46:25 -0700 | [diff] [blame] | 2098 | if depTag == procMacroDepTag || depTag == customBindgenDepTag { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 2099 | return false |
| 2100 | } |
| 2101 | |
Colin Cross | 8acea3e | 2024-12-12 14:53:30 -0800 | [diff] [blame] | 2102 | if mod.Static() && cc.IsSharedDepTag(depTag) { |
| 2103 | // shared_lib dependency from a static lib is considered as crossing |
| 2104 | // the APEX boundary because the dependency doesn't actually is |
| 2105 | // linked; the dependency is used only during the compilation phase. |
| 2106 | return false |
| 2107 | } |
| 2108 | |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 2109 | if depTag == cc.StubImplDepTag { |
| 2110 | // We don't track from an implementation library to its stubs. |
| 2111 | return false |
| 2112 | } |
| 2113 | |
| 2114 | if cc.ExcludeInApexDepTag(depTag) { |
| 2115 | return false |
| 2116 | } |
| 2117 | |
| 2118 | // TODO(b/362509506): remove once all apex_exclude uses are switched to stubs. |
| 2119 | if mod.ApexExclude() { |
| 2120 | return false |
| 2121 | } |
| 2122 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 2123 | return true |
| 2124 | } |
| 2125 | |
Colin Cross | f7bbd2f | 2024-12-05 13:57:10 -0800 | [diff] [blame] | 2126 | func (mod *Module) IncomingDepIsInSameApex(depTag blueprint.DependencyTag) bool { |
Colin Cross | 1cea530 | 2024-12-03 16:40:08 -0800 | [diff] [blame^] | 2127 | if mod.Host() { |
| 2128 | return false |
| 2129 | } |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 2130 | // TODO(b/362509506): remove once all apex_exclude uses are switched to stubs. |
| 2131 | if mod.ApexExclude() { |
| 2132 | return false |
| 2133 | } |
| 2134 | |
| 2135 | if mod.HasStubsVariants() { |
Colin Cross | bd930bc | 2025-02-03 12:17:42 -0800 | [diff] [blame] | 2136 | if cc.IsSharedDepTag(depTag) && !cc.IsExplicitImplSharedDepTag(depTag) { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 2137 | // dynamic dep to a stubs lib crosses APEX boundary |
| 2138 | return false |
| 2139 | } |
| 2140 | if cc.IsRuntimeDepTag(depTag) { |
| 2141 | // runtime dep to a stubs lib also crosses APEX boundary |
| 2142 | return false |
| 2143 | } |
| 2144 | if cc.IsHeaderDepTag(depTag) { |
| 2145 | return false |
| 2146 | } |
| 2147 | } |
| 2148 | return true |
Colin Cross | f7bbd2f | 2024-12-05 13:57:10 -0800 | [diff] [blame] | 2149 | } |
| 2150 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 2151 | // Overrides ApexModule.IsInstallabeToApex() |
| 2152 | func (mod *Module) IsInstallableToApex() bool { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 2153 | // TODO(b/362509506): remove once all apex_exclude uses are switched to stubs. |
| 2154 | if mod.ApexExclude() { |
| 2155 | return false |
| 2156 | } |
| 2157 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 2158 | if mod.compiler != nil { |
Ivan Lozano | a8a1fa1 | 2024-10-30 18:15:59 +0000 | [diff] [blame] | 2159 | if lib, ok := mod.compiler.(libraryInterface); ok { |
| 2160 | return (lib.shared() || lib.dylib()) && !lib.BuildStubs() |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 2161 | } |
| 2162 | if _, ok := mod.compiler.(*binaryDecorator); ok { |
| 2163 | return true |
| 2164 | } |
| 2165 | } |
| 2166 | return false |
| 2167 | } |
| 2168 | |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 2169 | // If a library file has a "lib" prefix, extract the library name without the prefix. |
| 2170 | func libNameFromFilePath(filepath android.Path) (string, bool) { |
| 2171 | libName := strings.TrimSuffix(filepath.Base(), filepath.Ext()) |
| 2172 | if strings.HasPrefix(libName, "lib") { |
| 2173 | libName = libName[3:] |
| 2174 | return libName, true |
| 2175 | } |
| 2176 | return "", false |
| 2177 | } |
| 2178 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 2179 | func kytheExtractRustFactory() android.Singleton { |
| 2180 | return &kytheExtractRustSingleton{} |
| 2181 | } |
| 2182 | |
| 2183 | type kytheExtractRustSingleton struct { |
| 2184 | } |
| 2185 | |
| 2186 | func (k kytheExtractRustSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 2187 | var xrefTargets android.Paths |
| 2188 | ctx.VisitAllModules(func(module android.Module) { |
| 2189 | if rustModule, ok := module.(xref); ok { |
| 2190 | xrefTargets = append(xrefTargets, rustModule.XrefRustFiles()...) |
| 2191 | } |
| 2192 | }) |
| 2193 | if len(xrefTargets) > 0 { |
| 2194 | ctx.Phony("xref_rust", xrefTargets...) |
| 2195 | } |
| 2196 | } |
| 2197 | |
Jihoon Kang | f78a890 | 2022-09-01 22:47:07 +0000 | [diff] [blame] | 2198 | func (c *Module) Partition() string { |
| 2199 | return "" |
| 2200 | } |
| 2201 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 2202 | var Bool = proptools.Bool |
| 2203 | var BoolDefault = proptools.BoolDefault |
| 2204 | var String = proptools.String |
| 2205 | var StringPtr = proptools.StringPtr |