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