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