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