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