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