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