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