ndk_prebuilt.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. package cc
  15. import (
  16. "strings"
  17. "android/soong/android"
  18. )
  19. func init() {
  20. android.RegisterModuleType("ndk_prebuilt_static_stl", NdkPrebuiltStaticStlFactory)
  21. android.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory)
  22. }
  23. // NDK prebuilt libraries.
  24. //
  25. // These differ from regular prebuilts in that they aren't stripped and usually aren't installed
  26. // either (with the exception of the shared STLs, which are installed to the app's directory rather
  27. // than to the system image).
  28. type ndkPrebuiltStlLinker struct {
  29. *libraryDecorator
  30. }
  31. func (ndk *ndkPrebuiltStlLinker) linkerProps() []interface{} {
  32. return append(ndk.libraryDecorator.linkerProps(), &ndk.Properties, &ndk.flagExporter.Properties)
  33. }
  34. func (*ndkPrebuiltStlLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
  35. // NDK libraries can't have any dependencies
  36. return deps
  37. }
  38. func (*ndkPrebuiltStlLinker) availableFor(what string) bool {
  39. // ndk prebuilt objects are available to everywhere
  40. return true
  41. }
  42. // ndk_prebuilt_shared_stl exports a precompiled ndk shared standard template
  43. // library (stl) library for linking operation. The soong's module name format
  44. // is ndk_<NAME>.so where the library is located under
  45. // ./prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/$(HOST_ARCH)/<NAME>.so.
  46. func NdkPrebuiltSharedStlFactory() android.Module {
  47. module, library := NewLibrary(android.DeviceSupported)
  48. library.BuildOnlyShared()
  49. module.compiler = nil
  50. module.linker = &ndkPrebuiltStlLinker{
  51. libraryDecorator: library,
  52. }
  53. module.installer = nil
  54. module.Properties.Sdk_version = StringPtr("minimum")
  55. module.Properties.AlwaysSdk = true
  56. module.stl.Properties.Stl = StringPtr("none")
  57. return module.Init()
  58. }
  59. // ndk_prebuilt_static_stl exports a precompiled ndk static standard template
  60. // library (stl) library for linking operation. The soong's module name format
  61. // is ndk_<NAME>.a where the library is located under
  62. // ./prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs/$(HOST_ARCH)/<NAME>.a.
  63. func NdkPrebuiltStaticStlFactory() android.Module {
  64. module, library := NewLibrary(android.DeviceSupported)
  65. library.BuildOnlyStatic()
  66. module.compiler = nil
  67. module.linker = &ndkPrebuiltStlLinker{
  68. libraryDecorator: library,
  69. }
  70. module.installer = nil
  71. module.Properties.Sdk_version = StringPtr("minimum")
  72. module.Properties.HideFromMake = true
  73. module.Properties.AlwaysSdk = true
  74. module.Properties.Sdk_version = StringPtr("current")
  75. module.stl.Properties.Stl = StringPtr("none")
  76. return module.Init()
  77. }
  78. func getNdkStlLibDir(ctx android.ModuleContext) android.SourcePath {
  79. libDir := "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs"
  80. return android.PathForSource(ctx, libDir).Join(ctx, ctx.Arch().Abi[0])
  81. }
  82. func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
  83. deps PathDeps, objs Objects) android.Path {
  84. // A null build step, but it sets up the output path.
  85. if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") {
  86. ctx.ModuleErrorf("NDK prebuilt libraries must have an ndk_lib prefixed name")
  87. }
  88. ndk.libraryDecorator.flagExporter.exportIncludesAsSystem(ctx)
  89. libName := strings.TrimPrefix(ctx.ModuleName(), "ndk_")
  90. libExt := flags.Toolchain.ShlibSuffix()
  91. if ndk.static() {
  92. libExt = staticLibraryExtension
  93. }
  94. libDir := getNdkStlLibDir(ctx)
  95. lib := libDir.Join(ctx, libName+libExt)
  96. ndk.libraryDecorator.flagExporter.setProvider(ctx)
  97. if ndk.static() {
  98. depSet := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(lib).Build()
  99. ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
  100. StaticLibrary: lib,
  101. TransitiveStaticLibrariesForOrdering: depSet,
  102. })
  103. } else {
  104. ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
  105. SharedLibrary: lib,
  106. Target: ctx.Target(),
  107. })
  108. }
  109. return lib
  110. }