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