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