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