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" |
| 25 | "android/soong/cc" |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 26 | cc_config "android/soong/cc/config" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 27 | "android/soong/rust/config" |
| 28 | ) |
| 29 | |
| 30 | var pctx = android.NewPackageContext("android/soong/rust") |
| 31 | |
| 32 | func init() { |
| 33 | // Only allow rust modules to be defined for certain projects |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 34 | |
| 35 | android.AddNeverAllowRules( |
| 36 | android.NeverAllow(). |
Ivan Lozano | e169ad7 | 2019-09-18 08:42:54 -0700 | [diff] [blame] | 37 | NotIn(config.RustAllowedPaths...). |
| 38 | ModuleType(config.RustModuleTypes...)) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 39 | |
| 40 | android.RegisterModuleType("rust_defaults", defaultsFactory) |
| 41 | android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 42 | ctx.BottomUp("rust_libraries", LibraryMutator).Parallel() |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 43 | ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel() |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 44 | ctx.BottomUp("rust_begin", BeginMutator).Parallel() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 45 | }) |
| 46 | pctx.Import("android/soong/rust/config") |
Thiébaud Weksteen | 682c9d7 | 2020-08-31 10:06:16 +0200 | [diff] [blame] | 47 | pctx.ImportAs("cc_config", "android/soong/cc/config") |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | type Flags struct { |
Ivan Lozano | 8a23fa4 | 2020-06-16 10:26:57 -0400 | [diff] [blame] | 51 | GlobalRustFlags []string // Flags that apply globally to rust |
| 52 | GlobalLinkFlags []string // Flags that apply globally to linker |
| 53 | RustFlags []string // Flags that apply to rust |
| 54 | LinkFlags []string // Flags that apply to linker |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 55 | ClippyFlags []string // Flags that apply to clippy-driver, during the linting |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 56 | Toolchain config.Toolchain |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 57 | Coverage bool |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 58 | Clippy bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | type BaseProperties struct { |
| 62 | AndroidMkRlibs []string |
| 63 | AndroidMkDylibs []string |
| 64 | AndroidMkProcMacroLibs []string |
| 65 | AndroidMkSharedLibs []string |
| 66 | AndroidMkStaticLibs []string |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 67 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 68 | ImageVariationPrefix string `blueprint:"mutated"` |
| 69 | VndkVersion string `blueprint:"mutated"` |
| 70 | SubName string `blueprint:"mutated"` |
| 71 | |
| 72 | // Set by imageMutator |
| 73 | CoreVariantNeeded bool `blueprint:"mutated"` |
| 74 | ExtraVariants []string `blueprint:"mutated"` |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 75 | |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 76 | // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX). |
| 77 | Min_sdk_version *string |
| 78 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 79 | PreventInstall bool |
| 80 | HideFromMake bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | type Module struct { |
| 84 | android.ModuleBase |
| 85 | android.DefaultableModuleBase |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 86 | android.ApexModuleBase |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 87 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 88 | VendorProperties cc.VendorProperties |
| 89 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 90 | Properties BaseProperties |
| 91 | |
| 92 | hod android.HostOrDeviceSupported |
| 93 | multilib android.Multilib |
| 94 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 95 | makeLinkType string |
| 96 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 97 | compiler compiler |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 98 | coverage *coverage |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 99 | clippy *clippy |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 100 | cachedToolchain config.Toolchain |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 101 | sourceProvider SourceProvider |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 102 | subAndroidMkOnce map[SubAndroidMkProvider]bool |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 103 | |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 104 | outputFile android.OptionalPath |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 105 | |
| 106 | hideApexVariantFromMake bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 109 | func (mod *Module) Header() bool { |
| 110 | //TODO: If Rust libraries provide header variants, this needs to be updated. |
| 111 | return false |
| 112 | } |
| 113 | |
| 114 | func (mod *Module) SetPreventInstall() { |
| 115 | mod.Properties.PreventInstall = true |
| 116 | } |
| 117 | |
| 118 | // Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor |
| 119 | func (mod *Module) InVendor() bool { |
| 120 | return mod.Properties.ImageVariationPrefix == cc.VendorVariationPrefix |
| 121 | } |
| 122 | |
| 123 | func (mod *Module) SetHideFromMake() { |
| 124 | mod.Properties.HideFromMake = true |
| 125 | } |
| 126 | |
| 127 | func (mod *Module) SanitizePropDefined() bool { |
| 128 | return false |
| 129 | } |
| 130 | |
| 131 | func (mod *Module) IsDependencyRoot() bool { |
| 132 | if mod.compiler != nil { |
| 133 | return mod.compiler.isDependencyRoot() |
| 134 | } |
| 135 | panic("IsDependencyRoot called on a non-compiler Rust module") |
| 136 | } |
| 137 | |
| 138 | func (mod *Module) IsPrebuilt() bool { |
| 139 | if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok { |
| 140 | return true |
| 141 | } |
| 142 | return false |
| 143 | } |
| 144 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 145 | func (mod *Module) OutputFiles(tag string) (android.Paths, error) { |
| 146 | switch tag { |
| 147 | case "": |
Andrei Homescu | 5db69cc | 2020-08-06 15:27:45 -0700 | [diff] [blame] | 148 | if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) { |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 149 | return mod.sourceProvider.Srcs(), nil |
| 150 | } else { |
| 151 | if mod.outputFile.Valid() { |
| 152 | return android.Paths{mod.outputFile.Path()}, nil |
| 153 | } |
| 154 | return android.Paths{}, nil |
| 155 | } |
| 156 | default: |
| 157 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 158 | } |
| 159 | } |
| 160 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 161 | func (mod *Module) SelectedStl() string { |
| 162 | return "" |
| 163 | } |
| 164 | |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 165 | func (mod *Module) NonCcVariants() bool { |
| 166 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 167 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 168 | return false |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName())) |
| 172 | } |
| 173 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 174 | func (mod *Module) Static() bool { |
| 175 | if mod.compiler != nil { |
| 176 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 177 | return library.static() |
| 178 | } |
| 179 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 180 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | func (mod *Module) Shared() bool { |
| 184 | if mod.compiler != nil { |
| 185 | if library, ok := mod.compiler.(libraryInterface); ok { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 186 | return library.shared() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 187 | } |
| 188 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 189 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | func (mod *Module) Toc() android.OptionalPath { |
| 193 | if mod.compiler != nil { |
| 194 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 195 | return android.OptionalPath{} |
| 196 | } |
| 197 | } |
| 198 | panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName())) |
| 199 | } |
| 200 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 201 | func (mod *Module) UseSdk() bool { |
| 202 | return false |
| 203 | } |
| 204 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 205 | // Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64. |
| 206 | // "product" and "vendor" variant modules return true for this function. |
| 207 | // When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true", |
| 208 | // "soc_specific: true" and more vendor installed modules are included here. |
| 209 | // When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or |
| 210 | // "product_specific: true" modules are included here. |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 211 | func (mod *Module) UseVndk() bool { |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 212 | return mod.Properties.VndkVersion != "" |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | func (mod *Module) MustUseVendorVariant() bool { |
| 216 | return false |
| 217 | } |
| 218 | |
| 219 | func (mod *Module) IsVndk() bool { |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 220 | // TODO(b/165791368) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 221 | return false |
| 222 | } |
| 223 | |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 224 | func (mod *Module) IsVndkExt() bool { |
| 225 | return false |
| 226 | } |
| 227 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 228 | func (c *Module) IsVndkPrivate() bool { |
| 229 | return false |
| 230 | } |
| 231 | |
| 232 | func (c *Module) IsLlndk() bool { |
| 233 | return false |
| 234 | } |
| 235 | |
| 236 | func (c *Module) IsLlndkPublic() bool { |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 237 | return false |
| 238 | } |
| 239 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 240 | func (mod *Module) SdkVersion() string { |
| 241 | return "" |
| 242 | } |
| 243 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 244 | func (mod *Module) AlwaysSdk() bool { |
| 245 | return false |
| 246 | } |
| 247 | |
Jiyong Park | 2286afd | 2020-06-16 21:58:53 +0900 | [diff] [blame] | 248 | func (mod *Module) IsSdkVariant() bool { |
| 249 | return false |
| 250 | } |
| 251 | |
Colin Cross | 1348ce3 | 2020-10-01 13:37:16 -0700 | [diff] [blame] | 252 | func (mod *Module) SplitPerApiLevel() bool { |
| 253 | return false |
| 254 | } |
| 255 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 256 | type Deps struct { |
| 257 | Dylibs []string |
| 258 | Rlibs []string |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 259 | Rustlibs []string |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 260 | Stdlibs []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 261 | ProcMacros []string |
| 262 | SharedLibs []string |
| 263 | StaticLibs []string |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 264 | HeaderLibs []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 265 | |
| 266 | CrtBegin, CrtEnd string |
| 267 | } |
| 268 | |
| 269 | type PathDeps struct { |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame^] | 270 | DyLibs RustLibraries |
| 271 | RLibs RustLibraries |
| 272 | SharedLibs android.Paths |
| 273 | SharedLibDeps android.Paths |
| 274 | StaticLibs android.Paths |
| 275 | ProcMacros RustLibraries |
| 276 | linkDirs []string |
| 277 | depFlags []string |
| 278 | linkObjects []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 279 | //ReexportedDeps android.Paths |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 280 | |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 281 | // Used by bindgen modules which call clang |
| 282 | depClangFlags []string |
| 283 | depIncludePaths android.Paths |
Ivan Lozano | ddd0bdb | 2020-08-28 17:00:26 -0400 | [diff] [blame] | 284 | depGeneratedHeaders android.Paths |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 285 | depSystemIncludePaths android.Paths |
| 286 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 287 | coverageFiles android.Paths |
| 288 | |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 289 | CrtBegin android.OptionalPath |
| 290 | CrtEnd android.OptionalPath |
Chih-Hung Hsieh | bbd25ae | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 291 | |
| 292 | // Paths to generated source files |
Ivan Lozano | 9d74a52 | 2020-12-01 09:25:22 -0500 | [diff] [blame] | 293 | SrcDeps android.Paths |
| 294 | srcProviderFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | type RustLibraries []RustLibrary |
| 298 | |
| 299 | type RustLibrary struct { |
| 300 | Path android.Path |
| 301 | CrateName string |
| 302 | } |
| 303 | |
| 304 | type compiler interface { |
| 305 | compilerFlags(ctx ModuleContext, flags Flags) Flags |
| 306 | compilerProps() []interface{} |
| 307 | compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path |
| 308 | compilerDeps(ctx DepsContext, deps Deps) Deps |
| 309 | crateName() string |
| 310 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 311 | inData() bool |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 312 | install(ctx ModuleContext) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 313 | relativeInstallPath() string |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 314 | |
| 315 | nativeCoverage() bool |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 316 | |
| 317 | Disabled() bool |
| 318 | SetDisabled() |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 319 | |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 320 | stdLinkage(ctx *depsContext) RustLinkage |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 321 | isDependencyRoot() bool |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 322 | } |
| 323 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 324 | type exportedFlagsProducer interface { |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 325 | exportLinkDirs(...string) |
| 326 | exportDepFlags(...string) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 327 | exportLinkObjects(...string) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | type flagExporter struct { |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 331 | depFlags []string |
| 332 | linkDirs []string |
| 333 | linkObjects []string |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 336 | func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) { |
| 337 | flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...)) |
| 338 | } |
| 339 | |
| 340 | func (flagExporter *flagExporter) exportDepFlags(flags ...string) { |
| 341 | flagExporter.depFlags = android.FirstUniqueStrings(append(flagExporter.depFlags, flags...)) |
| 342 | } |
| 343 | |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 344 | func (flagExporter *flagExporter) exportLinkObjects(flags ...string) { |
| 345 | flagExporter.linkObjects = android.FirstUniqueStrings(append(flagExporter.linkObjects, flags...)) |
| 346 | } |
| 347 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 348 | func (flagExporter *flagExporter) setProvider(ctx ModuleContext) { |
| 349 | ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{ |
| 350 | Flags: flagExporter.depFlags, |
| 351 | LinkDirs: flagExporter.linkDirs, |
| 352 | LinkObjects: flagExporter.linkObjects, |
| 353 | }) |
| 354 | } |
| 355 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 356 | var _ exportedFlagsProducer = (*flagExporter)(nil) |
| 357 | |
| 358 | func NewFlagExporter() *flagExporter { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 359 | return &flagExporter{} |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 362 | type FlagExporterInfo struct { |
| 363 | Flags []string |
| 364 | LinkDirs []string // TODO: this should be android.Paths |
| 365 | LinkObjects []string // TODO: this should be android.Paths |
| 366 | } |
| 367 | |
| 368 | var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{}) |
| 369 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 370 | func (mod *Module) isCoverageVariant() bool { |
| 371 | return mod.coverage.Properties.IsCoverageVariant |
| 372 | } |
| 373 | |
| 374 | var _ cc.Coverage = (*Module)(nil) |
| 375 | |
| 376 | func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 377 | return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant |
| 378 | } |
| 379 | |
| 380 | func (mod *Module) PreventInstall() { |
| 381 | mod.Properties.PreventInstall = true |
| 382 | } |
| 383 | |
| 384 | func (mod *Module) HideFromMake() { |
| 385 | mod.Properties.HideFromMake = true |
| 386 | } |
| 387 | |
| 388 | func (mod *Module) MarkAsCoverageVariant(coverage bool) { |
| 389 | mod.coverage.Properties.IsCoverageVariant = coverage |
| 390 | } |
| 391 | |
| 392 | func (mod *Module) EnableCoverageIfNeeded() { |
| 393 | mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | func defaultsFactory() android.Module { |
| 397 | return DefaultsFactory() |
| 398 | } |
| 399 | |
| 400 | type Defaults struct { |
| 401 | android.ModuleBase |
| 402 | android.DefaultsModuleBase |
| 403 | } |
| 404 | |
| 405 | func DefaultsFactory(props ...interface{}) android.Module { |
| 406 | module := &Defaults{} |
| 407 | |
| 408 | module.AddProperties(props...) |
| 409 | module.AddProperties( |
| 410 | &BaseProperties{}, |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 411 | &cc.VendorProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 412 | &BindgenProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 413 | &BaseCompilerProperties{}, |
| 414 | &BinaryCompilerProperties{}, |
| 415 | &LibraryCompilerProperties{}, |
| 416 | &ProcMacroCompilerProperties{}, |
| 417 | &PrebuiltProperties{}, |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 418 | &SourceProviderProperties{}, |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 419 | &TestProperties{}, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 420 | &cc.CoverageProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 421 | &cc.RustBindgenClangProperties{}, |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 422 | &ClippyProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 423 | ) |
| 424 | |
| 425 | android.InitDefaultsModule(module) |
| 426 | return module |
| 427 | } |
| 428 | |
| 429 | func (mod *Module) CrateName() string { |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 430 | return mod.compiler.crateName() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 433 | func (mod *Module) CcLibrary() bool { |
| 434 | if mod.compiler != nil { |
| 435 | if _, ok := mod.compiler.(*libraryDecorator); ok { |
| 436 | return true |
| 437 | } |
| 438 | } |
| 439 | return false |
| 440 | } |
| 441 | |
| 442 | func (mod *Module) CcLibraryInterface() bool { |
| 443 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 444 | // use build{Static,Shared}() instead of {static,shared}() here because this might be called before |
| 445 | // VariantIs{Static,Shared} is set. |
| 446 | if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 447 | return true |
| 448 | } |
| 449 | } |
| 450 | return false |
| 451 | } |
| 452 | |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 453 | func (mod *Module) IncludeDirs() android.Paths { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 454 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 455 | if library, ok := mod.compiler.(*libraryDecorator); ok { |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 456 | return library.includeDirs |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName())) |
| 460 | } |
| 461 | |
| 462 | func (mod *Module) SetStatic() { |
| 463 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 464 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 465 | library.setStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 466 | return |
| 467 | } |
| 468 | } |
| 469 | panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName())) |
| 470 | } |
| 471 | |
| 472 | func (mod *Module) SetShared() { |
| 473 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 474 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 475 | library.setShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 476 | return |
| 477 | } |
| 478 | } |
| 479 | panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName())) |
| 480 | } |
| 481 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 482 | func (mod *Module) BuildStaticVariant() bool { |
| 483 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 484 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 485 | return library.buildStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName())) |
| 489 | } |
| 490 | |
| 491 | func (mod *Module) BuildSharedVariant() bool { |
| 492 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 493 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 494 | return library.buildShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName())) |
| 498 | } |
| 499 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 500 | func (mod *Module) Module() android.Module { |
| 501 | return mod |
| 502 | } |
| 503 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 504 | func (mod *Module) OutputFile() android.OptionalPath { |
| 505 | return mod.outputFile |
| 506 | } |
| 507 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 508 | func (mod *Module) CoverageFiles() android.Paths { |
| 509 | if mod.compiler != nil { |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 510 | if !mod.compiler.nativeCoverage() { |
| 511 | return android.Paths{} |
| 512 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 513 | if library, ok := mod.compiler.(*libraryDecorator); ok { |
| 514 | if library.coverageFile != nil { |
| 515 | return android.Paths{library.coverageFile} |
| 516 | } |
| 517 | return android.Paths{} |
| 518 | } |
| 519 | } |
| 520 | panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName())) |
| 521 | } |
| 522 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 523 | func (mod *Module) installable(apexInfo android.ApexInfo) bool { |
| 524 | // The apex variant is not installable because it is included in the APEX and won't appear |
| 525 | // in the system partition as a standalone file. |
| 526 | if !apexInfo.IsForPlatform() { |
| 527 | return false |
| 528 | } |
| 529 | |
| 530 | return mod.outputFile.Valid() && !mod.Properties.PreventInstall |
| 531 | } |
| 532 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 533 | var _ cc.LinkableInterface = (*Module)(nil) |
| 534 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 535 | func (mod *Module) Init() android.Module { |
| 536 | mod.AddProperties(&mod.Properties) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 537 | mod.AddProperties(&mod.VendorProperties) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 538 | |
| 539 | if mod.compiler != nil { |
| 540 | mod.AddProperties(mod.compiler.compilerProps()...) |
| 541 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 542 | if mod.coverage != nil { |
| 543 | mod.AddProperties(mod.coverage.props()...) |
| 544 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 545 | if mod.clippy != nil { |
| 546 | mod.AddProperties(mod.clippy.props()...) |
| 547 | } |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 548 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 549 | mod.AddProperties(mod.sourceProvider.SourceProviderProps()...) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 550 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 551 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 552 | android.InitAndroidArchModule(mod, mod.hod, mod.multilib) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 553 | android.InitApexModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 554 | |
| 555 | android.InitDefaultableModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 556 | return mod |
| 557 | } |
| 558 | |
| 559 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 560 | return &Module{ |
| 561 | hod: hod, |
| 562 | multilib: multilib, |
| 563 | } |
| 564 | } |
| 565 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 566 | module := newBaseModule(hod, multilib) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 567 | module.coverage = &coverage{} |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 568 | module.clippy = &clippy{} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 569 | return module |
| 570 | } |
| 571 | |
| 572 | type ModuleContext interface { |
| 573 | android.ModuleContext |
| 574 | ModuleContextIntf |
| 575 | } |
| 576 | |
| 577 | type BaseModuleContext interface { |
| 578 | android.BaseModuleContext |
| 579 | ModuleContextIntf |
| 580 | } |
| 581 | |
| 582 | type DepsContext interface { |
| 583 | android.BottomUpMutatorContext |
| 584 | ModuleContextIntf |
| 585 | } |
| 586 | |
| 587 | type ModuleContextIntf interface { |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 588 | RustModule() *Module |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 589 | toolchain() config.Toolchain |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | type depsContext struct { |
| 593 | android.BottomUpMutatorContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | type moduleContext struct { |
| 597 | android.ModuleContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 600 | type baseModuleContext struct { |
| 601 | android.BaseModuleContext |
| 602 | } |
| 603 | |
| 604 | func (ctx *moduleContext) RustModule() *Module { |
| 605 | return ctx.Module().(*Module) |
| 606 | } |
| 607 | |
| 608 | func (ctx *moduleContext) toolchain() config.Toolchain { |
| 609 | return ctx.RustModule().toolchain(ctx) |
| 610 | } |
| 611 | |
| 612 | func (ctx *depsContext) RustModule() *Module { |
| 613 | return ctx.Module().(*Module) |
| 614 | } |
| 615 | |
| 616 | func (ctx *depsContext) toolchain() config.Toolchain { |
| 617 | return ctx.RustModule().toolchain(ctx) |
| 618 | } |
| 619 | |
| 620 | func (ctx *baseModuleContext) RustModule() *Module { |
| 621 | return ctx.Module().(*Module) |
| 622 | } |
| 623 | |
| 624 | func (ctx *baseModuleContext) toolchain() config.Toolchain { |
| 625 | return ctx.RustModule().toolchain(ctx) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | func (mod *Module) nativeCoverage() bool { |
| 629 | return mod.compiler != nil && mod.compiler.nativeCoverage() |
| 630 | } |
| 631 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 632 | func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain { |
| 633 | if mod.cachedToolchain == nil { |
| 634 | mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 635 | } |
| 636 | return mod.cachedToolchain |
| 637 | } |
| 638 | |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 639 | func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain { |
| 640 | return cc_config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 641 | } |
| 642 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 643 | func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 644 | } |
| 645 | |
| 646 | func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
| 647 | ctx := &moduleContext{ |
| 648 | ModuleContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 649 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 650 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 651 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 652 | if !apexInfo.IsForPlatform() { |
| 653 | mod.hideApexVariantFromMake = true |
| 654 | } |
| 655 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 656 | toolchain := mod.toolchain(ctx) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 657 | mod.makeLinkType = cc.GetMakeLinkType(actx, mod) |
| 658 | |
| 659 | // Differentiate static libraries that are vendor available |
| 660 | if mod.UseVndk() { |
| 661 | mod.Properties.SubName += ".vendor" |
| 662 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 663 | |
| 664 | if !toolchain.Supported() { |
| 665 | // This toolchain's unsupported, there's nothing to do for this mod. |
| 666 | return |
| 667 | } |
| 668 | |
| 669 | deps := mod.depsToPaths(ctx) |
| 670 | flags := Flags{ |
| 671 | Toolchain: toolchain, |
| 672 | } |
| 673 | |
| 674 | if mod.compiler != nil { |
| 675 | flags = mod.compiler.compilerFlags(ctx, flags) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 676 | } |
| 677 | if mod.coverage != nil { |
| 678 | flags, deps = mod.coverage.flags(ctx, flags, deps) |
| 679 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 680 | if mod.clippy != nil { |
| 681 | flags, deps = mod.clippy.flags(ctx, flags, deps) |
| 682 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 683 | |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 684 | // SourceProvider needs to call GenerateSource() before compiler calls |
| 685 | // compile() so it can provide the source. A SourceProvider has |
| 686 | // multiple variants (e.g. source, rlib, dylib). Only the "source" |
| 687 | // variant is responsible for effectively generating the source. The |
| 688 | // remaining variants relies on the "source" variant output. |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 689 | if mod.sourceProvider != nil { |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 690 | if mod.compiler.(libraryInterface).source() { |
| 691 | mod.sourceProvider.GenerateSource(ctx, deps) |
| 692 | mod.sourceProvider.setSubName(ctx.ModuleSubDir()) |
| 693 | } else { |
| 694 | sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag) |
| 695 | sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator) |
Chih-Hung Hsieh | c49649c | 2020-10-01 21:25:05 -0700 | [diff] [blame] | 696 | mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs()) |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 697 | } |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | if mod.compiler != nil && !mod.compiler.Disabled() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 701 | outputFile := mod.compiler.compile(ctx, flags, deps) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 702 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 703 | mod.outputFile = android.OptionalPathForPath(outputFile) |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 704 | |
| 705 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 706 | if mod.installable(apexInfo) { |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 707 | mod.compiler.install(ctx) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 708 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | |
| 712 | func (mod *Module) deps(ctx DepsContext) Deps { |
| 713 | deps := Deps{} |
| 714 | |
| 715 | if mod.compiler != nil { |
| 716 | deps = mod.compiler.compilerDeps(ctx, deps) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 717 | } |
| 718 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 719 | deps = mod.sourceProvider.SourceProviderDeps(ctx, deps) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 722 | if mod.coverage != nil { |
| 723 | deps = mod.coverage.deps(ctx, deps) |
| 724 | } |
| 725 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 726 | deps.Rlibs = android.LastUniqueStrings(deps.Rlibs) |
| 727 | deps.Dylibs = android.LastUniqueStrings(deps.Dylibs) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 728 | deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 729 | deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros) |
| 730 | deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) |
| 731 | deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) |
| 732 | |
| 733 | return deps |
| 734 | |
| 735 | } |
| 736 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 737 | type dependencyTag struct { |
| 738 | blueprint.BaseDependencyTag |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 739 | name string |
| 740 | library bool |
| 741 | procMacro bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 744 | // InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive |
| 745 | // dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary. |
| 746 | func (d dependencyTag) InstallDepNeeded() bool { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 747 | return d.library || d.procMacro |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | var _ android.InstallNeededDependencyTag = dependencyTag{} |
| 751 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 752 | var ( |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 753 | customBindgenDepTag = dependencyTag{name: "customBindgenTag"} |
| 754 | rlibDepTag = dependencyTag{name: "rlibTag", library: true} |
| 755 | dylibDepTag = dependencyTag{name: "dylib", library: true} |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 756 | procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true} |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 757 | testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"} |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 758 | sourceDepTag = dependencyTag{name: "source"} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 759 | ) |
| 760 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 761 | func IsDylibDepTag(depTag blueprint.DependencyTag) bool { |
| 762 | tag, ok := depTag.(dependencyTag) |
| 763 | return ok && tag == dylibDepTag |
| 764 | } |
| 765 | |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 766 | type autoDep struct { |
| 767 | variation string |
| 768 | depTag dependencyTag |
| 769 | } |
| 770 | |
| 771 | var ( |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 772 | rlibVariation = "rlib" |
| 773 | dylibVariation = "dylib" |
| 774 | rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag} |
| 775 | dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag} |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 776 | ) |
| 777 | |
| 778 | type autoDeppable interface { |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 779 | autoDep(ctx BaseModuleContext) autoDep |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 782 | func (mod *Module) begin(ctx BaseModuleContext) { |
| 783 | if mod.coverage != nil { |
| 784 | mod.coverage.begin(ctx) |
| 785 | } |
| 786 | } |
| 787 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 788 | func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
| 789 | var depPaths PathDeps |
| 790 | |
| 791 | directRlibDeps := []*Module{} |
| 792 | directDylibDeps := []*Module{} |
| 793 | directProcMacroDeps := []*Module{} |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 794 | directSharedLibDeps := [](cc.LinkableInterface){} |
| 795 | directStaticLibDeps := [](cc.LinkableInterface){} |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 796 | directSrcProvidersDeps := []*Module{} |
| 797 | directSrcDeps := [](android.SourceFileProducer){} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 798 | |
| 799 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 800 | depName := ctx.OtherModuleName(dep) |
| 801 | depTag := ctx.OtherModuleDependencyTag(dep) |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 802 | if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 803 | //Handle Rust Modules |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 804 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 805 | switch depTag { |
| 806 | case dylibDepTag: |
| 807 | dylib, ok := rustDep.compiler.(libraryInterface) |
| 808 | if !ok || !dylib.dylib() { |
| 809 | ctx.ModuleErrorf("mod %q not an dylib library", depName) |
| 810 | return |
| 811 | } |
| 812 | directDylibDeps = append(directDylibDeps, rustDep) |
| 813 | mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, depName) |
| 814 | case rlibDepTag: |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 815 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 816 | rlib, ok := rustDep.compiler.(libraryInterface) |
| 817 | if !ok || !rlib.rlib() { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 818 | ctx.ModuleErrorf("mod %q not an rlib library", depName+rustDep.Properties.SubName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 819 | return |
| 820 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 821 | depPaths.coverageFiles = append(depPaths.coverageFiles, rustDep.CoverageFiles()...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 822 | directRlibDeps = append(directRlibDeps, rustDep) |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 823 | mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, depName+rustDep.Properties.SubName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 824 | case procMacroDepTag: |
| 825 | directProcMacroDeps = append(directProcMacroDeps, rustDep) |
| 826 | mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, depName) |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 827 | case android.SourceDepTag: |
| 828 | // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct |
| 829 | // OS/Arch variant is used. |
| 830 | var helper string |
| 831 | if ctx.Host() { |
| 832 | helper = "missing 'host_supported'?" |
| 833 | } else { |
| 834 | helper = "device module defined?" |
| 835 | } |
| 836 | |
| 837 | if dep.Target().Os != ctx.Os() { |
| 838 | ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper) |
| 839 | return |
| 840 | } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType { |
| 841 | ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper) |
| 842 | return |
| 843 | } |
| 844 | directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 845 | } |
| 846 | |
Ivan Lozano | 2bbcacf | 2020-08-07 09:00:50 -0400 | [diff] [blame] | 847 | //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] | 848 | if depTag != procMacroDepTag { |
| 849 | exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo) |
| 850 | depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...) |
| 851 | depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...) |
| 852 | depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 855 | if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag { |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 856 | linkFile := rustDep.outputFile |
| 857 | if !linkFile.Valid() { |
| 858 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", |
| 859 | depName, ctx.ModuleName()) |
| 860 | return |
| 861 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 862 | linkDir := linkPathFromFilePath(linkFile.Path()) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 863 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok { |
| 864 | lib.exportLinkDirs(linkDir) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 865 | } |
| 866 | } |
| 867 | |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 868 | } else if ccDep, ok := dep.(cc.LinkableInterface); ok { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 869 | //Handle C dependencies |
| 870 | if _, ok := ccDep.(*Module); !ok { |
| 871 | if ccDep.Module().Target().Os != ctx.Os() { |
| 872 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) |
| 873 | return |
| 874 | } |
| 875 | if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType { |
| 876 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) |
| 877 | return |
| 878 | } |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 879 | } |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 880 | linkObject := ccDep.OutputFile() |
| 881 | linkPath := linkPathFromFilePath(linkObject.Path()) |
Ivan Lozano | 6aa6602 | 2020-02-06 13:22:43 -0500 | [diff] [blame] | 882 | |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 883 | if !linkObject.Valid() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 884 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) |
| 885 | } |
| 886 | |
| 887 | exportDep := false |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 888 | switch { |
| 889 | case cc.IsStaticDepTag(depTag): |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 890 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 891 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String()) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 892 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 893 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 894 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 895 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 896 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 897 | depPaths.coverageFiles = append(depPaths.coverageFiles, ccDep.CoverageFiles()...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 898 | directStaticLibDeps = append(directStaticLibDeps, ccDep) |
| 899 | mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, depName) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 900 | case cc.IsSharedDepTag(depTag): |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 901 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 902 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String()) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 903 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 904 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 905 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 906 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 907 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 908 | directSharedLibDeps = append(directSharedLibDeps, ccDep) |
| 909 | mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName) |
| 910 | exportDep = true |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 911 | case cc.IsHeaderDepTag(depTag): |
| 912 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 913 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 914 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 915 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 916 | case depTag == cc.CrtBeginDepTag: |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 917 | depPaths.CrtBegin = linkObject |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 918 | case depTag == cc.CrtEndDepTag: |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 919 | depPaths.CrtEnd = linkObject |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | // Make sure these dependencies are propagated |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 923 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep { |
| 924 | lib.exportLinkDirs(linkPath) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 925 | lib.exportLinkObjects(linkObject.String()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 926 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 927 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 928 | |
| 929 | if srcDep, ok := dep.(android.SourceFileProducer); ok { |
| 930 | switch depTag { |
| 931 | case android.SourceDepTag: |
| 932 | // These are usually genrules which don't have per-target variants. |
| 933 | directSrcDeps = append(directSrcDeps, srcDep) |
| 934 | } |
| 935 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 936 | }) |
| 937 | |
| 938 | var rlibDepFiles RustLibraries |
| 939 | for _, dep := range directRlibDeps { |
| 940 | rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()}) |
| 941 | } |
| 942 | var dylibDepFiles RustLibraries |
| 943 | for _, dep := range directDylibDeps { |
| 944 | dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()}) |
| 945 | } |
| 946 | var procMacroDepFiles RustLibraries |
| 947 | for _, dep := range directProcMacroDeps { |
| 948 | procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.outputFile.Path(), CrateName: dep.CrateName()}) |
| 949 | } |
| 950 | |
| 951 | var staticLibDepFiles android.Paths |
| 952 | for _, dep := range directStaticLibDeps { |
| 953 | staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path()) |
| 954 | } |
| 955 | |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame^] | 956 | var sharedLibFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 957 | var sharedLibDepFiles android.Paths |
| 958 | for _, dep := range directSharedLibDeps { |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame^] | 959 | sharedLibFiles = append(sharedLibFiles, dep.OutputFile().Path()) |
| 960 | if dep.Toc().Valid() { |
| 961 | sharedLibDepFiles = append(sharedLibDepFiles, dep.Toc().Path()) |
| 962 | } else { |
| 963 | sharedLibDepFiles = append(sharedLibDepFiles, dep.OutputFile().Path()) |
| 964 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 965 | } |
| 966 | |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 967 | var srcProviderDepFiles android.Paths |
| 968 | for _, dep := range directSrcProvidersDeps { |
| 969 | srcs, _ := dep.OutputFiles("") |
| 970 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 971 | } |
| 972 | for _, dep := range directSrcDeps { |
| 973 | srcs := dep.Srcs() |
| 974 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 975 | } |
| 976 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 977 | depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...) |
| 978 | depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...) |
| 979 | depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame^] | 980 | depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, sharedLibDepFiles...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 981 | depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...) |
| 982 | depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...) |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 983 | depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 984 | |
| 985 | // Dedup exported flags from dependencies |
| 986 | depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame^] | 987 | depPaths.linkObjects = android.FirstUniqueStrings(depPaths.linkObjects) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 988 | depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags) |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 989 | depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags) |
| 990 | depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths) |
| 991 | depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 992 | |
| 993 | return depPaths |
| 994 | } |
| 995 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 996 | func (mod *Module) InstallInData() bool { |
| 997 | if mod.compiler == nil { |
| 998 | return false |
| 999 | } |
| 1000 | return mod.compiler.inData() |
| 1001 | } |
| 1002 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1003 | func linkPathFromFilePath(filepath android.Path) string { |
| 1004 | return strings.Split(filepath.String(), filepath.Base())[0] |
| 1005 | } |
Ivan Lozano | d648c43 | 2020-02-06 12:05:10 -0500 | [diff] [blame] | 1006 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1007 | func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { |
| 1008 | ctx := &depsContext{ |
| 1009 | BottomUpMutatorContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1010 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1011 | |
| 1012 | deps := mod.deps(ctx) |
Colin Cross | 3146c5c | 2020-09-30 15:34:40 -0700 | [diff] [blame] | 1013 | var commonDepVariations []blueprint.Variation |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1014 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1015 | stdLinkage := "dylib-std" |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1016 | if mod.compiler.stdLinkage(ctx) == RlibLinkage { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1017 | stdLinkage = "rlib-std" |
| 1018 | } |
| 1019 | |
| 1020 | rlibDepVariations := commonDepVariations |
| 1021 | if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() { |
| 1022 | rlibDepVariations = append(rlibDepVariations, |
| 1023 | blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage}) |
| 1024 | } |
| 1025 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1026 | actx.AddVariationDependencies( |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1027 | append(rlibDepVariations, []blueprint.Variation{ |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1028 | {Mutator: "rust_libraries", Variation: rlibVariation}}...), |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1029 | rlibDepTag, deps.Rlibs...) |
| 1030 | actx.AddVariationDependencies( |
| 1031 | append(commonDepVariations, []blueprint.Variation{ |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1032 | {Mutator: "rust_libraries", Variation: dylibVariation}}...), |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1033 | dylibDepTag, deps.Dylibs...) |
| 1034 | |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 1035 | if deps.Rustlibs != nil && !mod.compiler.Disabled() { |
| 1036 | autoDep := mod.compiler.(autoDeppable).autoDep(ctx) |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1037 | if autoDep.depTag == rlibDepTag { |
| 1038 | actx.AddVariationDependencies( |
| 1039 | append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}), |
| 1040 | autoDep.depTag, deps.Rustlibs...) |
| 1041 | } else { |
| 1042 | actx.AddVariationDependencies( |
| 1043 | append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}), |
| 1044 | autoDep.depTag, deps.Rustlibs...) |
| 1045 | } |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1046 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1047 | if deps.Stdlibs != nil { |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1048 | if mod.compiler.stdLinkage(ctx) == RlibLinkage { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1049 | actx.AddVariationDependencies( |
| 1050 | append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "rlib"}), |
| 1051 | rlibDepTag, deps.Stdlibs...) |
| 1052 | } else { |
| 1053 | actx.AddVariationDependencies( |
| 1054 | append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}), |
| 1055 | dylibDepTag, deps.Stdlibs...) |
| 1056 | } |
| 1057 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1058 | actx.AddVariationDependencies(append(commonDepVariations, |
| 1059 | blueprint.Variation{Mutator: "link", Variation: "shared"}), |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1060 | cc.SharedDepTag(), deps.SharedLibs...) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1061 | actx.AddVariationDependencies(append(commonDepVariations, |
| 1062 | blueprint.Variation{Mutator: "link", Variation: "static"}), |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1063 | cc.StaticDepTag(), deps.StaticLibs...) |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1064 | |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 1065 | actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...) |
| 1066 | |
Colin Cross | 565cafd | 2020-09-25 18:47:38 -0700 | [diff] [blame] | 1067 | crtVariations := cc.GetCrtVariations(ctx, mod) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1068 | if deps.CrtBegin != "" { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 1069 | actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, deps.CrtBegin) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1070 | } |
| 1071 | if deps.CrtEnd != "" { |
Dan Albert | 92fe740 | 2020-07-15 13:33:30 -0700 | [diff] [blame] | 1072 | actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, deps.CrtEnd) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1075 | if mod.sourceProvider != nil { |
| 1076 | if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok && |
| 1077 | bindgen.Properties.Custom_bindgen != "" { |
| 1078 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag, |
| 1079 | bindgen.Properties.Custom_bindgen) |
| 1080 | } |
| 1081 | } |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1082 | // 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] | 1083 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1086 | func BeginMutator(ctx android.BottomUpMutatorContext) { |
| 1087 | if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() { |
| 1088 | mod.beginMutator(ctx) |
| 1089 | } |
| 1090 | } |
| 1091 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1092 | func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) { |
| 1093 | ctx := &baseModuleContext{ |
| 1094 | BaseModuleContext: actx, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1095 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1096 | |
| 1097 | mod.begin(ctx) |
| 1098 | } |
| 1099 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1100 | func (mod *Module) Name() string { |
| 1101 | name := mod.ModuleBase.Name() |
| 1102 | if p, ok := mod.compiler.(interface { |
| 1103 | Name(string) string |
| 1104 | }); ok { |
| 1105 | name = p.Name(name) |
| 1106 | } |
| 1107 | return name |
| 1108 | } |
| 1109 | |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1110 | func (mod *Module) disableClippy() { |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1111 | if mod.clippy != nil { |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1112 | mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none") |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1116 | var _ android.HostToolProvider = (*Module)(nil) |
| 1117 | |
| 1118 | func (mod *Module) HostToolPath() android.OptionalPath { |
| 1119 | if !mod.Host() { |
| 1120 | return android.OptionalPath{} |
| 1121 | } |
Chih-Hung Hsieh | a756270 | 2020-08-10 21:50:43 -0700 | [diff] [blame] | 1122 | if binary, ok := mod.compiler.(*binaryDecorator); ok { |
| 1123 | return android.OptionalPathForPath(binary.baseCompiler.path) |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1124 | } |
| 1125 | return android.OptionalPath{} |
| 1126 | } |
| 1127 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1128 | var _ android.ApexModule = (*Module)(nil) |
| 1129 | |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1130 | func (mod *Module) minSdkVersion() string { |
| 1131 | return String(mod.Properties.Min_sdk_version) |
| 1132 | } |
| 1133 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1134 | var _ android.ApexModule = (*Module)(nil) |
| 1135 | |
| 1136 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1137 | func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1138 | minSdkVersion := mod.minSdkVersion() |
| 1139 | if minSdkVersion == "apex_inherit" { |
| 1140 | return nil |
| 1141 | } |
| 1142 | if minSdkVersion == "" { |
| 1143 | return fmt.Errorf("min_sdk_version is not specificed") |
| 1144 | } |
| 1145 | |
| 1146 | // Not using nativeApiLevelFromUser because the context here is not |
| 1147 | // necessarily a native context. |
| 1148 | ver, err := android.ApiLevelFromUser(ctx, minSdkVersion) |
| 1149 | if err != nil { |
| 1150 | return err |
| 1151 | } |
| 1152 | |
| 1153 | if ver.GreaterThan(sdkVersion) { |
| 1154 | return fmt.Errorf("newer SDK(%v)", ver) |
| 1155 | } |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1156 | return nil |
| 1157 | } |
| 1158 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1159 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1160 | func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 1161 | depTag := ctx.OtherModuleDependencyTag(dep) |
| 1162 | |
| 1163 | if ccm, ok := dep.(*cc.Module); ok { |
| 1164 | if ccm.HasStubsVariants() { |
| 1165 | if cc.IsSharedDepTag(depTag) { |
| 1166 | // dynamic dep to a stubs lib crosses APEX boundary |
| 1167 | return false |
| 1168 | } |
| 1169 | if cc.IsRuntimeDepTag(depTag) { |
| 1170 | // runtime dep to a stubs lib also crosses APEX boundary |
| 1171 | return false |
| 1172 | } |
| 1173 | |
| 1174 | if cc.IsHeaderDepTag(depTag) { |
| 1175 | return false |
| 1176 | } |
| 1177 | } |
| 1178 | if mod.Static() && cc.IsSharedDepTag(depTag) { |
| 1179 | // shared_lib dependency from a static lib is considered as crossing |
| 1180 | // the APEX boundary because the dependency doesn't actually is |
| 1181 | // linked; the dependency is used only during the compilation phase. |
| 1182 | return false |
| 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | if depTag == procMacroDepTag { |
| 1187 | return false |
| 1188 | } |
| 1189 | |
| 1190 | return true |
| 1191 | } |
| 1192 | |
| 1193 | // Overrides ApexModule.IsInstallabeToApex() |
| 1194 | func (mod *Module) IsInstallableToApex() bool { |
| 1195 | if mod.compiler != nil { |
| 1196 | if lib, ok := mod.compiler.(*libraryDecorator); ok && (lib.shared() || lib.dylib()) { |
| 1197 | return true |
| 1198 | } |
| 1199 | if _, ok := mod.compiler.(*binaryDecorator); ok { |
| 1200 | return true |
| 1201 | } |
| 1202 | } |
| 1203 | return false |
| 1204 | } |
| 1205 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1206 | var Bool = proptools.Bool |
| 1207 | var BoolDefault = proptools.BoolDefault |
| 1208 | var String = proptools.String |
| 1209 | var StringPtr = proptools.StringPtr |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 1210 | |
| 1211 | var _ android.OutputFileProducer = (*Module)(nil) |