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