blob: f503982cdac7e0144a0413cb6b46f8e1f21eddc0 [file] [log] [blame]
Colin Cross4d9c2d12016-07-29 12:48:20 -07001// Copyright 2016 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 (
Colin Cross4d9c2d12016-07-29 12:48:20 -070018 "strings"
19
Colin Cross4d9c2d12016-07-29 12:48:20 -070020 "android/soong/android"
21)
22
23func init() {
Jooyung Hanb90e4912019-12-09 18:21:48 +090024 android.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
Jaewoong Jung710756a2019-06-04 11:53:47 -070025 android.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
Colin Cross4d9c2d12016-07-29 12:48:20 -070026}
27
28// NDK prebuilt libraries.
29//
30// These differ from regular prebuilts in that they aren't stripped and usually aren't installed
31// either (with the exception of the shared STLs, which are installed to the app's directory rather
32// than to the system image).
33
Ryan Prichardb1703652018-03-26 16:30:31 -070034type ndkPrebuiltStlLinker struct {
Colin Crossb916a382016-07-29 17:28:03 -070035 *libraryDecorator
Colin Cross4d9c2d12016-07-29 12:48:20 -070036}
37
Ryan Prichardb1703652018-03-26 16:30:31 -070038func (ndk *ndkPrebuiltStlLinker) linkerProps() []interface{} {
Colin Crossb916a382016-07-29 17:28:03 -070039 return append(ndk.libraryDecorator.linkerProps(), &ndk.Properties, &ndk.flagExporter.Properties)
Colin Cross4d9c2d12016-07-29 12:48:20 -070040}
41
Ryan Prichardb1703652018-03-26 16:30:31 -070042func (*ndkPrebuiltStlLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
Colin Cross4d9c2d12016-07-29 12:48:20 -070043 // NDK libraries can't have any dependencies
44 return deps
45}
46
Jiyong Parke01e2282020-03-09 16:24:11 +090047func (*ndkPrebuiltStlLinker) availableFor(what string) bool {
48 // ndk prebuilt objects are available to everywhere
49 return true
50}
51
Patrice Arruda8c856372019-04-01 17:29:59 -070052// ndk_prebuilt_shared_stl exports a precompiled ndk shared standard template
53// library (stl) library for linking operation. The soong's module name format
54// is ndk_<NAME>.so where the library is located under
55// ./prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/$(HOST_ARCH)/<NAME>.so.
Jaewoong Jung710756a2019-06-04 11:53:47 -070056func NdkPrebuiltSharedStlFactory() android.Module {
Colin Crossab3b7322016-12-09 14:46:15 -080057 module, library := NewLibrary(android.DeviceSupported)
58 library.BuildOnlyShared()
Colin Crossb916a382016-07-29 17:28:03 -070059 module.compiler = nil
Ryan Prichardb1703652018-03-26 16:30:31 -070060 module.linker = &ndkPrebuiltStlLinker{
61 libraryDecorator: library,
62 }
Colin Crossb916a382016-07-29 17:28:03 -070063 module.installer = nil
Colin Crossc511bc52020-04-07 16:50:32 +000064 module.Properties.Sdk_version = StringPtr("minimum")
65 module.Properties.AlwaysSdk = true
66 module.stl.Properties.Stl = StringPtr("none")
Colin Cross4d9c2d12016-07-29 12:48:20 -070067 return module.Init()
68}
69
Patrice Arruda8c856372019-04-01 17:29:59 -070070// ndk_prebuilt_static_stl exports a precompiled ndk static standard template
71// library (stl) library for linking operation. The soong's module name format
72// is ndk_<NAME>.a where the library is located under
73// ./prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/$(HOST_ARCH)/<NAME>.a.
Jooyung Hanb90e4912019-12-09 18:21:48 +090074func NdkPrebuiltStaticStlFactory() android.Module {
Colin Crossab3b7322016-12-09 14:46:15 -080075 module, library := NewLibrary(android.DeviceSupported)
76 library.BuildOnlyStatic()
Colin Crossb916a382016-07-29 17:28:03 -070077 module.compiler = nil
Ryan Prichardb1703652018-03-26 16:30:31 -070078 module.linker = &ndkPrebuiltStlLinker{
79 libraryDecorator: library,
80 }
Colin Crossb916a382016-07-29 17:28:03 -070081 module.installer = nil
Jooyung Han749dc692020-04-15 11:03:39 +090082 module.Properties.Sdk_version = StringPtr("minimum")
Colin Cross4d9c2d12016-07-29 12:48:20 -070083 module.Properties.HideFromMake = true
Colin Crossc511bc52020-04-07 16:50:32 +000084 module.Properties.AlwaysSdk = true
85 module.Properties.Sdk_version = StringPtr("current")
86 module.stl.Properties.Stl = StringPtr("none")
Colin Cross4d9c2d12016-07-29 12:48:20 -070087 return module.Init()
88}
89
Spandan Das6e332d22023-09-13 17:58:52 +000090const (
91 libDir = "current/sources/cxx-stl/llvm-libc++/libs"
92)
93
Ryan Prichardb1703652018-03-26 16:30:31 -070094func getNdkStlLibDir(ctx android.ModuleContext) android.SourcePath {
Spandan Das6e332d22023-09-13 17:58:52 +000095 return android.PathForSource(ctx, ctx.ModuleDir(), libDir).Join(ctx, ctx.Arch().Abi[0])
Colin Cross4d9c2d12016-07-29 12:48:20 -070096}
97
98func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
Dan Willemsen5cb580f2016-09-26 17:33:01 -070099 deps PathDeps, objs Objects) android.Path {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700100 // A null build step, but it sets up the output path.
101 if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") {
Ryan Prichardb1703652018-03-26 16:30:31 -0700102 ctx.ModuleErrorf("NDK prebuilt libraries must have an ndk_lib prefixed name")
Colin Cross4d9c2d12016-07-29 12:48:20 -0700103 }
104
Colin Cross0de8a1e2020-09-18 14:15:30 -0700105 ndk.libraryDecorator.flagExporter.exportIncludesAsSystem(ctx)
Colin Cross4d9c2d12016-07-29 12:48:20 -0700106
107 libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_")
108 libExt := flags.Toolchain.ShlibSuffix()
Colin Crossa48ab5b2017-02-14 15:28:44 -0800109 if ndk.static() {
Colin Cross4d9c2d12016-07-29 12:48:20 -0700110 libExt = staticLibraryExtension
111 }
112
Ryan Prichardb1703652018-03-26 16:30:31 -0700113 libDir := getNdkStlLibDir(ctx)
Colin Cross0de8a1e2020-09-18 14:15:30 -0700114 lib := libDir.Join(ctx, libName+libExt)
115
116 ndk.libraryDecorator.flagExporter.setProvider(ctx)
117
118 if ndk.static() {
Colin Crossc85750b2022-04-21 12:50:51 -0700119 depSet := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(lib).Build()
Colin Cross40213022023-12-13 15:19:49 -0800120 android.SetProvider(ctx, StaticLibraryInfoProvider, StaticLibraryInfo{
Colin Cross0de8a1e2020-09-18 14:15:30 -0700121 StaticLibrary: lib,
122
123 TransitiveStaticLibrariesForOrdering: depSet,
124 })
125 } else {
Colin Cross40213022023-12-13 15:19:49 -0800126 android.SetProvider(ctx, SharedLibraryInfoProvider, SharedLibraryInfo{
Liz Kammeref6dfea2021-06-08 15:37:09 -0400127 SharedLibrary: lib,
128 Target: ctx.Target(),
Colin Cross0de8a1e2020-09-18 14:15:30 -0700129 })
130 }
131
132 return lib
Colin Cross4d9c2d12016-07-29 12:48:20 -0700133}