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