Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 1 | // 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 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | var ( |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 24 | vndkSuffix = ".vndk." |
| 25 | binder32Suffix = ".binder32" |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | // Creates vndk prebuilts that include the VNDK version. |
| 29 | // |
| 30 | // Example: |
| 31 | // |
| 32 | // vndk_prebuilt_shared { |
| 33 | // name: "libfoo", |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 34 | // version: "27", |
| 35 | // target_arch: "arm64", |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 36 | // vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 37 | // product_available: true, |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 38 | // vndk: { |
| 39 | // enabled: true, |
| 40 | // }, |
| 41 | // export_include_dirs: ["include/external/libfoo/vndk_include"], |
| 42 | // arch: { |
| 43 | // arm64: { |
| 44 | // srcs: ["arm/lib64/libfoo.so"], |
| 45 | // }, |
| 46 | // arm: { |
| 47 | // srcs: ["arm/lib/libfoo.so"], |
| 48 | // }, |
| 49 | // }, |
| 50 | // } |
| 51 | // |
| 52 | type vndkPrebuiltProperties struct { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 53 | // VNDK snapshot version. |
| 54 | Version *string |
| 55 | |
SzuWei Lin | 31c4dfc | 2020-11-03 18:27:32 +0800 | [diff] [blame] | 56 | // Target arch name of the snapshot (e.g. 'arm64' for variant 'aosp_arm64') |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 57 | Target_arch *string |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 58 | |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 59 | // If the prebuilt snapshot lib is built with 32 bit binder, this must be set to true. |
| 60 | // The lib with 64 bit binder does not need to set this property. |
| 61 | Binder32bit *bool |
| 62 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 63 | // Prebuilt files for each arch. |
| 64 | Srcs []string `android:"arch_variant"` |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 65 | |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 66 | // list of flags that will be used for any module that links against this module. |
| 67 | Export_flags []string `android:"arch_variant"` |
| 68 | |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 69 | // Check the prebuilt ELF files (e.g. DT_SONAME, DT_NEEDED, resolution of undefined symbols, |
| 70 | // etc). |
| 71 | Check_elf_files *bool |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | type vndkPrebuiltLibraryDecorator struct { |
| 75 | *libraryDecorator |
Inseob Kim | 2b96bf5 | 2020-02-17 18:00:39 +0900 | [diff] [blame] | 76 | properties vndkPrebuiltProperties |
| 77 | androidMkSuffix string |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | func (p *vndkPrebuiltLibraryDecorator) Name(name string) string { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 81 | return name + p.NameSuffix() |
| 82 | } |
| 83 | |
| 84 | func (p *vndkPrebuiltLibraryDecorator) NameSuffix() string { |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 85 | suffix := p.version() |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 86 | if p.arch() != "" { |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 87 | suffix += "." + p.arch() |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 88 | } |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 89 | if Bool(p.properties.Binder32bit) { |
| 90 | suffix += binder32Suffix |
| 91 | } |
| 92 | return vndkSuffix + suffix |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | func (p *vndkPrebuiltLibraryDecorator) version() string { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 96 | return String(p.properties.Version) |
| 97 | } |
| 98 | |
| 99 | func (p *vndkPrebuiltLibraryDecorator) arch() string { |
| 100 | return String(p.properties.Target_arch) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 101 | } |
| 102 | |
Justin Yun | 3e2323d | 2018-06-08 15:08:40 +0900 | [diff] [blame] | 103 | func (p *vndkPrebuiltLibraryDecorator) binderBit() string { |
| 104 | if Bool(p.properties.Binder32bit) { |
| 105 | return "32" |
| 106 | } |
| 107 | return "64" |
| 108 | } |
| 109 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 110 | func (p *vndkPrebuiltLibraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { |
Jae Shin | 43ef264 | 2017-12-29 16:20:21 +0900 | [diff] [blame] | 111 | p.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), p.NameSuffix()) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 112 | return p.libraryDecorator.linkerFlags(ctx, flags) |
| 113 | } |
| 114 | |
| 115 | func (p *vndkPrebuiltLibraryDecorator) singleSourcePath(ctx ModuleContext) android.Path { |
| 116 | if len(p.properties.Srcs) == 0 { |
| 117 | ctx.PropertyErrorf("srcs", "missing prebuilt source file") |
| 118 | return nil |
| 119 | } |
| 120 | |
| 121 | if len(p.properties.Srcs) > 1 { |
| 122 | ctx.PropertyErrorf("srcs", "multiple prebuilt source files") |
| 123 | return nil |
| 124 | } |
| 125 | |
| 126 | return android.PathForModuleSrc(ctx, p.properties.Srcs[0]) |
| 127 | } |
| 128 | |
| 129 | func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext, |
| 130 | flags Flags, deps PathDeps, objs Objects) android.Path { |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 131 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 132 | if !p.matchesWithDevice(ctx.DeviceConfig()) { |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 133 | ctx.Module().HideFromMake() |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 134 | return nil |
| 135 | } |
| 136 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 137 | if len(p.properties.Srcs) > 0 && p.shared() { |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 138 | p.libraryDecorator.exportIncludes(ctx) |
Inseob Kim | ae55303 | 2019-05-14 18:52:49 +0900 | [diff] [blame] | 139 | p.libraryDecorator.reexportFlags(p.properties.Export_flags...) |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 140 | // current VNDK prebuilts are only shared libs. |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 141 | |
| 142 | in := p.singleSourcePath(ctx) |
| 143 | builderFlags := flagsToBuilderFlags(flags) |
| 144 | p.unstrippedOutputFile = in |
| 145 | libName := in.Base() |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 146 | if p.stripper.NeedsStrip(ctx) { |
| 147 | stripFlags := flagsToStripFlags(flags) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 148 | stripped := android.PathForModuleOut(ctx, "stripped", libName) |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 149 | p.stripper.StripExecutableOrSharedLib(ctx, in, stripped, stripFlags) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 150 | in = stripped |
| 151 | } |
| 152 | |
| 153 | // Optimize out relinking against shared libraries whose interface hasn't changed by |
| 154 | // depending on a table of contents file instead of the library itself. |
| 155 | tocFile := android.PathForModuleOut(ctx, libName+".toc") |
| 156 | p.tocFile = android.OptionalPathForPath(tocFile) |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 157 | transformSharedObjectToToc(ctx, in, tocFile, builderFlags) |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 158 | |
Inseob Kim | 2b96bf5 | 2020-02-17 18:00:39 +0900 | [diff] [blame] | 159 | p.androidMkSuffix = p.NameSuffix() |
| 160 | |
| 161 | vndkVersion := ctx.DeviceConfig().VndkVersion() |
| 162 | if vndkVersion == p.version() { |
| 163 | p.androidMkSuffix = "" |
| 164 | } |
| 165 | |
Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 166 | ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ |
| 167 | SharedLibrary: in, |
| 168 | UnstrippedSharedLibrary: p.unstrippedOutputFile, |
| 169 | |
| 170 | TableOfContents: p.tocFile, |
| 171 | }) |
| 172 | |
Inseob Kim | 70cb3b6 | 2020-10-16 16:23:05 +0900 | [diff] [blame] | 173 | p.libraryDecorator.flagExporter.setProvider(ctx) |
| 174 | |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 175 | return in |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 176 | } |
Colin Cross | ff6c33d | 2019-10-02 16:01:35 -0700 | [diff] [blame] | 177 | |
Colin Cross | a9c8c9f | 2020-12-16 10:20:23 -0800 | [diff] [blame] | 178 | ctx.Module().HideFromMake() |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 179 | return nil |
| 180 | } |
| 181 | |
Jooyung Han | 31c470b | 2019-10-18 16:26:59 +0900 | [diff] [blame] | 182 | func (p *vndkPrebuiltLibraryDecorator) matchesWithDevice(config android.DeviceConfig) bool { |
| 183 | arches := config.Arches() |
| 184 | if len(arches) == 0 || arches[0].ArchType.String() != p.arch() { |
| 185 | return false |
| 186 | } |
| 187 | if config.BinderBitness() != p.binderBit() { |
| 188 | return false |
| 189 | } |
| 190 | if len(p.properties.Srcs) == 0 { |
| 191 | return false |
| 192 | } |
| 193 | return true |
| 194 | } |
| 195 | |
Inseob Kim | c9fa4a3 | 2019-09-09 10:49:03 +0900 | [diff] [blame] | 196 | func (p *vndkPrebuiltLibraryDecorator) nativeCoverage() bool { |
| 197 | return false |
| 198 | } |
| 199 | |
Inseob Kim | 1042d29 | 2020-06-01 23:23:05 +0900 | [diff] [blame] | 200 | func (p *vndkPrebuiltLibraryDecorator) isSnapshotPrebuilt() bool { |
| 201 | return true |
| 202 | } |
| 203 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 204 | func (p *vndkPrebuiltLibraryDecorator) install(ctx ModuleContext, file android.Path) { |
Jooyung Han | 261e158 | 2020-10-20 18:54:21 +0900 | [diff] [blame] | 205 | // do not install vndk libs |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | func vndkPrebuiltSharedLibrary() *Module { |
| 209 | module, library := NewLibrary(android.DeviceSupported) |
| 210 | library.BuildOnlyShared() |
| 211 | module.stl = nil |
| 212 | module.sanitize = nil |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 213 | library.disableStripping() |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 214 | |
| 215 | prebuilt := &vndkPrebuiltLibraryDecorator{ |
| 216 | libraryDecorator: library, |
| 217 | } |
| 218 | |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 219 | prebuilt.properties.Check_elf_files = BoolPtr(false) |
Inseob Kim | 64c4395 | 2019-08-26 16:52:35 +0900 | [diff] [blame] | 220 | prebuilt.baseLinker.Properties.No_libcrt = BoolPtr(true) |
| 221 | prebuilt.baseLinker.Properties.Nocrt = BoolPtr(true) |
| 222 | |
| 223 | // Prevent default system libs (libc, libm, and libdl) from being linked |
| 224 | if prebuilt.baseLinker.Properties.System_shared_libs == nil { |
| 225 | prebuilt.baseLinker.Properties.System_shared_libs = []string{} |
| 226 | } |
Logan Chien | 4fcea3d | 2018-11-20 11:59:08 +0800 | [diff] [blame] | 227 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 228 | module.compiler = nil |
| 229 | module.linker = prebuilt |
| 230 | module.installer = prebuilt |
| 231 | |
| 232 | module.AddProperties( |
| 233 | &prebuilt.properties, |
| 234 | ) |
| 235 | |
Inseob Kim | 81235ff | 2020-10-23 14:36:11 +0900 | [diff] [blame] | 236 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { |
| 237 | // empty BOARD_VNDK_VERSION implies that the device won't support |
| 238 | // system only OTA. In this case, VNDK snapshots aren't needed. |
| 239 | if ctx.DeviceConfig().VndkVersion() == "" { |
| 240 | ctx.Module().Disable() |
| 241 | } |
| 242 | }) |
| 243 | |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 244 | return module |
| 245 | } |
| 246 | |
Patrice Arruda | ad03150 | 2019-04-01 10:56:49 -0700 | [diff] [blame] | 247 | // vndk_prebuilt_shared installs Vendor Native Development kit (VNDK) snapshot |
| 248 | // shared libraries for system build. Example: |
| 249 | // |
| 250 | // vndk_prebuilt_shared { |
| 251 | // name: "libfoo", |
Inseob Kim | eec88e1 | 2020-01-22 11:11:29 +0900 | [diff] [blame] | 252 | // version: "27", |
| 253 | // target_arch: "arm64", |
Patrice Arruda | ad03150 | 2019-04-01 10:56:49 -0700 | [diff] [blame] | 254 | // vendor_available: true, |
Justin Yun | 63e9ec7 | 2020-10-29 16:49:43 +0900 | [diff] [blame] | 255 | // product_available: true, |
Patrice Arruda | ad03150 | 2019-04-01 10:56:49 -0700 | [diff] [blame] | 256 | // vndk: { |
| 257 | // enabled: true, |
| 258 | // }, |
| 259 | // export_include_dirs: ["include/external/libfoo/vndk_include"], |
| 260 | // arch: { |
| 261 | // arm64: { |
| 262 | // srcs: ["arm/lib64/libfoo.so"], |
| 263 | // }, |
| 264 | // arm: { |
| 265 | // srcs: ["arm/lib/libfoo.so"], |
| 266 | // }, |
| 267 | // }, |
| 268 | // } |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 269 | func VndkPrebuiltSharedFactory() android.Module { |
Justin Yun | 7154928 | 2017-11-17 12:10:28 +0900 | [diff] [blame] | 270 | module := vndkPrebuiltSharedLibrary() |
| 271 | return module.Init() |
| 272 | } |
| 273 | |
| 274 | func init() { |
Jooyung Han | 344d543 | 2019-08-23 11:17:39 +0900 | [diff] [blame] | 275 | android.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory) |
Colin Cross | 7a6fcbe | 2017-12-06 13:08:00 -0800 | [diff] [blame] | 276 | } |