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