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