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