blob: 3b4f40a5595e19d0072ca91009a044a792835d5a [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 (
18 "android/soong/android"
19)
20
21func init() {
Matthew Maurerc761eec2020-06-25 00:47:46 -070022 android.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -070023 android.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -070024 android.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -070025}
26
27type PrebuiltProperties struct {
28 // path to the prebuilt file
29 Srcs []string `android:"path,arch_variant"`
Matthew Maurerbb3add12020-06-25 09:34:12 -070030 // directories containing associated rlib dependencies
31 Link_dirs []string `android:"path,arch_variant"`
Ivan Lozanoffee3342019-08-27 12:03:00 -070032}
33
34type prebuiltLibraryDecorator struct {
35 *libraryDecorator
36 Properties PrebuiltProperties
37}
38
39var _ compiler = (*prebuiltLibraryDecorator)(nil)
Matthew Maurerbb3add12020-06-25 09:34:12 -070040var _ exportedFlagsProducer = (*prebuiltLibraryDecorator)(nil)
Ivan Lozanoffee3342019-08-27 12:03:00 -070041
Matthew Maurerc761eec2020-06-25 00:47:46 -070042func PrebuiltLibraryFactory() android.Module {
43 module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
44 return module.Init()
45}
46
Ivan Lozanoffee3342019-08-27 12:03:00 -070047func PrebuiltDylibFactory() android.Module {
48 module, _ := NewPrebuiltDylib(android.HostAndDeviceSupported)
49 return module.Init()
50}
51
Matthew Maurerc761eec2020-06-25 00:47:46 -070052func PrebuiltRlibFactory() android.Module {
53 module, _ := NewPrebuiltRlib(android.HostAndDeviceSupported)
54 return module.Init()
55}
56
57func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
58 module, library := NewRustLibrary(hod)
59 library.BuildOnlyRust()
60 library.setNoStdlibs()
61 prebuilt := &prebuiltLibraryDecorator{
62 libraryDecorator: library,
63 }
64 module.compiler = prebuilt
65 return module, prebuilt
66}
67
Ivan Lozanoffee3342019-08-27 12:03:00 -070068func NewPrebuiltDylib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
69 module, library := NewRustLibrary(hod)
70 library.BuildOnlyDylib()
Matthew Maurer99020b02019-10-31 10:44:40 -070071 library.setNoStdlibs()
Matthew Maurerc761eec2020-06-25 00:47:46 -070072 prebuilt := &prebuiltLibraryDecorator{
73 libraryDecorator: library,
74 }
75 module.compiler = prebuilt
76 return module, prebuilt
77}
78
79func NewPrebuiltRlib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
80 module, library := NewRustLibrary(hod)
81 library.BuildOnlyRlib()
82 library.setNoStdlibs()
Ivan Lozanoffee3342019-08-27 12:03:00 -070083 prebuilt := &prebuiltLibraryDecorator{
84 libraryDecorator: library,
85 }
86 module.compiler = prebuilt
Ivan Lozanoffee3342019-08-27 12:03:00 -070087 return module, prebuilt
88}
89
90func (prebuilt *prebuiltLibraryDecorator) compilerProps() []interface{} {
Matthew Maurer128f53b2020-06-29 13:31:04 -070091 return append(prebuilt.libraryDecorator.compilerProps(),
Ivan Lozanoffee3342019-08-27 12:03:00 -070092 &prebuilt.Properties)
93}
94
95func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
Matthew Maurerbb3add12020-06-25 09:34:12 -070096 prebuilt.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
97
Chih-Hung Hsiehbbd25ae2020-05-15 17:36:30 -070098 srcPath, paths := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
99 deps.SrcDeps = paths
Ivan Lozanoffee3342019-08-27 12:03:00 -0700100
101 prebuilt.unstrippedOutputFile = srcPath
102
103 return srcPath
104}
Ivan Lozanof1c84332019-09-20 11:00:37 -0700105
106func (prebuilt *prebuiltLibraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
107 deps = prebuilt.baseCompiler.compilerDeps(ctx, deps)
108 return deps
109}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400110
111func (prebuilt *prebuiltLibraryDecorator) nativeCoverage() bool {
112 return false
113}
Matthew Maurerc761eec2020-06-25 00:47:46 -0700114
115func (prebuilt *prebuiltLibraryDecorator) prebuiltSrcs() []string {
116 srcs := prebuilt.Properties.Srcs
117 if prebuilt.rlib() {
118 srcs = append(srcs, prebuilt.libraryDecorator.Properties.Rlib.Srcs...)
119 }
120 if prebuilt.dylib() {
121 srcs = append(srcs, prebuilt.libraryDecorator.Properties.Dylib.Srcs...)
122 }
123
124 return srcs
125}