| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 1 | // 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 |  | 
|  | 15 | package cc | 
|  | 16 |  | 
|  | 17 | import ( | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 18 | "strings" | 
|  | 19 |  | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 20 | "android/soong/android" | 
|  | 21 | ) | 
|  | 22 |  | 
|  | 23 | func init() { | 
| Jooyung Han | b90e491 | 2019-12-09 18:21:48 +0900 | [diff] [blame] | 24 | android.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory) | 
| Jaewoong Jung | 710756a | 2019-06-04 11:53:47 -0700 | [diff] [blame] | 25 | android.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 26 | } | 
|  | 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 Prichard | b170365 | 2018-03-26 16:30:31 -0700 | [diff] [blame] | 34 | type ndkPrebuiltStlLinker struct { | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 35 | *libraryDecorator | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 36 | } | 
|  | 37 |  | 
| Ryan Prichard | b170365 | 2018-03-26 16:30:31 -0700 | [diff] [blame] | 38 | func (ndk *ndkPrebuiltStlLinker) linkerProps() []interface{} { | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 39 | return append(ndk.libraryDecorator.linkerProps(), &ndk.Properties, &ndk.flagExporter.Properties) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 40 | } | 
|  | 41 |  | 
| Ryan Prichard | b170365 | 2018-03-26 16:30:31 -0700 | [diff] [blame] | 42 | func (*ndkPrebuiltStlLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 43 | // NDK libraries can't have any dependencies | 
|  | 44 | return deps | 
|  | 45 | } | 
|  | 46 |  | 
| Jiyong Park | e01e228 | 2020-03-09 16:24:11 +0900 | [diff] [blame] | 47 | func (*ndkPrebuiltStlLinker) availableFor(what string) bool { | 
|  | 48 | // ndk prebuilt objects are available to everywhere | 
|  | 49 | return true | 
|  | 50 | } | 
|  | 51 |  | 
| Patrice Arruda | 8c85637 | 2019-04-01 17:29:59 -0700 | [diff] [blame] | 52 | // 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 Jung | 710756a | 2019-06-04 11:53:47 -0700 | [diff] [blame] | 56 | func NdkPrebuiltSharedStlFactory() android.Module { | 
| Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 57 | module, library := NewLibrary(android.DeviceSupported) | 
|  | 58 | library.BuildOnlyShared() | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 59 | module.compiler = nil | 
| Ryan Prichard | b170365 | 2018-03-26 16:30:31 -0700 | [diff] [blame] | 60 | module.linker = &ndkPrebuiltStlLinker{ | 
|  | 61 | libraryDecorator: library, | 
|  | 62 | } | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 63 | module.installer = nil | 
| Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 64 | module.Properties.Sdk_version = StringPtr("minimum") | 
|  | 65 | module.Properties.AlwaysSdk = true | 
|  | 66 | module.stl.Properties.Stl = StringPtr("none") | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 67 | return module.Init() | 
|  | 68 | } | 
|  | 69 |  | 
| Patrice Arruda | 8c85637 | 2019-04-01 17:29:59 -0700 | [diff] [blame] | 70 | // 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 Han | b90e491 | 2019-12-09 18:21:48 +0900 | [diff] [blame] | 74 | func NdkPrebuiltStaticStlFactory() android.Module { | 
| Colin Cross | ab3b732 | 2016-12-09 14:46:15 -0800 | [diff] [blame] | 75 | module, library := NewLibrary(android.DeviceSupported) | 
|  | 76 | library.BuildOnlyStatic() | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 77 | module.compiler = nil | 
| Ryan Prichard | b170365 | 2018-03-26 16:30:31 -0700 | [diff] [blame] | 78 | module.linker = &ndkPrebuiltStlLinker{ | 
|  | 79 | libraryDecorator: library, | 
|  | 80 | } | 
| Colin Cross | b916a38 | 2016-07-29 17:28:03 -0700 | [diff] [blame] | 81 | module.installer = nil | 
| Jooyung Han | 749dc69 | 2020-04-15 11:03:39 +0900 | [diff] [blame] | 82 | module.Properties.Sdk_version = StringPtr("minimum") | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 83 | module.Properties.HideFromMake = true | 
| Colin Cross | c511bc5 | 2020-04-07 16:50:32 +0000 | [diff] [blame] | 84 | module.Properties.AlwaysSdk = true | 
|  | 85 | module.Properties.Sdk_version = StringPtr("current") | 
|  | 86 | module.stl.Properties.Stl = StringPtr("none") | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 87 | return module.Init() | 
|  | 88 | } | 
|  | 89 |  | 
| Spandan Das | 6e332d2 | 2023-09-13 17:58:52 +0000 | [diff] [blame] | 90 | const ( | 
|  | 91 | libDir = "current/sources/cxx-stl/llvm-libc++/libs" | 
|  | 92 | ) | 
|  | 93 |  | 
| Ryan Prichard | b170365 | 2018-03-26 16:30:31 -0700 | [diff] [blame] | 94 | func getNdkStlLibDir(ctx android.ModuleContext) android.SourcePath { | 
| Spandan Das | 6e332d2 | 2023-09-13 17:58:52 +0000 | [diff] [blame] | 95 | return android.PathForSource(ctx, ctx.ModuleDir(), libDir).Join(ctx, ctx.Arch().Abi[0]) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 96 | } | 
|  | 97 |  | 
|  | 98 | func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags, | 
| Dan Willemsen | 5cb580f | 2016-09-26 17:33:01 -0700 | [diff] [blame] | 99 | deps PathDeps, objs Objects) android.Path { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 100 | // A null build step, but it sets up the output path. | 
|  | 101 | if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") { | 
| Ryan Prichard | b170365 | 2018-03-26 16:30:31 -0700 | [diff] [blame] | 102 | ctx.ModuleErrorf("NDK prebuilt libraries must have an ndk_lib prefixed name") | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 103 | } | 
|  | 104 |  | 
| Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 105 | ndk.libraryDecorator.flagExporter.exportIncludesAsSystem(ctx) | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 106 |  | 
|  | 107 | libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_") | 
|  | 108 | libExt := flags.Toolchain.ShlibSuffix() | 
| Colin Cross | a48ab5b | 2017-02-14 15:28:44 -0800 | [diff] [blame] | 109 | if ndk.static() { | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 110 | libExt = staticLibraryExtension | 
|  | 111 | } | 
|  | 112 |  | 
| Ryan Prichard | b170365 | 2018-03-26 16:30:31 -0700 | [diff] [blame] | 113 | libDir := getNdkStlLibDir(ctx) | 
| Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 114 | lib := libDir.Join(ctx, libName+libExt) | 
|  | 115 |  | 
|  | 116 | ndk.libraryDecorator.flagExporter.setProvider(ctx) | 
|  | 117 |  | 
|  | 118 | if ndk.static() { | 
| Colin Cross | c85750b | 2022-04-21 12:50:51 -0700 | [diff] [blame] | 119 | depSet := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(lib).Build() | 
| Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 120 | android.SetProvider(ctx, StaticLibraryInfoProvider, StaticLibraryInfo{ | 
| Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 121 | StaticLibrary: lib, | 
|  | 122 |  | 
|  | 123 | TransitiveStaticLibrariesForOrdering: depSet, | 
|  | 124 | }) | 
|  | 125 | } else { | 
| Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 126 | android.SetProvider(ctx, SharedLibraryInfoProvider, SharedLibraryInfo{ | 
| Liz Kammer | ef6dfea | 2021-06-08 15:37:09 -0400 | [diff] [blame] | 127 | SharedLibrary: lib, | 
|  | 128 | Target:        ctx.Target(), | 
| Colin Cross | 0de8a1e | 2020-09-18 14:15:30 -0700 | [diff] [blame] | 129 | }) | 
|  | 130 | } | 
|  | 131 |  | 
|  | 132 | return lib | 
| Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 133 | } |