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 ( |
Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 18 | "fmt" |
| 19 | "strings" |
| 20 | |
Vinh Tran | b4bb20f | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 21 | "android/soong/bazel" |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 22 | "android/soong/bloaty" |
Aditya Choudhary | 87b2ab2 | 2023-11-17 15:27:06 +0000 | [diff] [blame] | 23 | "android/soong/testing" |
Vinh Tran | bcb5f57 | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 24 | "android/soong/ui/metrics/bp2build_metrics_proto" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 25 | |
| 26 | "github.com/google/blueprint" |
| 27 | "github.com/google/blueprint/proptools" |
| 28 | |
LaMont Jones | 0c97185 | 2023-12-07 21:56:59 +0000 | [diff] [blame^] | 29 | "android/soong/aconfig" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 30 | "android/soong/android" |
| 31 | "android/soong/cc" |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 32 | cc_config "android/soong/cc/config" |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 33 | "android/soong/fuzz" |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 34 | "android/soong/multitree" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 35 | "android/soong/rust/config" |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 36 | "android/soong/snapshot" |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 37 | ) |
| 38 | |
| 39 | var pctx = android.NewPackageContext("android/soong/rust") |
| 40 | |
| 41 | func init() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 42 | android.RegisterModuleType("rust_defaults", defaultsFactory) |
| 43 | android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { |
| 44 | ctx.BottomUp("rust_libraries", LibraryMutator).Parallel() |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 45 | ctx.BottomUp("rust_stdlinkage", LibstdMutator).Parallel() |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 46 | ctx.BottomUp("rust_begin", BeginMutator).Parallel() |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 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 | }) |
Inseob Kim | 3b24406 | 2023-07-11 13:31:36 +0900 | [diff] [blame] | 51 | pctx.Import("android/soong/android") |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 52 | pctx.Import("android/soong/rust/config") |
Thiébaud Weksteen | 682c9d7 | 2020-08-31 10:06:16 +0200 | [diff] [blame] | 53 | pctx.ImportAs("cc_config", "android/soong/cc/config") |
LaMont Jones | 0c10e4d | 2023-05-16 00:58:37 +0000 | [diff] [blame] | 54 | android.InitRegistrationContext.RegisterParallelSingletonType("kythe_rust_extract", kytheExtractRustFactory) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | type Flags struct { |
Ivan Lozano | 8a23fa4 | 2020-06-16 10:26:57 -0400 | [diff] [blame] | 58 | GlobalRustFlags []string // Flags that apply globally to rust |
| 59 | GlobalLinkFlags []string // Flags that apply globally to linker |
| 60 | RustFlags []string // Flags that apply to rust |
| 61 | LinkFlags []string // Flags that apply to linker |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 62 | ClippyFlags []string // Flags that apply to clippy-driver, during the linting |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 63 | RustdocFlags []string // Flags that apply to rustdoc |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 64 | Toolchain config.Toolchain |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 65 | Coverage bool |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 66 | Clippy bool |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 67 | EmitXrefs bool // If true, emit rules to aid cross-referencing |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | type BaseProperties struct { |
Liz Kammer | 884fe9e | 2023-02-28 14:29:13 -0500 | [diff] [blame] | 71 | AndroidMkRlibs []string `blueprint:"mutated"` |
| 72 | AndroidMkDylibs []string `blueprint:"mutated"` |
| 73 | AndroidMkProcMacroLibs []string `blueprint:"mutated"` |
Liz Kammer | 884fe9e | 2023-02-28 14:29:13 -0500 | [diff] [blame] | 74 | AndroidMkStaticLibs []string `blueprint:"mutated"` |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 75 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 76 | ImageVariationPrefix string `blueprint:"mutated"` |
| 77 | VndkVersion string `blueprint:"mutated"` |
| 78 | SubName string `blueprint:"mutated"` |
| 79 | |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 80 | // SubName is used by CC for tracking image variants / SDK versions. RustSubName is used for Rust-specific |
| 81 | // subnaming which shouldn't be visible to CC modules (such as the rlib stdlinkage subname). This should be |
| 82 | // appended before SubName. |
| 83 | RustSubName string `blueprint:"mutated"` |
| 84 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 85 | // Set by imageMutator |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 86 | CoreVariantNeeded bool `blueprint:"mutated"` |
| 87 | VendorRamdiskVariantNeeded bool `blueprint:"mutated"` |
Matthew Maurer | c686838 | 2021-07-13 14:12:37 -0700 | [diff] [blame] | 88 | RamdiskVariantNeeded bool `blueprint:"mutated"` |
Matthew Maurer | 460ee94 | 2021-02-11 12:31:46 -0800 | [diff] [blame] | 89 | RecoveryVariantNeeded bool `blueprint:"mutated"` |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 90 | ExtraVariants []string `blueprint:"mutated"` |
| 91 | |
Ivan Lozano | a226863 | 2021-07-22 10:52:06 -0400 | [diff] [blame] | 92 | // Allows this module to use non-APEX version of libraries. Useful |
| 93 | // for building binaries that are started before APEXes are activated. |
| 94 | Bootstrap *bool |
| 95 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 96 | // Used by vendor snapshot to record dependencies from snapshot modules. |
| 97 | SnapshotSharedLibs []string `blueprint:"mutated"` |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 98 | SnapshotStaticLibs []string `blueprint:"mutated"` |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 99 | SnapshotRlibs []string `blueprint:"mutated"` |
| 100 | SnapshotDylibs []string `blueprint:"mutated"` |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 101 | |
Matthew Maurer | c686838 | 2021-07-13 14:12:37 -0700 | [diff] [blame] | 102 | // Make this module available when building for ramdisk. |
| 103 | // On device without a dedicated recovery partition, the module is only |
| 104 | // available after switching root into |
| 105 | // /first_stage_ramdisk. To expose the module before switching root, install |
| 106 | // the recovery variant instead. |
| 107 | Ramdisk_available *bool |
| 108 | |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 109 | // Make this module available when building for vendor ramdisk. |
| 110 | // On device without a dedicated recovery partition, the module is only |
| 111 | // available after switching root into |
| 112 | // /first_stage_ramdisk. To expose the module before switching root, install |
Matthew Maurer | 460ee94 | 2021-02-11 12:31:46 -0800 | [diff] [blame] | 113 | // the recovery variant instead |
Ivan Lozano | e6d3098 | 2021-02-05 10:57:43 -0500 | [diff] [blame] | 114 | Vendor_ramdisk_available *bool |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 115 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 116 | // Normally Soong uses the directory structure to decide which modules |
| 117 | // should be included (framework) or excluded (non-framework) from the |
| 118 | // different snapshots (vendor, recovery, etc.), but this property |
| 119 | // allows a partner to exclude a module normally thought of as a |
| 120 | // framework module from the vendor snapshot. |
| 121 | Exclude_from_vendor_snapshot *bool |
| 122 | |
| 123 | // Normally Soong uses the directory structure to decide which modules |
| 124 | // should be included (framework) or excluded (non-framework) from the |
| 125 | // different snapshots (vendor, recovery, etc.), but this property |
| 126 | // allows a partner to exclude a module normally thought of as a |
| 127 | // framework module from the recovery snapshot. |
| 128 | Exclude_from_recovery_snapshot *bool |
| 129 | |
Matthew Maurer | 460ee94 | 2021-02-11 12:31:46 -0800 | [diff] [blame] | 130 | // Make this module available when building for recovery |
| 131 | Recovery_available *bool |
| 132 | |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 133 | // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX). |
| 134 | Min_sdk_version *string |
| 135 | |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 136 | HideFromMake bool `blueprint:"mutated"` |
| 137 | PreventInstall bool `blueprint:"mutated"` |
| 138 | |
| 139 | Installable *bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | type Module struct { |
hamzeh | c0a671f | 2021-07-22 12:05:08 -0700 | [diff] [blame] | 143 | fuzz.FuzzModule |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 144 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 145 | VendorProperties cc.VendorProperties |
| 146 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 147 | Properties BaseProperties |
| 148 | |
Aditya Choudhary | 87b2ab2 | 2023-11-17 15:27:06 +0000 | [diff] [blame] | 149 | hod android.HostOrDeviceSupported |
| 150 | multilib android.Multilib |
| 151 | testModule bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 152 | |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 153 | makeLinkType string |
| 154 | |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 155 | afdo *afdo |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 156 | compiler compiler |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 157 | coverage *coverage |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 158 | clippy *clippy |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 159 | sanitize *sanitize |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 160 | cachedToolchain config.Toolchain |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 161 | sourceProvider SourceProvider |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 162 | subAndroidMkOnce map[SubAndroidMkProvider]bool |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 163 | |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 164 | // Output file to be installed, may be stripped or unstripped. |
| 165 | outputFile android.OptionalPath |
| 166 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 167 | // Cross-reference input file |
| 168 | kytheFiles android.Paths |
| 169 | |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 170 | docTimestampFile android.OptionalPath |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 171 | |
| 172 | hideApexVariantFromMake bool |
Ivan Lozano | e950cda | 2021-11-09 11:26:04 -0500 | [diff] [blame] | 173 | |
| 174 | // For apex variants, this is set as apex.min_sdk_version |
| 175 | apexSdkVersion android.ApiLevel |
Cole Faust | b6e6f99 | 2023-08-17 17:42:26 -0700 | [diff] [blame] | 176 | |
| 177 | transitiveAndroidMkSharedLibs *android.DepSet[string] |
Vinh Tran | bcb5f57 | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 178 | |
| 179 | android.BazelModuleBase |
LaMont Jones | 0c97185 | 2023-12-07 21:56:59 +0000 | [diff] [blame^] | 180 | |
| 181 | // Aconfig files for all transitive deps. Also exposed via TransitiveDeclarationsInfo |
| 182 | mergedAconfigFiles map[string]android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 185 | func (mod *Module) Header() bool { |
| 186 | //TODO: If Rust libraries provide header variants, this needs to be updated. |
| 187 | return false |
| 188 | } |
| 189 | |
| 190 | func (mod *Module) SetPreventInstall() { |
| 191 | mod.Properties.PreventInstall = true |
| 192 | } |
| 193 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 194 | func (mod *Module) SetHideFromMake() { |
| 195 | mod.Properties.HideFromMake = true |
| 196 | } |
| 197 | |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 198 | func (mod *Module) HiddenFromMake() bool { |
| 199 | return mod.Properties.HideFromMake |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 200 | } |
| 201 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 202 | func (mod *Module) SanitizePropDefined() bool { |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 203 | // Because compiler is not set for some Rust modules where sanitize might be set, check that compiler is also not |
| 204 | // nil since we need compiler to actually sanitize. |
| 205 | return mod.sanitize != nil && mod.compiler != nil |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 206 | } |
| 207 | |
Ivan Lozano | 3968d8f | 2020-12-14 11:27:52 -0500 | [diff] [blame] | 208 | func (mod *Module) IsPrebuilt() bool { |
| 209 | if _, ok := mod.compiler.(*prebuiltLibraryDecorator); ok { |
| 210 | return true |
| 211 | } |
| 212 | return false |
| 213 | } |
| 214 | |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 215 | func (mod *Module) OutputFiles(tag string) (android.Paths, error) { |
| 216 | switch tag { |
| 217 | case "": |
Andrei Homescu | 5db69cc | 2020-08-06 15:27:45 -0700 | [diff] [blame] | 218 | if mod.sourceProvider != nil && (mod.compiler == nil || mod.compiler.Disabled()) { |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 219 | return mod.sourceProvider.Srcs(), nil |
| 220 | } else { |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 221 | if mod.OutputFile().Valid() { |
| 222 | return android.Paths{mod.OutputFile().Path()}, nil |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 223 | } |
| 224 | return android.Paths{}, nil |
| 225 | } |
Ivan Lozano | 0f9963e | 2023-02-06 13:31:02 -0500 | [diff] [blame] | 226 | case "unstripped": |
| 227 | if mod.compiler != nil { |
| 228 | return android.PathsIfNonNil(mod.compiler.unstrippedOutputFilePath()), nil |
| 229 | } |
| 230 | return nil, nil |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 231 | default: |
| 232 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 233 | } |
| 234 | } |
| 235 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 236 | func (mod *Module) SelectedStl() string { |
| 237 | return "" |
| 238 | } |
| 239 | |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 240 | func (mod *Module) NonCcVariants() bool { |
| 241 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 242 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 243 | return false |
Ivan Lozano | 2b26297 | 2019-11-21 12:30:50 -0800 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | panic(fmt.Errorf("NonCcVariants called on non-library module: %q", mod.BaseModuleName())) |
| 247 | } |
| 248 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 249 | func (mod *Module) Static() bool { |
| 250 | if mod.compiler != nil { |
| 251 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 252 | return library.static() |
| 253 | } |
| 254 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 255 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | func (mod *Module) Shared() bool { |
| 259 | if mod.compiler != nil { |
| 260 | if library, ok := mod.compiler.(libraryInterface); ok { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 261 | return library.shared() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 262 | } |
| 263 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 264 | return false |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 267 | func (mod *Module) Dylib() bool { |
| 268 | if mod.compiler != nil { |
| 269 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 270 | return library.dylib() |
| 271 | } |
| 272 | } |
| 273 | return false |
| 274 | } |
| 275 | |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 276 | func (mod *Module) Source() bool { |
| 277 | if mod.compiler != nil { |
| 278 | if library, ok := mod.compiler.(libraryInterface); ok && mod.sourceProvider != nil { |
| 279 | return library.source() |
| 280 | } |
| 281 | } |
| 282 | return false |
| 283 | } |
| 284 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 285 | func (mod *Module) RlibStd() bool { |
| 286 | if mod.compiler != nil { |
| 287 | if library, ok := mod.compiler.(libraryInterface); ok && library.rlib() { |
| 288 | return library.rlibStd() |
| 289 | } |
| 290 | } |
| 291 | panic(fmt.Errorf("RlibStd() called on non-rlib module: %q", mod.BaseModuleName())) |
| 292 | } |
| 293 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 294 | func (mod *Module) Rlib() bool { |
| 295 | if mod.compiler != nil { |
| 296 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 297 | return library.rlib() |
| 298 | } |
| 299 | } |
| 300 | return false |
| 301 | } |
| 302 | |
| 303 | func (mod *Module) Binary() bool { |
Ivan Lozano | 21fa0a5 | 2021-11-01 09:19:45 -0400 | [diff] [blame] | 304 | if binary, ok := mod.compiler.(binaryInterface); ok { |
| 305 | return binary.binary() |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 306 | } |
| 307 | return false |
| 308 | } |
| 309 | |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 310 | func (mod *Module) StaticExecutable() bool { |
| 311 | if !mod.Binary() { |
| 312 | return false |
| 313 | } |
Ivan Lozano | 21fa0a5 | 2021-11-01 09:19:45 -0400 | [diff] [blame] | 314 | return mod.StaticallyLinked() |
Justin Yun | 5e03586 | 2021-06-29 20:50:37 +0900 | [diff] [blame] | 315 | } |
| 316 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 317 | func (mod *Module) Object() bool { |
| 318 | // Rust has no modules which produce only object files. |
| 319 | return false |
| 320 | } |
| 321 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 322 | func (mod *Module) Toc() android.OptionalPath { |
| 323 | if mod.compiler != nil { |
Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 324 | if lib, ok := mod.compiler.(libraryInterface); ok { |
| 325 | return lib.toc() |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName())) |
| 329 | } |
| 330 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 331 | func (mod *Module) UseSdk() bool { |
| 332 | return false |
| 333 | } |
| 334 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 335 | func (mod *Module) RelativeInstallPath() string { |
| 336 | if mod.compiler != nil { |
| 337 | return mod.compiler.relativeInstallPath() |
| 338 | } |
| 339 | return "" |
| 340 | } |
| 341 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 342 | func (mod *Module) UseVndk() bool { |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 343 | return mod.Properties.VndkVersion != "" |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 346 | func (mod *Module) Bootstrap() bool { |
Ivan Lozano | a226863 | 2021-07-22 10:52:06 -0400 | [diff] [blame] | 347 | return Bool(mod.Properties.Bootstrap) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 348 | } |
| 349 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 350 | func (mod *Module) MustUseVendorVariant() bool { |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 351 | return true |
| 352 | } |
| 353 | |
| 354 | func (mod *Module) SubName() string { |
| 355 | return mod.Properties.SubName |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | func (mod *Module) IsVndk() bool { |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 359 | // TODO(b/165791368) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 360 | return false |
| 361 | } |
| 362 | |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 363 | func (mod *Module) IsVndkExt() bool { |
| 364 | return false |
| 365 | } |
| 366 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 367 | func (mod *Module) IsVndkSp() bool { |
| 368 | return false |
| 369 | } |
| 370 | |
Ivan Lozano | f1868af | 2022-04-12 13:08:36 -0400 | [diff] [blame] | 371 | func (mod *Module) IsVndkPrebuiltLibrary() bool { |
| 372 | // Rust modules do not provide VNDK prebuilts |
| 373 | return false |
| 374 | } |
| 375 | |
| 376 | func (mod *Module) IsVendorPublicLibrary() bool { |
| 377 | return mod.VendorProperties.IsVendorPublicLibrary |
| 378 | } |
| 379 | |
| 380 | func (mod *Module) SdkAndPlatformVariantVisibleToMake() bool { |
| 381 | // Rust modules to not provide Sdk variants |
| 382 | return false |
| 383 | } |
| 384 | |
Colin Cross | 127bb8b | 2020-12-16 16:46:01 -0800 | [diff] [blame] | 385 | func (c *Module) IsVndkPrivate() bool { |
| 386 | return false |
| 387 | } |
| 388 | |
| 389 | func (c *Module) IsLlndk() bool { |
| 390 | return false |
| 391 | } |
| 392 | |
| 393 | func (c *Module) IsLlndkPublic() bool { |
Ivan Lozano | f9e2172 | 2020-12-02 09:00:51 -0500 | [diff] [blame] | 394 | return false |
| 395 | } |
| 396 | |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 397 | func (mod *Module) KernelHeadersDecorator() bool { |
| 398 | return false |
| 399 | } |
| 400 | |
Colin Cross | 1f3f130 | 2021-04-26 18:37:44 -0700 | [diff] [blame] | 401 | func (m *Module) NeedsLlndkVariants() bool { |
Ivan Lozano | 3a7d000 | 2021-03-30 12:19:36 -0400 | [diff] [blame] | 402 | return false |
| 403 | } |
| 404 | |
Colin Cross | 5271fea | 2021-04-27 13:06:04 -0700 | [diff] [blame] | 405 | func (m *Module) NeedsVendorPublicLibraryVariants() bool { |
| 406 | return false |
| 407 | } |
| 408 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 409 | func (mod *Module) HasLlndkStubs() bool { |
| 410 | return false |
| 411 | } |
| 412 | |
| 413 | func (mod *Module) StubsVersion() string { |
| 414 | panic(fmt.Errorf("StubsVersion called on non-versioned module: %q", mod.BaseModuleName())) |
| 415 | } |
| 416 | |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 417 | func (mod *Module) SdkVersion() string { |
| 418 | return "" |
| 419 | } |
| 420 | |
Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 421 | func (mod *Module) AlwaysSdk() bool { |
| 422 | return false |
| 423 | } |
| 424 | |
Jiyong Park | 2286afd | 2020-06-16 21:58:53 +0900 | [diff] [blame] | 425 | func (mod *Module) IsSdkVariant() bool { |
| 426 | return false |
| 427 | } |
| 428 | |
Colin Cross | 1348ce3 | 2020-10-01 13:37:16 -0700 | [diff] [blame] | 429 | func (mod *Module) SplitPerApiLevel() bool { |
| 430 | return false |
| 431 | } |
| 432 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 433 | func (mod *Module) XrefRustFiles() android.Paths { |
| 434 | return mod.kytheFiles |
| 435 | } |
| 436 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 437 | type Deps struct { |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 438 | Dylibs []string |
| 439 | Rlibs []string |
| 440 | Rustlibs []string |
| 441 | Stdlibs []string |
| 442 | ProcMacros []string |
| 443 | SharedLibs []string |
| 444 | StaticLibs []string |
| 445 | WholeStaticLibs []string |
| 446 | HeaderLibs []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 447 | |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 448 | // Used for data dependencies adjacent to tests |
| 449 | DataLibs []string |
| 450 | DataBins []string |
| 451 | |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 452 | CrtBegin, CrtEnd []string |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | type PathDeps struct { |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 456 | DyLibs RustLibraries |
| 457 | RLibs RustLibraries |
| 458 | SharedLibs android.Paths |
| 459 | SharedLibDeps android.Paths |
| 460 | StaticLibs android.Paths |
| 461 | ProcMacros RustLibraries |
| 462 | AfdoProfiles android.Paths |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 463 | |
| 464 | // depFlags and depLinkFlags are rustc and linker (clang) flags. |
| 465 | depFlags []string |
| 466 | depLinkFlags []string |
| 467 | |
| 468 | // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker. |
| 469 | // Both of these are exported and propagate to dependencies. |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 470 | linkDirs []string |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 471 | linkObjects []string |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 472 | |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 473 | // Used by bindgen modules which call clang |
| 474 | depClangFlags []string |
| 475 | depIncludePaths android.Paths |
Ivan Lozano | ddd0bdb | 2020-08-28 17:00:26 -0400 | [diff] [blame] | 476 | depGeneratedHeaders android.Paths |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 477 | depSystemIncludePaths android.Paths |
| 478 | |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 479 | CrtBegin android.Paths |
| 480 | CrtEnd android.Paths |
Chih-Hung Hsieh | bbd25ae | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 481 | |
| 482 | // Paths to generated source files |
Ivan Lozano | 9d74a52 | 2020-12-01 09:25:22 -0500 | [diff] [blame] | 483 | SrcDeps android.Paths |
| 484 | srcProviderFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | type RustLibraries []RustLibrary |
| 488 | |
| 489 | type RustLibrary struct { |
| 490 | Path android.Path |
| 491 | CrateName string |
| 492 | } |
| 493 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 494 | type exportedFlagsProducer interface { |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 495 | exportLinkDirs(...string) |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 496 | exportLinkObjects(...string) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 499 | type xref interface { |
| 500 | XrefRustFiles() android.Paths |
| 501 | } |
| 502 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 503 | type flagExporter struct { |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 504 | linkDirs []string |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 505 | linkObjects []string |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 506 | } |
| 507 | |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 508 | func (flagExporter *flagExporter) exportLinkDirs(dirs ...string) { |
| 509 | flagExporter.linkDirs = android.FirstUniqueStrings(append(flagExporter.linkDirs, dirs...)) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 512 | func (flagExporter *flagExporter) exportLinkObjects(flags ...string) { |
| 513 | flagExporter.linkObjects = android.FirstUniqueStrings(append(flagExporter.linkObjects, flags...)) |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 514 | } |
| 515 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 516 | func (flagExporter *flagExporter) setProvider(ctx ModuleContext) { |
| 517 | ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{ |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 518 | LinkDirs: flagExporter.linkDirs, |
| 519 | LinkObjects: flagExporter.linkObjects, |
| 520 | }) |
| 521 | } |
| 522 | |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 523 | var _ exportedFlagsProducer = (*flagExporter)(nil) |
| 524 | |
| 525 | func NewFlagExporter() *flagExporter { |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 526 | return &flagExporter{} |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 529 | type FlagExporterInfo struct { |
| 530 | Flags []string |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 531 | LinkDirs []string // TODO: this should be android.Paths |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 532 | LinkObjects []string // TODO: this should be android.Paths |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{}) |
| 536 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 537 | func (mod *Module) isCoverageVariant() bool { |
| 538 | return mod.coverage.Properties.IsCoverageVariant |
| 539 | } |
| 540 | |
| 541 | var _ cc.Coverage = (*Module)(nil) |
| 542 | |
| 543 | func (mod *Module) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { |
| 544 | return mod.coverage != nil && mod.coverage.Properties.NeedCoverageVariant |
| 545 | } |
| 546 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 547 | func (mod *Module) VndkVersion() string { |
| 548 | return mod.Properties.VndkVersion |
| 549 | } |
| 550 | |
| 551 | func (mod *Module) PreventInstall() bool { |
| 552 | return mod.Properties.PreventInstall |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 553 | } |
| 554 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 555 | func (mod *Module) MarkAsCoverageVariant(coverage bool) { |
| 556 | mod.coverage.Properties.IsCoverageVariant = coverage |
| 557 | } |
| 558 | |
| 559 | func (mod *Module) EnableCoverageIfNeeded() { |
| 560 | mod.coverage.Properties.CoverageEnabled = mod.coverage.Properties.NeedCoverageBuild |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | func defaultsFactory() android.Module { |
| 564 | return DefaultsFactory() |
| 565 | } |
| 566 | |
| 567 | type Defaults struct { |
| 568 | android.ModuleBase |
| 569 | android.DefaultsModuleBase |
| 570 | } |
| 571 | |
| 572 | func DefaultsFactory(props ...interface{}) android.Module { |
| 573 | module := &Defaults{} |
| 574 | |
| 575 | module.AddProperties(props...) |
| 576 | module.AddProperties( |
| 577 | &BaseProperties{}, |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 578 | &cc.AfdoProperties{}, |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 579 | &cc.VendorProperties{}, |
Jakub Kotur | 1d640d0 | 2021-01-06 12:40:43 +0100 | [diff] [blame] | 580 | &BenchmarkProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 581 | &BindgenProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 582 | &BaseCompilerProperties{}, |
| 583 | &BinaryCompilerProperties{}, |
| 584 | &LibraryCompilerProperties{}, |
| 585 | &ProcMacroCompilerProperties{}, |
| 586 | &PrebuiltProperties{}, |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 587 | &SourceProviderProperties{}, |
Chih-Hung Hsieh | 41805be | 2019-10-31 20:56:47 -0700 | [diff] [blame] | 588 | &TestProperties{}, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 589 | &cc.CoverageProperties{}, |
Ivan Lozano | bc9e421 | 2020-09-25 16:08:34 -0400 | [diff] [blame] | 590 | &cc.RustBindgenClangProperties{}, |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 591 | &ClippyProperties{}, |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 592 | &SanitizeProperties{}, |
Pawan Wagh | ccb7558 | 2023-08-16 23:58:25 +0000 | [diff] [blame] | 593 | &fuzz.FuzzProperties{}, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 594 | ) |
| 595 | |
| 596 | android.InitDefaultsModule(module) |
| 597 | return module |
| 598 | } |
| 599 | |
| 600 | func (mod *Module) CrateName() string { |
Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 601 | return mod.compiler.crateName() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 604 | func (mod *Module) CcLibrary() bool { |
| 605 | if mod.compiler != nil { |
Ivan Lozano | 45e0e5b | 2021-11-13 07:42:36 -0500 | [diff] [blame] | 606 | if _, ok := mod.compiler.(libraryInterface); ok { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 607 | return true |
| 608 | } |
| 609 | } |
| 610 | return false |
| 611 | } |
| 612 | |
| 613 | func (mod *Module) CcLibraryInterface() bool { |
| 614 | if mod.compiler != nil { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 615 | // use build{Static,Shared}() instead of {static,shared}() here because this might be called before |
| 616 | // VariantIs{Static,Shared} is set. |
| 617 | if lib, ok := mod.compiler.(libraryInterface); ok && (lib.buildShared() || lib.buildStatic()) { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 618 | return true |
| 619 | } |
| 620 | } |
| 621 | return false |
| 622 | } |
| 623 | |
Ivan Lozano | 61c02cc | 2023-06-09 14:06:44 -0400 | [diff] [blame] | 624 | func (mod *Module) RustLibraryInterface() bool { |
| 625 | if mod.compiler != nil { |
| 626 | if _, ok := mod.compiler.(libraryInterface); ok { |
| 627 | return true |
| 628 | } |
| 629 | } |
| 630 | return false |
| 631 | } |
| 632 | |
Ivan Lozano | 0f9963e | 2023-02-06 13:31:02 -0500 | [diff] [blame] | 633 | func (mod *Module) IsFuzzModule() bool { |
| 634 | if _, ok := mod.compiler.(*fuzzDecorator); ok { |
| 635 | return true |
| 636 | } |
| 637 | return false |
| 638 | } |
| 639 | |
| 640 | func (mod *Module) FuzzModuleStruct() fuzz.FuzzModule { |
| 641 | return mod.FuzzModule |
| 642 | } |
| 643 | |
| 644 | func (mod *Module) FuzzPackagedModule() fuzz.FuzzPackagedModule { |
| 645 | if fuzzer, ok := mod.compiler.(*fuzzDecorator); ok { |
| 646 | return fuzzer.fuzzPackagedModule |
| 647 | } |
| 648 | panic(fmt.Errorf("FuzzPackagedModule called on non-fuzz module: %q", mod.BaseModuleName())) |
| 649 | } |
| 650 | |
Hamzeh Zawawy | 3891749 | 2023-04-05 22:08:46 +0000 | [diff] [blame] | 651 | func (mod *Module) FuzzSharedLibraries() android.RuleBuilderInstalls { |
Ivan Lozano | 0f9963e | 2023-02-06 13:31:02 -0500 | [diff] [blame] | 652 | if fuzzer, ok := mod.compiler.(*fuzzDecorator); ok { |
| 653 | return fuzzer.sharedLibraries |
| 654 | } |
| 655 | panic(fmt.Errorf("FuzzSharedLibraries called on non-fuzz module: %q", mod.BaseModuleName())) |
| 656 | } |
| 657 | |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 658 | func (mod *Module) UnstrippedOutputFile() android.Path { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 659 | if mod.compiler != nil { |
| 660 | return mod.compiler.unstrippedOutputFilePath() |
Ivan Lozano | 39b0bf0 | 2021-10-14 12:22:09 -0400 | [diff] [blame] | 661 | } |
| 662 | return nil |
| 663 | } |
| 664 | |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 665 | func (mod *Module) IncludeDirs() android.Paths { |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 666 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 667 | if library, ok := mod.compiler.(*libraryDecorator); ok { |
Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 668 | return library.includeDirs |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | panic(fmt.Errorf("IncludeDirs called on non-library module: %q", mod.BaseModuleName())) |
| 672 | } |
| 673 | |
| 674 | func (mod *Module) SetStatic() { |
| 675 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 676 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 677 | library.setStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 678 | return |
| 679 | } |
| 680 | } |
| 681 | panic(fmt.Errorf("SetStatic called on non-library module: %q", mod.BaseModuleName())) |
| 682 | } |
| 683 | |
| 684 | func (mod *Module) SetShared() { |
| 685 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 686 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 687 | library.setShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 688 | return |
| 689 | } |
| 690 | } |
| 691 | panic(fmt.Errorf("SetShared called on non-library module: %q", mod.BaseModuleName())) |
| 692 | } |
| 693 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 694 | func (mod *Module) BuildStaticVariant() bool { |
| 695 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 696 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 697 | return library.buildStatic() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", mod.BaseModuleName())) |
| 701 | } |
| 702 | |
| 703 | func (mod *Module) BuildSharedVariant() bool { |
| 704 | if mod.compiler != nil { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 705 | if library, ok := mod.compiler.(libraryInterface); ok { |
| 706 | return library.buildShared() |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", mod.BaseModuleName())) |
| 710 | } |
| 711 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 712 | func (mod *Module) Module() android.Module { |
| 713 | return mod |
| 714 | } |
| 715 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 716 | func (mod *Module) OutputFile() android.OptionalPath { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 717 | return mod.outputFile |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 718 | } |
| 719 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 720 | func (mod *Module) CoverageFiles() android.Paths { |
| 721 | if mod.compiler != nil { |
Joel Galenson | fa04938 | 2021-01-14 16:03:18 -0800 | [diff] [blame] | 722 | return android.Paths{} |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 723 | } |
| 724 | panic(fmt.Errorf("CoverageFiles called on non-library module: %q", mod.BaseModuleName())) |
| 725 | } |
| 726 | |
Ivan Lozano | 7f67c2a | 2022-06-27 16:00:26 -0400 | [diff] [blame] | 727 | // Rust does not produce gcno files, and therefore does not produce a coverage archive. |
| 728 | func (mod *Module) CoverageOutputFile() android.OptionalPath { |
| 729 | return android.OptionalPath{} |
| 730 | } |
| 731 | |
| 732 | func (mod *Module) IsNdk(config android.Config) bool { |
| 733 | return false |
| 734 | } |
| 735 | |
| 736 | func (mod *Module) IsStubs() bool { |
| 737 | return false |
| 738 | } |
| 739 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 740 | func (mod *Module) installable(apexInfo android.ApexInfo) bool { |
Jiyong Park | 2811e07 | 2021-09-30 17:25:21 +0900 | [diff] [blame] | 741 | if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) { |
Jiyong Park | bf8147a | 2021-05-17 13:19:33 +0900 | [diff] [blame] | 742 | return false |
| 743 | } |
| 744 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 745 | // The apex variant is not installable because it is included in the APEX and won't appear |
| 746 | // in the system partition as a standalone file. |
| 747 | if !apexInfo.IsForPlatform() { |
| 748 | return false |
| 749 | } |
| 750 | |
Jiyong Park | e54f07e | 2021-04-07 15:08:04 +0900 | [diff] [blame] | 751 | return mod.OutputFile().Valid() && !mod.Properties.PreventInstall |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 752 | } |
| 753 | |
Ivan Lozano | e950cda | 2021-11-09 11:26:04 -0500 | [diff] [blame] | 754 | func (ctx moduleContext) apexVariationName() string { |
| 755 | return ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName |
| 756 | } |
| 757 | |
Ivan Lozano | 183a321 | 2019-10-18 14:18:45 -0700 | [diff] [blame] | 758 | var _ cc.LinkableInterface = (*Module)(nil) |
| 759 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 760 | func (mod *Module) Init() android.Module { |
| 761 | mod.AddProperties(&mod.Properties) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 762 | mod.AddProperties(&mod.VendorProperties) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 763 | |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 764 | if mod.afdo != nil { |
| 765 | mod.AddProperties(mod.afdo.props()...) |
| 766 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 767 | if mod.compiler != nil { |
| 768 | mod.AddProperties(mod.compiler.compilerProps()...) |
| 769 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 770 | if mod.coverage != nil { |
| 771 | mod.AddProperties(mod.coverage.props()...) |
| 772 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 773 | if mod.clippy != nil { |
| 774 | mod.AddProperties(mod.clippy.props()...) |
| 775 | } |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 776 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 777 | mod.AddProperties(mod.sourceProvider.SourceProviderProps()...) |
Ivan Lozano | 4fef93c | 2020-07-08 08:39:44 -0400 | [diff] [blame] | 778 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 779 | if mod.sanitize != nil { |
| 780 | mod.AddProperties(mod.sanitize.props()...) |
| 781 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 782 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 783 | android.InitAndroidArchModule(mod, mod.hod, mod.multilib) |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 784 | android.InitApexModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 785 | |
| 786 | android.InitDefaultableModule(mod) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 787 | return mod |
| 788 | } |
| 789 | |
| 790 | func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 791 | return &Module{ |
| 792 | hod: hod, |
| 793 | multilib: multilib, |
| 794 | } |
| 795 | } |
| 796 | func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module { |
| 797 | module := newBaseModule(hod, multilib) |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 798 | module.afdo = &afdo{} |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 799 | module.coverage = &coverage{} |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 800 | module.clippy = &clippy{} |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 801 | module.sanitize = &sanitize{} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 802 | return module |
| 803 | } |
| 804 | |
| 805 | type ModuleContext interface { |
| 806 | android.ModuleContext |
| 807 | ModuleContextIntf |
| 808 | } |
| 809 | |
| 810 | type BaseModuleContext interface { |
| 811 | android.BaseModuleContext |
| 812 | ModuleContextIntf |
| 813 | } |
| 814 | |
| 815 | type DepsContext interface { |
| 816 | android.BottomUpMutatorContext |
| 817 | ModuleContextIntf |
| 818 | } |
| 819 | |
| 820 | type ModuleContextIntf interface { |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 821 | RustModule() *Module |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 822 | toolchain() config.Toolchain |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | type depsContext struct { |
| 826 | android.BottomUpMutatorContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | type moduleContext struct { |
| 830 | android.ModuleContext |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 831 | } |
| 832 | |
Thiébaud Weksteen | 1f7f70f | 2020-06-24 11:32:48 +0200 | [diff] [blame] | 833 | type baseModuleContext struct { |
| 834 | android.BaseModuleContext |
| 835 | } |
| 836 | |
| 837 | func (ctx *moduleContext) RustModule() *Module { |
| 838 | return ctx.Module().(*Module) |
| 839 | } |
| 840 | |
| 841 | func (ctx *moduleContext) toolchain() config.Toolchain { |
| 842 | return ctx.RustModule().toolchain(ctx) |
| 843 | } |
| 844 | |
| 845 | func (ctx *depsContext) RustModule() *Module { |
| 846 | return ctx.Module().(*Module) |
| 847 | } |
| 848 | |
| 849 | func (ctx *depsContext) toolchain() config.Toolchain { |
| 850 | return ctx.RustModule().toolchain(ctx) |
| 851 | } |
| 852 | |
| 853 | func (ctx *baseModuleContext) RustModule() *Module { |
| 854 | return ctx.Module().(*Module) |
| 855 | } |
| 856 | |
| 857 | func (ctx *baseModuleContext) toolchain() config.Toolchain { |
| 858 | return ctx.RustModule().toolchain(ctx) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | func (mod *Module) nativeCoverage() bool { |
Matthew Maurer | a61e31f | 2021-05-27 11:09:11 -0700 | [diff] [blame] | 862 | // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage |
| 863 | if mod.Target().NativeBridge == android.NativeBridgeEnabled { |
| 864 | return false |
| 865 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 866 | return mod.compiler != nil && mod.compiler.nativeCoverage() |
| 867 | } |
| 868 | |
Ivan Lozano | d7586b6 | 2021-04-01 09:49:36 -0400 | [diff] [blame] | 869 | func (mod *Module) EverInstallable() bool { |
| 870 | return mod.compiler != nil && |
| 871 | // Check to see whether the module is actually ever installable. |
| 872 | mod.compiler.everInstallable() |
| 873 | } |
| 874 | |
| 875 | func (mod *Module) Installable() *bool { |
| 876 | return mod.Properties.Installable |
| 877 | } |
| 878 | |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 879 | func (mod *Module) ProcMacro() bool { |
| 880 | if pm, ok := mod.compiler.(procMacroInterface); ok { |
| 881 | return pm.ProcMacro() |
| 882 | } |
| 883 | return false |
| 884 | } |
| 885 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 886 | func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain { |
| 887 | if mod.cachedToolchain == nil { |
| 888 | mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 889 | } |
| 890 | return mod.cachedToolchain |
| 891 | } |
| 892 | |
Thiébaud Weksteen | 31f1bb8 | 2020-08-27 13:37:29 +0200 | [diff] [blame] | 893 | func (mod *Module) ccToolchain(ctx android.BaseModuleContext) cc_config.Toolchain { |
| 894 | return cc_config.FindToolchain(ctx.Os(), ctx.Arch()) |
| 895 | } |
| 896 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 897 | func (d *Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 898 | } |
| 899 | |
| 900 | func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { |
| 901 | ctx := &moduleContext{ |
| 902 | ModuleContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 903 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 904 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 905 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 906 | if !apexInfo.IsForPlatform() { |
| 907 | mod.hideApexVariantFromMake = true |
| 908 | } |
| 909 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 910 | toolchain := mod.toolchain(ctx) |
Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 911 | mod.makeLinkType = cc.GetMakeLinkType(actx, mod) |
| 912 | |
Ivan Lozano | f1868af | 2022-04-12 13:08:36 -0400 | [diff] [blame] | 913 | mod.Properties.SubName = cc.GetSubnameProperty(actx, mod) |
Matthew Maurer | a61e31f | 2021-05-27 11:09:11 -0700 | [diff] [blame] | 914 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 915 | if !toolchain.Supported() { |
| 916 | // This toolchain's unsupported, there's nothing to do for this mod. |
| 917 | return |
| 918 | } |
| 919 | |
| 920 | deps := mod.depsToPaths(ctx) |
| 921 | flags := Flags{ |
| 922 | Toolchain: toolchain, |
| 923 | } |
| 924 | |
Ivan Lozano | 67eada3 | 2021-09-23 11:50:33 -0400 | [diff] [blame] | 925 | // Calculate rustc flags |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 926 | if mod.afdo != nil { |
Vinh Tran | cde1016 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 927 | flags, deps = mod.afdo.flags(actx, flags, deps) |
Yi Kong | 46c6e59 | 2022-01-20 22:55:00 +0800 | [diff] [blame] | 928 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 929 | if mod.compiler != nil { |
| 930 | flags = mod.compiler.compilerFlags(ctx, flags) |
Ivan Lozano | 67eada3 | 2021-09-23 11:50:33 -0400 | [diff] [blame] | 931 | flags = mod.compiler.cfgFlags(ctx, flags) |
| 932 | flags = mod.compiler.featureFlags(ctx, flags) |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 933 | } |
| 934 | if mod.coverage != nil { |
| 935 | flags, deps = mod.coverage.flags(ctx, flags, deps) |
| 936 | } |
Thiébaud Weksteen | 92f703b | 2020-06-22 13:28:02 +0200 | [diff] [blame] | 937 | if mod.clippy != nil { |
| 938 | flags, deps = mod.clippy.flags(ctx, flags, deps) |
| 939 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 940 | if mod.sanitize != nil { |
| 941 | flags, deps = mod.sanitize.flags(ctx, flags, deps) |
| 942 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 943 | |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 944 | // SourceProvider needs to call GenerateSource() before compiler calls |
| 945 | // compile() so it can provide the source. A SourceProvider has |
| 946 | // multiple variants (e.g. source, rlib, dylib). Only the "source" |
| 947 | // variant is responsible for effectively generating the source. The |
| 948 | // remaining variants relies on the "source" variant output. |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 949 | if mod.sourceProvider != nil { |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 950 | if mod.compiler.(libraryInterface).source() { |
| 951 | mod.sourceProvider.GenerateSource(ctx, deps) |
| 952 | mod.sourceProvider.setSubName(ctx.ModuleSubDir()) |
| 953 | } else { |
| 954 | sourceMod := actx.GetDirectDepWithTag(mod.Name(), sourceDepTag) |
| 955 | sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator) |
Chih-Hung Hsieh | c49649c | 2020-10-01 21:25:05 -0700 | [diff] [blame] | 956 | mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs()) |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 957 | } |
Aditya Choudhary | 26df39f | 2023-11-29 16:42:42 +0000 | [diff] [blame] | 958 | ctx.SetProvider(blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: mod.sourceProvider.Srcs().Strings()}) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | if mod.compiler != nil && !mod.compiler.Disabled() { |
Thiébaud Weksteen | ee6a89b | 2021-02-25 16:30:57 +0100 | [diff] [blame] | 962 | mod.compiler.initialize(ctx) |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 963 | buildOutput := mod.compiler.compile(ctx, flags, deps) |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 964 | if ctx.Failed() { |
| 965 | return |
| 966 | } |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 967 | mod.outputFile = android.OptionalPathForPath(buildOutput.outputFile) |
| 968 | if buildOutput.kytheFile != nil { |
| 969 | mod.kytheFiles = append(mod.kytheFiles, buildOutput.kytheFile) |
| 970 | } |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 971 | bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), android.OptionalPathForPath(mod.compiler.unstrippedOutputFilePath())) |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 972 | |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 973 | mod.docTimestampFile = mod.compiler.rustdoc(ctx, flags, deps) |
Matthew Maurer | e380363 | 2021-12-10 21:57:21 +0000 | [diff] [blame] | 974 | if mod.docTimestampFile.Valid() { |
| 975 | ctx.CheckbuildFile(mod.docTimestampFile.Path()) |
| 976 | } |
Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 977 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 978 | // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or |
| 979 | // RECOVERY_SNAPSHOT_VERSION is current. |
| 980 | if lib, ok := mod.compiler.(snapshotLibraryInterface); ok { |
| 981 | if cc.ShouldCollectHeadersForSnapshot(ctx, mod, apexInfo) { |
| 982 | lib.collectHeadersForSnapshot(ctx, deps) |
| 983 | } |
| 984 | } |
| 985 | |
Jiyong Park | 459feca | 2020-12-15 11:02:21 +0900 | [diff] [blame] | 986 | apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 987 | if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) && !mod.ProcMacro() { |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 988 | // If the module has been specifically configure to not be installed then |
| 989 | // hide from make as otherwise it will break when running inside make as the |
| 990 | // output path to install will not be specified. Not all uninstallable |
| 991 | // modules can be hidden from make as some are needed for resolving make |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 992 | // side dependencies. In particular, proc-macros need to be captured in the |
| 993 | // host snapshot. |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 994 | mod.HideFromMake() |
| 995 | } else if !mod.installable(apexInfo) { |
| 996 | mod.SkipInstall() |
| 997 | } |
| 998 | |
| 999 | // Still call install though, the installs will be stored as PackageSpecs to allow |
| 1000 | // using the outputs in a genrule. |
| 1001 | if mod.OutputFile().Valid() { |
Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 1002 | mod.compiler.install(ctx) |
Jiyong Park | d1e366a | 2021-10-05 09:12:41 +0900 | [diff] [blame] | 1003 | if ctx.Failed() { |
| 1004 | return |
| 1005 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1006 | } |
Chris Wailes | 74be764 | 2021-07-22 16:20:28 -0700 | [diff] [blame] | 1007 | |
| 1008 | ctx.Phony("rust", ctx.RustModule().OutputFile().Path()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1009 | } |
Aditya Choudhary | 87b2ab2 | 2023-11-17 15:27:06 +0000 | [diff] [blame] | 1010 | if mod.testModule { |
| 1011 | ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{}) |
| 1012 | } |
LaMont Jones | 0c97185 | 2023-12-07 21:56:59 +0000 | [diff] [blame^] | 1013 | |
| 1014 | aconfig.CollectDependencyAconfigFiles(ctx, &mod.mergedAconfigFiles) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | func (mod *Module) deps(ctx DepsContext) Deps { |
| 1018 | deps := Deps{} |
| 1019 | |
| 1020 | if mod.compiler != nil { |
| 1021 | deps = mod.compiler.compilerDeps(ctx, deps) |
Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 1022 | } |
| 1023 | if mod.sourceProvider != nil { |
Andrei Homescu | c776792 | 2020-08-05 06:36:19 -0700 | [diff] [blame] | 1024 | deps = mod.sourceProvider.SourceProviderDeps(ctx, deps) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1027 | if mod.coverage != nil { |
| 1028 | deps = mod.coverage.deps(ctx, deps) |
| 1029 | } |
| 1030 | |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 1031 | if mod.sanitize != nil { |
| 1032 | deps = mod.sanitize.deps(ctx, deps) |
| 1033 | } |
| 1034 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1035 | deps.Rlibs = android.LastUniqueStrings(deps.Rlibs) |
| 1036 | deps.Dylibs = android.LastUniqueStrings(deps.Dylibs) |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1037 | deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1038 | deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros) |
| 1039 | deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs) |
| 1040 | deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs) |
Andrew Walbran | 797e4be | 2022-03-07 15:41:53 +0000 | [diff] [blame] | 1041 | deps.Stdlibs = android.LastUniqueStrings(deps.Stdlibs) |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1042 | deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1043 | return deps |
| 1044 | |
| 1045 | } |
| 1046 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1047 | type dependencyTag struct { |
| 1048 | blueprint.BaseDependencyTag |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1049 | name string |
| 1050 | library bool |
| 1051 | procMacro bool |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1052 | dynamic bool |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 1055 | // InstallDepNeeded returns true for rlibs, dylibs, and proc macros so that they or their transitive |
| 1056 | // dependencies (especially C/C++ shared libs) are installed as dependencies of a rust binary. |
| 1057 | func (d dependencyTag) InstallDepNeeded() bool { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1058 | return d.library || d.procMacro |
Jiyong Park | 65b6224 | 2020-11-25 12:44:59 +0900 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | var _ android.InstallNeededDependencyTag = dependencyTag{} |
| 1062 | |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1063 | func (d dependencyTag) LicenseAnnotations() []android.LicenseAnnotation { |
| 1064 | if d.library && d.dynamic { |
| 1065 | return []android.LicenseAnnotation{android.LicenseAnnotationSharedDependency} |
| 1066 | } |
| 1067 | return nil |
| 1068 | } |
| 1069 | |
| 1070 | var _ android.LicenseAnnotationsDependencyTag = dependencyTag{} |
| 1071 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1072 | var ( |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1073 | customBindgenDepTag = dependencyTag{name: "customBindgenTag"} |
| 1074 | rlibDepTag = dependencyTag{name: "rlibTag", library: true} |
Colin Cross | 65cb314 | 2021-12-10 23:05:02 +0000 | [diff] [blame] | 1075 | dylibDepTag = dependencyTag{name: "dylib", library: true, dynamic: true} |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 1076 | procMacroDepTag = dependencyTag{name: "procMacro", procMacro: true} |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1077 | testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"} |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1078 | sourceDepTag = dependencyTag{name: "source"} |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 1079 | dataLibDepTag = dependencyTag{name: "data lib"} |
| 1080 | dataBinDepTag = dependencyTag{name: "data bin"} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1081 | ) |
| 1082 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1083 | func IsDylibDepTag(depTag blueprint.DependencyTag) bool { |
| 1084 | tag, ok := depTag.(dependencyTag) |
| 1085 | return ok && tag == dylibDepTag |
| 1086 | } |
| 1087 | |
Jiyong Park | 94e22fd | 2021-04-08 18:19:15 +0900 | [diff] [blame] | 1088 | func IsRlibDepTag(depTag blueprint.DependencyTag) bool { |
| 1089 | tag, ok := depTag.(dependencyTag) |
| 1090 | return ok && tag == rlibDepTag |
| 1091 | } |
| 1092 | |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1093 | type autoDep struct { |
| 1094 | variation string |
| 1095 | depTag dependencyTag |
| 1096 | } |
| 1097 | |
| 1098 | var ( |
Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 1099 | rlibVariation = "rlib" |
| 1100 | dylibVariation = "dylib" |
| 1101 | rlibAutoDep = autoDep{variation: rlibVariation, depTag: rlibDepTag} |
| 1102 | dylibAutoDep = autoDep{variation: dylibVariation, depTag: dylibDepTag} |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1103 | ) |
| 1104 | |
| 1105 | type autoDeppable interface { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 1106 | autoDep(ctx android.BottomUpMutatorContext) autoDep |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1109 | func (mod *Module) begin(ctx BaseModuleContext) { |
| 1110 | if mod.coverage != nil { |
| 1111 | mod.coverage.begin(ctx) |
| 1112 | } |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 1113 | if mod.sanitize != nil { |
| 1114 | mod.sanitize.begin(ctx) |
| 1115 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1116 | } |
| 1117 | |
Ivan Lozano | fba2aa2 | 2021-11-11 09:29:07 -0500 | [diff] [blame] | 1118 | func (mod *Module) Prebuilt() *android.Prebuilt { |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1119 | if p, ok := mod.compiler.(rustPrebuilt); ok { |
Ivan Lozano | fba2aa2 | 2021-11-11 09:29:07 -0500 | [diff] [blame] | 1120 | return p.prebuilt() |
| 1121 | } |
| 1122 | return nil |
| 1123 | } |
| 1124 | |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 1125 | func rustMakeLibName(ctx android.ModuleContext, c cc.LinkableInterface, dep cc.LinkableInterface, depName string) string { |
| 1126 | if rustDep, ok := dep.(*Module); ok { |
| 1127 | // Use base module name for snapshots when exporting to Makefile. |
| 1128 | if snapshotPrebuilt, ok := rustDep.compiler.(cc.SnapshotInterface); ok { |
| 1129 | baseName := rustDep.BaseModuleName() |
| 1130 | return baseName + snapshotPrebuilt.SnapshotAndroidMkSuffix() + rustDep.AndroidMkSuffix() |
| 1131 | } |
| 1132 | } |
| 1133 | return cc.MakeLibName(ctx, c, dep, depName) |
| 1134 | } |
| 1135 | |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1136 | func collectIncludedProtos(mod *Module, dep *Module) { |
| 1137 | if protoMod, ok := mod.sourceProvider.(*protobufDecorator); ok { |
| 1138 | if _, ok := dep.sourceProvider.(*protobufDecorator); ok { |
| 1139 | protoMod.additionalCrates = append(protoMod.additionalCrates, dep.CrateName()) |
| 1140 | } |
| 1141 | } |
| 1142 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1143 | func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { |
| 1144 | var depPaths PathDeps |
| 1145 | |
| 1146 | directRlibDeps := []*Module{} |
| 1147 | directDylibDeps := []*Module{} |
| 1148 | directProcMacroDeps := []*Module{} |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1149 | directSharedLibDeps := []cc.SharedLibraryInfo{} |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1150 | directStaticLibDeps := [](cc.LinkableInterface){} |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1151 | directSrcProvidersDeps := []*Module{} |
| 1152 | directSrcDeps := [](android.SourceFileProducer){} |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1153 | |
Ivan Lozano | e950cda | 2021-11-09 11:26:04 -0500 | [diff] [blame] | 1154 | // For the dependency from platform to apex, use the latest stubs |
| 1155 | mod.apexSdkVersion = android.FutureApiLevel |
| 1156 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 1157 | if !apexInfo.IsForPlatform() { |
| 1158 | mod.apexSdkVersion = apexInfo.MinSdkVersion |
| 1159 | } |
| 1160 | |
| 1161 | if android.InList("hwaddress", ctx.Config().SanitizeDevice()) { |
| 1162 | // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000) |
| 1163 | // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)). |
| 1164 | // (b/144430859) |
| 1165 | mod.apexSdkVersion = android.FutureApiLevel |
| 1166 | } |
| 1167 | |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1168 | skipModuleList := map[string]bool{} |
| 1169 | |
| 1170 | var apiImportInfo multitree.ApiImportInfo |
| 1171 | hasApiImportInfo := false |
| 1172 | |
| 1173 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1174 | if dep.Name() == "api_imports" { |
| 1175 | apiImportInfo = ctx.OtherModuleProvider(dep, multitree.ApiImportsProvider).(multitree.ApiImportInfo) |
| 1176 | hasApiImportInfo = true |
| 1177 | } |
| 1178 | }) |
| 1179 | |
| 1180 | if hasApiImportInfo { |
| 1181 | targetStubModuleList := map[string]string{} |
| 1182 | targetOrigModuleList := map[string]string{} |
| 1183 | |
| 1184 | // Search for dependency which both original module and API imported library with APEX stub exists |
| 1185 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1186 | depName := ctx.OtherModuleName(dep) |
| 1187 | if apiLibrary, ok := apiImportInfo.ApexSharedLibs[depName]; ok { |
| 1188 | targetStubModuleList[apiLibrary] = depName |
| 1189 | } |
| 1190 | }) |
| 1191 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1192 | depName := ctx.OtherModuleName(dep) |
| 1193 | if origLibrary, ok := targetStubModuleList[depName]; ok { |
| 1194 | targetOrigModuleList[origLibrary] = depName |
| 1195 | } |
| 1196 | }) |
| 1197 | |
| 1198 | // Decide which library should be used between original and API imported library |
| 1199 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1200 | depName := ctx.OtherModuleName(dep) |
| 1201 | if apiLibrary, ok := targetOrigModuleList[depName]; ok { |
| 1202 | if cc.ShouldUseStubForApex(ctx, dep) { |
| 1203 | skipModuleList[depName] = true |
| 1204 | } else { |
| 1205 | skipModuleList[apiLibrary] = true |
| 1206 | } |
| 1207 | } |
| 1208 | }) |
| 1209 | } |
| 1210 | |
Cole Faust | b6e6f99 | 2023-08-17 17:42:26 -0700 | [diff] [blame] | 1211 | var transitiveAndroidMkSharedLibs []*android.DepSet[string] |
| 1212 | var directAndroidMkSharedLibs []string |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1213 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1214 | ctx.VisitDirectDeps(func(dep android.Module) { |
| 1215 | depName := ctx.OtherModuleName(dep) |
| 1216 | depTag := ctx.OtherModuleDependencyTag(dep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1217 | |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1218 | if _, exists := skipModuleList[depName]; exists { |
| 1219 | return |
| 1220 | } |
A. Cody Schuffelen | c183e3a | 2023-08-14 21:09:47 -0700 | [diff] [blame] | 1221 | |
| 1222 | if depTag == android.DarwinUniversalVariantTag { |
| 1223 | return |
| 1224 | } |
| 1225 | |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1226 | if rustDep, ok := dep.(*Module); ok && !rustDep.CcLibraryInterface() { |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1227 | //Handle Rust Modules |
Justin Yun | 24b246a | 2023-03-16 10:36:16 +0900 | [diff] [blame] | 1228 | makeLibName := rustMakeLibName(ctx, mod, rustDep, depName+rustDep.Properties.RustSubName) |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 1229 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1230 | switch depTag { |
| 1231 | case dylibDepTag: |
| 1232 | dylib, ok := rustDep.compiler.(libraryInterface) |
| 1233 | if !ok || !dylib.dylib() { |
| 1234 | ctx.ModuleErrorf("mod %q not an dylib library", depName) |
| 1235 | return |
| 1236 | } |
| 1237 | directDylibDeps = append(directDylibDeps, rustDep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1238 | mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1239 | mod.Properties.SnapshotDylibs = append(mod.Properties.SnapshotDylibs, cc.BaseLibName(depName)) |
| 1240 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1241 | case rlibDepTag: |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1242 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1243 | rlib, ok := rustDep.compiler.(libraryInterface) |
| 1244 | if !ok || !rlib.rlib() { |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1245 | ctx.ModuleErrorf("mod %q not an rlib library", makeLibName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1246 | return |
| 1247 | } |
| 1248 | directRlibDeps = append(directRlibDeps, rustDep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1249 | mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName) |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1250 | mod.Properties.SnapshotRlibs = append(mod.Properties.SnapshotRlibs, cc.BaseLibName(depName)) |
| 1251 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1252 | case procMacroDepTag: |
| 1253 | directProcMacroDeps = append(directProcMacroDeps, rustDep) |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1254 | mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName) |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1255 | |
| 1256 | case sourceDepTag: |
| 1257 | if _, ok := mod.sourceProvider.(*protobufDecorator); ok { |
| 1258 | collectIncludedProtos(mod, rustDep) |
| 1259 | } |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 1260 | } |
| 1261 | |
Cole Faust | b6e6f99 | 2023-08-17 17:42:26 -0700 | [diff] [blame] | 1262 | transitiveAndroidMkSharedLibs = append(transitiveAndroidMkSharedLibs, rustDep.transitiveAndroidMkSharedLibs) |
| 1263 | |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 1264 | if android.IsSourceDepTagWithOutputTag(depTag, "") { |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1265 | // Since these deps are added in path_properties.go via AddDependencies, we need to ensure the correct |
| 1266 | // OS/Arch variant is used. |
| 1267 | var helper string |
| 1268 | if ctx.Host() { |
| 1269 | helper = "missing 'host_supported'?" |
| 1270 | } else { |
| 1271 | helper = "device module defined?" |
| 1272 | } |
| 1273 | |
| 1274 | if dep.Target().Os != ctx.Os() { |
| 1275 | ctx.ModuleErrorf("OS mismatch on dependency %q (%s)", dep.Name(), helper) |
| 1276 | return |
| 1277 | } else if dep.Target().Arch.ArchType != ctx.Arch().ArchType { |
| 1278 | ctx.ModuleErrorf("Arch mismatch on dependency %q (%s)", dep.Name(), helper) |
| 1279 | return |
| 1280 | } |
| 1281 | directSrcProvidersDeps = append(directSrcProvidersDeps, rustDep) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
Ivan Lozano | 2bbcacf | 2020-08-07 09:00:50 -0400 | [diff] [blame] | 1284 | //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] | 1285 | if depTag != procMacroDepTag { |
| 1286 | exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo) |
| 1287 | depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...) |
| 1288 | depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...) |
| 1289 | depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1292 | if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag { |
Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 1293 | linkFile := rustDep.UnstrippedOutputFile() |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1294 | linkDir := linkPathFromFilePath(linkFile) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 1295 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok { |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1296 | lib.exportLinkDirs(linkDir) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1297 | } |
| 1298 | } |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1299 | if depTag == sourceDepTag { |
| 1300 | if _, ok := mod.sourceProvider.(*protobufDecorator); ok && mod.Source() { |
| 1301 | if _, ok := rustDep.sourceProvider.(*protobufDecorator); ok { |
| 1302 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 1303 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1304 | } |
| 1305 | } |
| 1306 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1307 | } else if ccDep, ok := dep.(cc.LinkableInterface); ok { |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1308 | //Handle C dependencies |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1309 | makeLibName := cc.MakeLibName(ctx, mod, ccDep, depName) |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1310 | if _, ok := ccDep.(*Module); !ok { |
| 1311 | if ccDep.Module().Target().Os != ctx.Os() { |
| 1312 | ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) |
| 1313 | return |
| 1314 | } |
| 1315 | if ccDep.Module().Target().Arch.ArchType != ctx.Arch().ArchType { |
| 1316 | ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName) |
| 1317 | return |
| 1318 | } |
Ivan Lozano | 70e0a07 | 2019-09-13 14:23:15 -0700 | [diff] [blame] | 1319 | } |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 1320 | linkObject := ccDep.OutputFile() |
Ivan Lozano | 2093af2 | 2020-08-25 12:48:19 -0400 | [diff] [blame] | 1321 | if !linkObject.Valid() { |
Colin Cross | a86ea0e | 2023-08-01 09:57:22 -0700 | [diff] [blame] | 1322 | if !ctx.Config().AllowMissingDependencies() { |
| 1323 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) |
| 1324 | } else { |
| 1325 | ctx.AddMissingDependencies([]string{depName}) |
| 1326 | } |
| 1327 | return |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1328 | } |
| 1329 | |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1330 | linkPath := linkPathFromFilePath(linkObject.Path()) |
Colin Cross | a86ea0e | 2023-08-01 09:57:22 -0700 | [diff] [blame] | 1331 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1332 | exportDep := false |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1333 | switch { |
| 1334 | case cc.IsStaticDepTag(depTag): |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1335 | if cc.IsWholeStaticLib(depTag) { |
| 1336 | // rustc will bundle static libraries when they're passed with "-lstatic=<lib>". This will fail |
| 1337 | // if the library is not prefixed by "lib". |
Ivan Lozano | fdadcd7 | 2021-11-01 09:04:23 -0400 | [diff] [blame] | 1338 | if mod.Binary() { |
| 1339 | // Binaries may sometimes need to link whole static libraries that don't start with 'lib'. |
| 1340 | // Since binaries don't need to 'rebundle' these like libraries and only use these for the |
| 1341 | // final linkage, pass the args directly to the linker to handle these cases. |
| 1342 | depPaths.depLinkFlags = append(depPaths.depLinkFlags, []string{"-Wl,--whole-archive", linkObject.Path().String(), "-Wl,--no-whole-archive"}...) |
| 1343 | } else if libName, ok := libNameFromFilePath(linkObject.Path()); ok { |
Ivan Lozano | fb6f36f | 2021-02-05 12:27:08 -0500 | [diff] [blame] | 1344 | depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName) |
Ivan Lozano | 63bb768 | 2021-03-23 15:53:44 -0400 | [diff] [blame] | 1345 | } else { |
| 1346 | 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] | 1347 | } |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | // Add this to linkObjects to pass the library directly to the linker as well. This propagates |
| 1351 | // to dependencies to avoid having to redeclare static libraries for dependents of the dylib variant. |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1352 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String()) |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1353 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
| 1354 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1355 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 1356 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1357 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1358 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 1359 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1360 | directStaticLibDeps = append(directStaticLibDeps, ccDep) |
Justin Yun | 2b3ed64 | 2022-02-16 08:15:07 +0900 | [diff] [blame] | 1361 | |
| 1362 | // Record baseLibName for snapshots. |
| 1363 | mod.Properties.SnapshotStaticLibs = append(mod.Properties.SnapshotStaticLibs, cc.BaseLibName(depName)) |
| 1364 | |
Ivan Lozano | c08897c | 2021-04-02 12:41:32 -0400 | [diff] [blame] | 1365 | mod.Properties.AndroidMkStaticLibs = append(mod.Properties.AndroidMkStaticLibs, makeLibName) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1366 | case cc.IsSharedDepTag(depTag): |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1367 | // For the shared lib dependencies, we may link to the stub variant |
| 1368 | // of the dependency depending on the context (e.g. if this |
| 1369 | // dependency crosses the APEX boundaries). |
| 1370 | sharedLibraryInfo, exportedInfo := cc.ChooseStubOrImpl(ctx, dep) |
| 1371 | |
| 1372 | // Re-get linkObject as ChooseStubOrImpl actually tells us which |
| 1373 | // object (either from stub or non-stub) to use. |
| 1374 | linkObject = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary) |
Colin Cross | a86ea0e | 2023-08-01 09:57:22 -0700 | [diff] [blame] | 1375 | if !linkObject.Valid() { |
| 1376 | if !ctx.Config().AllowMissingDependencies() { |
| 1377 | ctx.ModuleErrorf("Invalid output file when adding dep %q to %q", depName, ctx.ModuleName()) |
| 1378 | } else { |
| 1379 | ctx.AddMissingDependencies([]string{depName}) |
| 1380 | } |
| 1381 | return |
| 1382 | } |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1383 | linkPath = linkPathFromFilePath(linkObject.Path()) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1384 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1385 | depPaths.linkDirs = append(depPaths.linkDirs, linkPath) |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1386 | depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String()) |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 1387 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1388 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1389 | depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) |
| 1390 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1391 | directSharedLibDeps = append(directSharedLibDeps, sharedLibraryInfo) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1392 | |
| 1393 | // Record baseLibName for snapshots. |
| 1394 | mod.Properties.SnapshotSharedLibs = append(mod.Properties.SnapshotSharedLibs, cc.BaseLibName(depName)) |
| 1395 | |
Cole Faust | b6e6f99 | 2023-08-17 17:42:26 -0700 | [diff] [blame] | 1396 | directAndroidMkSharedLibs = append(directAndroidMkSharedLibs, makeLibName) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1397 | exportDep = true |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 1398 | case cc.IsHeaderDepTag(depTag): |
| 1399 | exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo) |
| 1400 | depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...) |
| 1401 | depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) |
| 1402 | depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1403 | case depTag == cc.CrtBeginDepTag: |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 1404 | depPaths.CrtBegin = append(depPaths.CrtBegin, linkObject.Path()) |
Colin Cross | 6e511a9 | 2020-07-27 21:26:48 -0700 | [diff] [blame] | 1405 | case depTag == cc.CrtEndDepTag: |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 1406 | depPaths.CrtEnd = append(depPaths.CrtEnd, linkObject.Path()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | // Make sure these dependencies are propagated |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 1410 | if lib, ok := mod.compiler.(exportedFlagsProducer); ok && exportDep { |
| 1411 | lib.exportLinkDirs(linkPath) |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1412 | lib.exportLinkObjects(linkObject.String()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1413 | } |
Colin Cross | 018cbeb | 2022-01-24 17:22:45 -0800 | [diff] [blame] | 1414 | } else { |
| 1415 | switch { |
| 1416 | case depTag == cc.CrtBeginDepTag: |
| 1417 | depPaths.CrtBegin = append(depPaths.CrtBegin, android.OutputFileForModule(ctx, dep, "")) |
| 1418 | case depTag == cc.CrtEndDepTag: |
| 1419 | depPaths.CrtEnd = append(depPaths.CrtEnd, android.OutputFileForModule(ctx, dep, "")) |
| 1420 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1421 | } |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1422 | |
| 1423 | if srcDep, ok := dep.(android.SourceFileProducer); ok { |
Paul Duffin | d5cf92e | 2021-07-09 17:38:55 +0100 | [diff] [blame] | 1424 | if android.IsSourceDepTagWithOutputTag(depTag, "") { |
Ivan Lozano | 89435d1 | 2020-07-31 11:01:18 -0400 | [diff] [blame] | 1425 | // These are usually genrules which don't have per-target variants. |
| 1426 | directSrcDeps = append(directSrcDeps, srcDep) |
| 1427 | } |
| 1428 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1429 | }) |
| 1430 | |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1431 | mod.transitiveAndroidMkSharedLibs = android.NewDepSet[string](android.PREORDER, directAndroidMkSharedLibs, transitiveAndroidMkSharedLibs) |
| 1432 | |
| 1433 | var rlibDepFiles RustLibraries |
| 1434 | for _, dep := range directRlibDeps { |
| 1435 | rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()}) |
| 1436 | } |
| 1437 | var dylibDepFiles RustLibraries |
| 1438 | for _, dep := range directDylibDeps { |
| 1439 | dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()}) |
| 1440 | } |
| 1441 | var procMacroDepFiles RustLibraries |
| 1442 | for _, dep := range directProcMacroDeps { |
| 1443 | procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()}) |
| 1444 | } |
| 1445 | |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1446 | var staticLibDepFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1447 | for _, dep := range directStaticLibDeps { |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1448 | staticLibDepFiles = append(staticLibDepFiles, dep.OutputFile().Path()) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1451 | var sharedLibFiles android.Paths |
| 1452 | var sharedLibDepFiles android.Paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1453 | for _, dep := range directSharedLibDeps { |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1454 | sharedLibFiles = append(sharedLibFiles, dep.SharedLibrary) |
Jiyong Park | 7d55b61 | 2021-06-11 17:22:09 +0900 | [diff] [blame] | 1455 | if dep.TableOfContents.Valid() { |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1456 | sharedLibDepFiles = append(sharedLibDepFiles, dep.TableOfContents.Path()) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1457 | } else { |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1458 | sharedLibDepFiles = append(sharedLibDepFiles, dep.SharedLibrary) |
Ivan Lozano | ec6e991 | 2021-01-21 15:23:29 -0500 | [diff] [blame] | 1459 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1462 | var srcProviderDepFiles android.Paths |
| 1463 | for _, dep := range directSrcProvidersDeps { |
| 1464 | srcs, _ := dep.OutputFiles("") |
| 1465 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 1466 | } |
| 1467 | for _, dep := range directSrcDeps { |
| 1468 | srcs := dep.Srcs() |
| 1469 | srcProviderDepFiles = append(srcProviderDepFiles, srcs...) |
| 1470 | } |
| 1471 | |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1472 | depPaths.RLibs = append(depPaths.RLibs, rlibDepFiles...) |
| 1473 | depPaths.DyLibs = append(depPaths.DyLibs, dylibDepFiles...) |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1474 | depPaths.SharedLibs = append(depPaths.SharedLibs, sharedLibFiles...) |
| 1475 | depPaths.SharedLibDeps = append(depPaths.SharedLibDeps, sharedLibDepFiles...) |
| 1476 | depPaths.StaticLibs = append(depPaths.StaticLibs, staticLibDepFiles...) |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1477 | depPaths.ProcMacros = append(depPaths.ProcMacros, procMacroDepFiles...) |
Ivan Lozano | 07cbaf4 | 2020-07-22 16:09:13 -0400 | [diff] [blame] | 1478 | depPaths.SrcDeps = append(depPaths.SrcDeps, srcProviderDepFiles...) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1479 | |
| 1480 | // Dedup exported flags from dependencies |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1481 | depPaths.linkDirs = android.FirstUniqueStrings(depPaths.linkDirs) |
Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 1482 | depPaths.linkObjects = android.FirstUniqueStrings(depPaths.linkObjects) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1483 | depPaths.depFlags = android.FirstUniqueStrings(depPaths.depFlags) |
Ivan Lozano | 45901ed | 2020-07-24 16:05:01 -0400 | [diff] [blame] | 1484 | depPaths.depClangFlags = android.FirstUniqueStrings(depPaths.depClangFlags) |
| 1485 | depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths) |
| 1486 | depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1487 | |
| 1488 | return depPaths |
| 1489 | } |
| 1490 | |
Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 1491 | func (mod *Module) InstallInData() bool { |
| 1492 | if mod.compiler == nil { |
| 1493 | return false |
| 1494 | } |
| 1495 | return mod.compiler.inData() |
| 1496 | } |
| 1497 | |
Matthew Maurer | 9f59e8d | 2021-08-19 13:10:05 -0700 | [diff] [blame] | 1498 | func (mod *Module) InstallInRamdisk() bool { |
| 1499 | return mod.InRamdisk() |
| 1500 | } |
| 1501 | |
| 1502 | func (mod *Module) InstallInVendorRamdisk() bool { |
| 1503 | return mod.InVendorRamdisk() |
| 1504 | } |
| 1505 | |
| 1506 | func (mod *Module) InstallInRecovery() bool { |
| 1507 | return mod.InRecovery() |
| 1508 | } |
| 1509 | |
Wen-yi Chu | 41326c1 | 2023-09-22 03:58:59 +0000 | [diff] [blame] | 1510 | func linkPathFromFilePath(filepath android.Path) string { |
| 1511 | return strings.Split(filepath.String(), filepath.Base())[0] |
| 1512 | } |
| 1513 | |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1514 | // usePublicApi returns true if the rust variant should link against NDK (publicapi) |
| 1515 | func (r *Module) usePublicApi() bool { |
| 1516 | return r.Device() && r.UseSdk() |
| 1517 | } |
| 1518 | |
| 1519 | // useVendorApi returns true if the rust variant should link against LLNDK (vendorapi) |
| 1520 | func (r *Module) useVendorApi() bool { |
| 1521 | return r.Device() && (r.InVendor() || r.InProduct()) |
| 1522 | } |
| 1523 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1524 | func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { |
| 1525 | ctx := &depsContext{ |
| 1526 | BottomUpMutatorContext: actx, |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1527 | } |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1528 | |
| 1529 | deps := mod.deps(ctx) |
Colin Cross | 3146c5c | 2020-09-30 15:34:40 -0700 | [diff] [blame] | 1530 | var commonDepVariations []blueprint.Variation |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1531 | var snapshotInfo *cc.SnapshotInfo |
| 1532 | |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1533 | apiImportInfo := cc.GetApiImports(mod, actx) |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1534 | if mod.usePublicApi() || mod.useVendorApi() { |
| 1535 | for idx, lib := range deps.SharedLibs { |
| 1536 | deps.SharedLibs[idx] = cc.GetReplaceModuleName(lib, apiImportInfo.SharedLibs) |
| 1537 | } |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1538 | } |
| 1539 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1540 | if ctx.Os() == android.Android { |
| 1541 | deps.SharedLibs, _ = cc.RewriteLibs(mod, &snapshotInfo, actx, ctx.Config(), deps.SharedLibs) |
| 1542 | } |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1543 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1544 | stdLinkage := "dylib-std" |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1545 | if mod.compiler.stdLinkage(ctx) == RlibLinkage { |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1546 | stdLinkage = "rlib-std" |
| 1547 | } |
| 1548 | |
| 1549 | rlibDepVariations := commonDepVariations |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1550 | |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1551 | if lib, ok := mod.compiler.(libraryInterface); !ok || !lib.sysroot() { |
| 1552 | rlibDepVariations = append(rlibDepVariations, |
| 1553 | blueprint.Variation{Mutator: "rust_stdlinkage", Variation: stdLinkage}) |
| 1554 | } |
| 1555 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1556 | // rlibs |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1557 | rlibDepVariations = append(rlibDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: rlibVariation}) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1558 | for _, lib := range deps.Rlibs { |
| 1559 | depTag := rlibDepTag |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1560 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1561 | |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1562 | actx.AddVariationDependencies(rlibDepVariations, depTag, lib) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1563 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1564 | |
| 1565 | // dylibs |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1566 | dylibDepVariations := append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: dylibVariation}) |
| 1567 | for _, lib := range deps.Dylibs { |
| 1568 | addDylibDependency(actx, lib, mod, &snapshotInfo, dylibDepVariations, dylibDepTag) |
| 1569 | } |
Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 1570 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1571 | // rustlibs |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1572 | if deps.Rustlibs != nil { |
| 1573 | if !mod.compiler.Disabled() { |
| 1574 | for _, lib := range deps.Rustlibs { |
| 1575 | autoDep := mod.compiler.(autoDeppable).autoDep(ctx) |
| 1576 | if autoDep.depTag == rlibDepTag { |
| 1577 | // Handle the rlib deptag case |
Inseob Kim | cd2b46a | 2023-03-31 18:04:12 +0900 | [diff] [blame] | 1578 | addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations) |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1579 | } else { |
| 1580 | // autoDep.depTag is a dylib depTag. Not all rustlibs may be available as a dylib however. |
| 1581 | // Check for the existence of the dylib deptag variant. Select it if available, |
| 1582 | // otherwise select the rlib variant. |
| 1583 | autoDepVariations := append(commonDepVariations, |
| 1584 | blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}) |
| 1585 | |
| 1586 | replacementLib := cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Dylibs) |
| 1587 | |
| 1588 | if actx.OtherModuleDependencyVariantExists(autoDepVariations, replacementLib) { |
| 1589 | addDylibDependency(actx, lib, mod, &snapshotInfo, autoDepVariations, autoDep.depTag) |
| 1590 | } else { |
| 1591 | // If there's no dylib dependency available, try to add the rlib dependency instead. |
| 1592 | addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations) |
| 1593 | } |
| 1594 | } |
| 1595 | } |
| 1596 | } else if _, ok := mod.sourceProvider.(*protobufDecorator); ok { |
| 1597 | for _, lib := range deps.Rustlibs { |
| 1598 | replacementLib := cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Dylibs) |
| 1599 | srcProviderVariations := append(commonDepVariations, |
| 1600 | blueprint.Variation{Mutator: "rust_libraries", Variation: "source"}) |
| 1601 | |
| 1602 | if actx.OtherModuleDependencyVariantExists(srcProviderVariations, replacementLib) { |
| 1603 | actx.AddVariationDependencies(srcProviderVariations, sourceDepTag, lib) |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1604 | } |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1605 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1606 | } |
Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 1607 | } |
Ivan Lozano | d106efe | 2023-09-21 23:30:26 -0400 | [diff] [blame] | 1608 | |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1609 | // stdlibs |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1610 | if deps.Stdlibs != nil { |
Ivan Lozano | dd05547 | 2020-09-28 13:22:45 -0400 | [diff] [blame] | 1611 | if mod.compiler.stdLinkage(ctx) == RlibLinkage { |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1612 | for _, lib := range deps.Stdlibs { |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1613 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1614 | actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...), |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1615 | rlibDepTag, lib) |
Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 1616 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1617 | } else { |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1618 | for _, lib := range deps.Stdlibs { |
| 1619 | addDylibDependency(actx, lib, mod, &snapshotInfo, dylibDepVariations, dylibDepTag) |
| 1620 | } |
Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 1621 | } |
| 1622 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1623 | |
| 1624 | for _, lib := range deps.SharedLibs { |
| 1625 | depTag := cc.SharedDepTag() |
| 1626 | name, version := cc.StubsLibNameAndVersion(lib) |
| 1627 | |
| 1628 | variations := []blueprint.Variation{ |
| 1629 | {Mutator: "link", Variation: "shared"}, |
| 1630 | } |
Spandan Das | 604f376 | 2023-03-16 22:51:40 +0000 | [diff] [blame] | 1631 | // For core variant, add a dep on the implementation (if it exists) and its .apiimport (if it exists) |
| 1632 | // GenerateAndroidBuildActions will pick the correct impl/stub based on the api_domain boundary |
| 1633 | if _, ok := apiImportInfo.ApexSharedLibs[name]; !ok || ctx.OtherModuleExists(name) { |
| 1634 | cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, name, version, false) |
| 1635 | } |
| 1636 | |
| 1637 | if apiLibraryName, ok := apiImportInfo.ApexSharedLibs[name]; ok { |
| 1638 | cc.AddSharedLibDependenciesWithVersions(ctx, mod, variations, depTag, apiLibraryName, version, false) |
| 1639 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | for _, lib := range deps.WholeStaticLibs { |
| 1643 | depTag := cc.StaticDepTag(true) |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1644 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1645 | |
| 1646 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1647 | {Mutator: "link", Variation: "static"}, |
| 1648 | }, depTag, lib) |
| 1649 | } |
| 1650 | |
| 1651 | for _, lib := range deps.StaticLibs { |
| 1652 | depTag := cc.StaticDepTag(false) |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1653 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).StaticLibs) |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1654 | |
| 1655 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1656 | {Mutator: "link", Variation: "static"}, |
| 1657 | }, depTag, lib) |
| 1658 | } |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1659 | |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 1660 | actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...) |
| 1661 | |
Colin Cross | 565cafd | 2020-09-25 18:47:38 -0700 | [diff] [blame] | 1662 | crtVariations := cc.GetCrtVariations(ctx, mod) |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 1663 | for _, crt := range deps.CrtBegin { |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1664 | actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1665 | cc.GetReplaceModuleName(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects)) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1666 | } |
Colin Cross | fe605e1 | 2022-01-23 20:46:16 -0800 | [diff] [blame] | 1667 | for _, crt := range deps.CrtEnd { |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1668 | actx.AddVariationDependencies(crtVariations, cc.CrtEndDepTag, |
Kiyoung Kim | 487689e | 2022-07-26 09:48:22 +0900 | [diff] [blame] | 1669 | cc.GetReplaceModuleName(crt, cc.GetSnapshot(mod, &snapshotInfo, actx).Objects)) |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 1670 | } |
| 1671 | |
Ivan Lozano | c564d2d | 2020-08-04 15:43:37 -0400 | [diff] [blame] | 1672 | if mod.sourceProvider != nil { |
| 1673 | if bindgen, ok := mod.sourceProvider.(*bindgenDecorator); ok && |
| 1674 | bindgen.Properties.Custom_bindgen != "" { |
| 1675 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), customBindgenDepTag, |
| 1676 | bindgen.Properties.Custom_bindgen) |
| 1677 | } |
| 1678 | } |
Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 1679 | |
Ivan Lozano | 4e5f07d | 2021-11-04 14:09:38 -0400 | [diff] [blame] | 1680 | actx.AddVariationDependencies([]blueprint.Variation{ |
| 1681 | {Mutator: "link", Variation: "shared"}, |
| 1682 | }, dataLibDepTag, deps.DataLibs...) |
| 1683 | |
| 1684 | actx.AddVariationDependencies(nil, dataBinDepTag, deps.DataBins...) |
| 1685 | |
Ivan Lozano | 5ca5ef6 | 2019-09-23 10:10:40 -0700 | [diff] [blame] | 1686 | // 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] | 1687 | actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...) |
Vinh Tran | cde1016 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 1688 | |
| 1689 | mod.afdo.addDep(ctx, actx) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1692 | // addRlibDependency will add an rlib dependency, rewriting to the snapshot library if available. |
Inseob Kim | cd2b46a | 2023-03-31 18:04:12 +0900 | [diff] [blame] | 1693 | func addRlibDependency(actx android.BottomUpMutatorContext, lib string, mod *Module, snapshotInfo **cc.SnapshotInfo, variations []blueprint.Variation) { |
| 1694 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, snapshotInfo, actx).Rlibs) |
Ivan Lozano | 2d40763 | 2022-04-07 12:59:11 -0400 | [diff] [blame] | 1695 | actx.AddVariationDependencies(variations, rlibDepTag, lib) |
| 1696 | } |
| 1697 | |
Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 1698 | func addDylibDependency(actx android.BottomUpMutatorContext, lib string, mod *Module, snapshotInfo **cc.SnapshotInfo, variations []blueprint.Variation, depTag dependencyTag) { |
| 1699 | lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, snapshotInfo, actx).Dylibs) |
| 1700 | actx.AddVariationDependencies(variations, depTag, lib) |
| 1701 | } |
| 1702 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1703 | func BeginMutator(ctx android.BottomUpMutatorContext) { |
| 1704 | if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() { |
| 1705 | mod.beginMutator(ctx) |
| 1706 | } |
| 1707 | } |
| 1708 | |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1709 | func (mod *Module) beginMutator(actx android.BottomUpMutatorContext) { |
| 1710 | ctx := &baseModuleContext{ |
| 1711 | BaseModuleContext: actx, |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1712 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 1713 | |
| 1714 | mod.begin(ctx) |
| 1715 | } |
| 1716 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1717 | func (mod *Module) Name() string { |
| 1718 | name := mod.ModuleBase.Name() |
| 1719 | if p, ok := mod.compiler.(interface { |
| 1720 | Name(string) string |
| 1721 | }); ok { |
| 1722 | name = p.Name(name) |
| 1723 | } |
| 1724 | return name |
| 1725 | } |
| 1726 | |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1727 | func (mod *Module) disableClippy() { |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1728 | if mod.clippy != nil { |
Thiébaud Weksteen | 9e8451e | 2020-08-13 12:55:59 +0200 | [diff] [blame] | 1729 | mod.clippy.Properties.Clippy_lints = proptools.StringPtr("none") |
Ivan Lozano | 32267c8 | 2020-08-04 16:27:16 -0400 | [diff] [blame] | 1730 | } |
| 1731 | } |
| 1732 | |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1733 | var _ android.HostToolProvider = (*Module)(nil) |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1734 | var _ snapshot.RelativeInstallPath = (*Module)(nil) |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1735 | |
| 1736 | func (mod *Module) HostToolPath() android.OptionalPath { |
| 1737 | if !mod.Host() { |
| 1738 | return android.OptionalPath{} |
| 1739 | } |
Chih-Hung Hsieh | a756270 | 2020-08-10 21:50:43 -0700 | [diff] [blame] | 1740 | if binary, ok := mod.compiler.(*binaryDecorator); ok { |
| 1741 | return android.OptionalPathForPath(binary.baseCompiler.path) |
Ivan Lozano | 872d579 | 2022-03-23 17:31:39 -0400 | [diff] [blame] | 1742 | } else if pm, ok := mod.compiler.(*procMacroDecorator); ok { |
| 1743 | // Even though proc-macros aren't strictly "tools", since they target the compiler |
| 1744 | // and act as compiler plugins, we treat them similarly. |
| 1745 | return android.OptionalPathForPath(pm.baseCompiler.path) |
Chih-Hung Hsieh | 5c4e489 | 2020-05-15 17:36:30 -0700 | [diff] [blame] | 1746 | } |
| 1747 | return android.OptionalPath{} |
| 1748 | } |
| 1749 | |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1750 | var _ android.ApexModule = (*Module)(nil) |
| 1751 | |
Ivan Lozano | a91ba25 | 2022-01-11 12:02:06 -0500 | [diff] [blame] | 1752 | func (mod *Module) MinSdkVersion() string { |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1753 | return String(mod.Properties.Min_sdk_version) |
| 1754 | } |
| 1755 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1756 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1757 | func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { |
Ivan Lozano | a91ba25 | 2022-01-11 12:02:06 -0500 | [diff] [blame] | 1758 | minSdkVersion := mod.MinSdkVersion() |
Ivan Lozano | 3e9f9e4 | 2020-12-04 15:05:43 -0500 | [diff] [blame] | 1759 | if minSdkVersion == "apex_inherit" { |
| 1760 | return nil |
| 1761 | } |
| 1762 | if minSdkVersion == "" { |
| 1763 | return fmt.Errorf("min_sdk_version is not specificed") |
| 1764 | } |
| 1765 | |
| 1766 | // Not using nativeApiLevelFromUser because the context here is not |
| 1767 | // necessarily a native context. |
| 1768 | ver, err := android.ApiLevelFromUser(ctx, minSdkVersion) |
| 1769 | if err != nil { |
| 1770 | return err |
| 1771 | } |
| 1772 | |
| 1773 | if ver.GreaterThan(sdkVersion) { |
| 1774 | return fmt.Errorf("newer SDK(%v)", ver) |
| 1775 | } |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1776 | return nil |
| 1777 | } |
| 1778 | |
Jiyong Park | 45bf82e | 2020-12-15 22:29:02 +0900 | [diff] [blame] | 1779 | // Implements android.ApexModule |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1780 | func (mod *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool { |
| 1781 | depTag := ctx.OtherModuleDependencyTag(dep) |
| 1782 | |
| 1783 | if ccm, ok := dep.(*cc.Module); ok { |
| 1784 | if ccm.HasStubsVariants() { |
| 1785 | if cc.IsSharedDepTag(depTag) { |
| 1786 | // dynamic dep to a stubs lib crosses APEX boundary |
| 1787 | return false |
| 1788 | } |
| 1789 | if cc.IsRuntimeDepTag(depTag) { |
| 1790 | // runtime dep to a stubs lib also crosses APEX boundary |
| 1791 | return false |
| 1792 | } |
| 1793 | |
| 1794 | if cc.IsHeaderDepTag(depTag) { |
| 1795 | return false |
| 1796 | } |
| 1797 | } |
| 1798 | if mod.Static() && cc.IsSharedDepTag(depTag) { |
| 1799 | // shared_lib dependency from a static lib is considered as crossing |
| 1800 | // the APEX boundary because the dependency doesn't actually is |
| 1801 | // linked; the dependency is used only during the compilation phase. |
| 1802 | return false |
| 1803 | } |
| 1804 | } |
| 1805 | |
Matthew Maurer | 581b6d8 | 2022-09-29 16:46:25 -0700 | [diff] [blame] | 1806 | if depTag == procMacroDepTag || depTag == customBindgenDepTag { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1807 | return false |
| 1808 | } |
| 1809 | |
| 1810 | return true |
| 1811 | } |
| 1812 | |
| 1813 | // Overrides ApexModule.IsInstallabeToApex() |
| 1814 | func (mod *Module) IsInstallableToApex() bool { |
| 1815 | if mod.compiler != nil { |
Ivan Lozano | 45e0e5b | 2021-11-13 07:42:36 -0500 | [diff] [blame] | 1816 | if lib, ok := mod.compiler.(libraryInterface); ok && (lib.shared() || lib.dylib()) { |
Jiyong Park | 99644e9 | 2020-11-17 22:21:02 +0900 | [diff] [blame] | 1817 | return true |
| 1818 | } |
| 1819 | if _, ok := mod.compiler.(*binaryDecorator); ok { |
| 1820 | return true |
| 1821 | } |
| 1822 | } |
| 1823 | return false |
| 1824 | } |
| 1825 | |
Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 1826 | // If a library file has a "lib" prefix, extract the library name without the prefix. |
| 1827 | func libNameFromFilePath(filepath android.Path) (string, bool) { |
| 1828 | libName := strings.TrimSuffix(filepath.Base(), filepath.Ext()) |
| 1829 | if strings.HasPrefix(libName, "lib") { |
| 1830 | libName = libName[3:] |
| 1831 | return libName, true |
| 1832 | } |
| 1833 | return "", false |
| 1834 | } |
| 1835 | |
Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 1836 | func kytheExtractRustFactory() android.Singleton { |
| 1837 | return &kytheExtractRustSingleton{} |
| 1838 | } |
| 1839 | |
| 1840 | type kytheExtractRustSingleton struct { |
| 1841 | } |
| 1842 | |
| 1843 | func (k kytheExtractRustSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 1844 | var xrefTargets android.Paths |
| 1845 | ctx.VisitAllModules(func(module android.Module) { |
| 1846 | if rustModule, ok := module.(xref); ok { |
| 1847 | xrefTargets = append(xrefTargets, rustModule.XrefRustFiles()...) |
| 1848 | } |
| 1849 | }) |
| 1850 | if len(xrefTargets) > 0 { |
| 1851 | ctx.Phony("xref_rust", xrefTargets...) |
| 1852 | } |
| 1853 | } |
| 1854 | |
Jihoon Kang | f78a890 | 2022-09-01 22:47:07 +0000 | [diff] [blame] | 1855 | func (c *Module) Partition() string { |
| 1856 | return "" |
| 1857 | } |
| 1858 | |
Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 1859 | func (m *Module) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { |
Vinh Tran | bcb5f57 | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 1860 | if ctx.ModuleType() == "rust_library_host" || ctx.ModuleType() == "rust_library" { |
| 1861 | libraryBp2build(ctx, m) |
Vinh Tran | b4bb20f | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 1862 | } else if ctx.ModuleType() == "rust_proc_macro" { |
| 1863 | procMacroBp2build(ctx, m) |
Vinh Tran | 093a57e | 2023-08-24 12:10:49 -0400 | [diff] [blame] | 1864 | } else if ctx.ModuleType() == "rust_binary_host" { |
| 1865 | binaryBp2build(ctx, m) |
Vinh Tran | 47faaad | 2023-09-25 14:47:19 -0400 | [diff] [blame] | 1866 | } else if ctx.ModuleType() == "rust_protobuf_host" || ctx.ModuleType() == "rust_protobuf" { |
Vinh Tran | 0c4b9ec | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 1867 | protoLibraryBp2build(ctx, m) |
Vinh Tran | 7515994 | 2023-10-17 16:28:04 -0400 | [diff] [blame] | 1868 | } else if ctx.ModuleType() == "rust_ffi_static" { |
| 1869 | ffiStaticBp2build(ctx, m) |
Vinh Tran | bcb5f57 | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 1870 | } else { |
| 1871 | ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "") |
| 1872 | } |
| 1873 | } |
| 1874 | |
Vinh Tran | b4bb20f | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 1875 | // This is a workaround by assuming the conventions that rust crate repos are structured |
Vinh Tran | c1a6cee | 2023-08-24 12:10:49 -0400 | [diff] [blame] | 1876 | // while waiting for the sandboxing work to complete. |
Vinh Tran | b4bb20f | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 1877 | // TODO(b/297344471): When crate_root prop is set which enforces inputs sandboxing, |
| 1878 | // always use `srcs` and `compile_data` props to generate `srcs` and `compile_data` attributes |
| 1879 | // instead of using globs. |
Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 1880 | func srcsAndCompileDataAttrs(ctx android.Bp2buildMutatorContext, c baseCompiler) (bazel.LabelList, bazel.LabelList) { |
Vinh Tran | b4bb20f | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 1881 | var srcs bazel.LabelList |
| 1882 | var compileData bazel.LabelList |
| 1883 | |
| 1884 | if c.Properties.Srcs[0] == "src/lib.rs" { |
| 1885 | srcs = android.BazelLabelForModuleSrc(ctx, []string{"src/**/*.rs"}) |
| 1886 | compileData = android.BazelLabelForModuleSrc( |
| 1887 | ctx, |
| 1888 | []string{ |
| 1889 | "src/**/*.proto", |
| 1890 | "examples/**/*.rs", |
| 1891 | "**/*.md", |
| 1892 | }, |
| 1893 | ) |
| 1894 | } else { |
| 1895 | srcs = android.BazelLabelForModuleSrc(ctx, c.Properties.Srcs) |
| 1896 | } |
| 1897 | |
| 1898 | return srcs, compileData |
| 1899 | } |
| 1900 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 1901 | var Bool = proptools.Bool |
| 1902 | var BoolDefault = proptools.BoolDefault |
| 1903 | var String = proptools.String |
| 1904 | var StringPtr = proptools.StringPtr |
Ivan Lozano | 4384568 | 2020-07-09 21:03:28 -0400 | [diff] [blame] | 1905 | |
| 1906 | var _ android.OutputFileProducer = (*Module)(nil) |