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