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