blob: 730000114749481dbf7f6cab05fdd6c630ca8a23 [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
Ivan Lozanoffee3342019-08-27 12:03:00 -070023 "android/soong/android"
Colin Cross0de8a1e2020-09-18 14:15:30 -070024 "android/soong/cc"
Ivan Lozanoffee3342019-08-27 12:03:00 -070025)
26
Ivan Lozano2b081132020-09-08 12:46:52 -040027var (
Ivan Lozano4df02572023-06-15 14:21:09 -040028 RlibStdlibSuffix = ".rlib-std"
Ivan Lozano2b081132020-09-08 12:46:52 -040029)
30
Ivan Lozanoffee3342019-08-27 12:03:00 -070031func init() {
32 android.RegisterModuleType("rust_library", RustLibraryFactory)
33 android.RegisterModuleType("rust_library_dylib", RustLibraryDylibFactory)
34 android.RegisterModuleType("rust_library_rlib", RustLibraryRlibFactory)
35 android.RegisterModuleType("rust_library_host", RustLibraryHostFactory)
36 android.RegisterModuleType("rust_library_host_dylib", RustLibraryDylibHostFactory)
37 android.RegisterModuleType("rust_library_host_rlib", RustLibraryRlibHostFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -070038 android.RegisterModuleType("rust_ffi", RustFFIFactory)
39 android.RegisterModuleType("rust_ffi_shared", RustFFISharedFactory)
Ivan Lozano0a468a42024-05-13 21:03:34 -040040 android.RegisterModuleType("rust_ffi_rlib", RustFFIRlibFactory)
Matthew Maurer2ae05132020-06-23 14:28:53 -070041 android.RegisterModuleType("rust_ffi_host", RustFFIHostFactory)
42 android.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
Ivan Lozano0a468a42024-05-13 21:03:34 -040043 android.RegisterModuleType("rust_ffi_host_rlib", RustFFIRlibHostFactory)
44
45 // TODO: Remove when all instances of rust_ffi_static have been switched to rust_ffi_rlib
46 // Alias rust_ffi_static to the combined rust_ffi_rlib factory
47 android.RegisterModuleType("rust_ffi_static", RustFFIStaticRlibFactory)
48 android.RegisterModuleType("rust_ffi_host_static", RustFFIStaticRlibHostFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -070049}
50
51type VariantLibraryProperties struct {
Matthew Maurerc761eec2020-06-25 00:47:46 -070052 Enabled *bool `android:"arch_variant"`
53 Srcs []string `android:"path,arch_variant"`
Ivan Lozanoffee3342019-08-27 12:03:00 -070054}
55
56type LibraryCompilerProperties struct {
Ivan Lozano52767be2019-10-18 14:49:46 -070057 Rlib VariantLibraryProperties `android:"arch_variant"`
58 Dylib VariantLibraryProperties `android:"arch_variant"`
59 Shared VariantLibraryProperties `android:"arch_variant"`
60 Static VariantLibraryProperties `android:"arch_variant"`
Ivan Lozanoffee3342019-08-27 12:03:00 -070061
Ivan Lozanof033ca62024-03-21 13:43:14 -040062 // TODO: Remove this when all instances of Include_dirs have been removed from rust_ffi modules.
63 // 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 -070064 Include_dirs []string `android:"path,arch_variant"`
Ivan Lozano2b081132020-09-08 12:46:52 -040065
Ivan Lozanof033ca62024-03-21 13:43:14 -040066 // path to include directories to export to cc_* modules, only relevant for static/shared variants.
67 Export_include_dirs []string `android:"path,arch_variant"`
68
Ivan Lozano2b081132020-09-08 12:46:52 -040069 // Whether this library is part of the Rust toolchain sysroot.
70 Sysroot *bool
Ivan Lozanoffee3342019-08-27 12:03:00 -070071}
72
73type LibraryMutatedProperties struct {
Ivan Lozanoffee3342019-08-27 12:03:00 -070074 // Build a dylib variant
75 BuildDylib bool `blueprint:"mutated"`
76 // Build an rlib variant
77 BuildRlib bool `blueprint:"mutated"`
Ivan Lozano52767be2019-10-18 14:49:46 -070078 // Build a shared library variant
79 BuildShared bool `blueprint:"mutated"`
80 // Build a static library variant
81 BuildStatic bool `blueprint:"mutated"`
Ivan Lozanoffee3342019-08-27 12:03:00 -070082
83 // This variant is a dylib
84 VariantIsDylib bool `blueprint:"mutated"`
85 // This variant is an rlib
86 VariantIsRlib bool `blueprint:"mutated"`
Ivan Lozano52767be2019-10-18 14:49:46 -070087 // This variant is a shared library
88 VariantIsShared bool `blueprint:"mutated"`
89 // This variant is a static library
90 VariantIsStatic 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 Lozano0a468a42024-05-13 21:03:34 -0400112 isFFI bool
113
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400114 // table-of-contents file for cdylib crates to optimize out relinking when possible
115 tocFile android.OptionalPath
Ivan Lozanoffee3342019-08-27 12:03:00 -0700116}
117
118type libraryInterface interface {
119 rlib() bool
120 dylib() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700121 static() bool
122 shared() bool
Ivan Lozano2b081132020-09-08 12:46:52 -0400123 sysroot() bool
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200124 source() bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700125
126 // Returns true if the build options for the module have selected a particular build type
127 buildRlib() bool
128 buildDylib() bool
Ivan Lozano52767be2019-10-18 14:49:46 -0700129 buildShared() bool
130 buildStatic() bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700131
132 // Sets a particular variant type
133 setRlib()
134 setDylib()
Ivan Lozano52767be2019-10-18 14:49:46 -0700135 setShared()
136 setStatic()
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200137 setSource()
Ivan Lozano52767be2019-10-18 14:49:46 -0700138
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400139 // libstd linkage functions
140 rlibStd() bool
Ivan Lozano2b081132020-09-08 12:46:52 -0400141 setRlibStd()
142 setDylibStd()
143
Ivan Lozano52767be2019-10-18 14:49:46 -0700144 // Build a specific library variant
Matthew Maurer2ae05132020-06-23 14:28:53 -0700145 BuildOnlyFFI()
146 BuildOnlyRust()
Ivan Lozano52767be2019-10-18 14:49:46 -0700147 BuildOnlyRlib()
148 BuildOnlyDylib()
149 BuildOnlyStatic()
150 BuildOnlyShared()
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400151
152 toc() android.OptionalPath
Ivan Lozano0a468a42024-05-13 21:03:34 -0400153
154 isFFILibrary() bool
Ivan Lozanoffee3342019-08-27 12:03:00 -0700155}
156
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400157func (library *libraryDecorator) nativeCoverage() bool {
158 return true
159}
160
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400161func (library *libraryDecorator) toc() android.OptionalPath {
162 return library.tocFile
163}
164
Ivan Lozanoffee3342019-08-27 12:03:00 -0700165func (library *libraryDecorator) rlib() bool {
166 return library.MutatedProperties.VariantIsRlib
167}
168
Ivan Lozano2b081132020-09-08 12:46:52 -0400169func (library *libraryDecorator) sysroot() bool {
170 return Bool(library.Properties.Sysroot)
171}
172
Ivan Lozanoffee3342019-08-27 12:03:00 -0700173func (library *libraryDecorator) dylib() bool {
174 return library.MutatedProperties.VariantIsDylib
175}
176
Ivan Lozano52767be2019-10-18 14:49:46 -0700177func (library *libraryDecorator) shared() bool {
178 return library.MutatedProperties.VariantIsShared
179}
180
181func (library *libraryDecorator) static() bool {
182 return library.MutatedProperties.VariantIsStatic
183}
184
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200185func (library *libraryDecorator) source() bool {
186 return library.MutatedProperties.VariantIsSource
187}
188
Ivan Lozanoffee3342019-08-27 12:03:00 -0700189func (library *libraryDecorator) buildRlib() bool {
190 return library.MutatedProperties.BuildRlib && BoolDefault(library.Properties.Rlib.Enabled, true)
191}
192
193func (library *libraryDecorator) buildDylib() bool {
194 return library.MutatedProperties.BuildDylib && BoolDefault(library.Properties.Dylib.Enabled, true)
195}
196
Ivan Lozano52767be2019-10-18 14:49:46 -0700197func (library *libraryDecorator) buildShared() bool {
198 return library.MutatedProperties.BuildShared && BoolDefault(library.Properties.Shared.Enabled, true)
199}
200
201func (library *libraryDecorator) buildStatic() bool {
202 return library.MutatedProperties.BuildStatic && BoolDefault(library.Properties.Static.Enabled, true)
203}
204
Ivan Lozanoffee3342019-08-27 12:03:00 -0700205func (library *libraryDecorator) setRlib() {
206 library.MutatedProperties.VariantIsRlib = true
207 library.MutatedProperties.VariantIsDylib = false
Ivan Lozano52767be2019-10-18 14:49:46 -0700208 library.MutatedProperties.VariantIsStatic = false
209 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.VariantIsStatic = false
216 library.MutatedProperties.VariantIsShared = false
217}
218
Ivan Lozano3149e6e2021-06-01 15:09:53 -0400219func (library *libraryDecorator) rlibStd() bool {
220 return library.MutatedProperties.VariantIsStaticStd
221}
222
Ivan Lozano2b081132020-09-08 12:46:52 -0400223func (library *libraryDecorator) setRlibStd() {
224 library.MutatedProperties.VariantIsStaticStd = true
225}
226
227func (library *libraryDecorator) setDylibStd() {
228 library.MutatedProperties.VariantIsStaticStd = false
229}
230
Ivan Lozano52767be2019-10-18 14:49:46 -0700231func (library *libraryDecorator) setShared() {
232 library.MutatedProperties.VariantIsStatic = false
233 library.MutatedProperties.VariantIsShared = true
234 library.MutatedProperties.VariantIsRlib = false
235 library.MutatedProperties.VariantIsDylib = false
236}
237
238func (library *libraryDecorator) setStatic() {
239 library.MutatedProperties.VariantIsStatic = true
240 library.MutatedProperties.VariantIsShared = false
241 library.MutatedProperties.VariantIsRlib = false
242 library.MutatedProperties.VariantIsDylib = false
Ivan Lozanoffee3342019-08-27 12:03:00 -0700243}
244
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200245func (library *libraryDecorator) setSource() {
246 library.MutatedProperties.VariantIsSource = true
247}
248
Liz Kammer356f7d42021-01-26 09:18:53 -0500249func (library *libraryDecorator) autoDep(ctx android.BottomUpMutatorContext) autoDep {
Ivan Lozanoadd122a2023-07-13 11:01:41 -0400250 if library.preferRlib() {
Ivan Lozanoea086132020-12-08 14:43:00 -0500251 return rlibAutoDep
252 } else if library.rlib() || library.static() {
Matthew Maurer0f003b12020-06-29 14:34:06 -0700253 return rlibAutoDep
254 } else if library.dylib() || library.shared() {
255 return dylibAutoDep
256 } else {
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200257 panic(fmt.Errorf("autoDep called on library %q that has no enabled variants.", ctx.ModuleName()))
Matthew Maurer0f003b12020-06-29 14:34:06 -0700258 }
259}
260
Ivan Lozanoea086132020-12-08 14:43:00 -0500261func (library *libraryDecorator) stdLinkage(ctx *depsContext) RustLinkage {
Ivan Lozano0a468a42024-05-13 21:03:34 -0400262 if library.static() || library.MutatedProperties.VariantIsStaticStd || (library.rlib() && library.isFFILibrary()) {
Ivan Lozanoea086132020-12-08 14:43:00 -0500263 return RlibLinkage
264 } else if library.baseCompiler.preferRlib() {
265 return RlibLinkage
266 }
267 return DefaultLinkage
268}
269
Ivan Lozanoffee3342019-08-27 12:03:00 -0700270var _ compiler = (*libraryDecorator)(nil)
Ivan Lozano52767be2019-10-18 14:49:46 -0700271var _ libraryInterface = (*libraryDecorator)(nil)
Matthew Maurerbb3add12020-06-25 09:34:12 -0700272var _ exportedFlagsProducer = (*libraryDecorator)(nil)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700273
Martin Geisler67ec0542022-11-18 12:08:55 +0100274// rust_library produces all Rust variants (rust_library_dylib and
275// rust_library_rlib).
Ivan Lozanoffee3342019-08-27 12:03:00 -0700276func RustLibraryFactory() android.Module {
Matthew Maurer2ae05132020-06-23 14:28:53 -0700277 module, library := NewRustLibrary(android.HostAndDeviceSupported)
278 library.BuildOnlyRust()
279 return module.Init()
280}
281
Ivan Lozano0a468a42024-05-13 21:03:34 -0400282// rust_ffi produces all FFI variants (rust_ffi_shared, rust_ffi_static, and
283// rust_ffi_rlib).
Matthew Maurer2ae05132020-06-23 14:28:53 -0700284func RustFFIFactory() android.Module {
285 module, library := NewRustLibrary(android.HostAndDeviceSupported)
286 library.BuildOnlyFFI()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700287 return module.Init()
288}
289
Martin Geisler67ec0542022-11-18 12:08:55 +0100290// rust_library_dylib produces a Rust dylib (Rust crate type "dylib").
Ivan Lozanoffee3342019-08-27 12:03:00 -0700291func RustLibraryDylibFactory() android.Module {
292 module, library := NewRustLibrary(android.HostAndDeviceSupported)
293 library.BuildOnlyDylib()
294 return module.Init()
295}
296
Martin Geisler67ec0542022-11-18 12:08:55 +0100297// rust_library_rlib produces an rlib (Rust crate type "rlib").
Ivan Lozanoffee3342019-08-27 12:03:00 -0700298func RustLibraryRlibFactory() android.Module {
299 module, library := NewRustLibrary(android.HostAndDeviceSupported)
300 library.BuildOnlyRlib()
301 return module.Init()
302}
303
Martin Geisler67ec0542022-11-18 12:08:55 +0100304// rust_ffi_shared produces a shared library (Rust crate type
305// "cdylib").
Matthew Maurer2ae05132020-06-23 14:28:53 -0700306func RustFFISharedFactory() android.Module {
Ivan Lozano52767be2019-10-18 14:49:46 -0700307 module, library := NewRustLibrary(android.HostAndDeviceSupported)
308 library.BuildOnlyShared()
309 return module.Init()
310}
311
Martin Geisler67ec0542022-11-18 12:08:55 +0100312// rust_library_host produces all Rust variants for the host
313// (rust_library_dylib_host and rust_library_rlib_host).
Ivan Lozanoffee3342019-08-27 12:03:00 -0700314func RustLibraryHostFactory() android.Module {
Matthew Maurer2ae05132020-06-23 14:28:53 -0700315 module, library := NewRustLibrary(android.HostSupported)
316 library.BuildOnlyRust()
317 return module.Init()
318}
319
Martin Geisler67ec0542022-11-18 12:08:55 +0100320// rust_ffi_host produces all FFI variants for the host
Ivan Lozano0a468a42024-05-13 21:03:34 -0400321// (rust_ffi_rlib_host, rust_ffi_static_host, and rust_ffi_shared_host).
Matthew Maurer2ae05132020-06-23 14:28:53 -0700322func RustFFIHostFactory() android.Module {
323 module, library := NewRustLibrary(android.HostSupported)
324 library.BuildOnlyFFI()
Ivan Lozanoffee3342019-08-27 12:03:00 -0700325 return module.Init()
326}
327
Martin Geisler67ec0542022-11-18 12:08:55 +0100328// rust_library_dylib_host produces a dylib for the host (Rust crate
329// type "dylib").
Ivan Lozanoffee3342019-08-27 12:03:00 -0700330func RustLibraryDylibHostFactory() android.Module {
331 module, library := NewRustLibrary(android.HostSupported)
332 library.BuildOnlyDylib()
333 return module.Init()
334}
335
Martin Geisler67ec0542022-11-18 12:08:55 +0100336// rust_library_rlib_host produces an rlib for the host (Rust crate
337// type "rlib").
Ivan Lozanoffee3342019-08-27 12:03:00 -0700338func RustLibraryRlibHostFactory() android.Module {
339 module, library := NewRustLibrary(android.HostSupported)
340 library.BuildOnlyRlib()
341 return module.Init()
342}
343
Martin Geisler67ec0542022-11-18 12:08:55 +0100344// rust_ffi_shared_host produces an shared library for the host (Rust
345// crate type "cdylib").
Matthew Maurer2ae05132020-06-23 14:28:53 -0700346func RustFFISharedHostFactory() android.Module {
Ivan Lozano52767be2019-10-18 14:49:46 -0700347 module, library := NewRustLibrary(android.HostSupported)
348 library.BuildOnlyShared()
349 return module.Init()
350}
351
Ivan Lozano0a468a42024-05-13 21:03:34 -0400352// rust_ffi_rlib_host produces an rlib for the host (Rust crate
353// type "rlib").
354func RustFFIRlibHostFactory() android.Module {
355 module, library := NewRustLibrary(android.HostSupported)
356 library.BuildOnlyRlibStatic()
357
358 library.isFFI = true
359 return module.Init()
360}
361
362// rust_ffi_rlib produces an rlib (Rust crate type "rlib").
363func RustFFIRlibFactory() android.Module {
364 module, library := NewRustLibrary(android.HostAndDeviceSupported)
365 library.BuildOnlyRlib()
366
367 library.isFFI = true
368 return module.Init()
369}
370
371// rust_ffi_static produces a staticlib and an rlib variant
372func RustFFIStaticRlibFactory() android.Module {
373 module, library := NewRustLibrary(android.HostAndDeviceSupported)
374 library.BuildOnlyRlibStatic()
375
376 library.isFFI = true
377 return module.Init()
378}
379
380// rust_ffi_static_host produces a staticlib and an rlib variant for the host
381func RustFFIStaticRlibHostFactory() android.Module {
382 module, library := NewRustLibrary(android.HostSupported)
383 library.BuildOnlyRlibStatic()
384
385 library.isFFI = true
386 return module.Init()
387}
388
Matthew Maurer2ae05132020-06-23 14:28:53 -0700389func (library *libraryDecorator) BuildOnlyFFI() {
390 library.MutatedProperties.BuildDylib = false
Ivan Lozano0a468a42024-05-13 21:03:34 -0400391 // we build rlibs for later static ffi linkage.
392 library.MutatedProperties.BuildRlib = true
Matthew Maurer2ae05132020-06-23 14:28:53 -0700393 library.MutatedProperties.BuildShared = true
394 library.MutatedProperties.BuildStatic = true
Ivan Lozano0a468a42024-05-13 21:03:34 -0400395
396 library.isFFI = true
Matthew Maurer2ae05132020-06-23 14:28:53 -0700397}
398
399func (library *libraryDecorator) BuildOnlyRust() {
400 library.MutatedProperties.BuildDylib = true
401 library.MutatedProperties.BuildRlib = true
402 library.MutatedProperties.BuildShared = false
403 library.MutatedProperties.BuildStatic = false
404}
405
Ivan Lozanoffee3342019-08-27 12:03:00 -0700406func (library *libraryDecorator) BuildOnlyDylib() {
Matthew Maurer2ae05132020-06-23 14:28:53 -0700407 library.MutatedProperties.BuildDylib = true
Ivan Lozanoffee3342019-08-27 12:03:00 -0700408 library.MutatedProperties.BuildRlib = false
Ivan Lozano52767be2019-10-18 14:49:46 -0700409 library.MutatedProperties.BuildShared = false
410 library.MutatedProperties.BuildStatic = false
Ivan Lozanoffee3342019-08-27 12:03:00 -0700411}
412
413func (library *libraryDecorator) BuildOnlyRlib() {
414 library.MutatedProperties.BuildDylib = false
Matthew Maurer2ae05132020-06-23 14:28:53 -0700415 library.MutatedProperties.BuildRlib = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700416 library.MutatedProperties.BuildShared = false
417 library.MutatedProperties.BuildStatic = false
418}
419
Ivan Lozano0a468a42024-05-13 21:03:34 -0400420func (library *libraryDecorator) BuildOnlyRlibStatic() {
421 library.MutatedProperties.BuildDylib = false
422 library.MutatedProperties.BuildRlib = true
423 library.MutatedProperties.BuildShared = false
424 library.MutatedProperties.BuildStatic = true
425 library.isFFI = true
426}
427
Ivan Lozano52767be2019-10-18 14:49:46 -0700428func (library *libraryDecorator) BuildOnlyStatic() {
Ivan Lozano52767be2019-10-18 14:49:46 -0700429 library.MutatedProperties.BuildRlib = false
430 library.MutatedProperties.BuildDylib = false
Matthew Maurer2ae05132020-06-23 14:28:53 -0700431 library.MutatedProperties.BuildShared = false
432 library.MutatedProperties.BuildStatic = true
Ivan Lozano0a468a42024-05-13 21:03:34 -0400433
434 library.isFFI = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700435}
436
437func (library *libraryDecorator) BuildOnlyShared() {
Ivan Lozano52767be2019-10-18 14:49:46 -0700438 library.MutatedProperties.BuildRlib = false
439 library.MutatedProperties.BuildDylib = false
Matthew Maurer2ae05132020-06-23 14:28:53 -0700440 library.MutatedProperties.BuildStatic = false
441 library.MutatedProperties.BuildShared = true
Ivan Lozano0a468a42024-05-13 21:03:34 -0400442
443 library.isFFI = true
444}
445
446func (library *libraryDecorator) isFFILibrary() bool {
447 return library.isFFI
Ivan Lozanoffee3342019-08-27 12:03:00 -0700448}
449
450func NewRustLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
Ivan Lozano9d1df102020-04-28 10:10:23 -0400451 module := newModule(hod, android.MultilibBoth)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700452
453 library := &libraryDecorator{
454 MutatedProperties: LibraryMutatedProperties{
Matthew Maurer2ae05132020-06-23 14:28:53 -0700455 BuildDylib: false,
456 BuildRlib: false,
457 BuildShared: false,
458 BuildStatic: false,
Ivan Lozanoffee3342019-08-27 12:03:00 -0700459 },
Chih-Hung Hsieh9a4a7ba2019-12-12 19:36:05 -0800460 baseCompiler: NewBaseCompiler("lib", "lib64", InstallInSystem),
Matthew Maurerbb3add12020-06-25 09:34:12 -0700461 flagExporter: NewFlagExporter(),
Ivan Lozanoffee3342019-08-27 12:03:00 -0700462 }
463
464 module.compiler = library
465
466 return module, library
467}
468
469func (library *libraryDecorator) compilerProps() []interface{} {
470 return append(library.baseCompiler.compilerProps(),
471 &library.Properties,
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200472 &library.MutatedProperties,
473 &library.stripper.StripProperties)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700474}
475
Ivan Lozanof1c84332019-09-20 11:00:37 -0700476func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
477 deps = library.baseCompiler.compilerDeps(ctx, deps)
478
Colin Crosse32f0932022-01-23 20:48:36 -0800479 if library.dylib() || library.shared() {
480 if ctx.toolchain().Bionic() {
481 deps = bionicDeps(ctx, deps, false)
482 deps.CrtBegin = []string{"crtbegin_so"}
483 deps.CrtEnd = []string{"crtend_so"}
484 } else if ctx.Os() == android.LinuxMusl {
485 deps = muslDeps(ctx, deps, false)
486 deps.CrtBegin = []string{"libc_musl_crtbegin_so"}
487 deps.CrtEnd = []string{"libc_musl_crtend_so"}
488 }
Ivan Lozanof1c84332019-09-20 11:00:37 -0700489 }
490
491 return deps
492}
Ivan Lozanobec05ea2020-06-09 08:27:49 -0400493
494func (library *libraryDecorator) sharedLibFilename(ctx ModuleContext) string {
495 return library.getStem(ctx) + ctx.toolchain().SharedLibSuffix()
496}
497
Ivan Lozano28ed8f42024-05-06 21:46:39 -0400498// Library cfg flags common to all variants
499func CommonLibraryCfgFlags(ctx android.ModuleContext, flags Flags) Flags {
500 return flags
501}
502
Ivan Lozano67eada32021-09-23 11:50:33 -0400503func (library *libraryDecorator) cfgFlags(ctx ModuleContext, flags Flags) Flags {
504 flags = library.baseCompiler.cfgFlags(ctx, flags)
Ivan Lozano28ed8f42024-05-06 21:46:39 -0400505 flags = CommonLibraryCfgFlags(ctx, flags)
506
Stephen Crane0dbfc562021-07-07 19:05:02 -0700507 if library.dylib() {
508 // We need to add a dependency on std in order to link crates as dylibs.
509 // The hack to add this dependency is guarded by the following cfg so
510 // that we don't force a dependency when it isn't needed.
511 library.baseCompiler.Properties.Cfgs = append(library.baseCompiler.Properties.Cfgs, "android_dylib")
512 }
Ivan Lozano67eada32021-09-23 11:50:33 -0400513
Ivan Lozano28ed8f42024-05-06 21:46:39 -0400514 flags.RustFlags = append(flags.RustFlags, cfgsToFlags(library.baseCompiler.Properties.Cfgs)...)
515 flags.RustdocFlags = append(flags.RustdocFlags, cfgsToFlags(library.baseCompiler.Properties.Cfgs)...)
516
517 return flags
518}
519
520// Common flags applied to all libraries irrespective of properties or variant should be included here
521func CommonLibraryCompilerFlags(ctx android.ModuleContext, flags Flags) Flags {
522 flags.RustFlags = append(flags.RustFlags, "-C metadata="+ctx.ModuleName())
Ivan Lozano67eada32021-09-23 11:50:33 -0400523
524 return flags
525}
526
527func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800528 flags = library.baseCompiler.compilerFlags(ctx, flags)
Ivan Lozano67eada32021-09-23 11:50:33 -0400529
Ivan Lozano28ed8f42024-05-06 21:46:39 -0400530 flags = CommonLibraryCompilerFlags(ctx, flags)
531
Ivan Lozano0a468a42024-05-13 21:03:34 -0400532 if library.isFFI {
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800533 library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Include_dirs)...)
Ivan Lozanof033ca62024-03-21 13:43:14 -0400534 library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Export_include_dirs)...)
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800535 }
Ivan Lozano0a468a42024-05-13 21:03:34 -0400536
Ivan Lozanobec05ea2020-06-09 08:27:49 -0400537 if library.shared() {
A. Cody Schuffelenc183e3a2023-08-14 21:09:47 -0700538 if ctx.Darwin() {
539 flags.LinkFlags = append(
540 flags.LinkFlags,
541 "-dynamic_lib",
542 "-install_name @rpath/"+library.sharedLibFilename(ctx),
543 )
544 } else {
545 flags.LinkFlags = append(flags.LinkFlags, "-Wl,-soname="+library.sharedLibFilename(ctx))
546 }
Ivan Lozanobec05ea2020-06-09 08:27:49 -0400547 }
548
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800549 return flags
550}
Ivan Lozanof1c84332019-09-20 11:00:37 -0700551
Sasha Smundaka76acba2022-04-18 20:12:56 -0700552func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) buildOutput {
553 var outputFile android.ModuleOutPath
554 var ret buildOutput
Thiébaud Weksteenfabaff62020-08-27 13:48:36 +0200555 var fileName string
Matthew Maurera28404a2023-11-20 23:33:28 +0000556 crateRootPath := crateRootPath(ctx, library)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700557
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400558 if library.sourceProvider != nil {
Ivan Lozano9d74a522020-12-01 09:25:22 -0500559 deps.srcProviderFiles = append(deps.srcProviderFiles, library.sourceProvider.Srcs()...)
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400560 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700561
Ivan Lozano0a468a42024-05-13 21:03:34 -0400562 // Ensure link dirs are not duplicated
563 deps.linkDirs = android.FirstUniqueStrings(deps.linkDirs)
564
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400565 // Calculate output filename
566 if library.rlib() {
567 fileName = library.getStem(ctx) + ctx.toolchain().RlibSuffix()
568 outputFile = android.PathForModuleOut(ctx, fileName)
Sasha Smundaka76acba2022-04-18 20:12:56 -0700569 ret.outputFile = outputFile
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400570 } else if library.dylib() {
571 fileName = library.getStem(ctx) + ctx.toolchain().DylibSuffix()
572 outputFile = android.PathForModuleOut(ctx, fileName)
Sasha Smundaka76acba2022-04-18 20:12:56 -0700573 ret.outputFile = outputFile
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400574 } else if library.static() {
575 fileName = library.getStem(ctx) + ctx.toolchain().StaticLibSuffix()
576 outputFile = android.PathForModuleOut(ctx, fileName)
Sasha Smundaka76acba2022-04-18 20:12:56 -0700577 ret.outputFile = outputFile
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400578 } else if library.shared() {
579 fileName = library.sharedLibFilename(ctx)
580 outputFile = android.PathForModuleOut(ctx, fileName)
Sasha Smundaka76acba2022-04-18 20:12:56 -0700581 ret.outputFile = outputFile
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400582 }
583
584 if !library.rlib() && !library.static() && library.stripper.NeedsStrip(ctx) {
585 strippedOutputFile := outputFile
586 outputFile = android.PathForModuleOut(ctx, "unstripped", fileName)
587 library.stripper.StripExecutableOrSharedLib(ctx, outputFile, strippedOutputFile)
588
589 library.baseCompiler.strippedOutputFile = android.OptionalPathForPath(strippedOutputFile)
590 }
591 library.baseCompiler.unstrippedOutputFile = outputFile
592
Ivan Lozanoffee3342019-08-27 12:03:00 -0700593 flags.RustFlags = append(flags.RustFlags, deps.depFlags...)
Ivan Lozano3dfa12d2021-02-04 11:29:41 -0500594 flags.LinkFlags = append(flags.LinkFlags, deps.depLinkFlags...)
Colin Cross004bd3f2023-10-02 11:39:17 -0700595 flags.LinkFlags = append(flags.LinkFlags, deps.linkObjects...)
Ivan Lozanoffee3342019-08-27 12:03:00 -0700596
Matthew Maurer46c46cc2020-01-13 16:34:34 -0800597 if library.dylib() {
Ivan Lozano52767be2019-10-18 14:49:46 -0700598 // We need prefer-dynamic for now to avoid linking in the static stdlib. See:
599 // https://github.com/rust-lang/rust/issues/19680
600 // https://github.com/rust-lang/rust/issues/34909
601 flags.RustFlags = append(flags.RustFlags, "-C prefer-dynamic")
602 }
603
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400604 // Call the appropriate builder for this library type
Ivan Lozanoffee3342019-08-27 12:03:00 -0700605 if library.rlib() {
Sam Delmerico63ca14e2023-09-25 12:13:17 +0000606 ret.kytheFile = TransformSrctoRlib(ctx, crateRootPath, deps, flags, outputFile).kytheFile
Ivan Lozanoffee3342019-08-27 12:03:00 -0700607 } else if library.dylib() {
Sam Delmerico63ca14e2023-09-25 12:13:17 +0000608 ret.kytheFile = TransformSrctoDylib(ctx, crateRootPath, deps, flags, outputFile).kytheFile
Ivan Lozano52767be2019-10-18 14:49:46 -0700609 } else if library.static() {
Sam Delmerico63ca14e2023-09-25 12:13:17 +0000610 ret.kytheFile = TransformSrctoStatic(ctx, crateRootPath, deps, flags, outputFile).kytheFile
Ivan Lozano52767be2019-10-18 14:49:46 -0700611 } else if library.shared() {
Sam Delmerico63ca14e2023-09-25 12:13:17 +0000612 ret.kytheFile = TransformSrctoShared(ctx, crateRootPath, deps, flags, outputFile).kytheFile
Ivan Lozanoffee3342019-08-27 12:03:00 -0700613 }
614
Ivan Lozano52767be2019-10-18 14:49:46 -0700615 if library.rlib() || library.dylib() {
Colin Cross0de8a1e2020-09-18 14:15:30 -0700616 library.flagExporter.exportLinkDirs(deps.linkDirs...)
Colin Cross0de8a1e2020-09-18 14:15:30 -0700617 library.flagExporter.exportLinkObjects(deps.linkObjects...)
Ivan Lozano52767be2019-10-18 14:49:46 -0700618 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700619
Ivan Lozano0a468a42024-05-13 21:03:34 -0400620 // Since we have FFI rlibs, we need to collect their includes as well
621 if library.static() || library.shared() || library.rlib() {
Colin Cross40213022023-12-13 15:19:49 -0800622 android.SetProvider(ctx, cc.FlagExporterInfoProvider, cc.FlagExporterInfo{
Ivan Lozano0a468a42024-05-13 21:03:34 -0400623 IncludeDirs: android.FirstUniquePaths(library.includeDirs),
Colin Cross0de8a1e2020-09-18 14:15:30 -0700624 })
625 }
626
627 if library.shared() {
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400628 // Optimize out relinking against shared libraries whose interface hasn't changed by
629 // depending on a table of contents file instead of the library itself.
630 tocFile := outputFile.ReplaceExtension(ctx, flags.Toolchain.SharedLibSuffix()[1:]+".toc")
631 library.tocFile = android.OptionalPathForPath(tocFile)
632 cc.TransformSharedObjectToToc(ctx, outputFile, tocFile)
633
Colin Cross40213022023-12-13 15:19:49 -0800634 android.SetProvider(ctx, cc.SharedLibraryInfoProvider, cc.SharedLibraryInfo{
Ivan Lozano7b0781d2021-11-03 15:30:18 -0400635 TableOfContents: android.OptionalPathForPath(tocFile),
636 SharedLibrary: outputFile,
637 Target: ctx.Target(),
Colin Cross0de8a1e2020-09-18 14:15:30 -0700638 })
639 }
640
641 if library.static() {
Colin Crossc85750b2022-04-21 12:50:51 -0700642 depSet := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(outputFile).Build()
Colin Cross40213022023-12-13 15:19:49 -0800643 android.SetProvider(ctx, cc.StaticLibraryInfoProvider, cc.StaticLibraryInfo{
Colin Cross0de8a1e2020-09-18 14:15:30 -0700644 StaticLibrary: outputFile,
645
646 TransitiveStaticLibrariesForOrdering: depSet,
647 })
648 }
649
650 library.flagExporter.setProvider(ctx)
651
Ivan Lozano8d10fc32021-11-05 16:36:47 -0400652 return ret
Ivan Lozanoffee3342019-08-27 12:03:00 -0700653}
654
Matthew Maurera28404a2023-11-20 23:33:28 +0000655func (library *libraryDecorator) checkedCrateRootPath() (android.Path, error) {
Dan Albert06feee92021-03-19 15:06:02 -0700656 if library.sourceProvider != nil {
Matthew Maurera28404a2023-11-20 23:33:28 +0000657 srcs := library.sourceProvider.Srcs()
658 if len(srcs) == 0 {
659 return nil, errors.New("Source provider generated 0 sources")
660 }
Dan Albert06feee92021-03-19 15:06:02 -0700661 // Assume the first source from the source provider is the library entry point.
Matthew Maurera28404a2023-11-20 23:33:28 +0000662 return srcs[0], nil
Sam Delmerico63ca14e2023-09-25 12:13:17 +0000663 } else {
Matthew Maurera28404a2023-11-20 23:33:28 +0000664 return library.baseCompiler.checkedCrateRootPath()
Dan Albert06feee92021-03-19 15:06:02 -0700665 }
666}
667
668func (library *libraryDecorator) rustdoc(ctx ModuleContext, flags Flags,
669 deps PathDeps) android.OptionalPath {
670 // rustdoc has builtin support for documenting config specific information
671 // regardless of the actual config it was given
672 // (https://doc.rust-lang.org/rustdoc/advanced-features.html#cfgdoc-documenting-platform-specific-or-feature-specific-information),
673 // so we generate the rustdoc for only the primary module so that we have a
674 // single set of docs to refer to.
675 if ctx.Module() != ctx.PrimaryModule() {
676 return android.OptionalPath{}
677 }
678
Matthew Maurera28404a2023-11-20 23:33:28 +0000679 return android.OptionalPathForPath(Rustdoc(ctx, crateRootPath(ctx, library),
Dan Albert06feee92021-03-19 15:06:02 -0700680 deps, flags))
681}
682
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700683func (library *libraryDecorator) getStem(ctx ModuleContext) string {
684 stem := library.baseCompiler.getStemWithoutSuffix(ctx)
685 validateLibraryStem(ctx, stem, library.crateName())
686
687 return stem + String(library.baseCompiler.Properties.Suffix)
688}
689
Ivan Lozano2b081132020-09-08 12:46:52 -0400690func (library *libraryDecorator) install(ctx ModuleContext) {
691 // Only shared and dylib variants make sense to install.
692 if library.shared() || library.dylib() {
693 library.baseCompiler.install(ctx)
694 }
695}
696
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400697func (library *libraryDecorator) Disabled() bool {
698 return library.MutatedProperties.VariantIsDisabled
699}
700
701func (library *libraryDecorator) SetDisabled() {
702 library.MutatedProperties.VariantIsDisabled = true
703}
704
Ivan Lozanoad8b18b2019-10-31 19:38:29 -0700705var validCrateName = regexp.MustCompile("[^a-zA-Z0-9_]+")
706
707func validateLibraryStem(ctx BaseModuleContext, filename string, crate_name string) {
708 if crate_name == "" {
709 ctx.PropertyErrorf("crate_name", "crate_name must be defined.")
710 }
711
712 // crate_names are used for the library output file, and rustc expects these
713 // to be alphanumeric with underscores allowed.
714 if validCrateName.MatchString(crate_name) {
715 ctx.PropertyErrorf("crate_name",
716 "library crate_names must be alphanumeric with underscores allowed")
717 }
718
719 // Libraries are expected to begin with "lib" followed by the crate_name
720 if !strings.HasPrefix(filename, "lib"+crate_name) {
721 ctx.ModuleErrorf("Invalid name or stem property; library filenames must start with lib<crate_name>")
722 }
723}
724
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200725// LibraryMutator mutates the libraries into variants according to the
726// build{Rlib,Dylib} attributes.
Ivan Lozanoffee3342019-08-27 12:03:00 -0700727func LibraryMutator(mctx android.BottomUpMutatorContext) {
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200728 // Only mutate on Rust libraries.
729 m, ok := mctx.Module().(*Module)
730 if !ok || m.compiler == nil {
731 return
732 }
733 library, ok := m.compiler.(libraryInterface)
734 if !ok {
735 return
736 }
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400737
Ivan Lozano0a468a42024-05-13 21:03:34 -0400738 // Don't produce rlib/dylib/source variants for shared or static variants
739 if library.shared() || library.static() {
740 return
741 }
742
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200743 var variants []string
744 // The source variant is used for SourceProvider modules. The other variants (i.e. rlib and dylib)
745 // depend on this variant. It must be the first variant to be declared.
746 sourceVariant := false
747 if m.sourceProvider != nil {
748 variants = append(variants, "source")
749 sourceVariant = true
750 }
751 if library.buildRlib() {
752 variants = append(variants, rlibVariation)
753 }
754 if library.buildDylib() {
755 variants = append(variants, dylibVariation)
756 }
Ivan Lozano26ecd6c2020-07-31 13:40:31 -0400757
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200758 if len(variants) == 0 {
759 return
760 }
761 modules := mctx.CreateLocalVariations(variants...)
762
763 // The order of the variations (modules) matches the variant names provided. Iterate
764 // through the new variation modules and set their mutated properties.
765 for i, v := range modules {
766 switch variants[i] {
767 case rlibVariation:
768 v.(*Module).compiler.(libraryInterface).setRlib()
769 case dylibVariation:
770 v.(*Module).compiler.(libraryInterface).setDylib()
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400771 if v.(*Module).ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation {
Ivan Lozano6a884432020-12-02 09:15:16 -0500772 // TODO(b/165791368)
Ivan Lozanoc08897c2021-04-02 12:41:32 -0400773 // Disable dylib Vendor Ramdisk variations until we support these.
Ivan Lozano6a884432020-12-02 09:15:16 -0500774 v.(*Module).Disable()
775 }
Ivan Lozano1921e802021-05-20 13:39:16 -0400776
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200777 case "source":
778 v.(*Module).compiler.(libraryInterface).setSource()
779 // The source variant does not produce any library.
780 // Disable the compilation steps.
781 v.(*Module).compiler.SetDisabled()
Ivan Lozano0a468a42024-05-13 21:03:34 -0400782 case "":
783 // if there's an empty variant, alias it so it is the default variant
784 mctx.AliasVariation("")
Ivan Lozanoffee3342019-08-27 12:03:00 -0700785 }
786 }
Thiébaud Weksteen295c72b2020-09-23 18:10:17 +0200787
788 // If a source variant is created, add an inter-variant dependency
789 // between the other variants and the source variant.
790 if sourceVariant {
791 sv := modules[0]
792 for _, v := range modules[1:] {
793 if !v.Enabled() {
794 continue
795 }
796 mctx.AddInterVariantDependency(sourceDepTag, v, sv)
797 }
798 // Alias the source variation so it can be named directly in "srcs" properties.
799 mctx.AliasVariation("source")
800 }
Ivan Lozanoffee3342019-08-27 12:03:00 -0700801}
Ivan Lozano2b081132020-09-08 12:46:52 -0400802
803func LibstdMutator(mctx android.BottomUpMutatorContext) {
804 if m, ok := mctx.Module().(*Module); ok && m.compiler != nil && !m.compiler.Disabled() {
805 switch library := m.compiler.(type) {
806 case libraryInterface:
807 // Only create a variant if a library is actually being built.
808 if library.rlib() && !library.sysroot() {
Ivan Lozano0a468a42024-05-13 21:03:34 -0400809 // If this is a rust_ffi variant it only needs rlib-std
810 if library.isFFILibrary() {
811 variants := []string{"rlib-std"}
812 modules := mctx.CreateLocalVariations(variants...)
813 rlib := modules[0].(*Module)
814 rlib.compiler.(libraryInterface).setRlibStd()
815 rlib.Properties.RustSubName += RlibStdlibSuffix
816 } else {
817 variants := []string{"rlib-std", "dylib-std"}
818 modules := mctx.CreateLocalVariations(variants...)
Ivan Lozano2b081132020-09-08 12:46:52 -0400819
Ivan Lozano0a468a42024-05-13 21:03:34 -0400820 rlib := modules[0].(*Module)
821 dylib := modules[1].(*Module)
822 rlib.compiler.(libraryInterface).setRlibStd()
823 dylib.compiler.(libraryInterface).setDylibStd()
824 if dylib.ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation {
825 // TODO(b/165791368)
826 // Disable rlibs that link against dylib-std on vendor ramdisk variations until those dylib
827 // variants are properly supported.
828 dylib.Disable()
829 }
830 rlib.Properties.RustSubName += RlibStdlibSuffix
Ivan Lozano6a884432020-12-02 09:15:16 -0500831 }
Ivan Lozano2b081132020-09-08 12:46:52 -0400832 }
833 }
834 }
835}