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