blob: c941c4691f483674d7f0c5fa2676561ab229b032 [file] [log] [blame]
Justin Yun71549282017-11-17 12:10:28 +09001// Copyright 2017 Google Inc. All rights reserved.
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 cc
16
17import (
18 "strings"
19
20 "android/soong/android"
21)
22
23var (
Justin Yun3e2323d2018-06-08 15:08:40 +090024 vndkSuffix = ".vndk."
25 binder32Suffix = ".binder32"
Justin Yun71549282017-11-17 12:10:28 +090026)
27
28// Creates vndk prebuilts that include the VNDK version.
29//
30// Example:
31//
32// vndk_prebuilt_shared {
33// name: "libfoo",
34// version: "27.1.0",
35// vendor_available: true,
36// vndk: {
37// enabled: true,
38// },
39// export_include_dirs: ["include/external/libfoo/vndk_include"],
40// arch: {
41// arm64: {
42// srcs: ["arm/lib64/libfoo.so"],
43// },
44// arm: {
45// srcs: ["arm/lib/libfoo.so"],
46// },
47// },
48// }
49//
50type vndkPrebuiltProperties struct {
Jae Shin43ef2642017-12-29 16:20:21 +090051 // VNDK snapshot version.
52 Version *string
53
54 // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64_ab')
55 Target_arch *string
Justin Yun71549282017-11-17 12:10:28 +090056
Justin Yun3e2323d2018-06-08 15:08:40 +090057 // If the prebuilt snapshot lib is built with 32 bit binder, this must be set to true.
58 // The lib with 64 bit binder does not need to set this property.
59 Binder32bit *bool
60
Justin Yun71549282017-11-17 12:10:28 +090061 // Prebuilt files for each arch.
62 Srcs []string `android:"arch_variant"`
Logan Chien4fcea3d2018-11-20 11:59:08 +080063
Inseob Kimae553032019-05-14 18:52:49 +090064 // list of directories relative to the Blueprints file that will be added to the include
65 // path (using -isystem) for any module that links against this module.
66 Export_system_include_dirs []string `android:"arch_variant"`
67
68 // list of flags that will be used for any module that links against this module.
69 Export_flags []string `android:"arch_variant"`
70
Logan Chien4fcea3d2018-11-20 11:59:08 +080071 // Check the prebuilt ELF files (e.g. DT_SONAME, DT_NEEDED, resolution of undefined symbols,
72 // etc).
73 Check_elf_files *bool
Justin Yun71549282017-11-17 12:10:28 +090074}
75
76type vndkPrebuiltLibraryDecorator struct {
77 *libraryDecorator
78 properties vndkPrebuiltProperties
79}
80
81func (p *vndkPrebuiltLibraryDecorator) Name(name string) string {
Jae Shin43ef2642017-12-29 16:20:21 +090082 return name + p.NameSuffix()
83}
84
85func (p *vndkPrebuiltLibraryDecorator) NameSuffix() string {
Justin Yun3e2323d2018-06-08 15:08:40 +090086 suffix := p.version()
Jae Shin43ef2642017-12-29 16:20:21 +090087 if p.arch() != "" {
Justin Yun3e2323d2018-06-08 15:08:40 +090088 suffix += "." + p.arch()
Jae Shin43ef2642017-12-29 16:20:21 +090089 }
Justin Yun3e2323d2018-06-08 15:08:40 +090090 if Bool(p.properties.Binder32bit) {
91 suffix += binder32Suffix
92 }
93 return vndkSuffix + suffix
Justin Yun71549282017-11-17 12:10:28 +090094}
95
96func (p *vndkPrebuiltLibraryDecorator) version() string {
Jae Shin43ef2642017-12-29 16:20:21 +090097 return String(p.properties.Version)
98}
99
100func (p *vndkPrebuiltLibraryDecorator) arch() string {
101 return String(p.properties.Target_arch)
Justin Yun71549282017-11-17 12:10:28 +0900102}
103
Justin Yun3e2323d2018-06-08 15:08:40 +0900104func (p *vndkPrebuiltLibraryDecorator) binderBit() string {
105 if Bool(p.properties.Binder32bit) {
106 return "32"
107 }
108 return "64"
109}
110
Justin Yun71549282017-11-17 12:10:28 +0900111func (p *vndkPrebuiltLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
Jae Shin43ef2642017-12-29 16:20:21 +0900112 p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix())
Justin Yun71549282017-11-17 12:10:28 +0900113 return p.libraryDecorator.linkerFlags(ctx, flags)
114}
115
116func (p *vndkPrebuiltLibraryDecorator) singleSourcePath(ctx ModuleContext) android.Path {
117 if len(p.properties.Srcs) == 0 {
118 ctx.PropertyErrorf("srcs", "missing prebuilt source file")
119 return nil
120 }
121
122 if len(p.properties.Srcs) > 1 {
123 ctx.PropertyErrorf("srcs", "multiple prebuilt source files")
124 return nil
125 }
126
127 return android.PathForModuleSrc(ctx, p.properties.Srcs[0])
128}
129
130func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext,
131 flags Flags, deps PathDeps, objs Objects) android.Path {
Colin Crossff6c33d2019-10-02 16:01:35 -0700132
Jooyung Han31c470b2019-10-18 16:26:59 +0900133 if !p.matchesWithDevice(ctx.DeviceConfig()) {
Colin Crossff6c33d2019-10-02 16:01:35 -0700134 ctx.Module().SkipInstall()
135 return nil
136 }
137
Justin Yun71549282017-11-17 12:10:28 +0900138 if len(p.properties.Srcs) > 0 && p.shared() {
Inseob Kimae553032019-05-14 18:52:49 +0900139 p.libraryDecorator.exportIncludes(ctx)
Jiyong Park74955042019-10-22 20:19:51 +0900140 p.libraryDecorator.reexportSystemDirs(
141 android.PathsForModuleSrc(ctx, p.properties.Export_system_include_dirs)...)
Inseob Kimae553032019-05-14 18:52:49 +0900142 p.libraryDecorator.reexportFlags(p.properties.Export_flags...)
Justin Yun71549282017-11-17 12:10:28 +0900143 // current VNDK prebuilts are only shared libs.
144 return p.singleSourcePath(ctx)
145 }
Colin Crossff6c33d2019-10-02 16:01:35 -0700146
147 ctx.Module().SkipInstall()
Justin Yun71549282017-11-17 12:10:28 +0900148 return nil
149}
150
Jooyung Han31c470b2019-10-18 16:26:59 +0900151func (p *vndkPrebuiltLibraryDecorator) matchesWithDevice(config android.DeviceConfig) bool {
152 arches := config.Arches()
153 if len(arches) == 0 || arches[0].ArchType.String() != p.arch() {
154 return false
155 }
156 if config.BinderBitness() != p.binderBit() {
157 return false
158 }
159 if len(p.properties.Srcs) == 0 {
160 return false
161 }
162 return true
163}
164
Inseob Kimc9fa4a32019-09-09 10:49:03 +0900165func (p *vndkPrebuiltLibraryDecorator) nativeCoverage() bool {
166 return false
167}
168
Justin Yun71549282017-11-17 12:10:28 +0900169func (p *vndkPrebuiltLibraryDecorator) install(ctx ModuleContext, file android.Path) {
Justin Yun312ccb92018-01-23 12:07:46 +0900170 arches := ctx.DeviceConfig().Arches()
171 if len(arches) == 0 || arches[0].ArchType.String() != p.arch() {
172 return
173 }
Justin Yun3e2323d2018-06-08 15:08:40 +0900174 if ctx.DeviceConfig().BinderBitness() != p.binderBit() {
175 return
176 }
Justin Yun71549282017-11-17 12:10:28 +0900177 if p.shared() {
Justin Yun3e15b962018-01-10 18:28:48 +0900178 if ctx.isVndkSp() {
179 p.baseInstaller.subDir = "vndk-sp-" + p.version()
180 } else if ctx.isVndk() {
181 p.baseInstaller.subDir = "vndk-" + p.version()
Justin Yun71549282017-11-17 12:10:28 +0900182 }
183 p.baseInstaller.install(ctx, file)
184 }
185}
186
187func vndkPrebuiltSharedLibrary() *Module {
188 module, library := NewLibrary(android.DeviceSupported)
189 library.BuildOnlyShared()
190 module.stl = nil
191 module.sanitize = nil
192 library.StripProperties.Strip.None = BoolPtr(true)
193
194 prebuilt := &vndkPrebuiltLibraryDecorator{
195 libraryDecorator: library,
196 }
197
Logan Chien4fcea3d2018-11-20 11:59:08 +0800198 prebuilt.properties.Check_elf_files = BoolPtr(false)
Inseob Kim64c43952019-08-26 16:52:35 +0900199 prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true)
200 prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true)
201
202 // Prevent default system libs (libc, libm, and libdl) from being linked
203 if prebuilt.baseLinker.Properties.System_shared_libs == nil {
204 prebuilt.baseLinker.Properties.System_shared_libs = []string{}
205 }
Logan Chien4fcea3d2018-11-20 11:59:08 +0800206
Justin Yun71549282017-11-17 12:10:28 +0900207 module.compiler = nil
208 module.linker = prebuilt
209 module.installer = prebuilt
210
211 module.AddProperties(
212 &prebuilt.properties,
213 )
214
215 return module
216}
217
Patrice Arrudaad031502019-04-01 10:56:49 -0700218// vndk_prebuilt_shared installs Vendor Native Development kit (VNDK) snapshot
219// shared libraries for system build. Example:
220//
221// vndk_prebuilt_shared {
222// name: "libfoo",
223// version: "27.1.0",
224// vendor_available: true,
225// vndk: {
226// enabled: true,
227// },
228// export_include_dirs: ["include/external/libfoo/vndk_include"],
229// arch: {
230// arm64: {
231// srcs: ["arm/lib64/libfoo.so"],
232// },
233// arm: {
234// srcs: ["arm/lib/libfoo.so"],
235// },
236// },
237// }
Jooyung Han344d5432019-08-23 11:17:39 +0900238func VndkPrebuiltSharedFactory() android.Module {
Justin Yun71549282017-11-17 12:10:28 +0900239 module := vndkPrebuiltSharedLibrary()
240 return module.Init()
241}
242
243func init() {
Jooyung Han344d5432019-08-23 11:17:39 +0900244 android.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
Colin Cross7a6fcbe2017-12-06 13:08:00 -0800245}