blob: ffc8ab0003aff66dcc21bbb935ab0a85612771eb [file] [log] [blame]
Ivan Lozanoffee3342019-08-27 12:03:00 -07001// 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
15package rust
16
17import (
Matthew Maurera28404a2023-11-20 23:33:28 +000018 "errors"
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +020019 "fmt"
Ivan Lozanoad8b18b2019-10-31 19:38:29 -070020 "regexp"
21 "strings"
22
Colin Cross8a49a3d2024-05-20 12:22:27 -070023 "github.com/google/blueprint"
Colin Crossa14fb6a2024-10-23 16:57:06 -070024 "github.com/google/blueprint/depset"
Colin Cross8a49a3d2024-05-20 12:22:27 -070025
Ivan Lozanoffee3342019-08-27 12:03:00 -070026 "android/soong/android"
Colin Cross0de8a1e2020-09-18 14:15:30 -070027 "android/soong/cc"
Ivan Lozanoffee3342019-08-27 12:03:00 -070028)
29
Ivan Lozano2b081132020-09-08 12:46:52 -040030var (
Ivan Lozano4df02572023-06-15 14:21:09 -040031 RlibStdlibSuffix = ".rlib-std"
Ivan Lozano2b081132020-09-08 12:46:52 -040032)
33
Ivan Lozanoffee3342019-08-27 12:03:00 -070034func init() {
35 android.RegisterModuleType("rust_library", RustLibraryFactory)
36 android.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
37 android.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
38 android.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
39 android.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
40 android.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -070041 android.RegisterModuleType("rust_ffi", RustFFIFactory)
42 android.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -070043 android.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
44 android.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
Ivan Lozano806efd32024-12-11 21:38:53 +000045 android.RegisterModuleType("rust_ffi_static", RustLibraryRlibFactory)
46 android.RegisterModuleType("rust_ffi_host_static", RustLibraryRlibHostFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -070047}
48
49type VariantLibraryProperties struct {
Matthew Maurerc761eec2020-06-25 00:47:46 -070050 Enabled *bool `android:"arch_variant"`
51 Srcs []string `android:"path,arch_variant"`
Ivan Lozanoffee3342019-08-27 12:03:00 -070052}
53
54type LibraryCompilerProperties struct {
Ivan Lozano52767be2019-10-18 14:49:46 -070055 Rlib VariantLibraryProperties `android:"arch_variant"`
56 Dylib VariantLibraryProperties `android:"arch_variant"`
57 Shared VariantLibraryProperties `android:"arch_variant"`
58 Static VariantLibraryProperties `android:"arch_variant"`
Ivan Lozanoffee3342019-08-27 12:03:00 -070059
Ivan Lozanof033ca62024-03-21 13:43:14 -040060 // TODO: Remove this when all instances of Include_dirs have been removed from rust_ffi modules.
61 // path to include directories to pass to cc_* modules, only relevant for static/shared variants (deprecated, use export_include_dirs instead).
Ivan Lozano52767be2019-10-18 14:49:46 -070062 Include_dirs []string `android:"path,arch_variant"`
Ivan Lozano2b081132020-09-08 12:46:52 -040063
Ivan Lozanof033ca62024-03-21 13:43:14 -040064 // path to include directories to export to cc_* modules, only relevant for static/shared variants.
65 Export_include_dirs []string `android:"path,arch_variant"`
66
Ivan Lozano2b081132020-09-08 12:46:52 -040067 // Whether this library is part of the Rust toolchain sysroot.
68 Sysroot *bool
Ashutosh Agarwal46e4fad2024-08-27 17:13:12 +000069
70 // Exclude this rust_ffi target from being included in APEXes.
71 // TODO(b/362509506): remove this once stubs are properly supported by rust_ffi targets.
72 Apex_exclude *bool
Ivan Lozanoffee3342019-08-27 12:03:00 -070073}
74
75type LibraryMutatedProperties struct {
Ivan Lozanoffee3342019-08-27 12:03:00 -070076 // Build a dylib variant
77 BuildDylib bool `blueprint:"mutated"`
78 // Build an rlib variant
79 BuildRlib bool `blueprint:"mutated"`
Ivan Lozano52767be2019-10-18 14:49:46 -070080 // Build a shared library variant
81 BuildShared bool `blueprint:"mutated"`
82 // Build a static library variant
83 BuildStatic bool `blueprint:"mutated"`
Ivan Lozanoffee3342019-08-27 12:03:00 -070084
85 // This variant is a dylib
86 VariantIsDylib bool `blueprint:"mutated"`
87 // This variant is an rlib
88 VariantIsRlib bool `blueprint:"mutated"`
Ivan Lozano52767be2019-10-18 14:49:46 -070089 // This variant is a shared library
90 VariantIsShared bool `blueprint:"mutated"`
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +020091 // This variant is a source provider
92 VariantIsSource bool `blueprint:"mutated"`
Ivan Lozano26ecd6c2020-07-31 13:40:31 -040093
94 // This variant is disabled and should not be compiled
95 // (used for SourceProvider variants that produce only source)
96 VariantIsDisabled bool `blueprint:"mutated"`
Ivan Lozano2b081132020-09-08 12:46:52 -040097
98 // Whether this library variant should be link libstd via rlibs
99 VariantIsStaticStd bool `blueprint:"mutated"`
Ivan Lozanoffee3342019-08-27 12:03:00 -0700100}
101
102type libraryDecorator struct {
103 *baseCompiler
Matthew Maurerbb3add12020-06-25 09:34:12 -0700104 *flagExporter
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200105 stripper Stripper
Ivan Lozanoffee3342019-08-27 12:03:00 -0700106
Ivan Lozano8a23fa42020-06-16 10:26:57 -0400107 Properties LibraryCompilerProperties
108 MutatedProperties LibraryMutatedProperties
109 includeDirs android.Paths
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400110 sourceProvider SourceProvider
Ivan Lozano1921e802021-05-20 13:39:16 -0400111
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400112 // table-of-contents file for cdylib crates to optimize out relinking when possible
113 tocFile android.OptionalPath
Ivan Lozanoffee3342019-08-27 12:03:00 -0700114}
115
116type libraryInterface interface {
117 rlib() bool
118 dylib() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700119 static() bool
120 shared() bool
Ivan Lozano2b081132020-09-08 12:46:52 -0400121 sysroot() bool
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200122 source() bool
Ashutosh Agarwal46e4fad2024-08-27 17:13:12 +0000123 apexExclude() bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700124
125 // Returns true if the build options for the module have selected a particular build type
126 buildRlib() bool
127 buildDylib() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700128 buildShared() bool
129 buildStatic() bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700130
131 // Sets a particular variant type
132 setRlib()
133 setDylib()
Ivan Lozano52767be2019-10-18 14:49:46 -0700134 setShared()
135 setStatic()
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200136 setSource()
Ivan Lozano52767be2019-10-18 14:49:46 -0700137
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400138 // libstd linkage functions
139 rlibStd() bool
Ivan Lozano2b081132020-09-08 12:46:52 -0400140 setRlibStd()
141 setDylibStd()
142
Ivan Lozano52767be2019-10-18 14:49:46 -0700143 // Build a specific library variant
Matthew Maurer2ae05132020-06-23 14:28:53 -0700144 BuildOnlyFFI()
145 BuildOnlyRust()
Ivan Lozano52767be2019-10-18 14:49:46 -0700146 BuildOnlyRlib()
147 BuildOnlyDylib()
148 BuildOnlyStatic()
149 BuildOnlyShared()
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400150
151 toc() android.OptionalPath
Ivan Lozanoffee3342019-08-27 12:03:00 -0700152}
153
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400154func (library *libraryDecorator) nativeCoverage() bool {
155 return true
156}
157
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400158func (library *libraryDecorator) toc() android.OptionalPath {
159 return library.tocFile
160}
161
Ivan Lozanoffee3342019-08-27 12:03:00 -0700162func (library *libraryDecorator) rlib() bool {
163 return library.MutatedProperties.VariantIsRlib
164}
165
Ivan Lozano2b081132020-09-08 12:46:52 -0400166func (library *libraryDecorator) sysroot() bool {
167 return Bool(library.Properties.Sysroot)
168}
169
Ivan Lozanoffee3342019-08-27 12:03:00 -0700170func (library *libraryDecorator) dylib() bool {
171 return library.MutatedProperties.VariantIsDylib
172}
173
Ivan Lozano52767be2019-10-18 14:49:46 -0700174func (library *libraryDecorator) shared() bool {
175 return library.MutatedProperties.VariantIsShared
176}
177
178func (library *libraryDecorator) static() bool {
Colin Cross17f9dc52024-07-01 20:05:54 -0700179 return false
Ivan Lozano52767be2019-10-18 14:49:46 -0700180}
181
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200182func (library *libraryDecorator) source() bool {
183 return library.MutatedProperties.VariantIsSource
184}
185
Ashutosh Agarwal46e4fad2024-08-27 17:13:12 +0000186func (library *libraryDecorator) apexExclude() bool {
187 return Bool(library.Properties.Apex_exclude)
188}
189
Ivan Lozanoffee3342019-08-27 12:03:00 -0700190func (library *libraryDecorator) buildRlib() bool {
191 return library.MutatedProperties.BuildRlib && BoolDefault(library.Properties.Rlib.Enabled, true)
192}
193
194func (library *libraryDecorator) buildDylib() bool {
195 return library.MutatedProperties.BuildDylib && BoolDefault(library.Properties.Dylib.Enabled, true)
196}
197
Ivan Lozano52767be2019-10-18 14:49:46 -0700198func (library *libraryDecorator) buildShared() bool {
199 return library.MutatedProperties.BuildShared && BoolDefault(library.Properties.Shared.Enabled, true)
200}
201
202func (library *libraryDecorator) buildStatic() bool {
203 return library.MutatedProperties.BuildStatic && BoolDefault(library.Properties.Static.Enabled, true)
204}
205
Ivan Lozanoffee3342019-08-27 12:03:00 -0700206func (library *libraryDecorator) setRlib() {
207 library.MutatedProperties.VariantIsRlib = true
208 library.MutatedProperties.VariantIsDylib = false
Ivan Lozano52767be2019-10-18 14:49:46 -0700209 library.MutatedProperties.VariantIsShared = false
Ivan Lozanoffee3342019-08-27 12:03:00 -0700210}
211
212func (library *libraryDecorator) setDylib() {
213 library.MutatedProperties.VariantIsRlib = false
214 library.MutatedProperties.VariantIsDylib = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700215 library.MutatedProperties.VariantIsShared = false
216}
217
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400218func (library *libraryDecorator) rlibStd() bool {
219 return library.MutatedProperties.VariantIsStaticStd
220}
221
Ivan Lozano2b081132020-09-08 12:46:52 -0400222func (library *libraryDecorator) setRlibStd() {
223 library.MutatedProperties.VariantIsStaticStd = true
224}
225
226func (library *libraryDecorator) setDylibStd() {
227 library.MutatedProperties.VariantIsStaticStd = false
228}
229
Ivan Lozano52767be2019-10-18 14:49:46 -0700230func (library *libraryDecorator) setShared() {
Ivan Lozano52767be2019-10-18 14:49:46 -0700231 library.MutatedProperties.VariantIsShared = true
232 library.MutatedProperties.VariantIsRlib = false
233 library.MutatedProperties.VariantIsDylib = false
234}
235
236func (library *libraryDecorator) setStatic() {
Colin Cross17f9dc52024-07-01 20:05:54 -0700237 panic(fmt.Errorf("static variant is not supported for rust modules, use the rlib variant instead"))
Ivan Lozanoffee3342019-08-27 12:03:00 -0700238}
239
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200240func (library *libraryDecorator) setSource() {
241 library.MutatedProperties.VariantIsSource = true
242}
243
Liz Kammer356f7d42021-01-26 09:18:53 -0500244func (library *libraryDecorator) autoDep(ctx android.BottomUpMutatorContext) autoDep {
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400245 if library.preferRlib() {
Ivan Lozanoea086132020-12-08 14:43:00 -0500246 return rlibAutoDep
247 } else if library.rlib() || library.static() {
Matthew Maurer0f003b12020-06-29 14:34:06 -0700248 return rlibAutoDep
249 } else if library.dylib() || library.shared() {
250 return dylibAutoDep
251 } else {
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200252 panic(fmt.Errorf("autoDep called on library %q that has no enabled variants.", ctx.ModuleName()))
Matthew Maurer0f003b12020-06-29 14:34:06 -0700253 }
254}
255
Ivan Lozano806efd32024-12-11 21:38:53 +0000256func (library *libraryDecorator) stdLinkage(device bool) RustLinkage {
257 if library.static() || library.MutatedProperties.VariantIsStaticStd {
Ivan Lozanoea086132020-12-08 14:43:00 -0500258 return RlibLinkage
259 } else if library.baseCompiler.preferRlib() {
260 return RlibLinkage
261 }
Ivan Lozano806efd32024-12-11 21:38:53 +0000262 return DylibLinkage
Ivan Lozanoea086132020-12-08 14:43:00 -0500263}
264
Ivan Lozanoffee3342019-08-27 12:03:00 -0700265var _ compiler = (*libraryDecorator)(nil)
Ivan Lozano52767be2019-10-18 14:49:46 -0700266var _ libraryInterface = (*libraryDecorator)(nil)
Matthew Maurerbb3add12020-06-25 09:34:12 -0700267var _ exportedFlagsProducer = (*libraryDecorator)(nil)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700268
Martin Geisler67ec0542022-11-18 12:08:55 +0100269// rust_library produces all Rust variants (rust_library_dylib and
270// rust_library_rlib).
Ivan Lozanoffee3342019-08-27 12:03:00 -0700271func RustLibraryFactory() android.Module {
Matthew Maurer2ae05132020-06-23 14:28:53 -0700272 module, library := NewRustLibrary(android.HostAndDeviceSupported)
273 library.BuildOnlyRust()
274 return module.Init()
275}
276
Ivan Lozano61848422024-12-13 19:45:00 +0000277// rust_ffi produces all FFI variants (rust_ffi_shared, rust_ffi_static).
Matthew Maurer2ae05132020-06-23 14:28:53 -0700278func RustFFIFactory() android.Module {
279 module, library := NewRustLibrary(android.HostAndDeviceSupported)
280 library.BuildOnlyFFI()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700281 return module.Init()
282}
283
Martin Geisler67ec0542022-11-18 12:08:55 +0100284// rust_library_dylib produces a Rust dylib (Rust crate type "dylib").
Ivan Lozanoffee3342019-08-27 12:03:00 -0700285func RustLibraryDylibFactory() android.Module {
286 module, library := NewRustLibrary(android.HostAndDeviceSupported)
287 library.BuildOnlyDylib()
288 return module.Init()
289}
290
Ivan Lozano806efd32024-12-11 21:38:53 +0000291// rust_library_rlib and rust_ffi_static produces an rlib (Rust crate type "rlib").
Ivan Lozanoffee3342019-08-27 12:03:00 -0700292func RustLibraryRlibFactory() android.Module {
293 module, library := NewRustLibrary(android.HostAndDeviceSupported)
294 library.BuildOnlyRlib()
295 return module.Init()
296}
297
Martin Geisler67ec0542022-11-18 12:08:55 +0100298// rust_ffi_shared produces a shared library (Rust crate type
299// "cdylib").
Matthew Maurer2ae05132020-06-23 14:28:53 -0700300func RustFFISharedFactory() android.Module {
Ivan Lozano52767be2019-10-18 14:49:46 -0700301 module, library := NewRustLibrary(android.HostAndDeviceSupported)
302 library.BuildOnlyShared()
303 return module.Init()
304}
305
Martin Geisler67ec0542022-11-18 12:08:55 +0100306// rust_library_host produces all Rust variants for the host
307// (rust_library_dylib_host and rust_library_rlib_host).
Ivan Lozanoffee3342019-08-27 12:03:00 -0700308func RustLibraryHostFactory() android.Module {
Matthew Maurer2ae05132020-06-23 14:28:53 -0700309 module, library := NewRustLibrary(android.HostSupported)
310 library.BuildOnlyRust()
311 return module.Init()
312}
313
Martin Geisler67ec0542022-11-18 12:08:55 +0100314// rust_ffi_host produces all FFI variants for the host
Ivan Lozano61848422024-12-13 19:45:00 +0000315// (rust_ffi_static_host and rust_ffi_shared_host).
Matthew Maurer2ae05132020-06-23 14:28:53 -0700316func RustFFIHostFactory() android.Module {
317 module, library := NewRustLibrary(android.HostSupported)
318 library.BuildOnlyFFI()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700319 return module.Init()
320}
321
Martin Geisler67ec0542022-11-18 12:08:55 +0100322// rust_library_dylib_host produces a dylib for the host (Rust crate
323// type "dylib").
Ivan Lozanoffee3342019-08-27 12:03:00 -0700324func RustLibraryDylibHostFactory() android.Module {
325 module, library := NewRustLibrary(android.HostSupported)
326 library.BuildOnlyDylib()
327 return module.Init()
328}
329
Ivan Lozano806efd32024-12-11 21:38:53 +0000330// rust_library_rlib_host and rust_ffi_static_host produces an rlib for the host
331// (Rust crate type "rlib").
Ivan Lozanoffee3342019-08-27 12:03:00 -0700332func RustLibraryRlibHostFactory() android.Module {
333 module, library := NewRustLibrary(android.HostSupported)
334 library.BuildOnlyRlib()
335 return module.Init()
336}
337
Martin Geisler67ec0542022-11-18 12:08:55 +0100338// rust_ffi_shared_host produces an shared library for the host (Rust
339// crate type "cdylib").
Matthew Maurer2ae05132020-06-23 14:28:53 -0700340func RustFFISharedHostFactory() android.Module {
Ivan Lozano52767be2019-10-18 14:49:46 -0700341 module, library := NewRustLibrary(android.HostSupported)
342 library.BuildOnlyShared()
343 return module.Init()
344}
345
Matthew Maurer2ae05132020-06-23 14:28:53 -0700346func (library *libraryDecorator) BuildOnlyFFI() {
347 library.MutatedProperties.BuildDylib = false
Ivan Lozano0a468a42024-05-13 21:03:34 -0400348 // we build rlibs for later static ffi linkage.
349 library.MutatedProperties.BuildRlib = true
Matthew Maurer2ae05132020-06-23 14:28:53 -0700350 library.MutatedProperties.BuildShared = true
Ivan Lozanofd47b1a2024-05-17 14:13:41 -0400351 library.MutatedProperties.BuildStatic = false
Matthew Maurer2ae05132020-06-23 14:28:53 -0700352}
353
354func (library *libraryDecorator) BuildOnlyRust() {
355 library.MutatedProperties.BuildDylib = true
356 library.MutatedProperties.BuildRlib = true
357 library.MutatedProperties.BuildShared = false
358 library.MutatedProperties.BuildStatic = false
359}
360
Ivan Lozanoffee3342019-08-27 12:03:00 -0700361func (library *libraryDecorator) BuildOnlyDylib() {
Matthew Maurer2ae05132020-06-23 14:28:53 -0700362 library.MutatedProperties.BuildDylib = true
Ivan Lozanoffee3342019-08-27 12:03:00 -0700363 library.MutatedProperties.BuildRlib = false
Ivan Lozano52767be2019-10-18 14:49:46 -0700364 library.MutatedProperties.BuildShared = false
365 library.MutatedProperties.BuildStatic = false
Ivan Lozanoffee3342019-08-27 12:03:00 -0700366}
367
368func (library *libraryDecorator) BuildOnlyRlib() {
369 library.MutatedProperties.BuildDylib = false
Matthew Maurer2ae05132020-06-23 14:28:53 -0700370 library.MutatedProperties.BuildRlib = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700371 library.MutatedProperties.BuildShared = false
372 library.MutatedProperties.BuildStatic = false
373}
374
375func (library *libraryDecorator) BuildOnlyStatic() {
Ivan Lozano52767be2019-10-18 14:49:46 -0700376 library.MutatedProperties.BuildRlib = false
377 library.MutatedProperties.BuildDylib = false
Matthew Maurer2ae05132020-06-23 14:28:53 -0700378 library.MutatedProperties.BuildShared = false
379 library.MutatedProperties.BuildStatic = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700380}
381
382func (library *libraryDecorator) BuildOnlyShared() {
Ivan Lozano52767be2019-10-18 14:49:46 -0700383 library.MutatedProperties.BuildRlib = false
384 library.MutatedProperties.BuildDylib = false
Matthew Maurer2ae05132020-06-23 14:28:53 -0700385 library.MutatedProperties.BuildStatic = false
386 library.MutatedProperties.BuildShared = true
Ivan Lozanoffee3342019-08-27 12:03:00 -0700387}
388
389func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
Ivan Lozano9d1df102020-04-28 10:10:23 -0400390 module := newModule(hod, android.MultilibBoth)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700391
392 library := &libraryDecorator{
393 MutatedProperties: LibraryMutatedProperties{
Matthew Maurer2ae05132020-06-23 14:28:53 -0700394 BuildDylib: false,
395 BuildRlib: false,
396 BuildShared: false,
397 BuildStatic: false,
Ivan Lozanoffee3342019-08-27 12:03:00 -0700398 },
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -0800399 baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem),
Matthew Maurerbb3add12020-06-25 09:34:12 -0700400 flagExporter: NewFlagExporter(),
Ivan Lozanoffee3342019-08-27 12:03:00 -0700401 }
402
403 module.compiler = library
404
405 return module, library
406}
407
408func (library *libraryDecorator) compilerProps() []interface{} {
409 return append(library.baseCompiler.compilerProps(),
410 &library.Properties,
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200411 &library.MutatedProperties,
412 &library.stripper.StripProperties)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700413}
414
Ivan Lozanof1c84332019-09-20 11:00:37 -0700415func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
416 deps = library.baseCompiler.compilerDeps(ctx, deps)
417
Colin Crosse32f0932022-01-23 20:48:36 -0800418 if library.dylib() || library.shared() {
419 if ctx.toolchain().Bionic() {
420 deps = bionicDeps(ctx, deps, false)
421 deps.CrtBegin = []string{"crtbegin_so"}
422 deps.CrtEnd = []string{"crtend_so"}
423 } else if ctx.Os() == android.LinuxMusl {
424 deps = muslDeps(ctx, deps, false)
425 deps.CrtBegin = []string{"libc_musl_crtbegin_so"}
426 deps.CrtEnd = []string{"libc_musl_crtend_so"}
427 }
Ivan Lozanof1c84332019-09-20 11:00:37 -0700428 }
429
430 return deps
431}
Ivan Lozanobec05ea2020-06-09 08:27:49 -0400432
433func (library *libraryDecorator) sharedLibFilename(ctx ModuleContext) string {
434 return library.getStem(ctx) + ctx.toolchain().SharedLibSuffix()
435}
436
Ivan Lozano28ed8f42024-05-06 21:46:39 -0400437// Library cfg flags common to all variants
438func CommonLibraryCfgFlags(ctx android.ModuleContext, flags Flags) Flags {
439 return flags
440}
441
Ivan Lozano67eada32021-09-23 11:50:33 -0400442func (library *libraryDecorator) cfgFlags(ctx ModuleContext, flags Flags) Flags {
443 flags = library.baseCompiler.cfgFlags(ctx, flags)
Ivan Lozano28ed8f42024-05-06 21:46:39 -0400444 flags = CommonLibraryCfgFlags(ctx, flags)
445
Cole Faustfdec8722024-05-22 11:38:29 -0700446 cfgs := library.baseCompiler.Properties.Cfgs.GetOrDefault(ctx, nil)
447
Stephen Crane0dbfc562021-07-07 19:05:02 -0700448 if library.dylib() {
449 // We need to add a dependency on std in order to link crates as dylibs.
450 // The hack to add this dependency is guarded by the following cfg so
451 // that we don't force a dependency when it isn't needed.
Cole Faustfdec8722024-05-22 11:38:29 -0700452 cfgs = append(cfgs, "android_dylib")
Stephen Crane0dbfc562021-07-07 19:05:02 -0700453 }
Ivan Lozano67eada32021-09-23 11:50:33 -0400454
Cole Faustfdec8722024-05-22 11:38:29 -0700455 cfgFlags := cfgsToFlags(cfgs)
456
457 flags.RustFlags = append(flags.RustFlags, cfgFlags...)
458 flags.RustdocFlags = append(flags.RustdocFlags, cfgFlags...)
Ivan Lozano28ed8f42024-05-06 21:46:39 -0400459
460 return flags
461}
462
463// Common flags applied to all libraries irrespective of properties or variant should be included here
464func CommonLibraryCompilerFlags(ctx android.ModuleContext, flags Flags) Flags {
465 flags.RustFlags = append(flags.RustFlags, "-C metadata="+ctx.ModuleName())
Ivan Lozano67eada32021-09-23 11:50:33 -0400466
467 return flags
468}
469
470func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800471 flags = library.baseCompiler.compilerFlags(ctx, flags)
Ivan Lozano67eada32021-09-23 11:50:33 -0400472
Ivan Lozano28ed8f42024-05-06 21:46:39 -0400473 flags = CommonLibraryCompilerFlags(ctx, flags)
474
Ivan Lozano806efd32024-12-11 21:38:53 +0000475 if library.rlib() || library.shared() {
476 // rlibs collect include dirs as well since they are used to
477 // produce staticlibs in the final C linkages
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800478 library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Include_dirs)...)
Ivan Lozanof033ca62024-03-21 13:43:14 -0400479 library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Export_include_dirs)...)
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800480 }
Ivan Lozano0a468a42024-05-13 21:03:34 -0400481
Ivan Lozanobec05ea2020-06-09 08:27:49 -0400482 if library.shared() {
A. Cody Schuffelenc183e3a2023-08-14 21:09:47 -0700483 if ctx.Darwin() {
484 flags.LinkFlags = append(
485 flags.LinkFlags,
486 "-dynamic_lib",
487 "-install_name @rpath/"+library.sharedLibFilename(ctx),
488 )
489 } else {
490 flags.LinkFlags = append(flags.LinkFlags, "-Wl,-soname="+library.sharedLibFilename(ctx))
491 }
Ivan Lozanobec05ea2020-06-09 08:27:49 -0400492 }
493
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800494 return flags
495}
Ivan Lozanof1c84332019-09-20 11:00:37 -0700496
Sasha Smundaka76acba2022-04-18 20:12:56 -0700497func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
498 var outputFile android.ModuleOutPath
499 var ret buildOutput
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200500 var fileName string
Matthew Maurera28404a2023-11-20 23:33:28 +0000501 crateRootPath := crateRootPath(ctx, library)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700502
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400503 if library.sourceProvider != nil {
Ivan Lozano9d74a522020-12-01 09:25:22 -0500504 deps.srcProviderFiles = append(deps.srcProviderFiles, library.sourceProvider.Srcs()...)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400505 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700506
Ivan Lozano0a468a42024-05-13 21:03:34 -0400507 // Ensure link dirs are not duplicated
508 deps.linkDirs = android.FirstUniqueStrings(deps.linkDirs)
509
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400510 // Calculate output filename
511 if library.rlib() {
512 fileName = library.getStem(ctx) + ctx.toolchain().RlibSuffix()
513 outputFile = android.PathForModuleOut(ctx, fileName)
Sasha Smundaka76acba2022-04-18 20:12:56 -0700514 ret.outputFile = outputFile
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400515 } else if library.dylib() {
516 fileName = library.getStem(ctx) + ctx.toolchain().DylibSuffix()
517 outputFile = android.PathForModuleOut(ctx, fileName)
Sasha Smundaka76acba2022-04-18 20:12:56 -0700518 ret.outputFile = outputFile
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400519 } else if library.static() {
520 fileName = library.getStem(ctx) + ctx.toolchain().StaticLibSuffix()
521 outputFile = android.PathForModuleOut(ctx, fileName)
Sasha Smundaka76acba2022-04-18 20:12:56 -0700522 ret.outputFile = outputFile
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400523 } else if library.shared() {
524 fileName = library.sharedLibFilename(ctx)
525 outputFile = android.PathForModuleOut(ctx, fileName)
Sasha Smundaka76acba2022-04-18 20:12:56 -0700526 ret.outputFile = outputFile
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400527 }
528
529 if !library.rlib() && !library.static() && library.stripper.NeedsStrip(ctx) {
530 strippedOutputFile := outputFile
531 outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
532 library.stripper.StripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile)
533
534 library.baseCompiler.strippedOutputFile = android.OptionalPathForPath(strippedOutputFile)
535 }
536 library.baseCompiler.unstrippedOutputFile = outputFile
537
Ivan Lozanoffee3342019-08-27 12:03:00 -0700538 flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500539 flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...)
Colin Cross004bd3f2023-10-02 11:39:17 -0700540 flags.LinkFlags = append(flags.LinkFlags, deps.linkObjects...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700541
Matthew Maurer46c46cc2020-01-13 16:34:34 -0800542 if library.dylib() {
Ivan Lozano52767be2019-10-18 14:49:46 -0700543 // We need prefer-dynamic for now to avoid linking in the static stdlib. See:
544 // https://github.com/rust-lang/rust/issues/19680
545 // https://github.com/rust-lang/rust/issues/34909
546 flags.RustFlags = append(flags.RustFlags, "-C prefer-dynamic")
547 }
548
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400549 // Call the appropriate builder for this library type
Ivan Lozanoffee3342019-08-27 12:03:00 -0700550 if library.rlib() {
Sam Delmerico63ca14e2023-09-25 12:13:17 +0000551 ret.kytheFile = TransformSrctoRlib(ctx, crateRootPath, deps, flags, outputFile).kytheFile
Ivan Lozanoffee3342019-08-27 12:03:00 -0700552 } else if library.dylib() {
Sam Delmerico63ca14e2023-09-25 12:13:17 +0000553 ret.kytheFile = TransformSrctoDylib(ctx, crateRootPath, deps, flags, outputFile).kytheFile
Ivan Lozano52767be2019-10-18 14:49:46 -0700554 } else if library.static() {
Sam Delmerico63ca14e2023-09-25 12:13:17 +0000555 ret.kytheFile = TransformSrctoStatic(ctx, crateRootPath, deps, flags, outputFile).kytheFile
Ivan Lozano52767be2019-10-18 14:49:46 -0700556 } else if library.shared() {
Sam Delmerico63ca14e2023-09-25 12:13:17 +0000557 ret.kytheFile = TransformSrctoShared(ctx, crateRootPath, deps, flags, outputFile).kytheFile
Ivan Lozanoffee3342019-08-27 12:03:00 -0700558 }
559
Ivan Lozano52767be2019-10-18 14:49:46 -0700560 if library.rlib() || library.dylib() {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700561 library.flagExporter.exportLinkDirs(deps.linkDirs...)
Colin Cross0de8a1e2020-09-18 14:15:30 -0700562 library.flagExporter.exportLinkObjects(deps.linkObjects...)
Ivan Lozano52767be2019-10-18 14:49:46 -0700563 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700564
Ivan Lozano0a468a42024-05-13 21:03:34 -0400565 // Since we have FFI rlibs, we need to collect their includes as well
566 if library.static() || library.shared() || library.rlib() {
Colin Cross40213022023-12-13 15:19:49 -0800567 android.SetProvider(ctx, cc.FlagExporterInfoProvider, cc.FlagExporterInfo{
Ivan Lozano0a468a42024-05-13 21:03:34 -0400568 IncludeDirs: android.FirstUniquePaths(library.includeDirs),
Colin Cross0de8a1e2020-09-18 14:15:30 -0700569 })
570 }
571
572 if library.shared() {
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400573 // Optimize out relinking against shared libraries whose interface hasn't changed by
574 // depending on a table of contents file instead of the library itself.
575 tocFile := outputFile.ReplaceExtension(ctx, flags.Toolchain.SharedLibSuffix()[1:]+".toc")
576 library.tocFile = android.OptionalPathForPath(tocFile)
577 cc.TransformSharedObjectToToc(ctx, outputFile, tocFile)
578
Colin Cross40213022023-12-13 15:19:49 -0800579 android.SetProvider(ctx, cc.SharedLibraryInfoProvider, cc.SharedLibraryInfo{
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400580 TableOfContents: android.OptionalPathForPath(tocFile),
581 SharedLibrary: outputFile,
582 Target: ctx.Target(),
Colin Crossb614cd42024-10-11 12:52:21 -0700583 // TODO: when rust supports stubs uses the stubs state rather than inferring it from
584 // apex_exclude.
585 IsStubs: Bool(library.Properties.Apex_exclude),
Colin Cross0de8a1e2020-09-18 14:15:30 -0700586 })
587 }
588
589 if library.static() {
Colin Crossa14fb6a2024-10-23 16:57:06 -0700590 depSet := depset.NewBuilder[android.Path](depset.TOPOLOGICAL).Direct(outputFile).Build()
Colin Cross40213022023-12-13 15:19:49 -0800591 android.SetProvider(ctx, cc.StaticLibraryInfoProvider, cc.StaticLibraryInfo{
Colin Cross0de8a1e2020-09-18 14:15:30 -0700592 StaticLibrary: outputFile,
593
594 TransitiveStaticLibrariesForOrdering: depSet,
595 })
596 }
597
598 library.flagExporter.setProvider(ctx)
599
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400600 return ret
Ivan Lozanoffee3342019-08-27 12:03:00 -0700601}
602
Matthew Maurera28404a2023-11-20 23:33:28 +0000603func (library *libraryDecorator) checkedCrateRootPath() (android.Path, error) {
Dan Albert06feee92021-03-19 15:06:02 -0700604 if library.sourceProvider != nil {
Matthew Maurera28404a2023-11-20 23:33:28 +0000605 srcs := library.sourceProvider.Srcs()
606 if len(srcs) == 0 {
607 return nil, errors.New("Source provider generated 0 sources")
608 }
Dan Albert06feee92021-03-19 15:06:02 -0700609 // Assume the first source from the source provider is the library entry point.
Matthew Maurera28404a2023-11-20 23:33:28 +0000610 return srcs[0], nil
Sam Delmerico63ca14e2023-09-25 12:13:17 +0000611 } else {
Matthew Maurera28404a2023-11-20 23:33:28 +0000612 return library.baseCompiler.checkedCrateRootPath()
Dan Albert06feee92021-03-19 15:06:02 -0700613 }
614}
615
616func (library *libraryDecorator) rustdoc(ctx ModuleContext, flags Flags,
617 deps PathDeps) android.OptionalPath {
618 // rustdoc has builtin support for documenting config specific information
619 // regardless of the actual config it was given
620 // (https://doc.rust-lang.org/rustdoc/advanced-features.html#cfgdoc-documenting-platform-specific-or-feature-specific-information),
621 // so we generate the rustdoc for only the primary module so that we have a
622 // single set of docs to refer to.
623 if ctx.Module() != ctx.PrimaryModule() {
624 return android.OptionalPath{}
625 }
626
Matthew Maurera28404a2023-11-20 23:33:28 +0000627 return android.OptionalPathForPath(Rustdoc(ctx, crateRootPath(ctx, library),
Dan Albert06feee92021-03-19 15:06:02 -0700628 deps, flags))
629}
630
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700631func (library *libraryDecorator) getStem(ctx ModuleContext) string {
632 stem := library.baseCompiler.getStemWithoutSuffix(ctx)
633 validateLibraryStem(ctx, stem, library.crateName())
634
635 return stem + String(library.baseCompiler.Properties.Suffix)
636}
637
Ivan Lozano2b081132020-09-08 12:46:52 -0400638func (library *libraryDecorator) install(ctx ModuleContext) {
639 // Only shared and dylib variants make sense to install.
640 if library.shared() || library.dylib() {
641 library.baseCompiler.install(ctx)
642 }
643}
644
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400645func (library *libraryDecorator) Disabled() bool {
646 return library.MutatedProperties.VariantIsDisabled
647}
648
649func (library *libraryDecorator) SetDisabled() {
650 library.MutatedProperties.VariantIsDisabled = true
651}
652
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700653var validCrateName = regexp.MustCompile("[^a-zA-Z0-9_]+")
654
655func validateLibraryStem(ctx BaseModuleContext, filename string, crate_name string) {
656 if crate_name == "" {
657 ctx.PropertyErrorf("crate_name", "crate_name must be defined.")
658 }
659
660 // crate_names are used for the library output file, and rustc expects these
661 // to be alphanumeric with underscores allowed.
662 if validCrateName.MatchString(crate_name) {
663 ctx.PropertyErrorf("crate_name",
664 "library crate_names must be alphanumeric with underscores allowed")
665 }
666
667 // Libraries are expected to begin with "lib" followed by the crate_name
668 if !strings.HasPrefix(filename, "lib"+crate_name) {
669 ctx.ModuleErrorf("Invalid name or stem property; library filenames must start with lib<crate_name>")
670 }
671}
672
Colin Cross8a49a3d2024-05-20 12:22:27 -0700673type libraryTransitionMutator struct{}
674
675func (libraryTransitionMutator) Split(ctx android.BaseModuleContext) []string {
676 m, ok := ctx.Module().(*Module)
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200677 if !ok || m.compiler == nil {
Colin Cross8a49a3d2024-05-20 12:22:27 -0700678 return []string{""}
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200679 }
680 library, ok := m.compiler.(libraryInterface)
681 if !ok {
Colin Cross8a49a3d2024-05-20 12:22:27 -0700682 return []string{""}
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200683 }
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400684
Ivan Lozano0a468a42024-05-13 21:03:34 -0400685 // Don't produce rlib/dylib/source variants for shared or static variants
686 if library.shared() || library.static() {
Colin Cross8a49a3d2024-05-20 12:22:27 -0700687 return []string{""}
Ivan Lozano0a468a42024-05-13 21:03:34 -0400688 }
689
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200690 var variants []string
691 // The source variant is used for SourceProvider modules. The other variants (i.e. rlib and dylib)
692 // depend on this variant. It must be the first variant to be declared.
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200693 if m.sourceProvider != nil {
Colin Cross8a49a3d2024-05-20 12:22:27 -0700694 variants = append(variants, sourceVariation)
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200695 }
696 if library.buildRlib() {
697 variants = append(variants, rlibVariation)
698 }
699 if library.buildDylib() {
700 variants = append(variants, dylibVariation)
701 }
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400702
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200703 if len(variants) == 0 {
Colin Cross8a49a3d2024-05-20 12:22:27 -0700704 return []string{""}
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200705 }
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200706
Colin Cross8a49a3d2024-05-20 12:22:27 -0700707 return variants
708}
Ivan Lozano1921e802021-05-20 13:39:16 -0400709
Colin Cross8a49a3d2024-05-20 12:22:27 -0700710func (libraryTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string {
711 return ""
712}
713
714func (libraryTransitionMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string {
715 m, ok := ctx.Module().(*Module)
716 if !ok || m.compiler == nil {
717 return ""
718 }
719 library, ok := m.compiler.(libraryInterface)
720 if !ok {
721 return ""
722 }
723
724 if incomingVariation == "" {
725 if m.sourceProvider != nil {
726 return sourceVariation
727 }
728 if library.shared() {
729 return ""
730 }
731 if library.buildRlib() {
732 return rlibVariation
733 }
734 if library.buildDylib() {
735 return dylibVariation
Ivan Lozanoffee3342019-08-27 12:03:00 -0700736 }
737 }
Colin Cross8a49a3d2024-05-20 12:22:27 -0700738 return incomingVariation
739}
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200740
Colin Cross8a49a3d2024-05-20 12:22:27 -0700741func (libraryTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, variation string) {
742 m, ok := ctx.Module().(*Module)
743 if !ok || m.compiler == nil {
744 return
745 }
746 library, ok := m.compiler.(libraryInterface)
747 if !ok {
748 return
749 }
750
751 switch variation {
752 case rlibVariation:
753 library.setRlib()
754 case dylibVariation:
755 library.setDylib()
756 if m.ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation {
757 // TODO(b/165791368)
758 // Disable dylib Vendor Ramdisk variations until we support these.
759 m.Disable()
760 }
761
762 case sourceVariation:
763 library.setSource()
764 // The source variant does not produce any library.
765 // Disable the compilation steps.
766 m.compiler.SetDisabled()
Ivan Lozanofd47b1a2024-05-17 14:13:41 -0400767 }
768
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200769 // If a source variant is created, add an inter-variant dependency
770 // between the other variants and the source variant.
Colin Cross8a49a3d2024-05-20 12:22:27 -0700771 if m.sourceProvider != nil && variation != sourceVariation {
772 ctx.AddVariationDependencies(
773 []blueprint.Variation{
774 {"rust_libraries", sourceVariation},
775 },
776 sourceDepTag, ctx.ModuleName())
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200777 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700778}
Ivan Lozano2b081132020-09-08 12:46:52 -0400779
Colin Cross8a49a3d2024-05-20 12:22:27 -0700780type libstdTransitionMutator struct{}
Ivan Lozano2b081132020-09-08 12:46:52 -0400781
Colin Cross8a49a3d2024-05-20 12:22:27 -0700782func (libstdTransitionMutator) Split(ctx android.BaseModuleContext) []string {
783 if m, ok := ctx.Module().(*Module); ok && m.compiler != nil && !m.compiler.Disabled() {
784 // Only create a variant if a library is actually being built.
785 if library, ok := m.compiler.(libraryInterface); ok {
786 if library.rlib() && !library.sysroot() {
Ivan Lozano806efd32024-12-11 21:38:53 +0000787 return []string{"rlib-std", "dylib-std"}
Ivan Lozano2b081132020-09-08 12:46:52 -0400788 }
789 }
790 }
Colin Cross8a49a3d2024-05-20 12:22:27 -0700791 return []string{""}
792}
793
794func (libstdTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string {
795 return ""
796}
797
798func (libstdTransitionMutator) IncomingTransition(ctx android.IncomingTransitionContext, incomingVariation string) string {
799 if m, ok := ctx.Module().(*Module); ok && m.compiler != nil && !m.compiler.Disabled() {
800 if library, ok := m.compiler.(libraryInterface); ok {
801 if library.shared() {
802 return ""
803 }
804 if library.rlib() && !library.sysroot() {
805 if incomingVariation != "" {
806 return incomingVariation
807 }
808 return "rlib-std"
809 }
810 }
811 }
812 return ""
813}
814
815func (libstdTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, variation string) {
816 if variation == "rlib-std" {
817 rlib := ctx.Module().(*Module)
818 rlib.compiler.(libraryInterface).setRlibStd()
819 rlib.Properties.RustSubName += RlibStdlibSuffix
820 } else if variation == "dylib-std" {
821 dylib := ctx.Module().(*Module)
822 dylib.compiler.(libraryInterface).setDylibStd()
823 if dylib.ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation {
824 // TODO(b/165791368)
825 // Disable rlibs that link against dylib-std on vendor ramdisk variations until those dylib
826 // variants are properly supported.
827 dylib.Disable()
828 }
829 }
Ivan Lozano2b081132020-09-08 12:46:52 -0400830}