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" |
Thiébaud Weksteen | e4dd14b | 2021-04-14 11:18:47 +0200 | [diff] [blame] | 25 | "android/soong/bloaty" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 26 | "android/soong/cc" |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 27 | cc_config "android/soong/cc/config" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 28 | "android/soong/rust/config" |
| 29 | ) |
| 30 | |
| 31 | var pctx = android.NewPackageContext("android/soong/rust") |
| 32 | |
| 33 | func init() { |
| 34 | // Only allow rust modules to be defined for certain projects |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 35 | |
| 36 | android.AddNeverAllowRules( |
| 37 | android.NeverAllow(). |
Ivan Lozano | 03a94c4 | 2021-06-28 11:27:11 -0400 | [diff] [blame] | 38 | NotIn(append(config.RustAllowedPaths, config.DownstreamRustAllowedPaths...)...). |
Ivan Lozano | e169ad7 | 2019-09-18 08:42:54 -0700 | [diff] [blame] | 39 | ModuleType(config.RustModuleTypes...)) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 40 | |
| 41 | android.RegisterModuleType("rust_defaults", defaultsFactory) |
| 42 | android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 43 | ctx.BottomUp("rust_libraries", LibraryMutator).Parallel() |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 44 | ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel() |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 45 | ctx.BottomUp("rust_begin", BeginMutator).Parallel() |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 46 | |
| 47 | }) |
| 48 | android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 49 | ctx.BottomUp("rust_sanitizers", rustSanitizerRuntimeMutator).Parallel() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 50 | }) |
| 51 | pctx.Import("android/soong/rust/config") |
Thiébaud Weksteen | 682c9d7 | 2020-08-31 10:06:16 +0200 | [diff] [blame] | 52 | pctx.ImportAs("cc_config", "android/soong/cc/config") |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | type Flags struct { |
Ivan Lozano | 8a23fa4 | 2020-06-16 10:26:57 -0400 | [diff] [blame] | 56 | GlobalRustFlags []string // Flags that apply globally to rust |
| 57 | GlobalLinkFlags []string // Flags that apply globally to linker |
| 58 | RustFlags []string // Flags that apply to rust |
| 59 | LinkFlags []string // Flags that apply to linker |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 60 | ClippyFlags []string // Flags that apply to clippy-driver, during the linting |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 61 | RustdocFlags []string // Flags that apply to rustdoc |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 62 | Toolchain config.Toolchain |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 63 | Coverage bool |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 64 | Clippy bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | type BaseProperties struct { |
| 68 | AndroidMkRlibs []string |
| 69 | AndroidMkDylibs []string |
| 70 | AndroidMkProcMacroLibs []string |
| 71 | AndroidMkSharedLibs []string |
| 72 | AndroidMkStaticLibs []string |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 73 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 74 | ImageVariationPrefix string `blueprint:"mutated"` |
| 75 | VndkVersion string `blueprint:"mutated"` |
| 76 | SubName string `blueprint:"mutated"` |
| 77 | |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 78 | // SubName is used by CC for tracking image variants / SDK versions. RustSubName is used for Rust-specific |
| 79 | // subnaming which shouldn't be visible to CC modules (such as the rlib stdlinkage subname). This should be |
| 80 | // appended before SubName. |
| 81 | RustSubName string `blueprint:"mutated"` |
| 82 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 83 | // Set by imageMutator |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 84 | CoreVariantNeeded bool `blueprint:"mutated"` |
| 85 | VendorRamdiskVariantNeeded bool `blueprint:"mutated"` |
| 86 | ExtraVariants []string `blueprint:"mutated"` |
| 87 | |
Ivan Lozano | a226863 | 2021-07-22 10:52:06 -0400 | [diff] [blame] | 88 | // Allows this module to use non-APEX version of libraries. Useful |
| 89 | // for building binaries that are started before APEXes are activated. |
| 90 | Bootstrap *bool |
| 91 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 92 | // Used by vendor snapshot to record dependencies from snapshot modules. |
| 93 | SnapshotSharedLibs []string `blueprint:"mutated"` |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 94 | SnapshotStaticLibs []string `blueprint:"mutated"` |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 95 | |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 96 | // Make this module available when building for vendor ramdisk. |
| 97 | // On device without a dedicated recovery partition, the module is only |
| 98 | // available after switching root into |
| 99 | // /first_stage_ramdisk. To expose the module before switching root, install |
| 100 | // the recovery variant instead (TODO(b/165791368) recovery not yet supported) |
| 101 | Vendor_ramdisk_available *bool |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 102 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 103 | // Normally Soong uses the directory structure to decide which modules |
| 104 | // should be included (framework) or excluded (non-framework) from the |
| 105 | // different snapshots (vendor, recovery, etc.), but this property |
| 106 | // allows a partner to exclude a module normally thought of as a |
| 107 | // framework module from the vendor snapshot. |
| 108 | Exclude_from_vendor_snapshot *bool |
| 109 | |
| 110 | // Normally Soong uses the directory structure to decide which modules |
| 111 | // should be included (framework) or excluded (non-framework) from the |
| 112 | // different snapshots (vendor, recovery, etc.), but this property |
| 113 | // allows a partner to exclude a module normally thought of as a |
| 114 | // framework module from the recovery snapshot. |
| 115 | Exclude_from_recovery_snapshot *bool |
| 116 | |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 117 | // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX). |
| 118 | Min_sdk_version *string |
| 119 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 120 | PreventInstall bool |
| 121 | HideFromMake bool |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 122 | Installable *bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | type Module struct { |
hamzeh | 41ad881 | 2021-07-07 14:00:07 -0700 | [diff] [blame] | 126 | cc.FuzzModule |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 127 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 128 | VendorProperties cc.VendorProperties |
| 129 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 130 | Properties BaseProperties |
| 131 | |
| 132 | hod android.HostOrDeviceSupported |
| 133 | multilib android.Multilib |
| 134 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 135 | makeLinkType string |
| 136 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 137 | compiler compiler |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 138 | coverage *coverage |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 139 | clippy *clippy |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 140 | sanitize *sanitize |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 141 | cachedToolchain config.Toolchain |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 142 | sourceProvider SourceProvider |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 143 | subAndroidMkOnce map[SubAndroidMkProvider]bool |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 144 | |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 145 | // Unstripped output. This is usually used when this module is linked to another module |
| 146 | // as a library. The stripped output which is used for installation can be found via |
| 147 | // compiler.strippedOutputFile if it exists. |
| 148 | unstrippedOutputFile android.OptionalPath |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 149 | docTimestampFile android.OptionalPath |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 150 | |
| 151 | hideApexVariantFromMake bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 154 | func (mod *Module) Header() bool { |
| 155 | //TODO: If Rust libraries provide header variants, this needs to be updated. |
| 156 | return false |
| 157 | } |
| 158 | |
| 159 | func (mod *Module) SetPreventInstall() { |
| 160 | mod.Properties.PreventInstall = true |
| 161 | } |
| 162 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 163 | func (mod *Module) SetHideFromMake() { |
| 164 | mod.Properties.HideFromMake = true |
| 165 | } |
| 166 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 167 | func (c *Module) HiddenFromMake() bool { |
| 168 | return c.Properties.HideFromMake |
| 169 | } |
| 170 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 171 | func (mod *Module) SanitizePropDefined() bool { |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 172 | // Because compiler is not set for some Rust modules where sanitize might be set, check that compiler is also not |
| 173 | // nil since we need compiler to actually sanitize. |
| 174 | return mod.sanitize != nil && mod.compiler != nil |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 175 | } |
| 176 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 177 | func (mod *Module) IsPrebuilt() bool { |
| 178 | if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok { |
| 179 | return true |
| 180 | } |
| 181 | return false |
| 182 | } |
| 183 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 184 | func (mod *Module) OutputFiles(tag string) (android.Paths, error) { |
| 185 | switch tag { |
| 186 | case "": |
Andrei Homescu | 5db69cc | 2020-08-06 15:27:45 -0700 | [diff] [blame] | 187 | if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) { |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 188 | return mod.sourceProvider.Srcs(), nil |
| 189 | } else { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 190 | if mod.OutputFile().Valid() { |
| 191 | return android.Paths{mod.OutputFile().Path()}, nil |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 192 | } |
| 193 | return android.Paths{}, nil |
| 194 | } |
| 195 | default: |
| 196 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 197 | } |
| 198 | } |
| 199 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 200 | func (mod *Module) SelectedStl() string { |
| 201 | return "" |
| 202 | } |
| 203 | |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 204 | func (mod *Module) NonCcVariants() bool { |
| 205 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 206 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 207 | return false |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName())) |
| 211 | } |
| 212 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 213 | func (mod *Module) Static() bool { |
| 214 | if mod.compiler != nil { |
| 215 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 216 | return library.static() |
| 217 | } |
| 218 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 219 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | func (mod *Module) Shared() bool { |
| 223 | if mod.compiler != nil { |
| 224 | if library, ok := mod.compiler.(libraryInterface); ok { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 225 | return library.shared() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 226 | } |
| 227 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 228 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 231 | func (mod *Module) Dylib() bool { |
| 232 | if mod.compiler != nil { |
| 233 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 234 | return library.dylib() |
| 235 | } |
| 236 | } |
| 237 | return false |
| 238 | } |
| 239 | |
| 240 | func (mod *Module) Rlib() bool { |
| 241 | if mod.compiler != nil { |
| 242 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 243 | return library.rlib() |
| 244 | } |
| 245 | } |
| 246 | return false |
| 247 | } |
| 248 | |
| 249 | func (mod *Module) Binary() bool { |
| 250 | if mod.compiler != nil { |
| 251 | if _, ok := mod.compiler.(*binaryDecorator); ok { |
| 252 | return true |
| 253 | } |
| 254 | } |
| 255 | return false |
| 256 | } |
| 257 | |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 258 | func (mod *Module) StaticExecutable() bool { |
| 259 | if !mod.Binary() { |
| 260 | return false |
| 261 | } |
| 262 | return Bool(mod.compiler.(*binaryDecorator).Properties.Static_executable) |
| 263 | } |
| 264 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 265 | func (mod *Module) Object() bool { |
| 266 | // Rust has no modules which produce only object files. |
| 267 | return false |
| 268 | } |
| 269 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 270 | func (mod *Module) Toc() android.OptionalPath { |
| 271 | if mod.compiler != nil { |
| 272 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 273 | return android.OptionalPath{} |
| 274 | } |
| 275 | } |
| 276 | panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName())) |
| 277 | } |
| 278 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 279 | func (mod *Module) UseSdk() bool { |
| 280 | return false |
| 281 | } |
| 282 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 283 | func (mod *Module) RelativeInstallPath() string { |
| 284 | if mod.compiler != nil { |
| 285 | return mod.compiler.relativeInstallPath() |
| 286 | } |
| 287 | return "" |
| 288 | } |
| 289 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 290 | func (mod *Module) UseVndk() bool { |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 291 | return mod.Properties.VndkVersion != "" |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 294 | func (mod *Module) Bootstrap() bool { |
Ivan Lozano | a226863 | 2021-07-22 10:52:06 -0400 | [diff] [blame] | 295 | return Bool(mod.Properties.Bootstrap) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 296 | } |
| 297 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 298 | func (mod *Module) MustUseVendorVariant() bool { |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 299 | return true |
| 300 | } |
| 301 | |
| 302 | func (mod *Module) SubName() string { |
| 303 | return mod.Properties.SubName |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | func (mod *Module) IsVndk() bool { |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 307 | // TODO(b/165791368) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 308 | return false |
| 309 | } |
| 310 | |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 311 | func (mod *Module) IsVndkExt() bool { |
| 312 | return false |
| 313 | } |
| 314 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 315 | func (mod *Module) IsVndkSp() bool { |
| 316 | return false |
| 317 | } |
| 318 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 319 | func (c *Module) IsVndkPrivate() bool { |
| 320 | return false |
| 321 | } |
| 322 | |
| 323 | func (c *Module) IsLlndk() bool { |
| 324 | return false |
| 325 | } |
| 326 | |
| 327 | func (c *Module) IsLlndkPublic() bool { |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 328 | return false |
| 329 | } |
| 330 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 331 | func (mod *Module) KernelHeadersDecorator() bool { |
| 332 | return false |
| 333 | } |
| 334 | |
Colin Cross | 1f3f130 | 2021-04-26 18:37:44 -0700 | [diff] [blame] | 335 | func (m *Module) NeedsLlndkVariants() bool { |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 336 | return false |
| 337 | } |
| 338 | |
Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 339 | func (m *Module) NeedsVendorPublicLibraryVariants() bool { |
| 340 | return false |
| 341 | } |
| 342 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 343 | func (mod *Module) HasLlndkStubs() bool { |
| 344 | return false |
| 345 | } |
| 346 | |
| 347 | func (mod *Module) StubsVersion() string { |
| 348 | panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", mod.BaseModuleName())) |
| 349 | } |
| 350 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 351 | func (mod *Module) SdkVersion() string { |
| 352 | return "" |
| 353 | } |
| 354 | |
Jiyong Park | fdaa5f7 | 2021-03-19 22:18:04 +0900 | [diff] [blame] | 355 | func (mod *Module) MinSdkVersion() string { |
| 356 | return "" |
| 357 | } |
| 358 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 359 | func (mod *Module) AlwaysSdk() bool { |
| 360 | return false |
| 361 | } |
| 362 | |
Jiyong Park | 2286afd | 2020-06-16 21:58:53 +0900 | [diff] [blame] | 363 | func (mod *Module) IsSdkVariant() bool { |
| 364 | return false |
| 365 | } |
| 366 | |
Colin Cross | 1348ce3 | 2020-10-01 13:37:16 -0700 | [diff] [blame] | 367 | func (mod *Module) SplitPerApiLevel() bool { |
| 368 | return false |
| 369 | } |
| 370 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 371 | type Deps struct { |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 372 | Dylibs []string |
| 373 | Rlibs []string |
| 374 | Rustlibs []string |
| 375 | Stdlibs []string |
| 376 | ProcMacros []string |
| 377 | SharedLibs []string |
| 378 | StaticLibs []string |
| 379 | WholeStaticLibs []string |
| 380 | HeaderLibs []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 381 | |
| 382 | CrtBegin, CrtEnd string |
| 383 | } |
| 384 | |
| 385 | type PathDeps struct { |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 386 | DyLibs RustLibraries |
| 387 | RLibs RustLibraries |
| 388 | SharedLibs android.Paths |
| 389 | SharedLibDeps android.Paths |
| 390 | StaticLibs android.Paths |
| 391 | ProcMacros RustLibraries |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 392 | |
| 393 | // depFlags and depLinkFlags are rustc and linker (clang) flags. |
| 394 | depFlags []string |
| 395 | depLinkFlags []string |
| 396 | |
| 397 | // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker. |
| 398 | // Both of these are exported and propagate to dependencies. |
| 399 | linkDirs []string |
| 400 | linkObjects []string |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 401 | |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 402 | // Used by bindgen modules which call clang |
| 403 | depClangFlags []string |
| 404 | depIncludePaths android.Paths |
Ivan Lozano | ddd0bdb | 2020-08-28 17:00:26 -0400 | [diff] [blame] | 405 | depGeneratedHeaders android.Paths |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 406 | depSystemIncludePaths android.Paths |
| 407 | |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 408 | CrtBegin android.OptionalPath |
| 409 | CrtEnd android.OptionalPath |
Chih-Hung Hsieh | bbd25ae | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 410 | |
| 411 | // Paths to generated source files |
Ivan Lozano | 9d74a52 | 2020-12-01 09:25:22 -0500 | [diff] [blame] | 412 | SrcDeps android.Paths |
| 413 | srcProviderFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | type RustLibraries []RustLibrary |
| 417 | |
| 418 | type RustLibrary struct { |
| 419 | Path android.Path |
| 420 | CrateName string |
| 421 | } |
| 422 | |
| 423 | type compiler interface { |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame] | 424 | initialize(ctx ModuleContext) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 425 | compilerFlags(ctx ModuleContext, flags Flags) Flags |
| 426 | compilerProps() []interface{} |
| 427 | compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path |
| 428 | compilerDeps(ctx DepsContext, deps Deps) Deps |
| 429 | crateName() string |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 430 | rustdoc(ctx ModuleContext, flags Flags, deps PathDeps) android.OptionalPath |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 431 | |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame] | 432 | // Output directory in which source-generated code from dependencies is |
| 433 | // copied. This is equivalent to Cargo's OUT_DIR variable. |
| 434 | CargoOutDir() android.OptionalPath |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 435 | |
Ivan Lozano | a9a1fc0 | 2021-08-11 15:13:43 -0400 | [diff] [blame^] | 436 | // CargoPkgVersion returns the value of the Cargo_pkg_version property. |
| 437 | CargoPkgVersion() string |
| 438 | |
| 439 | // CargoEnvCompat returns whether Cargo environment variables should be used. |
| 440 | CargoEnvCompat() bool |
| 441 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 442 | inData() bool |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 443 | install(ctx ModuleContext) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 444 | relativeInstallPath() string |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 445 | everInstallable() bool |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 446 | |
| 447 | nativeCoverage() bool |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 448 | |
| 449 | Disabled() bool |
| 450 | SetDisabled() |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 451 | |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 452 | stdLinkage(ctx *depsContext) RustLinkage |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 453 | |
| 454 | strippedOutputFilePath() android.OptionalPath |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 455 | } |
| 456 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 457 | type exportedFlagsProducer interface { |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 458 | exportLinkDirs(...string) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 459 | exportLinkObjects(...string) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | type flagExporter struct { |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 463 | linkDirs []string |
| 464 | linkObjects []string |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 467 | func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) { |
| 468 | flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...)) |
| 469 | } |
| 470 | |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 471 | func (flagExporter *flagExporter) exportLinkObjects(flags ...string) { |
| 472 | flagExporter.linkObjects = android.FirstUniqueStrings(append(flagExporter.linkObjects, flags...)) |
| 473 | } |
| 474 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 475 | func (flagExporter *flagExporter) setProvider(ctx ModuleContext) { |
| 476 | ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{ |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 477 | LinkDirs: flagExporter.linkDirs, |
| 478 | LinkObjects: flagExporter.linkObjects, |
| 479 | }) |
| 480 | } |
| 481 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 482 | var _ exportedFlagsProducer = (*flagExporter)(nil) |
| 483 | |
| 484 | func NewFlagExporter() *flagExporter { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 485 | return &flagExporter{} |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 488 | type FlagExporterInfo struct { |
| 489 | Flags []string |
| 490 | LinkDirs []string // TODO: this should be android.Paths |
| 491 | LinkObjects []string // TODO: this should be android.Paths |
| 492 | } |
| 493 | |
| 494 | var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{}) |
| 495 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 496 | func (mod *Module) isCoverageVariant() bool { |
| 497 | return mod.coverage.Properties.IsCoverageVariant |
| 498 | } |
| 499 | |
| 500 | var _ cc.Coverage = (*Module)(nil) |
| 501 | |
| 502 | func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 503 | return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant |
| 504 | } |
| 505 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 506 | func (mod *Module) VndkVersion() string { |
| 507 | return mod.Properties.VndkVersion |
| 508 | } |
| 509 | |
| 510 | func (mod *Module) PreventInstall() bool { |
| 511 | return mod.Properties.PreventInstall |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | func (mod *Module) HideFromMake() { |
| 515 | mod.Properties.HideFromMake = true |
| 516 | } |
| 517 | |
| 518 | func (mod *Module) MarkAsCoverageVariant(coverage bool) { |
| 519 | mod.coverage.Properties.IsCoverageVariant = coverage |
| 520 | } |
| 521 | |
| 522 | func (mod *Module) EnableCoverageIfNeeded() { |
| 523 | mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | func defaultsFactory() android.Module { |
| 527 | return DefaultsFactory() |
| 528 | } |
| 529 | |
| 530 | type Defaults struct { |
| 531 | android.ModuleBase |
| 532 | android.DefaultsModuleBase |
| 533 | } |
| 534 | |
| 535 | func DefaultsFactory(props ...interface{}) android.Module { |
| 536 | module := &Defaults{} |
| 537 | |
| 538 | module.AddProperties(props...) |
| 539 | module.AddProperties( |
| 540 | &BaseProperties{}, |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 541 | &cc.VendorProperties{}, |
Jakub Kotur | 1d640d0 | 2021-01-06 12:40:43 +0100 | [diff] [blame] | 542 | &BenchmarkProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 543 | &BindgenProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 544 | &BaseCompilerProperties{}, |
| 545 | &BinaryCompilerProperties{}, |
| 546 | &LibraryCompilerProperties{}, |
| 547 | &ProcMacroCompilerProperties{}, |
| 548 | &PrebuiltProperties{}, |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 549 | &SourceProviderProperties{}, |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 550 | &TestProperties{}, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 551 | &cc.CoverageProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 552 | &cc.RustBindgenClangProperties{}, |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 553 | &ClippyProperties{}, |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 554 | &SanitizeProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 555 | ) |
| 556 | |
| 557 | android.InitDefaultsModule(module) |
| 558 | return module |
| 559 | } |
| 560 | |
| 561 | func (mod *Module) CrateName() string { |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 562 | return mod.compiler.crateName() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 565 | func (mod *Module) CcLibrary() bool { |
| 566 | if mod.compiler != nil { |
| 567 | if _, ok := mod.compiler.(*libraryDecorator); ok { |
| 568 | return true |
| 569 | } |
| 570 | } |
| 571 | return false |
| 572 | } |
| 573 | |
| 574 | func (mod *Module) CcLibraryInterface() bool { |
| 575 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 576 | // use build{Static,Shared}() instead of {static,shared}() here because this might be called before |
| 577 | // VariantIs{Static,Shared} is set. |
| 578 | if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 579 | return true |
| 580 | } |
| 581 | } |
| 582 | return false |
| 583 | } |
| 584 | |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 585 | func (mod *Module) IncludeDirs() android.Paths { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 586 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 587 | if library, ok := mod.compiler.(*libraryDecorator); ok { |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 588 | return library.includeDirs |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 589 | } |
| 590 | } |
| 591 | panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName())) |
| 592 | } |
| 593 | |
| 594 | func (mod *Module) SetStatic() { |
| 595 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 596 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 597 | library.setStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 598 | return |
| 599 | } |
| 600 | } |
| 601 | panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName())) |
| 602 | } |
| 603 | |
| 604 | func (mod *Module) SetShared() { |
| 605 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 606 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 607 | library.setShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 608 | return |
| 609 | } |
| 610 | } |
| 611 | panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName())) |
| 612 | } |
| 613 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 614 | func (mod *Module) BuildStaticVariant() bool { |
| 615 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 616 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 617 | return library.buildStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName())) |
| 621 | } |
| 622 | |
| 623 | func (mod *Module) BuildSharedVariant() bool { |
| 624 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 625 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 626 | return library.buildShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName())) |
| 630 | } |
| 631 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 632 | func (mod *Module) Module() android.Module { |
| 633 | return mod |
| 634 | } |
| 635 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 636 | func (mod *Module) OutputFile() android.OptionalPath { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 637 | if mod.compiler != nil && mod.compiler.strippedOutputFilePath().Valid() { |
| 638 | return mod.compiler.strippedOutputFilePath() |
| 639 | } |
| 640 | return mod.unstrippedOutputFile |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 643 | func (mod *Module) CoverageFiles() android.Paths { |
| 644 | if mod.compiler != nil { |
Joel Galenson | fa04938 | 2021-01-14 16:03:18 -0800 | [diff] [blame] | 645 | return android.Paths{} |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 646 | } |
| 647 | panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName())) |
| 648 | } |
| 649 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 650 | func (mod *Module) installable(apexInfo android.ApexInfo) bool { |
Jiyong Park | bf8147a | 2021-05-17 13:19:33 +0900 | [diff] [blame] | 651 | if !mod.EverInstallable() { |
| 652 | return false |
| 653 | } |
| 654 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 655 | // The apex variant is not installable because it is included in the APEX and won't appear |
| 656 | // in the system partition as a standalone file. |
| 657 | if !apexInfo.IsForPlatform() { |
| 658 | return false |
| 659 | } |
| 660 | |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 661 | return mod.OutputFile().Valid() && !mod.Properties.PreventInstall |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 662 | } |
| 663 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 664 | var _ cc.LinkableInterface = (*Module)(nil) |
| 665 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 666 | func (mod *Module) Init() android.Module { |
| 667 | mod.AddProperties(&mod.Properties) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 668 | mod.AddProperties(&mod.VendorProperties) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 669 | |
| 670 | if mod.compiler != nil { |
| 671 | mod.AddProperties(mod.compiler.compilerProps()...) |
| 672 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 673 | if mod.coverage != nil { |
| 674 | mod.AddProperties(mod.coverage.props()...) |
| 675 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 676 | if mod.clippy != nil { |
| 677 | mod.AddProperties(mod.clippy.props()...) |
| 678 | } |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 679 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 680 | mod.AddProperties(mod.sourceProvider.SourceProviderProps()...) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 681 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 682 | if mod.sanitize != nil { |
| 683 | mod.AddProperties(mod.sanitize.props()...) |
| 684 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 685 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 686 | android.InitAndroidArchModule(mod, mod.hod, mod.multilib) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 687 | android.InitApexModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 688 | |
| 689 | android.InitDefaultableModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 690 | return mod |
| 691 | } |
| 692 | |
| 693 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 694 | return &Module{ |
| 695 | hod: hod, |
| 696 | multilib: multilib, |
| 697 | } |
| 698 | } |
| 699 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 700 | module := newBaseModule(hod, multilib) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 701 | module.coverage = &coverage{} |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 702 | module.clippy = &clippy{} |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 703 | module.sanitize = &sanitize{} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 704 | return module |
| 705 | } |
| 706 | |
| 707 | type ModuleContext interface { |
| 708 | android.ModuleContext |
| 709 | ModuleContextIntf |
| 710 | } |
| 711 | |
| 712 | type BaseModuleContext interface { |
| 713 | android.BaseModuleContext |
| 714 | ModuleContextIntf |
| 715 | } |
| 716 | |
| 717 | type DepsContext interface { |
| 718 | android.BottomUpMutatorContext |
| 719 | ModuleContextIntf |
| 720 | } |
| 721 | |
| 722 | type ModuleContextIntf interface { |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 723 | RustModule() *Module |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 724 | toolchain() config.Toolchain |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | type depsContext struct { |
| 728 | android.BottomUpMutatorContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | type moduleContext struct { |
| 732 | android.ModuleContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 733 | } |
| 734 | |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 735 | type baseModuleContext struct { |
| 736 | android.BaseModuleContext |
| 737 | } |
| 738 | |
| 739 | func (ctx *moduleContext) RustModule() *Module { |
| 740 | return ctx.Module().(*Module) |
| 741 | } |
| 742 | |
| 743 | func (ctx *moduleContext) toolchain() config.Toolchain { |
| 744 | return ctx.RustModule().toolchain(ctx) |
| 745 | } |
| 746 | |
| 747 | func (ctx *depsContext) RustModule() *Module { |
| 748 | return ctx.Module().(*Module) |
| 749 | } |
| 750 | |
| 751 | func (ctx *depsContext) toolchain() config.Toolchain { |
| 752 | return ctx.RustModule().toolchain(ctx) |
| 753 | } |
| 754 | |
| 755 | func (ctx *baseModuleContext) RustModule() *Module { |
| 756 | return ctx.Module().(*Module) |
| 757 | } |
| 758 | |
| 759 | func (ctx *baseModuleContext) toolchain() config.Toolchain { |
| 760 | return ctx.RustModule().toolchain(ctx) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | func (mod *Module) nativeCoverage() bool { |
| 764 | return mod.compiler != nil && mod.compiler.nativeCoverage() |
| 765 | } |
| 766 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 767 | func (mod *Module) EverInstallable() bool { |
| 768 | return mod.compiler != nil && |
| 769 | // Check to see whether the module is actually ever installable. |
| 770 | mod.compiler.everInstallable() |
| 771 | } |
| 772 | |
| 773 | func (mod *Module) Installable() *bool { |
| 774 | return mod.Properties.Installable |
| 775 | } |
| 776 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 777 | func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain { |
| 778 | if mod.cachedToolchain == nil { |
| 779 | mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 780 | } |
| 781 | return mod.cachedToolchain |
| 782 | } |
| 783 | |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 784 | func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain { |
| 785 | return cc_config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 786 | } |
| 787 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 788 | func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 789 | } |
| 790 | |
| 791 | func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
| 792 | ctx := &moduleContext{ |
| 793 | ModuleContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 794 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 795 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 796 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 797 | if !apexInfo.IsForPlatform() { |
| 798 | mod.hideApexVariantFromMake = true |
| 799 | } |
| 800 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 801 | toolchain := mod.toolchain(ctx) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 802 | mod.makeLinkType = cc.GetMakeLinkType(actx, mod) |
| 803 | |
| 804 | // Differentiate static libraries that are vendor available |
| 805 | if mod.UseVndk() { |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 806 | mod.Properties.SubName += cc.VendorSuffix |
| 807 | } else if mod.InVendorRamdisk() && !mod.OnlyInVendorRamdisk() { |
| 808 | mod.Properties.SubName += cc.VendorRamdiskSuffix |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 809 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 810 | |
| 811 | if !toolchain.Supported() { |
| 812 | // This toolchain's unsupported, there's nothing to do for this mod. |
| 813 | return |
| 814 | } |
| 815 | |
| 816 | deps := mod.depsToPaths(ctx) |
| 817 | flags := Flags{ |
| 818 | Toolchain: toolchain, |
| 819 | } |
| 820 | |
| 821 | if mod.compiler != nil { |
| 822 | flags = mod.compiler.compilerFlags(ctx, flags) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 823 | } |
| 824 | if mod.coverage != nil { |
| 825 | flags, deps = mod.coverage.flags(ctx, flags, deps) |
| 826 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 827 | if mod.clippy != nil { |
| 828 | flags, deps = mod.clippy.flags(ctx, flags, deps) |
| 829 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 830 | if mod.sanitize != nil { |
| 831 | flags, deps = mod.sanitize.flags(ctx, flags, deps) |
| 832 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 833 | |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 834 | // SourceProvider needs to call GenerateSource() before compiler calls |
| 835 | // compile() so it can provide the source. A SourceProvider has |
| 836 | // multiple variants (e.g. source, rlib, dylib). Only the "source" |
| 837 | // variant is responsible for effectively generating the source. The |
| 838 | // remaining variants relies on the "source" variant output. |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 839 | if mod.sourceProvider != nil { |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 840 | if mod.compiler.(libraryInterface).source() { |
| 841 | mod.sourceProvider.GenerateSource(ctx, deps) |
| 842 | mod.sourceProvider.setSubName(ctx.ModuleSubDir()) |
| 843 | } else { |
| 844 | sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag) |
| 845 | sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator) |
Chih-Hung Hsieh | c49649c | 2020-10-01 21:25:05 -0700 | [diff] [blame] | 846 | mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs()) |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 847 | } |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | if mod.compiler != nil && !mod.compiler.Disabled() { |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame] | 851 | mod.compiler.initialize(ctx) |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 852 | unstrippedOutputFile := mod.compiler.compile(ctx, flags, deps) |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 853 | mod.unstrippedOutputFile = android.OptionalPathForPath(unstrippedOutputFile) |
Thiébaud Weksteen | e4dd14b | 2021-04-14 11:18:47 +0200 | [diff] [blame] | 854 | bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), mod.unstrippedOutputFile) |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 855 | |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 856 | mod.docTimestampFile = mod.compiler.rustdoc(ctx, flags, deps) |
| 857 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 858 | // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or |
| 859 | // RECOVERY_SNAPSHOT_VERSION is current. |
| 860 | if lib, ok := mod.compiler.(snapshotLibraryInterface); ok { |
| 861 | if cc.ShouldCollectHeadersForSnapshot(ctx, mod, apexInfo) { |
| 862 | lib.collectHeadersForSnapshot(ctx, deps) |
| 863 | } |
| 864 | } |
| 865 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 866 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 867 | if mod.installable(apexInfo) { |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 868 | mod.compiler.install(ctx) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 869 | } |
Chris Wailes | 74be764 | 2021-07-22 16:20:28 -0700 | [diff] [blame] | 870 | |
| 871 | ctx.Phony("rust", ctx.RustModule().OutputFile().Path()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
| 875 | func (mod *Module) deps(ctx DepsContext) Deps { |
| 876 | deps := Deps{} |
| 877 | |
| 878 | if mod.compiler != nil { |
| 879 | deps = mod.compiler.compilerDeps(ctx, deps) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 880 | } |
| 881 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 882 | deps = mod.sourceProvider.SourceProviderDeps(ctx, deps) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 883 | } |
| 884 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 885 | if mod.coverage != nil { |
| 886 | deps = mod.coverage.deps(ctx, deps) |
| 887 | } |
| 888 | |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 889 | if mod.sanitize != nil { |
| 890 | deps = mod.sanitize.deps(ctx, deps) |
| 891 | } |
| 892 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 893 | deps.Rlibs = android.LastUniqueStrings(deps.Rlibs) |
| 894 | deps.Dylibs = android.LastUniqueStrings(deps.Dylibs) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 895 | deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 896 | deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros) |
| 897 | deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) |
| 898 | deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 899 | deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 900 | return deps |
| 901 | |
| 902 | } |
| 903 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 904 | type dependencyTag struct { |
| 905 | blueprint.BaseDependencyTag |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 906 | name string |
| 907 | library bool |
| 908 | procMacro bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 909 | } |
| 910 | |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 911 | // InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive |
| 912 | // dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary. |
| 913 | func (d dependencyTag) InstallDepNeeded() bool { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 914 | return d.library || d.procMacro |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | var _ android.InstallNeededDependencyTag = dependencyTag{} |
| 918 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 919 | var ( |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 920 | customBindgenDepTag = dependencyTag{name: "customBindgenTag"} |
| 921 | rlibDepTag = dependencyTag{name: "rlibTag", library: true} |
| 922 | dylibDepTag = dependencyTag{name: "dylib", library: true} |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 923 | procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true} |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 924 | testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"} |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 925 | sourceDepTag = dependencyTag{name: "source"} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 926 | ) |
| 927 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 928 | func IsDylibDepTag(depTag blueprint.DependencyTag) bool { |
| 929 | tag, ok := depTag.(dependencyTag) |
| 930 | return ok && tag == dylibDepTag |
| 931 | } |
| 932 | |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 933 | func IsRlibDepTag(depTag blueprint.DependencyTag) bool { |
| 934 | tag, ok := depTag.(dependencyTag) |
| 935 | return ok && tag == rlibDepTag |
| 936 | } |
| 937 | |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 938 | type autoDep struct { |
| 939 | variation string |
| 940 | depTag dependencyTag |
| 941 | } |
| 942 | |
| 943 | var ( |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 944 | rlibVariation = "rlib" |
| 945 | dylibVariation = "dylib" |
| 946 | rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag} |
| 947 | dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag} |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 948 | ) |
| 949 | |
| 950 | type autoDeppable interface { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 951 | autoDep(ctx android.BottomUpMutatorContext) autoDep |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 952 | } |
| 953 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 954 | func (mod *Module) begin(ctx BaseModuleContext) { |
| 955 | if mod.coverage != nil { |
| 956 | mod.coverage.begin(ctx) |
| 957 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 958 | if mod.sanitize != nil { |
| 959 | mod.sanitize.begin(ctx) |
| 960 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 961 | } |
| 962 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 963 | func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
| 964 | var depPaths PathDeps |
| 965 | |
| 966 | directRlibDeps := []*Module{} |
| 967 | directDylibDeps := []*Module{} |
| 968 | directProcMacroDeps := []*Module{} |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 969 | directSharedLibDeps := []cc.SharedLibraryInfo{} |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 970 | directStaticLibDeps := [](cc.LinkableInterface){} |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 971 | directSrcProvidersDeps := []*Module{} |
| 972 | directSrcDeps := [](android.SourceFileProducer){} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 973 | |
| 974 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 975 | depName := ctx.OtherModuleName(dep) |
| 976 | depTag := ctx.OtherModuleDependencyTag(dep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 977 | |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 978 | if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 979 | //Handle Rust Modules |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 980 | makeLibName := cc.MakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName) |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 981 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 982 | switch depTag { |
| 983 | case dylibDepTag: |
| 984 | dylib, ok := rustDep.compiler.(libraryInterface) |
| 985 | if !ok || !dylib.dylib() { |
| 986 | ctx.ModuleErrorf("mod %q not an dylib library", depName) |
| 987 | return |
| 988 | } |
| 989 | directDylibDeps = append(directDylibDeps, rustDep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 990 | mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 991 | case rlibDepTag: |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 992 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 993 | rlib, ok := rustDep.compiler.(libraryInterface) |
| 994 | if !ok || !rlib.rlib() { |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 995 | ctx.ModuleErrorf("mod %q not an rlib library", makeLibName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 996 | return |
| 997 | } |
| 998 | directRlibDeps = append(directRlibDeps, rustDep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 999 | mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1000 | case procMacroDepTag: |
| 1001 | directProcMacroDeps = append(directProcMacroDeps, rustDep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1002 | mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName) |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | if android.IsSourceDepTagWithOutputTag(depTag, "") { |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1006 | // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct |
| 1007 | // OS/Arch variant is used. |
| 1008 | var helper string |
| 1009 | if ctx.Host() { |
| 1010 | helper = "missing 'host_supported'?" |
| 1011 | } else { |
| 1012 | helper = "device module defined?" |
| 1013 | } |
| 1014 | |
| 1015 | if dep.Target().Os != ctx.Os() { |
| 1016 | ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper) |
| 1017 | return |
| 1018 | } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType { |
| 1019 | ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper) |
| 1020 | return |
| 1021 | } |
| 1022 | directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Ivan Lozano | 2bbcacf | 2020-08-07 09:00:50 -0400 | [diff] [blame] | 1025 | //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] | 1026 | if depTag != procMacroDepTag { |
| 1027 | exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo) |
| 1028 | depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...) |
| 1029 | depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...) |
| 1030 | depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1033 | if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 1034 | linkFile := rustDep.unstrippedOutputFile |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 1035 | if !linkFile.Valid() { |
| 1036 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", |
| 1037 | depName, ctx.ModuleName()) |
| 1038 | return |
| 1039 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1040 | linkDir := linkPathFromFilePath(linkFile.Path()) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 1041 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok { |
| 1042 | lib.exportLinkDirs(linkDir) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1043 | } |
| 1044 | } |
| 1045 | |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1046 | } else if ccDep, ok := dep.(cc.LinkableInterface); ok { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1047 | //Handle C dependencies |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1048 | makeLibName := cc.MakeLibName(ctx, mod, ccDep, depName) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1049 | if _, ok := ccDep.(*Module); !ok { |
| 1050 | if ccDep.Module().Target().Os != ctx.Os() { |
| 1051 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) |
| 1052 | return |
| 1053 | } |
| 1054 | if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType { |
| 1055 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) |
| 1056 | return |
| 1057 | } |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 1058 | } |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 1059 | linkObject := ccDep.OutputFile() |
| 1060 | linkPath := linkPathFromFilePath(linkObject.Path()) |
Ivan Lozano | 6aa6602 | 2020-02-06 13:22:43 -0500 | [diff] [blame] | 1061 | |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 1062 | if !linkObject.Valid() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1063 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) |
| 1064 | } |
| 1065 | |
| 1066 | exportDep := false |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1067 | switch { |
| 1068 | case cc.IsStaticDepTag(depTag): |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1069 | if cc.IsWholeStaticLib(depTag) { |
| 1070 | // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail |
| 1071 | // if the library is not prefixed by "lib". |
Ivan Lozano | fb6f36f | 2021-02-05 12:27:08 -0500 | [diff] [blame] | 1072 | if libName, ok := libNameFromFilePath(linkObject.Path()); ok { |
| 1073 | depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName) |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1074 | } else { |
| 1075 | ctx.ModuleErrorf("'%q' cannot be listed as a whole_static_library in Rust modules unless the output is prefixed by 'lib'", depName, ctx.ModuleName()) |
Ivan Lozano | fb6f36f | 2021-02-05 12:27:08 -0500 | [diff] [blame] | 1076 | } |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | // Add this to linkObjects to pass the library directly to the linker as well. This propagates |
| 1080 | // to dependencies to avoid having to redeclare static libraries for dependents of the dylib variant. |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 1081 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String()) |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1082 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
| 1083 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1084 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 1085 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1086 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1087 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 1088 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1089 | directStaticLibDeps = append(directStaticLibDeps, ccDep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1090 | mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, makeLibName) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1091 | case cc.IsSharedDepTag(depTag): |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1092 | // For the shared lib dependencies, we may link to the stub variant |
| 1093 | // of the dependency depending on the context (e.g. if this |
| 1094 | // dependency crosses the APEX boundaries). |
| 1095 | sharedLibraryInfo, exportedInfo := cc.ChooseStubOrImpl(ctx, dep) |
| 1096 | |
| 1097 | // Re-get linkObject as ChooseStubOrImpl actually tells us which |
| 1098 | // object (either from stub or non-stub) to use. |
| 1099 | linkObject = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary) |
| 1100 | linkPath = linkPathFromFilePath(linkObject.Path()) |
| 1101 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1102 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 1103 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String()) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1104 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1105 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1106 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 1107 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1108 | directSharedLibDeps = append(directSharedLibDeps, sharedLibraryInfo) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1109 | |
| 1110 | // Record baseLibName for snapshots. |
| 1111 | mod.Properties.SnapshotSharedLibs = append(mod.Properties.SnapshotSharedLibs, cc.BaseLibName(depName)) |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 1112 | mod.Properties.SnapshotStaticLibs = append(mod.Properties.SnapshotStaticLibs, cc.BaseLibName(depName)) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1113 | |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1114 | mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, makeLibName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1115 | exportDep = true |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 1116 | case cc.IsHeaderDepTag(depTag): |
| 1117 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 1118 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1119 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1120 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1121 | case depTag == cc.CrtBeginDepTag: |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 1122 | depPaths.CrtBegin = linkObject |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1123 | case depTag == cc.CrtEndDepTag: |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 1124 | depPaths.CrtEnd = linkObject |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | // Make sure these dependencies are propagated |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 1128 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep { |
| 1129 | lib.exportLinkDirs(linkPath) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 1130 | lib.exportLinkObjects(linkObject.String()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1131 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1132 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1133 | |
| 1134 | if srcDep, ok := dep.(android.SourceFileProducer); ok { |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 1135 | if android.IsSourceDepTagWithOutputTag(depTag, "") { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1136 | // These are usually genrules which don't have per-target variants. |
| 1137 | directSrcDeps = append(directSrcDeps, srcDep) |
| 1138 | } |
| 1139 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1140 | }) |
| 1141 | |
| 1142 | var rlibDepFiles RustLibraries |
| 1143 | for _, dep := range directRlibDeps { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 1144 | rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()}) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1145 | } |
| 1146 | var dylibDepFiles RustLibraries |
| 1147 | for _, dep := range directDylibDeps { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 1148 | dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()}) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1149 | } |
| 1150 | var procMacroDepFiles RustLibraries |
| 1151 | for _, dep := range directProcMacroDeps { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 1152 | procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()}) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | var staticLibDepFiles android.Paths |
| 1156 | for _, dep := range directStaticLibDeps { |
| 1157 | staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path()) |
| 1158 | } |
| 1159 | |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1160 | var sharedLibFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1161 | var sharedLibDepFiles android.Paths |
| 1162 | for _, dep := range directSharedLibDeps { |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1163 | sharedLibFiles = append(sharedLibFiles, dep.SharedLibrary) |
| 1164 | if dep.TableOfContents.Valid() { |
| 1165 | sharedLibDepFiles = append(sharedLibDepFiles, dep.TableOfContents.Path()) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1166 | } else { |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1167 | sharedLibDepFiles = append(sharedLibDepFiles, dep.SharedLibrary) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1168 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1171 | var srcProviderDepFiles android.Paths |
| 1172 | for _, dep := range directSrcProvidersDeps { |
| 1173 | srcs, _ := dep.OutputFiles("") |
| 1174 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 1175 | } |
| 1176 | for _, dep := range directSrcDeps { |
| 1177 | srcs := dep.Srcs() |
| 1178 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 1179 | } |
| 1180 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1181 | depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...) |
| 1182 | depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...) |
| 1183 | depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibDepFiles...) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1184 | depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, sharedLibDepFiles...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1185 | depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...) |
| 1186 | depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...) |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1187 | depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1188 | |
| 1189 | // Dedup exported flags from dependencies |
| 1190 | depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1191 | depPaths.linkObjects = android.FirstUniqueStrings(depPaths.linkObjects) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1192 | depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags) |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 1193 | depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags) |
| 1194 | depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths) |
| 1195 | depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1196 | |
| 1197 | return depPaths |
| 1198 | } |
| 1199 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 1200 | func (mod *Module) InstallInData() bool { |
| 1201 | if mod.compiler == nil { |
| 1202 | return false |
| 1203 | } |
| 1204 | return mod.compiler.inData() |
| 1205 | } |
| 1206 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1207 | func linkPathFromFilePath(filepath android.Path) string { |
| 1208 | return strings.Split(filepath.String(), filepath.Base())[0] |
| 1209 | } |
Ivan Lozano | d648c43 | 2020-02-06 12:05:10 -0500 | [diff] [blame] | 1210 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1211 | func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { |
| 1212 | ctx := &depsContext{ |
| 1213 | BottomUpMutatorContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1214 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1215 | |
| 1216 | deps := mod.deps(ctx) |
Colin Cross | 3146c5c | 2020-09-30 15:34:40 -0700 | [diff] [blame] | 1217 | var commonDepVariations []blueprint.Variation |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1218 | var snapshotInfo *cc.SnapshotInfo |
| 1219 | |
| 1220 | if ctx.Os() == android.Android { |
| 1221 | deps.SharedLibs, _ = cc.RewriteLibs(mod, &snapshotInfo, actx, ctx.Config(), deps.SharedLibs) |
| 1222 | } |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1223 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1224 | stdLinkage := "dylib-std" |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1225 | if mod.compiler.stdLinkage(ctx) == RlibLinkage { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1226 | stdLinkage = "rlib-std" |
| 1227 | } |
| 1228 | |
| 1229 | rlibDepVariations := commonDepVariations |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1230 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1231 | if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() { |
| 1232 | rlibDepVariations = append(rlibDepVariations, |
| 1233 | blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage}) |
| 1234 | } |
| 1235 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1236 | // rlibs |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1237 | for _, lib := range deps.Rlibs { |
| 1238 | depTag := rlibDepTag |
| 1239 | lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs) |
| 1240 | |
| 1241 | actx.AddVariationDependencies(append(rlibDepVariations, []blueprint.Variation{ |
| 1242 | {Mutator: "rust_libraries", Variation: rlibVariation}, |
| 1243 | }...), depTag, lib) |
| 1244 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1245 | |
| 1246 | // dylibs |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1247 | actx.AddVariationDependencies( |
| 1248 | append(commonDepVariations, []blueprint.Variation{ |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1249 | {Mutator: "rust_libraries", Variation: dylibVariation}}...), |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1250 | dylibDepTag, deps.Dylibs...) |
| 1251 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1252 | // rustlibs |
Ivan Lozano | 042504f | 2020-08-18 14:31:23 -0400 | [diff] [blame] | 1253 | if deps.Rustlibs != nil && !mod.compiler.Disabled() { |
| 1254 | autoDep := mod.compiler.(autoDeppable).autoDep(ctx) |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1255 | if autoDep.depTag == rlibDepTag { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1256 | for _, lib := range deps.Rustlibs { |
| 1257 | depTag := autoDep.depTag |
| 1258 | lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs) |
| 1259 | actx.AddVariationDependencies(append(rlibDepVariations, []blueprint.Variation{ |
| 1260 | {Mutator: "rust_libraries", Variation: autoDep.variation}, |
| 1261 | }...), depTag, lib) |
| 1262 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1263 | } else { |
| 1264 | actx.AddVariationDependencies( |
| 1265 | append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}), |
| 1266 | autoDep.depTag, deps.Rustlibs...) |
| 1267 | } |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1268 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1269 | |
| 1270 | // stdlibs |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1271 | if deps.Stdlibs != nil { |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1272 | if mod.compiler.stdLinkage(ctx) == RlibLinkage { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1273 | for _, lib := range deps.Stdlibs { |
| 1274 | depTag := rlibDepTag |
| 1275 | lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs) |
| 1276 | |
| 1277 | actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...), |
| 1278 | depTag, lib) |
| 1279 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1280 | } else { |
| 1281 | actx.AddVariationDependencies( |
| 1282 | append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}), |
| 1283 | dylibDepTag, deps.Stdlibs...) |
| 1284 | } |
| 1285 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1286 | |
| 1287 | for _, lib := range deps.SharedLibs { |
| 1288 | depTag := cc.SharedDepTag() |
| 1289 | name, version := cc.StubsLibNameAndVersion(lib) |
| 1290 | |
| 1291 | variations := []blueprint.Variation{ |
| 1292 | {Mutator: "link", Variation: "shared"}, |
| 1293 | } |
| 1294 | cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, name, version, false) |
| 1295 | } |
| 1296 | |
| 1297 | for _, lib := range deps.WholeStaticLibs { |
| 1298 | depTag := cc.StaticDepTag(true) |
| 1299 | lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs) |
| 1300 | |
| 1301 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1302 | {Mutator: "link", Variation: "static"}, |
| 1303 | }, depTag, lib) |
| 1304 | } |
| 1305 | |
| 1306 | for _, lib := range deps.StaticLibs { |
| 1307 | depTag := cc.StaticDepTag(false) |
| 1308 | lib = cc.RewriteSnapshotLib(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs) |
| 1309 | |
| 1310 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1311 | {Mutator: "link", Variation: "static"}, |
| 1312 | }, depTag, lib) |
| 1313 | } |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1314 | |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 1315 | actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...) |
| 1316 | |
Colin Cross | 565cafd | 2020-09-25 18:47:38 -0700 | [diff] [blame] | 1317 | crtVariations := cc.GetCrtVariations(ctx, mod) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1318 | if deps.CrtBegin != "" { |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1319 | actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, |
| 1320 | cc.RewriteSnapshotLib(deps.CrtBegin, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects)) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1321 | } |
| 1322 | if deps.CrtEnd != "" { |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1323 | actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, |
| 1324 | cc.RewriteSnapshotLib(deps.CrtEnd, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects)) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1327 | if mod.sourceProvider != nil { |
| 1328 | if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok && |
| 1329 | bindgen.Properties.Custom_bindgen != "" { |
| 1330 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag, |
| 1331 | bindgen.Properties.Custom_bindgen) |
| 1332 | } |
| 1333 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1334 | |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1335 | // 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] | 1336 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1339 | func BeginMutator(ctx android.BottomUpMutatorContext) { |
| 1340 | if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() { |
| 1341 | mod.beginMutator(ctx) |
| 1342 | } |
| 1343 | } |
| 1344 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1345 | func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) { |
| 1346 | ctx := &baseModuleContext{ |
| 1347 | BaseModuleContext: actx, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1348 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1349 | |
| 1350 | mod.begin(ctx) |
| 1351 | } |
| 1352 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1353 | func (mod *Module) Name() string { |
| 1354 | name := mod.ModuleBase.Name() |
| 1355 | if p, ok := mod.compiler.(interface { |
| 1356 | Name(string) string |
| 1357 | }); ok { |
| 1358 | name = p.Name(name) |
| 1359 | } |
| 1360 | return name |
| 1361 | } |
| 1362 | |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1363 | func (mod *Module) disableClippy() { |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1364 | if mod.clippy != nil { |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1365 | mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none") |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1366 | } |
| 1367 | } |
| 1368 | |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1369 | var _ android.HostToolProvider = (*Module)(nil) |
| 1370 | |
| 1371 | func (mod *Module) HostToolPath() android.OptionalPath { |
| 1372 | if !mod.Host() { |
| 1373 | return android.OptionalPath{} |
| 1374 | } |
Chih-Hung Hsieh | a756270 | 2020-08-10 21:50:43 -0700 | [diff] [blame] | 1375 | if binary, ok := mod.compiler.(*binaryDecorator); ok { |
| 1376 | return android.OptionalPathForPath(binary.baseCompiler.path) |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1377 | } |
| 1378 | return android.OptionalPath{} |
| 1379 | } |
| 1380 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1381 | var _ android.ApexModule = (*Module)(nil) |
| 1382 | |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1383 | func (mod *Module) minSdkVersion() string { |
| 1384 | return String(mod.Properties.Min_sdk_version) |
| 1385 | } |
| 1386 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1387 | var _ android.ApexModule = (*Module)(nil) |
| 1388 | |
| 1389 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1390 | func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1391 | minSdkVersion := mod.minSdkVersion() |
| 1392 | if minSdkVersion == "apex_inherit" { |
| 1393 | return nil |
| 1394 | } |
| 1395 | if minSdkVersion == "" { |
| 1396 | return fmt.Errorf("min_sdk_version is not specificed") |
| 1397 | } |
| 1398 | |
| 1399 | // Not using nativeApiLevelFromUser because the context here is not |
| 1400 | // necessarily a native context. |
| 1401 | ver, err := android.ApiLevelFromUser(ctx, minSdkVersion) |
| 1402 | if err != nil { |
| 1403 | return err |
| 1404 | } |
| 1405 | |
| 1406 | if ver.GreaterThan(sdkVersion) { |
| 1407 | return fmt.Errorf("newer SDK(%v)", ver) |
| 1408 | } |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1409 | return nil |
| 1410 | } |
| 1411 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1412 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1413 | func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 1414 | depTag := ctx.OtherModuleDependencyTag(dep) |
| 1415 | |
| 1416 | if ccm, ok := dep.(*cc.Module); ok { |
| 1417 | if ccm.HasStubsVariants() { |
| 1418 | if cc.IsSharedDepTag(depTag) { |
| 1419 | // dynamic dep to a stubs lib crosses APEX boundary |
| 1420 | return false |
| 1421 | } |
| 1422 | if cc.IsRuntimeDepTag(depTag) { |
| 1423 | // runtime dep to a stubs lib also crosses APEX boundary |
| 1424 | return false |
| 1425 | } |
| 1426 | |
| 1427 | if cc.IsHeaderDepTag(depTag) { |
| 1428 | return false |
| 1429 | } |
| 1430 | } |
| 1431 | if mod.Static() && cc.IsSharedDepTag(depTag) { |
| 1432 | // shared_lib dependency from a static lib is considered as crossing |
| 1433 | // the APEX boundary because the dependency doesn't actually is |
| 1434 | // linked; the dependency is used only during the compilation phase. |
| 1435 | return false |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | if depTag == procMacroDepTag { |
| 1440 | return false |
| 1441 | } |
| 1442 | |
| 1443 | return true |
| 1444 | } |
| 1445 | |
| 1446 | // Overrides ApexModule.IsInstallabeToApex() |
| 1447 | func (mod *Module) IsInstallableToApex() bool { |
| 1448 | if mod.compiler != nil { |
| 1449 | if lib, ok := mod.compiler.(*libraryDecorator); ok && (lib.shared() || lib.dylib()) { |
| 1450 | return true |
| 1451 | } |
| 1452 | if _, ok := mod.compiler.(*binaryDecorator); ok { |
| 1453 | return true |
| 1454 | } |
| 1455 | } |
| 1456 | return false |
| 1457 | } |
| 1458 | |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1459 | // If a library file has a "lib" prefix, extract the library name without the prefix. |
| 1460 | func libNameFromFilePath(filepath android.Path) (string, bool) { |
| 1461 | libName := strings.TrimSuffix(filepath.Base(), filepath.Ext()) |
| 1462 | if strings.HasPrefix(libName, "lib") { |
| 1463 | libName = libName[3:] |
| 1464 | return libName, true |
| 1465 | } |
| 1466 | return "", false |
| 1467 | } |
| 1468 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1469 | var Bool = proptools.Bool |
| 1470 | var BoolDefault = proptools.BoolDefault |
| 1471 | var String = proptools.String |
| 1472 | var StringPtr = proptools.StringPtr |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 1473 | |
| 1474 | var _ android.OutputFileProducer = (*Module)(nil) |