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