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