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