diff --git a/cc/cc.go b/cc/cc.go index b9c589a14..721f4b136 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1052,10 +1052,6 @@ func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag depe // These are always allowed return } - if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok { - // These are allowed, but they don't set sdk_version - return - } if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok { // These are allowed, but they don't set sdk_version return diff --git a/cc/library.go b/cc/library.go index 76f8a8cf9..98a96734b 100644 --- a/cc/library.go +++ b/cc/library.go @@ -601,25 +601,6 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, sharedLibs := deps.SharedLibs sharedLibs = append(sharedLibs, deps.LateSharedLibs...) - // TODO(danalbert): Clean this up when soong supports prebuilts. - if strings.HasPrefix(ctx.selectedStl(), "ndk_libc++") { - libDir := getNdkStlLibDir(ctx, "libc++") - - if strings.HasSuffix(ctx.selectedStl(), "_shared") { - deps.StaticLibs = append(deps.StaticLibs, - libDir.Join(ctx, "libandroid_support.a")) - } else { - deps.StaticLibs = append(deps.StaticLibs, - libDir.Join(ctx, "libc++abi.a"), - libDir.Join(ctx, "libandroid_support.a")) - } - - if ctx.Arch().ArchType == android.Arm { - deps.StaticLibs = append(deps.StaticLibs, - libDir.Join(ctx, "libunwind.a")) - } - } - linkerDeps = append(linkerDeps, deps.SharedLibsDeps...) linkerDeps = append(linkerDeps, deps.LateSharedLibsDeps...) linkerDeps = append(linkerDeps, objs.tidyFiles...) diff --git a/cc/ndk_prebuilt.go b/cc/ndk_prebuilt.go index 7e8d98916..4c633c245 100644 --- a/cc/ndk_prebuilt.go +++ b/cc/ndk_prebuilt.go @@ -23,7 +23,6 @@ import ( ) func init() { - android.RegisterModuleType("ndk_prebuilt_library", ndkPrebuiltLibraryFactory) android.RegisterModuleType("ndk_prebuilt_object", ndkPrebuiltObjectFactory) android.RegisterModuleType("ndk_prebuilt_static_stl", ndkPrebuiltStaticStlFactory) android.RegisterModuleType("ndk_prebuilt_shared_stl", ndkPrebuiltSharedStlFactory) @@ -80,66 +79,32 @@ func (c *ndkPrebuiltObjectLinker) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { // A null build step, but it sets up the output path. if !strings.HasPrefix(ctx.ModuleName(), "ndk_crt") { - ctx.ModuleErrorf("NDK prebuilts must have an ndk_crt prefixed name") + ctx.ModuleErrorf("NDK prebuilt objects must have an ndk_crt prefixed name") } return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, objectExtension, ctx.sdkVersion()) } -type ndkPrebuiltLibraryLinker struct { +type ndkPrebuiltStlLinker struct { *libraryDecorator } -func (ndk *ndkPrebuiltLibraryLinker) linkerProps() []interface{} { +func (ndk *ndkPrebuiltStlLinker) linkerProps() []interface{} { return append(ndk.libraryDecorator.linkerProps(), &ndk.Properties, &ndk.flagExporter.Properties) } -func (*ndkPrebuiltLibraryLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { +func (*ndkPrebuiltStlLinker) linkerDeps(ctx DepsContext, deps Deps) Deps { // NDK libraries can't have any dependencies return deps } -func ndkPrebuiltLibraryFactory() android.Module { - module, library := NewLibrary(android.DeviceSupported) - library.BuildOnlyShared() - linker := &ndkPrebuiltLibraryLinker{ - libraryDecorator: library, - } - module.compiler = nil - module.linker = linker - module.installer = nil - module.stl = nil - module.Properties.HideFromMake = true - return module.Init() -} - -func (ndk *ndkPrebuiltLibraryLinker) link(ctx ModuleContext, flags Flags, - deps PathDeps, objs Objects) android.Path { - // A null build step, but it sets up the output path. - ndk.exportIncludes(ctx, "-isystem") - - return ndkPrebuiltModuleToPath(ctx, flags.Toolchain, flags.Toolchain.ShlibSuffix(), - ctx.sdkVersion()) -} - -// The NDK STLs are slightly different from the prebuilt system libraries: -// * Are not specific to each platform version. -// * The libraries are not in a predictable location for each STL. - -type ndkPrebuiltStlLinker struct { - ndkPrebuiltLibraryLinker -} - func ndkPrebuiltSharedStlFactory() android.Module { module, library := NewLibrary(android.DeviceSupported) library.BuildOnlyShared() - linker := &ndkPrebuiltStlLinker{ - ndkPrebuiltLibraryLinker: ndkPrebuiltLibraryLinker{ - libraryDecorator: library, - }, - } module.compiler = nil - module.linker = linker + module.linker = &ndkPrebuiltStlLinker{ + libraryDecorator: library, + } module.installer = nil minVersionString := "minimum" noStlString := "none" @@ -151,29 +116,25 @@ func ndkPrebuiltSharedStlFactory() android.Module { func ndkPrebuiltStaticStlFactory() android.Module { module, library := NewLibrary(android.DeviceSupported) library.BuildOnlyStatic() - linker := &ndkPrebuiltStlLinker{ - ndkPrebuiltLibraryLinker: ndkPrebuiltLibraryLinker{ - libraryDecorator: library, - }, - } module.compiler = nil - module.linker = linker + module.linker = &ndkPrebuiltStlLinker{ + libraryDecorator: library, + } module.installer = nil module.Properties.HideFromMake = true return module.Init() } -func getNdkStlLibDir(ctx android.ModuleContext, stl string) android.SourcePath { - libDir := "cxx-stl/llvm-libc++/libs" - ndkSrcRoot := "prebuilts/ndk/current/sources" - return android.PathForSource(ctx, ndkSrcRoot).Join(ctx, libDir, ctx.Arch().Abi[0]) +func getNdkStlLibDir(ctx android.ModuleContext) android.SourcePath { + libDir := "prebuilts/ndk/current/sources/cxx-stl/llvm-libc++/libs" + return android.PathForSource(ctx, libDir).Join(ctx, ctx.Arch().Abi[0]) } func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { // A null build step, but it sets up the output path. if !strings.HasPrefix(ctx.ModuleName(), "ndk_lib") { - ctx.ModuleErrorf("NDK prebuilts must have an ndk_lib prefixed name") + ctx.ModuleErrorf("NDK prebuilt libraries must have an ndk_lib prefixed name") } ndk.exportIncludes(ctx, "-isystem") @@ -184,8 +145,6 @@ func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags, libExt = staticLibraryExtension } - stlName := strings.TrimSuffix(libName, "_shared") - stlName = strings.TrimSuffix(stlName, "_static") - libDir := getNdkStlLibDir(ctx, stlName) + libDir := getNdkStlLibDir(ctx) return libDir.Join(ctx, libName+libExt) } diff --git a/cc/stl.go b/cc/stl.go index 2da647184..6f63835c4 100644 --- a/cc/stl.go +++ b/cc/stl.go @@ -129,10 +129,16 @@ func (stl *stl) deps(ctx BaseModuleContext, deps Deps) Deps { // The system STL doesn't have a prebuilt (it uses the system's libstdc++), but it does have // its own includes. The includes are handled in CCBase.Flags(). deps.SharedLibs = append([]string{"libstdc++"}, deps.SharedLibs...) - case "ndk_libc++_shared": - deps.SharedLibs = append(deps.SharedLibs, stl.Properties.SelectedStl) - case "ndk_libc++_static": - deps.StaticLibs = append(deps.StaticLibs, stl.Properties.SelectedStl) + case "ndk_libc++_shared", "ndk_libc++_static": + if stl.Properties.SelectedStl == "ndk_libc++_shared" { + deps.SharedLibs = append(deps.SharedLibs, stl.Properties.SelectedStl) + } else { + deps.StaticLibs = append(deps.StaticLibs, stl.Properties.SelectedStl, "ndk_libc++abi") + } + deps.StaticLibs = append(deps.StaticLibs, "ndk_libandroid_support") + if ctx.Arch().ArchType == android.Arm { + deps.StaticLibs = append(deps.StaticLibs, "ndk_libunwind") + } default: panic(fmt.Errorf("Unknown stl: %q", stl.Properties.SelectedStl)) }