| 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 ( | 
| Matthew Maurer | a28404a | 2023-11-20 23:33:28 +0000 | [diff] [blame] | 18 | "errors" | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 19 | "fmt" | 
| Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 20 | "regexp" | 
|  | 21 | "strings" | 
|  | 22 |  | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 23 | "github.com/google/blueprint" | 
|  | 24 |  | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 25 | "android/soong/android" | 
| Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 26 | "android/soong/cc" | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 27 | ) | 
|  | 28 |  | 
| Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 29 | var ( | 
| Ivan Lozano | 4df0257 | 2023-06-15 14:21:09 -0400 | [diff] [blame] | 30 | RlibStdlibSuffix = ".rlib-std" | 
| Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 31 | ) | 
|  | 32 |  | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 33 | func init() { | 
|  | 34 | android.RegisterModuleType("rust_library", RustLibraryFactory) | 
|  | 35 | android.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory) | 
|  | 36 | android.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory) | 
|  | 37 | android.RegisterModuleType("rust_library_host", RustLibraryHostFactory) | 
|  | 38 | android.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory) | 
|  | 39 | android.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory) | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 40 | android.RegisterModuleType("rust_ffi", RustFFIFactory) | 
|  | 41 | android.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory) | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 42 | android.RegisterModuleType("rust_ffi_rlib", RustFFIRlibFactory) | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 43 | android.RegisterModuleType("rust_ffi_host", RustFFIHostFactory) | 
|  | 44 | android.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory) | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 45 | android.RegisterModuleType("rust_ffi_host_rlib", RustFFIRlibHostFactory) | 
|  | 46 |  | 
|  | 47 | // TODO: Remove when all instances of rust_ffi_static have been switched to rust_ffi_rlib | 
| Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 48 | // Alias rust_ffi_static to the rust_ffi_rlib factory | 
|  | 49 | android.RegisterModuleType("rust_ffi_static", RustFFIRlibFactory) | 
|  | 50 | android.RegisterModuleType("rust_ffi_host_static", RustFFIRlibHostFactory) | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 51 | } | 
|  | 52 |  | 
|  | 53 | type VariantLibraryProperties struct { | 
| Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 54 | Enabled *bool    `android:"arch_variant"` | 
|  | 55 | Srcs    []string `android:"path,arch_variant"` | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 56 | } | 
|  | 57 |  | 
|  | 58 | type LibraryCompilerProperties struct { | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 59 | Rlib   VariantLibraryProperties `android:"arch_variant"` | 
|  | 60 | Dylib  VariantLibraryProperties `android:"arch_variant"` | 
|  | 61 | Shared VariantLibraryProperties `android:"arch_variant"` | 
|  | 62 | Static VariantLibraryProperties `android:"arch_variant"` | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 63 |  | 
| Ivan Lozano | f033ca6 | 2024-03-21 13:43:14 -0400 | [diff] [blame] | 64 | // TODO: Remove this when all instances of Include_dirs have been removed from rust_ffi modules. | 
|  | 65 | // path to include directories to pass to cc_* modules, only relevant for static/shared variants (deprecated, use export_include_dirs instead). | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 66 | Include_dirs []string `android:"path,arch_variant"` | 
| Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 67 |  | 
| Ivan Lozano | f033ca6 | 2024-03-21 13:43:14 -0400 | [diff] [blame] | 68 | // path to include directories to export to cc_* modules, only relevant for static/shared variants. | 
|  | 69 | Export_include_dirs []string `android:"path,arch_variant"` | 
|  | 70 |  | 
| Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 71 | // Whether this library is part of the Rust toolchain sysroot. | 
|  | 72 | Sysroot *bool | 
| Ashutosh Agarwal | 46e4fad | 2024-08-27 17:13:12 +0000 | [diff] [blame] | 73 |  | 
|  | 74 | // Exclude this rust_ffi target from being included in APEXes. | 
|  | 75 | // TODO(b/362509506): remove this once stubs are properly supported by rust_ffi targets. | 
|  | 76 | Apex_exclude *bool | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 77 | } | 
|  | 78 |  | 
|  | 79 | type LibraryMutatedProperties struct { | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 80 | // Build a dylib variant | 
|  | 81 | BuildDylib bool `blueprint:"mutated"` | 
|  | 82 | // Build an rlib variant | 
|  | 83 | BuildRlib bool `blueprint:"mutated"` | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 84 | // Build a shared library variant | 
|  | 85 | BuildShared bool `blueprint:"mutated"` | 
|  | 86 | // Build a static library variant | 
|  | 87 | BuildStatic bool `blueprint:"mutated"` | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 88 |  | 
|  | 89 | // This variant is a dylib | 
|  | 90 | VariantIsDylib bool `blueprint:"mutated"` | 
|  | 91 | // This variant is an rlib | 
|  | 92 | VariantIsRlib bool `blueprint:"mutated"` | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 93 | // This variant is a shared library | 
|  | 94 | VariantIsShared bool `blueprint:"mutated"` | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 95 | // This variant is a source provider | 
|  | 96 | VariantIsSource bool `blueprint:"mutated"` | 
| Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 97 |  | 
|  | 98 | // This variant is disabled and should not be compiled | 
|  | 99 | // (used for SourceProvider variants that produce only source) | 
|  | 100 | VariantIsDisabled bool `blueprint:"mutated"` | 
| Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 101 |  | 
|  | 102 | // Whether this library variant should be link libstd via rlibs | 
|  | 103 | VariantIsStaticStd bool `blueprint:"mutated"` | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 104 | } | 
|  | 105 |  | 
|  | 106 | type libraryDecorator struct { | 
|  | 107 | *baseCompiler | 
| Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 108 | *flagExporter | 
| Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 109 | stripper Stripper | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 110 |  | 
| Ivan Lozano | 8a23fa4 | 2020-06-16 10:26:57 -0400 | [diff] [blame] | 111 | Properties        LibraryCompilerProperties | 
|  | 112 | MutatedProperties LibraryMutatedProperties | 
|  | 113 | includeDirs       android.Paths | 
| Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 114 | sourceProvider    SourceProvider | 
| Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 115 |  | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 116 | isFFI bool | 
|  | 117 |  | 
| Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 118 | // table-of-contents file for cdylib crates to optimize out relinking when possible | 
|  | 119 | tocFile android.OptionalPath | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 120 | } | 
|  | 121 |  | 
|  | 122 | type libraryInterface interface { | 
|  | 123 | rlib() bool | 
|  | 124 | dylib() bool | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 125 | static() bool | 
|  | 126 | shared() bool | 
| Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 127 | sysroot() bool | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 128 | source() bool | 
| Ashutosh Agarwal | 46e4fad | 2024-08-27 17:13:12 +0000 | [diff] [blame] | 129 | apexExclude() bool | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 130 |  | 
|  | 131 | // Returns true if the build options for the module have selected a particular build type | 
|  | 132 | buildRlib() bool | 
|  | 133 | buildDylib() bool | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 134 | buildShared() bool | 
|  | 135 | buildStatic() bool | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 136 |  | 
|  | 137 | // Sets a particular variant type | 
|  | 138 | setRlib() | 
|  | 139 | setDylib() | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 140 | setShared() | 
|  | 141 | setStatic() | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 142 | setSource() | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 143 |  | 
| Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 144 | // libstd linkage functions | 
|  | 145 | rlibStd() bool | 
| Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 146 | setRlibStd() | 
|  | 147 | setDylibStd() | 
|  | 148 |  | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 149 | // Build a specific library variant | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 150 | BuildOnlyFFI() | 
|  | 151 | BuildOnlyRust() | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 152 | BuildOnlyRlib() | 
|  | 153 | BuildOnlyDylib() | 
|  | 154 | BuildOnlyStatic() | 
|  | 155 | BuildOnlyShared() | 
| Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 156 |  | 
|  | 157 | toc() android.OptionalPath | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 158 |  | 
|  | 159 | isFFILibrary() bool | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 160 | } | 
|  | 161 |  | 
| Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 162 | func (library *libraryDecorator) nativeCoverage() bool { | 
|  | 163 | return true | 
|  | 164 | } | 
|  | 165 |  | 
| Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 166 | func (library *libraryDecorator) toc() android.OptionalPath { | 
|  | 167 | return library.tocFile | 
|  | 168 | } | 
|  | 169 |  | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 170 | func (library *libraryDecorator) rlib() bool { | 
|  | 171 | return library.MutatedProperties.VariantIsRlib | 
|  | 172 | } | 
|  | 173 |  | 
| Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 174 | func (library *libraryDecorator) sysroot() bool { | 
|  | 175 | return Bool(library.Properties.Sysroot) | 
|  | 176 | } | 
|  | 177 |  | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 178 | func (library *libraryDecorator) dylib() bool { | 
|  | 179 | return library.MutatedProperties.VariantIsDylib | 
|  | 180 | } | 
|  | 181 |  | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 182 | func (library *libraryDecorator) shared() bool { | 
|  | 183 | return library.MutatedProperties.VariantIsShared | 
|  | 184 | } | 
|  | 185 |  | 
|  | 186 | func (library *libraryDecorator) static() bool { | 
| Colin Cross | 17f9dc5 | 2024-07-01 20:05:54 -0700 | [diff] [blame] | 187 | return false | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 188 | } | 
|  | 189 |  | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 190 | func (library *libraryDecorator) source() bool { | 
|  | 191 | return library.MutatedProperties.VariantIsSource | 
|  | 192 | } | 
|  | 193 |  | 
| Ashutosh Agarwal | 46e4fad | 2024-08-27 17:13:12 +0000 | [diff] [blame] | 194 | func (library *libraryDecorator) apexExclude() bool { | 
|  | 195 | return Bool(library.Properties.Apex_exclude) | 
|  | 196 | } | 
|  | 197 |  | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 198 | func (library *libraryDecorator) buildRlib() bool { | 
|  | 199 | return library.MutatedProperties.BuildRlib && BoolDefault(library.Properties.Rlib.Enabled, true) | 
|  | 200 | } | 
|  | 201 |  | 
|  | 202 | func (library *libraryDecorator) buildDylib() bool { | 
|  | 203 | return library.MutatedProperties.BuildDylib && BoolDefault(library.Properties.Dylib.Enabled, true) | 
|  | 204 | } | 
|  | 205 |  | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 206 | func (library *libraryDecorator) buildShared() bool { | 
|  | 207 | return library.MutatedProperties.BuildShared && BoolDefault(library.Properties.Shared.Enabled, true) | 
|  | 208 | } | 
|  | 209 |  | 
|  | 210 | func (library *libraryDecorator) buildStatic() bool { | 
|  | 211 | return library.MutatedProperties.BuildStatic && BoolDefault(library.Properties.Static.Enabled, true) | 
|  | 212 | } | 
|  | 213 |  | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 214 | func (library *libraryDecorator) setRlib() { | 
|  | 215 | library.MutatedProperties.VariantIsRlib = true | 
|  | 216 | library.MutatedProperties.VariantIsDylib = false | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 217 | library.MutatedProperties.VariantIsShared = false | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 218 | } | 
|  | 219 |  | 
|  | 220 | func (library *libraryDecorator) setDylib() { | 
|  | 221 | library.MutatedProperties.VariantIsRlib = false | 
|  | 222 | library.MutatedProperties.VariantIsDylib = true | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 223 | library.MutatedProperties.VariantIsShared = false | 
|  | 224 | } | 
|  | 225 |  | 
| Ivan Lozano | 3149e6e | 2021-06-01 15:09:53 -0400 | [diff] [blame] | 226 | func (library *libraryDecorator) rlibStd() bool { | 
|  | 227 | return library.MutatedProperties.VariantIsStaticStd | 
|  | 228 | } | 
|  | 229 |  | 
| Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 230 | func (library *libraryDecorator) setRlibStd() { | 
|  | 231 | library.MutatedProperties.VariantIsStaticStd = true | 
|  | 232 | } | 
|  | 233 |  | 
|  | 234 | func (library *libraryDecorator) setDylibStd() { | 
|  | 235 | library.MutatedProperties.VariantIsStaticStd = false | 
|  | 236 | } | 
|  | 237 |  | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 238 | func (library *libraryDecorator) setShared() { | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 239 | library.MutatedProperties.VariantIsShared = true | 
|  | 240 | library.MutatedProperties.VariantIsRlib = false | 
|  | 241 | library.MutatedProperties.VariantIsDylib = false | 
|  | 242 | } | 
|  | 243 |  | 
|  | 244 | func (library *libraryDecorator) setStatic() { | 
| Colin Cross | 17f9dc5 | 2024-07-01 20:05:54 -0700 | [diff] [blame] | 245 | panic(fmt.Errorf("static variant is not supported for rust modules, use the rlib variant instead")) | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 246 | } | 
|  | 247 |  | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 248 | func (library *libraryDecorator) setSource() { | 
|  | 249 | library.MutatedProperties.VariantIsSource = true | 
|  | 250 | } | 
|  | 251 |  | 
| Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 252 | func (library *libraryDecorator) autoDep(ctx android.BottomUpMutatorContext) autoDep { | 
| Ivan Lozano | add122a | 2023-07-13 11:01:41 -0400 | [diff] [blame] | 253 | if library.preferRlib() { | 
| Ivan Lozano | ea08613 | 2020-12-08 14:43:00 -0500 | [diff] [blame] | 254 | return rlibAutoDep | 
|  | 255 | } else if library.rlib() || library.static() { | 
| Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 256 | return rlibAutoDep | 
|  | 257 | } else if library.dylib() || library.shared() { | 
|  | 258 | return dylibAutoDep | 
|  | 259 | } else { | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 260 | panic(fmt.Errorf("autoDep called on library %q that has no enabled variants.", ctx.ModuleName())) | 
| Matthew Maurer | 0f003b1 | 2020-06-29 14:34:06 -0700 | [diff] [blame] | 261 | } | 
|  | 262 | } | 
|  | 263 |  | 
| Ivan Lozano | ea08613 | 2020-12-08 14:43:00 -0500 | [diff] [blame] | 264 | func (library *libraryDecorator) stdLinkage(ctx *depsContext) RustLinkage { | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 265 | if library.static() || library.MutatedProperties.VariantIsStaticStd || (library.rlib() && library.isFFILibrary()) { | 
| Ivan Lozano | ea08613 | 2020-12-08 14:43:00 -0500 | [diff] [blame] | 266 | return RlibLinkage | 
|  | 267 | } else if library.baseCompiler.preferRlib() { | 
|  | 268 | return RlibLinkage | 
|  | 269 | } | 
|  | 270 | return DefaultLinkage | 
|  | 271 | } | 
|  | 272 |  | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 273 | var _ compiler = (*libraryDecorator)(nil) | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 274 | var _ libraryInterface = (*libraryDecorator)(nil) | 
| Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 275 | var _ exportedFlagsProducer = (*libraryDecorator)(nil) | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 276 |  | 
| Martin Geisler | 67ec054 | 2022-11-18 12:08:55 +0100 | [diff] [blame] | 277 | // rust_library produces all Rust variants (rust_library_dylib and | 
|  | 278 | // rust_library_rlib). | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 279 | func RustLibraryFactory() android.Module { | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 280 | module, library := NewRustLibrary(android.HostAndDeviceSupported) | 
|  | 281 | library.BuildOnlyRust() | 
|  | 282 | return module.Init() | 
|  | 283 | } | 
|  | 284 |  | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 285 | // rust_ffi produces all FFI variants (rust_ffi_shared, rust_ffi_static, and | 
|  | 286 | // rust_ffi_rlib). | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 287 | func RustFFIFactory() android.Module { | 
|  | 288 | module, library := NewRustLibrary(android.HostAndDeviceSupported) | 
|  | 289 | library.BuildOnlyFFI() | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 290 | return module.Init() | 
|  | 291 | } | 
|  | 292 |  | 
| Martin Geisler | 67ec054 | 2022-11-18 12:08:55 +0100 | [diff] [blame] | 293 | // rust_library_dylib produces a Rust dylib (Rust crate type "dylib"). | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 294 | func RustLibraryDylibFactory() android.Module { | 
|  | 295 | module, library := NewRustLibrary(android.HostAndDeviceSupported) | 
|  | 296 | library.BuildOnlyDylib() | 
|  | 297 | return module.Init() | 
|  | 298 | } | 
|  | 299 |  | 
| Martin Geisler | 67ec054 | 2022-11-18 12:08:55 +0100 | [diff] [blame] | 300 | // rust_library_rlib produces an rlib (Rust crate type "rlib"). | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 301 | func RustLibraryRlibFactory() android.Module { | 
|  | 302 | module, library := NewRustLibrary(android.HostAndDeviceSupported) | 
|  | 303 | library.BuildOnlyRlib() | 
|  | 304 | return module.Init() | 
|  | 305 | } | 
|  | 306 |  | 
| Martin Geisler | 67ec054 | 2022-11-18 12:08:55 +0100 | [diff] [blame] | 307 | // rust_ffi_shared produces a shared library (Rust crate type | 
|  | 308 | // "cdylib"). | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 309 | func RustFFISharedFactory() android.Module { | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 310 | module, library := NewRustLibrary(android.HostAndDeviceSupported) | 
|  | 311 | library.BuildOnlyShared() | 
|  | 312 | return module.Init() | 
|  | 313 | } | 
|  | 314 |  | 
| Martin Geisler | 67ec054 | 2022-11-18 12:08:55 +0100 | [diff] [blame] | 315 | // rust_library_host produces all Rust variants for the host | 
|  | 316 | // (rust_library_dylib_host and rust_library_rlib_host). | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 317 | func RustLibraryHostFactory() android.Module { | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 318 | module, library := NewRustLibrary(android.HostSupported) | 
|  | 319 | library.BuildOnlyRust() | 
|  | 320 | return module.Init() | 
|  | 321 | } | 
|  | 322 |  | 
| Martin Geisler | 67ec054 | 2022-11-18 12:08:55 +0100 | [diff] [blame] | 323 | // rust_ffi_host produces all FFI variants for the host | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 324 | // (rust_ffi_rlib_host, rust_ffi_static_host, and rust_ffi_shared_host). | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 325 | func RustFFIHostFactory() android.Module { | 
|  | 326 | module, library := NewRustLibrary(android.HostSupported) | 
|  | 327 | library.BuildOnlyFFI() | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 328 | return module.Init() | 
|  | 329 | } | 
|  | 330 |  | 
| Martin Geisler | 67ec054 | 2022-11-18 12:08:55 +0100 | [diff] [blame] | 331 | // rust_library_dylib_host produces a dylib for the host (Rust crate | 
|  | 332 | // type "dylib"). | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 333 | func RustLibraryDylibHostFactory() android.Module { | 
|  | 334 | module, library := NewRustLibrary(android.HostSupported) | 
|  | 335 | library.BuildOnlyDylib() | 
|  | 336 | return module.Init() | 
|  | 337 | } | 
|  | 338 |  | 
| Martin Geisler | 67ec054 | 2022-11-18 12:08:55 +0100 | [diff] [blame] | 339 | // rust_library_rlib_host produces an rlib for the host (Rust crate | 
|  | 340 | // type "rlib"). | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 341 | func RustLibraryRlibHostFactory() android.Module { | 
|  | 342 | module, library := NewRustLibrary(android.HostSupported) | 
|  | 343 | library.BuildOnlyRlib() | 
|  | 344 | return module.Init() | 
|  | 345 | } | 
|  | 346 |  | 
| Martin Geisler | 67ec054 | 2022-11-18 12:08:55 +0100 | [diff] [blame] | 347 | // rust_ffi_shared_host produces an shared library for the host (Rust | 
|  | 348 | // crate type "cdylib"). | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 349 | func RustFFISharedHostFactory() android.Module { | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 350 | module, library := NewRustLibrary(android.HostSupported) | 
|  | 351 | library.BuildOnlyShared() | 
|  | 352 | return module.Init() | 
|  | 353 | } | 
|  | 354 |  | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 355 | // rust_ffi_rlib_host produces an rlib for the host (Rust crate | 
|  | 356 | // type "rlib"). | 
|  | 357 | func RustFFIRlibHostFactory() android.Module { | 
|  | 358 | module, library := NewRustLibrary(android.HostSupported) | 
| Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 359 | library.BuildOnlyRlib() | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 360 |  | 
|  | 361 | library.isFFI = true | 
|  | 362 | return module.Init() | 
|  | 363 | } | 
|  | 364 |  | 
|  | 365 | // rust_ffi_rlib produces an rlib (Rust crate type "rlib"). | 
|  | 366 | func RustFFIRlibFactory() android.Module { | 
|  | 367 | module, library := NewRustLibrary(android.HostAndDeviceSupported) | 
|  | 368 | library.BuildOnlyRlib() | 
|  | 369 |  | 
|  | 370 | library.isFFI = true | 
|  | 371 | return module.Init() | 
|  | 372 | } | 
|  | 373 |  | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 374 | func (library *libraryDecorator) BuildOnlyFFI() { | 
|  | 375 | library.MutatedProperties.BuildDylib = false | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 376 | // we build rlibs for later static ffi linkage. | 
|  | 377 | library.MutatedProperties.BuildRlib = true | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 378 | library.MutatedProperties.BuildShared = true | 
| Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 379 | library.MutatedProperties.BuildStatic = false | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 380 |  | 
|  | 381 | library.isFFI = true | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 382 | } | 
|  | 383 |  | 
|  | 384 | func (library *libraryDecorator) BuildOnlyRust() { | 
|  | 385 | library.MutatedProperties.BuildDylib = true | 
|  | 386 | library.MutatedProperties.BuildRlib = true | 
|  | 387 | library.MutatedProperties.BuildShared = false | 
|  | 388 | library.MutatedProperties.BuildStatic = false | 
|  | 389 | } | 
|  | 390 |  | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 391 | func (library *libraryDecorator) BuildOnlyDylib() { | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 392 | library.MutatedProperties.BuildDylib = true | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 393 | library.MutatedProperties.BuildRlib = false | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 394 | library.MutatedProperties.BuildShared = false | 
|  | 395 | library.MutatedProperties.BuildStatic = false | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 396 | } | 
|  | 397 |  | 
|  | 398 | func (library *libraryDecorator) BuildOnlyRlib() { | 
|  | 399 | library.MutatedProperties.BuildDylib = false | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 400 | library.MutatedProperties.BuildRlib = true | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 401 | library.MutatedProperties.BuildShared = false | 
|  | 402 | library.MutatedProperties.BuildStatic = false | 
|  | 403 | } | 
|  | 404 |  | 
|  | 405 | func (library *libraryDecorator) BuildOnlyStatic() { | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 406 | library.MutatedProperties.BuildRlib = false | 
|  | 407 | library.MutatedProperties.BuildDylib = false | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 408 | library.MutatedProperties.BuildShared = false | 
|  | 409 | library.MutatedProperties.BuildStatic = true | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 410 |  | 
|  | 411 | library.isFFI = true | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 412 | } | 
|  | 413 |  | 
|  | 414 | func (library *libraryDecorator) BuildOnlyShared() { | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 415 | library.MutatedProperties.BuildRlib = false | 
|  | 416 | library.MutatedProperties.BuildDylib = false | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 417 | library.MutatedProperties.BuildStatic = false | 
|  | 418 | library.MutatedProperties.BuildShared = true | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 419 |  | 
|  | 420 | library.isFFI = true | 
|  | 421 | } | 
|  | 422 |  | 
|  | 423 | func (library *libraryDecorator) isFFILibrary() bool { | 
|  | 424 | return library.isFFI | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 425 | } | 
|  | 426 |  | 
|  | 427 | func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { | 
| Ivan Lozano | 9d1df10 | 2020-04-28 10:10:23 -0400 | [diff] [blame] | 428 | module := newModule(hod, android.MultilibBoth) | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 429 |  | 
|  | 430 | library := &libraryDecorator{ | 
|  | 431 | MutatedProperties: LibraryMutatedProperties{ | 
| Matthew Maurer | 2ae0513 | 2020-06-23 14:28:53 -0700 | [diff] [blame] | 432 | BuildDylib:  false, | 
|  | 433 | BuildRlib:   false, | 
|  | 434 | BuildShared: false, | 
|  | 435 | BuildStatic: false, | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 436 | }, | 
| Chih-Hung Hsieh | 9a4a7ba | 2019-12-12 19:36:05 -0800 | [diff] [blame] | 437 | baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem), | 
| Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 438 | flagExporter: NewFlagExporter(), | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 439 | } | 
|  | 440 |  | 
|  | 441 | module.compiler = library | 
|  | 442 |  | 
|  | 443 | return module, library | 
|  | 444 | } | 
|  | 445 |  | 
|  | 446 | func (library *libraryDecorator) compilerProps() []interface{} { | 
|  | 447 | return append(library.baseCompiler.compilerProps(), | 
|  | 448 | &library.Properties, | 
| Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 449 | &library.MutatedProperties, | 
|  | 450 | &library.stripper.StripProperties) | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 451 | } | 
|  | 452 |  | 
| Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 453 | func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps { | 
|  | 454 | deps = library.baseCompiler.compilerDeps(ctx, deps) | 
|  | 455 |  | 
| Colin Cross | e32f093 | 2022-01-23 20:48:36 -0800 | [diff] [blame] | 456 | if library.dylib() || library.shared() { | 
|  | 457 | if ctx.toolchain().Bionic() { | 
|  | 458 | deps = bionicDeps(ctx, deps, false) | 
|  | 459 | deps.CrtBegin = []string{"crtbegin_so"} | 
|  | 460 | deps.CrtEnd = []string{"crtend_so"} | 
|  | 461 | } else if ctx.Os() == android.LinuxMusl { | 
|  | 462 | deps = muslDeps(ctx, deps, false) | 
|  | 463 | deps.CrtBegin = []string{"libc_musl_crtbegin_so"} | 
|  | 464 | deps.CrtEnd = []string{"libc_musl_crtend_so"} | 
|  | 465 | } | 
| Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 466 | } | 
|  | 467 |  | 
|  | 468 | return deps | 
|  | 469 | } | 
| Ivan Lozano | bec05ea | 2020-06-09 08:27:49 -0400 | [diff] [blame] | 470 |  | 
|  | 471 | func (library *libraryDecorator) sharedLibFilename(ctx ModuleContext) string { | 
|  | 472 | return library.getStem(ctx) + ctx.toolchain().SharedLibSuffix() | 
|  | 473 | } | 
|  | 474 |  | 
| Ivan Lozano | 28ed8f4 | 2024-05-06 21:46:39 -0400 | [diff] [blame] | 475 | // Library cfg flags common to all variants | 
|  | 476 | func CommonLibraryCfgFlags(ctx android.ModuleContext, flags Flags) Flags { | 
|  | 477 | return flags | 
|  | 478 | } | 
|  | 479 |  | 
| Ivan Lozano | 67eada3 | 2021-09-23 11:50:33 -0400 | [diff] [blame] | 480 | func (library *libraryDecorator) cfgFlags(ctx ModuleContext, flags Flags) Flags { | 
|  | 481 | flags = library.baseCompiler.cfgFlags(ctx, flags) | 
| Ivan Lozano | 28ed8f4 | 2024-05-06 21:46:39 -0400 | [diff] [blame] | 482 | flags = CommonLibraryCfgFlags(ctx, flags) | 
|  | 483 |  | 
| Cole Faust | fdec872 | 2024-05-22 11:38:29 -0700 | [diff] [blame] | 484 | cfgs := library.baseCompiler.Properties.Cfgs.GetOrDefault(ctx, nil) | 
|  | 485 |  | 
| Stephen Crane | 0dbfc56 | 2021-07-07 19:05:02 -0700 | [diff] [blame] | 486 | if library.dylib() { | 
|  | 487 | // We need to add a dependency on std in order to link crates as dylibs. | 
|  | 488 | // The hack to add this dependency is guarded by the following cfg so | 
|  | 489 | // that we don't force a dependency when it isn't needed. | 
| Cole Faust | fdec872 | 2024-05-22 11:38:29 -0700 | [diff] [blame] | 490 | cfgs = append(cfgs, "android_dylib") | 
| Stephen Crane | 0dbfc56 | 2021-07-07 19:05:02 -0700 | [diff] [blame] | 491 | } | 
| Ivan Lozano | 67eada3 | 2021-09-23 11:50:33 -0400 | [diff] [blame] | 492 |  | 
| Cole Faust | fdec872 | 2024-05-22 11:38:29 -0700 | [diff] [blame] | 493 | cfgFlags := cfgsToFlags(cfgs) | 
|  | 494 |  | 
|  | 495 | flags.RustFlags = append(flags.RustFlags, cfgFlags...) | 
|  | 496 | flags.RustdocFlags = append(flags.RustdocFlags, cfgFlags...) | 
| Ivan Lozano | 28ed8f4 | 2024-05-06 21:46:39 -0400 | [diff] [blame] | 497 |  | 
|  | 498 | return flags | 
|  | 499 | } | 
|  | 500 |  | 
|  | 501 | // Common flags applied to all libraries irrespective of properties or variant should be included here | 
|  | 502 | func CommonLibraryCompilerFlags(ctx android.ModuleContext, flags Flags) Flags { | 
|  | 503 | flags.RustFlags = append(flags.RustFlags, "-C metadata="+ctx.ModuleName()) | 
| Ivan Lozano | 67eada3 | 2021-09-23 11:50:33 -0400 | [diff] [blame] | 504 |  | 
|  | 505 | return flags | 
|  | 506 | } | 
|  | 507 |  | 
|  | 508 | func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags { | 
| Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 509 | flags = library.baseCompiler.compilerFlags(ctx, flags) | 
| Ivan Lozano | 67eada3 | 2021-09-23 11:50:33 -0400 | [diff] [blame] | 510 |  | 
| Ivan Lozano | 28ed8f4 | 2024-05-06 21:46:39 -0400 | [diff] [blame] | 511 | flags = CommonLibraryCompilerFlags(ctx, flags) | 
|  | 512 |  | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 513 | if library.isFFI { | 
| Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 514 | library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Include_dirs)...) | 
| Ivan Lozano | f033ca6 | 2024-03-21 13:43:14 -0400 | [diff] [blame] | 515 | library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Export_include_dirs)...) | 
| Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 516 | } | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 517 |  | 
| Ivan Lozano | bec05ea | 2020-06-09 08:27:49 -0400 | [diff] [blame] | 518 | if library.shared() { | 
| A. Cody Schuffelen | c183e3a | 2023-08-14 21:09:47 -0700 | [diff] [blame] | 519 | if ctx.Darwin() { | 
|  | 520 | flags.LinkFlags = append( | 
|  | 521 | flags.LinkFlags, | 
|  | 522 | "-dynamic_lib", | 
|  | 523 | "-install_name @rpath/"+library.sharedLibFilename(ctx), | 
|  | 524 | ) | 
|  | 525 | } else { | 
|  | 526 | flags.LinkFlags = append(flags.LinkFlags, "-Wl,-soname="+library.sharedLibFilename(ctx)) | 
|  | 527 | } | 
| Ivan Lozano | bec05ea | 2020-06-09 08:27:49 -0400 | [diff] [blame] | 528 | } | 
|  | 529 |  | 
| Ivan Lozano | e0833b1 | 2019-11-06 19:15:49 -0800 | [diff] [blame] | 530 | return flags | 
|  | 531 | } | 
| Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 532 |  | 
| Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 533 | func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput { | 
|  | 534 | var outputFile android.ModuleOutPath | 
|  | 535 | var ret buildOutput | 
| Thiébaud Weksteen | fabaff6 | 2020-08-27 13:48:36 +0200 | [diff] [blame] | 536 | var fileName string | 
| Matthew Maurer | a28404a | 2023-11-20 23:33:28 +0000 | [diff] [blame] | 537 | crateRootPath := crateRootPath(ctx, library) | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 538 |  | 
| Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 539 | if library.sourceProvider != nil { | 
| Ivan Lozano | 9d74a52 | 2020-12-01 09:25:22 -0500 | [diff] [blame] | 540 | deps.srcProviderFiles = append(deps.srcProviderFiles, library.sourceProvider.Srcs()...) | 
| Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 541 | } | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 542 |  | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 543 | // Ensure link dirs are not duplicated | 
|  | 544 | deps.linkDirs = android.FirstUniqueStrings(deps.linkDirs) | 
|  | 545 |  | 
| Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 546 | // Calculate output filename | 
|  | 547 | if library.rlib() { | 
|  | 548 | fileName = library.getStem(ctx) + ctx.toolchain().RlibSuffix() | 
|  | 549 | outputFile = android.PathForModuleOut(ctx, fileName) | 
| Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 550 | ret.outputFile = outputFile | 
| Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 551 | } else if library.dylib() { | 
|  | 552 | fileName = library.getStem(ctx) + ctx.toolchain().DylibSuffix() | 
|  | 553 | outputFile = android.PathForModuleOut(ctx, fileName) | 
| Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 554 | ret.outputFile = outputFile | 
| Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 555 | } else if library.static() { | 
|  | 556 | fileName = library.getStem(ctx) + ctx.toolchain().StaticLibSuffix() | 
|  | 557 | outputFile = android.PathForModuleOut(ctx, fileName) | 
| Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 558 | ret.outputFile = outputFile | 
| Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 559 | } else if library.shared() { | 
|  | 560 | fileName = library.sharedLibFilename(ctx) | 
|  | 561 | outputFile = android.PathForModuleOut(ctx, fileName) | 
| Sasha Smundak | a76acba | 2022-04-18 20:12:56 -0700 | [diff] [blame] | 562 | ret.outputFile = outputFile | 
| Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 563 | } | 
|  | 564 |  | 
|  | 565 | if !library.rlib() && !library.static() && library.stripper.NeedsStrip(ctx) { | 
|  | 566 | strippedOutputFile := outputFile | 
|  | 567 | outputFile = android.PathForModuleOut(ctx, "unstripped", fileName) | 
|  | 568 | library.stripper.StripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile) | 
|  | 569 |  | 
|  | 570 | library.baseCompiler.strippedOutputFile = android.OptionalPathForPath(strippedOutputFile) | 
|  | 571 | } | 
|  | 572 | library.baseCompiler.unstrippedOutputFile = outputFile | 
|  | 573 |  | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 574 | flags.RustFlags = append(flags.RustFlags, deps.depFlags...) | 
| Ivan Lozano | 3dfa12d | 2021-02-04 11:29:41 -0500 | [diff] [blame] | 575 | flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...) | 
| Colin Cross | 004bd3f | 2023-10-02 11:39:17 -0700 | [diff] [blame] | 576 | flags.LinkFlags = append(flags.LinkFlags, deps.linkObjects...) | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 577 |  | 
| Matthew Maurer | 46c46cc | 2020-01-13 16:34:34 -0800 | [diff] [blame] | 578 | if library.dylib() { | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 579 | // We need prefer-dynamic for now to avoid linking in the static stdlib. See: | 
|  | 580 | // https://github.com/rust-lang/rust/issues/19680 | 
|  | 581 | // https://github.com/rust-lang/rust/issues/34909 | 
|  | 582 | flags.RustFlags = append(flags.RustFlags, "-C prefer-dynamic") | 
|  | 583 | } | 
|  | 584 |  | 
| Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 585 | // Call the appropriate builder for this library type | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 586 | if library.rlib() { | 
| Sam Delmerico | 63ca14e | 2023-09-25 12:13:17 +0000 | [diff] [blame] | 587 | ret.kytheFile = TransformSrctoRlib(ctx, crateRootPath, deps, flags, outputFile).kytheFile | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 588 | } else if library.dylib() { | 
| Sam Delmerico | 63ca14e | 2023-09-25 12:13:17 +0000 | [diff] [blame] | 589 | ret.kytheFile = TransformSrctoDylib(ctx, crateRootPath, deps, flags, outputFile).kytheFile | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 590 | } else if library.static() { | 
| Sam Delmerico | 63ca14e | 2023-09-25 12:13:17 +0000 | [diff] [blame] | 591 | ret.kytheFile = TransformSrctoStatic(ctx, crateRootPath, deps, flags, outputFile).kytheFile | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 592 | } else if library.shared() { | 
| Sam Delmerico | 63ca14e | 2023-09-25 12:13:17 +0000 | [diff] [blame] | 593 | ret.kytheFile = TransformSrctoShared(ctx, crateRootPath, deps, flags, outputFile).kytheFile | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 594 | } | 
|  | 595 |  | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 596 | if library.rlib() || library.dylib() { | 
| Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 597 | library.flagExporter.exportLinkDirs(deps.linkDirs...) | 
| Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 598 | library.flagExporter.exportLinkObjects(deps.linkObjects...) | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 599 | } | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 600 |  | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 601 | // Since we have FFI rlibs, we need to collect their includes as well | 
|  | 602 | if library.static() || library.shared() || library.rlib() { | 
| Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 603 | android.SetProvider(ctx, cc.FlagExporterInfoProvider, cc.FlagExporterInfo{ | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 604 | IncludeDirs: android.FirstUniquePaths(library.includeDirs), | 
| Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 605 | }) | 
|  | 606 | } | 
|  | 607 |  | 
|  | 608 | if library.shared() { | 
| Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 609 | // Optimize out relinking against shared libraries whose interface hasn't changed by | 
|  | 610 | // depending on a table of contents file instead of the library itself. | 
|  | 611 | tocFile := outputFile.ReplaceExtension(ctx, flags.Toolchain.SharedLibSuffix()[1:]+".toc") | 
|  | 612 | library.tocFile = android.OptionalPathForPath(tocFile) | 
|  | 613 | cc.TransformSharedObjectToToc(ctx, outputFile, tocFile) | 
|  | 614 |  | 
| Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 615 | android.SetProvider(ctx, cc.SharedLibraryInfoProvider, cc.SharedLibraryInfo{ | 
| Ivan Lozano | 7b0781d | 2021-11-03 15:30:18 -0400 | [diff] [blame] | 616 | TableOfContents: android.OptionalPathForPath(tocFile), | 
|  | 617 | SharedLibrary:   outputFile, | 
|  | 618 | Target:          ctx.Target(), | 
| Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 619 | }) | 
|  | 620 | } | 
|  | 621 |  | 
|  | 622 | if library.static() { | 
| Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame] | 623 | depSet := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(outputFile).Build() | 
| Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 624 | android.SetProvider(ctx, cc.StaticLibraryInfoProvider, cc.StaticLibraryInfo{ | 
| Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 625 | StaticLibrary: outputFile, | 
|  | 626 |  | 
|  | 627 | TransitiveStaticLibrariesForOrdering: depSet, | 
|  | 628 | }) | 
|  | 629 | } | 
|  | 630 |  | 
|  | 631 | library.flagExporter.setProvider(ctx) | 
|  | 632 |  | 
| Ivan Lozano | 8d10fc3 | 2021-11-05 16:36:47 -0400 | [diff] [blame] | 633 | return ret | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 634 | } | 
|  | 635 |  | 
| Matthew Maurer | a28404a | 2023-11-20 23:33:28 +0000 | [diff] [blame] | 636 | func (library *libraryDecorator) checkedCrateRootPath() (android.Path, error) { | 
| Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 637 | if library.sourceProvider != nil { | 
| Matthew Maurer | a28404a | 2023-11-20 23:33:28 +0000 | [diff] [blame] | 638 | srcs := library.sourceProvider.Srcs() | 
|  | 639 | if len(srcs) == 0 { | 
|  | 640 | return nil, errors.New("Source provider generated 0 sources") | 
|  | 641 | } | 
| Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 642 | // Assume the first source from the source provider is the library entry point. | 
| Matthew Maurer | a28404a | 2023-11-20 23:33:28 +0000 | [diff] [blame] | 643 | return srcs[0], nil | 
| Sam Delmerico | 63ca14e | 2023-09-25 12:13:17 +0000 | [diff] [blame] | 644 | } else { | 
| Matthew Maurer | a28404a | 2023-11-20 23:33:28 +0000 | [diff] [blame] | 645 | return library.baseCompiler.checkedCrateRootPath() | 
| Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 646 | } | 
|  | 647 | } | 
|  | 648 |  | 
|  | 649 | func (library *libraryDecorator) rustdoc(ctx ModuleContext, flags Flags, | 
|  | 650 | deps PathDeps) android.OptionalPath { | 
|  | 651 | // rustdoc has builtin support for documenting config specific information | 
|  | 652 | // regardless of the actual config it was given | 
|  | 653 | // (https://doc.rust-lang.org/rustdoc/advanced-features.html#cfgdoc-documenting-platform-specific-or-feature-specific-information), | 
|  | 654 | // so we generate the rustdoc for only the primary module so that we have a | 
|  | 655 | // single set of docs to refer to. | 
|  | 656 | if ctx.Module() != ctx.PrimaryModule() { | 
|  | 657 | return android.OptionalPath{} | 
|  | 658 | } | 
|  | 659 |  | 
| Matthew Maurer | a28404a | 2023-11-20 23:33:28 +0000 | [diff] [blame] | 660 | return android.OptionalPathForPath(Rustdoc(ctx, crateRootPath(ctx, library), | 
| Dan Albert | 06feee9 | 2021-03-19 15:06:02 -0700 | [diff] [blame] | 661 | deps, flags)) | 
|  | 662 | } | 
|  | 663 |  | 
| Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 664 | func (library *libraryDecorator) getStem(ctx ModuleContext) string { | 
|  | 665 | stem := library.baseCompiler.getStemWithoutSuffix(ctx) | 
|  | 666 | validateLibraryStem(ctx, stem, library.crateName()) | 
|  | 667 |  | 
|  | 668 | return stem + String(library.baseCompiler.Properties.Suffix) | 
|  | 669 | } | 
|  | 670 |  | 
| Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 671 | func (library *libraryDecorator) install(ctx ModuleContext) { | 
|  | 672 | // Only shared and dylib variants make sense to install. | 
|  | 673 | if library.shared() || library.dylib() { | 
|  | 674 | library.baseCompiler.install(ctx) | 
|  | 675 | } | 
|  | 676 | } | 
|  | 677 |  | 
| Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 678 | func (library *libraryDecorator) Disabled() bool { | 
|  | 679 | return library.MutatedProperties.VariantIsDisabled | 
|  | 680 | } | 
|  | 681 |  | 
|  | 682 | func (library *libraryDecorator) SetDisabled() { | 
|  | 683 | library.MutatedProperties.VariantIsDisabled = true | 
|  | 684 | } | 
|  | 685 |  | 
| Ivan Lozano | ad8b18b | 2019-10-31 19:38:29 -0700 | [diff] [blame] | 686 | var validCrateName = regexp.MustCompile("[^a-zA-Z0-9_]+") | 
|  | 687 |  | 
|  | 688 | func validateLibraryStem(ctx BaseModuleContext, filename string, crate_name string) { | 
|  | 689 | if crate_name == "" { | 
|  | 690 | ctx.PropertyErrorf("crate_name", "crate_name must be defined.") | 
|  | 691 | } | 
|  | 692 |  | 
|  | 693 | // crate_names are used for the library output file, and rustc expects these | 
|  | 694 | // to be alphanumeric with underscores allowed. | 
|  | 695 | if validCrateName.MatchString(crate_name) { | 
|  | 696 | ctx.PropertyErrorf("crate_name", | 
|  | 697 | "library crate_names must be alphanumeric with underscores allowed") | 
|  | 698 | } | 
|  | 699 |  | 
|  | 700 | // Libraries are expected to begin with "lib" followed by the crate_name | 
|  | 701 | if !strings.HasPrefix(filename, "lib"+crate_name) { | 
|  | 702 | ctx.ModuleErrorf("Invalid name or stem property; library filenames must start with lib<crate_name>") | 
|  | 703 | } | 
|  | 704 | } | 
|  | 705 |  | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 706 | type libraryTransitionMutator struct{} | 
|  | 707 |  | 
|  | 708 | func (libraryTransitionMutator) Split(ctx android.BaseModuleContext) []string { | 
|  | 709 | m, ok := ctx.Module().(*Module) | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 710 | if !ok || m.compiler == nil { | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 711 | return []string{""} | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 712 | } | 
|  | 713 | library, ok := m.compiler.(libraryInterface) | 
|  | 714 | if !ok { | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 715 | return []string{""} | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 716 | } | 
| Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 717 |  | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 718 | // Don't produce rlib/dylib/source variants for shared or static variants | 
|  | 719 | if library.shared() || library.static() { | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 720 | return []string{""} | 
| Ivan Lozano | 0a468a4 | 2024-05-13 21:03:34 -0400 | [diff] [blame] | 721 | } | 
|  | 722 |  | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 723 | var variants []string | 
|  | 724 | // The source variant is used for SourceProvider modules. The other variants (i.e. rlib and dylib) | 
|  | 725 | // depend on this variant. It must be the first variant to be declared. | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 726 | if m.sourceProvider != nil { | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 727 | variants = append(variants, sourceVariation) | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 728 | } | 
|  | 729 | if library.buildRlib() { | 
|  | 730 | variants = append(variants, rlibVariation) | 
|  | 731 | } | 
|  | 732 | if library.buildDylib() { | 
|  | 733 | variants = append(variants, dylibVariation) | 
|  | 734 | } | 
| Ivan Lozano | 26ecd6c | 2020-07-31 13:40:31 -0400 | [diff] [blame] | 735 |  | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 736 | if len(variants) == 0 { | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 737 | return []string{""} | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 738 | } | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 739 |  | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 740 | return variants | 
|  | 741 | } | 
| Ivan Lozano | 1921e80 | 2021-05-20 13:39:16 -0400 | [diff] [blame] | 742 |  | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 743 | func (libraryTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string { | 
|  | 744 | return "" | 
|  | 745 | } | 
|  | 746 |  | 
|  | 747 | func (libraryTransitionMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string { | 
|  | 748 | m, ok := ctx.Module().(*Module) | 
|  | 749 | if !ok || m.compiler == nil { | 
|  | 750 | return "" | 
|  | 751 | } | 
|  | 752 | library, ok := m.compiler.(libraryInterface) | 
|  | 753 | if !ok { | 
|  | 754 | return "" | 
|  | 755 | } | 
|  | 756 |  | 
|  | 757 | if incomingVariation == "" { | 
|  | 758 | if m.sourceProvider != nil { | 
|  | 759 | return sourceVariation | 
|  | 760 | } | 
|  | 761 | if library.shared() { | 
|  | 762 | return "" | 
|  | 763 | } | 
|  | 764 | if library.buildRlib() { | 
|  | 765 | return rlibVariation | 
|  | 766 | } | 
|  | 767 | if library.buildDylib() { | 
|  | 768 | return dylibVariation | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 769 | } | 
|  | 770 | } | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 771 | return incomingVariation | 
|  | 772 | } | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 773 |  | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 774 | func (libraryTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, variation string) { | 
|  | 775 | m, ok := ctx.Module().(*Module) | 
|  | 776 | if !ok || m.compiler == nil { | 
|  | 777 | return | 
|  | 778 | } | 
|  | 779 | library, ok := m.compiler.(libraryInterface) | 
|  | 780 | if !ok { | 
|  | 781 | return | 
|  | 782 | } | 
|  | 783 |  | 
|  | 784 | switch variation { | 
|  | 785 | case rlibVariation: | 
|  | 786 | library.setRlib() | 
|  | 787 | case dylibVariation: | 
|  | 788 | library.setDylib() | 
|  | 789 | if m.ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation { | 
|  | 790 | // TODO(b/165791368) | 
|  | 791 | // Disable dylib Vendor Ramdisk variations until we support these. | 
|  | 792 | m.Disable() | 
|  | 793 | } | 
|  | 794 |  | 
|  | 795 | case sourceVariation: | 
|  | 796 | library.setSource() | 
|  | 797 | // The source variant does not produce any library. | 
|  | 798 | // Disable the compilation steps. | 
|  | 799 | m.compiler.SetDisabled() | 
| Ivan Lozano | fd47b1a | 2024-05-17 14:13:41 -0400 | [diff] [blame] | 800 | } | 
|  | 801 |  | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 802 | // If a source variant is created, add an inter-variant dependency | 
|  | 803 | // between the other variants and the source variant. | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 804 | if m.sourceProvider != nil && variation != sourceVariation { | 
|  | 805 | ctx.AddVariationDependencies( | 
|  | 806 | []blueprint.Variation{ | 
|  | 807 | {"rust_libraries", sourceVariation}, | 
|  | 808 | }, | 
|  | 809 | sourceDepTag, ctx.ModuleName()) | 
| Thiébaud Weksteen | 295c72b | 2020-09-23 18:10:17 +0200 | [diff] [blame] | 810 | } | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 811 | } | 
| Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 812 |  | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 813 | type libstdTransitionMutator struct{} | 
| Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 814 |  | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 815 | func (libstdTransitionMutator) Split(ctx android.BaseModuleContext) []string { | 
|  | 816 | if m, ok := ctx.Module().(*Module); ok && m.compiler != nil && !m.compiler.Disabled() { | 
|  | 817 | // Only create a variant if a library is actually being built. | 
|  | 818 | if library, ok := m.compiler.(libraryInterface); ok { | 
|  | 819 | if library.rlib() && !library.sysroot() { | 
|  | 820 | if library.isFFILibrary() { | 
|  | 821 | return []string{"rlib-std"} | 
|  | 822 | } else { | 
|  | 823 | return []string{"rlib-std", "dylib-std"} | 
| Ivan Lozano | 6a88443 | 2020-12-02 09:15:16 -0500 | [diff] [blame] | 824 | } | 
| Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 825 | } | 
|  | 826 | } | 
|  | 827 | } | 
| Colin Cross | 8a49a3d | 2024-05-20 12:22:27 -0700 | [diff] [blame] | 828 | return []string{""} | 
|  | 829 | } | 
|  | 830 |  | 
|  | 831 | func (libstdTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string { | 
|  | 832 | return "" | 
|  | 833 | } | 
|  | 834 |  | 
|  | 835 | func (libstdTransitionMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string { | 
|  | 836 | if m, ok := ctx.Module().(*Module); ok && m.compiler != nil && !m.compiler.Disabled() { | 
|  | 837 | if library, ok := m.compiler.(libraryInterface); ok { | 
|  | 838 | if library.shared() { | 
|  | 839 | return "" | 
|  | 840 | } | 
|  | 841 | if library.rlib() && !library.sysroot() { | 
|  | 842 | if incomingVariation != "" { | 
|  | 843 | return incomingVariation | 
|  | 844 | } | 
|  | 845 | return "rlib-std" | 
|  | 846 | } | 
|  | 847 | } | 
|  | 848 | } | 
|  | 849 | return "" | 
|  | 850 | } | 
|  | 851 |  | 
|  | 852 | func (libstdTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, variation string) { | 
|  | 853 | if variation == "rlib-std" { | 
|  | 854 | rlib := ctx.Module().(*Module) | 
|  | 855 | rlib.compiler.(libraryInterface).setRlibStd() | 
|  | 856 | rlib.Properties.RustSubName += RlibStdlibSuffix | 
|  | 857 | } else if variation == "dylib-std" { | 
|  | 858 | dylib := ctx.Module().(*Module) | 
|  | 859 | dylib.compiler.(libraryInterface).setDylibStd() | 
|  | 860 | if dylib.ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation { | 
|  | 861 | // TODO(b/165791368) | 
|  | 862 | // Disable rlibs that link against dylib-std on vendor ramdisk variations until those dylib | 
|  | 863 | // variants are properly supported. | 
|  | 864 | dylib.Disable() | 
|  | 865 | } | 
|  | 866 | } | 
| Ivan Lozano | 2b08113 | 2020-09-08 12:46:52 -0400 | [diff] [blame] | 867 | } |