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