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