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