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