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