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