2016-01-04 23:34:37 +01:00
|
|
|
// Copyright 2016 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package cc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-07-20 22:17:15 +02:00
|
|
|
|
|
|
|
"android/soong/android"
|
2016-01-04 23:34:37 +01:00
|
|
|
)
|
|
|
|
|
2019-10-18 23:49:46 +02:00
|
|
|
func getNdkStlFamily(m LinkableInterface) string {
|
2018-09-05 01:28:17 +02:00
|
|
|
family, _ := getNdkStlFamilyAndLinkType(m)
|
|
|
|
return family
|
|
|
|
}
|
|
|
|
|
2022-05-12 17:42:33 +02:00
|
|
|
func deduplicateStlInput(stl string) string {
|
|
|
|
switch stl {
|
|
|
|
case "c++_shared":
|
|
|
|
return "libc++"
|
|
|
|
case "c++_static":
|
|
|
|
return "libc++_static"
|
|
|
|
}
|
|
|
|
return stl
|
|
|
|
}
|
|
|
|
|
2019-10-18 23:49:46 +02:00
|
|
|
func getNdkStlFamilyAndLinkType(m LinkableInterface) (string, string) {
|
|
|
|
stl := m.SelectedStl()
|
2017-12-15 22:56:59 +01:00
|
|
|
switch stl {
|
2023-01-17 21:06:45 +01:00
|
|
|
case "ndk_libc++_shared", "libc++":
|
2018-09-05 01:28:17 +02:00
|
|
|
return "libc++", "shared"
|
2023-01-17 21:06:45 +01:00
|
|
|
case "ndk_libc++_static", "libc++_static":
|
2018-09-05 01:28:17 +02:00
|
|
|
return "libc++", "static"
|
2017-12-15 22:56:59 +01:00
|
|
|
case "ndk_system":
|
2018-09-05 01:28:17 +02:00
|
|
|
return "system", "shared"
|
2017-12-15 22:56:59 +01:00
|
|
|
case "":
|
2018-09-05 01:28:17 +02:00
|
|
|
return "none", "none"
|
2017-12-15 22:56:59 +01:00
|
|
|
default:
|
2018-09-05 01:28:17 +02:00
|
|
|
panic(fmt.Errorf("stl: %q is not a valid STL", stl))
|
2017-12-15 22:56:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type StlProperties struct {
|
2018-01-04 23:21:14 +01:00
|
|
|
// Select the STL library to use. Possible values are "libc++",
|
|
|
|
// "libc++_static", "libstdc++", or "none". Leave blank to select the
|
|
|
|
// default.
|
2017-07-21 01:57:46 +02:00
|
|
|
Stl *string `android:"arch_variant"`
|
2016-01-04 23:34:37 +01:00
|
|
|
|
|
|
|
SelectedStl string `blueprint:"mutated"`
|
|
|
|
}
|
|
|
|
|
2016-04-05 00:07:06 +02:00
|
|
|
type stl struct {
|
2016-01-04 23:34:37 +01:00
|
|
|
Properties StlProperties
|
|
|
|
}
|
|
|
|
|
2016-04-05 00:07:06 +02:00
|
|
|
func (stl *stl) props() []interface{} {
|
2016-01-04 23:34:37 +01:00
|
|
|
return []interface{}{&stl.Properties}
|
|
|
|
}
|
|
|
|
|
2016-04-05 00:07:06 +02:00
|
|
|
func (stl *stl) begin(ctx BaseModuleContext) {
|
2016-01-04 23:34:37 +01:00
|
|
|
stl.Properties.SelectedStl = func() string {
|
2016-07-12 22:12:33 +02:00
|
|
|
s := ""
|
|
|
|
if stl.Properties.Stl != nil {
|
|
|
|
s = *stl.Properties.Stl
|
2021-04-27 02:07:17 +02:00
|
|
|
} else if ctx.header() {
|
|
|
|
s = "none"
|
2016-07-12 22:12:33 +02:00
|
|
|
}
|
2022-05-12 17:42:33 +02:00
|
|
|
if s == "none" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
s = deduplicateStlInput(s)
|
2023-07-26 18:42:41 +02:00
|
|
|
if ctx.useSdk() && ctx.Device() {
|
2016-07-12 22:12:33 +02:00
|
|
|
switch s {
|
2019-03-24 22:17:56 +01:00
|
|
|
case "", "system":
|
2016-01-04 23:34:37 +01:00
|
|
|
return "ndk_system"
|
2017-01-25 20:10:04 +01:00
|
|
|
case "libc++":
|
|
|
|
return "ndk_libc++_shared"
|
|
|
|
case "libc++_static":
|
|
|
|
return "ndk_libc++_static"
|
2016-01-04 23:34:37 +01:00
|
|
|
default:
|
2016-07-12 22:12:33 +02:00
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL with sdk_version set", s)
|
2016-01-04 23:34:37 +01:00
|
|
|
return ""
|
|
|
|
}
|
2017-04-04 21:59:48 +02:00
|
|
|
} else if ctx.Windows() {
|
2016-07-12 22:12:33 +02:00
|
|
|
switch s {
|
2018-08-08 19:28:12 +02:00
|
|
|
case "libc++", "libc++_static", "":
|
|
|
|
// Only use static libc++ for Windows.
|
|
|
|
return "libc++_static"
|
2016-01-04 23:34:37 +01:00
|
|
|
default:
|
2016-07-12 22:12:33 +02:00
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL for windows", s)
|
2016-01-04 23:34:37 +01:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
} else {
|
2016-07-12 22:12:33 +02:00
|
|
|
switch s {
|
2016-06-15 22:47:51 +02:00
|
|
|
case "libc++", "libc++_static":
|
2016-07-12 22:12:33 +02:00
|
|
|
return s
|
2020-04-07 18:50:32 +02:00
|
|
|
case "", "system":
|
2016-01-04 23:34:37 +01:00
|
|
|
if ctx.static() {
|
|
|
|
return "libc++_static"
|
|
|
|
} else {
|
|
|
|
return "libc++"
|
|
|
|
}
|
|
|
|
default:
|
2016-07-12 22:12:33 +02:00
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL", s)
|
2016-01-04 23:34:37 +01:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2020-02-13 02:13:25 +01:00
|
|
|
func staticUnwinder(ctx android.BaseModuleContext) string {
|
2021-04-08 12:28:28 +02:00
|
|
|
vndkVersion := ctx.Module().(*Module).VndkVersion()
|
|
|
|
|
|
|
|
// Modules using R vndk use different unwinder
|
|
|
|
if vndkVersion == "30" {
|
|
|
|
if ctx.Arch().ArchType == android.Arm {
|
|
|
|
return "libunwind_llvm"
|
|
|
|
} else {
|
|
|
|
return "libgcc_stripped"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-14 04:18:53 +01:00
|
|
|
return "libunwind"
|
2020-02-13 02:13:25 +01:00
|
|
|
}
|
|
|
|
|
2016-04-05 00:07:06 +02:00
|
|
|
func (stl *stl) deps(ctx BaseModuleContext, deps Deps) Deps {
|
2016-01-04 23:34:37 +01:00
|
|
|
switch stl.Properties.SelectedStl {
|
|
|
|
case "libstdc++":
|
2016-06-15 22:47:51 +02:00
|
|
|
// Nothing
|
2016-01-04 23:34:37 +01:00
|
|
|
case "libc++", "libc++_static":
|
|
|
|
if stl.Properties.SelectedStl == "libc++" {
|
|
|
|
deps.SharedLibs = append(deps.SharedLibs, stl.Properties.SelectedStl)
|
|
|
|
} else {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, stl.Properties.SelectedStl)
|
|
|
|
}
|
2019-07-24 21:17:40 +02:00
|
|
|
if ctx.Device() && !ctx.useSdk() {
|
|
|
|
// __cxa_demangle is not a part of libc++.so on the device since
|
|
|
|
// it's large and most processes don't need it. Statically link
|
|
|
|
// libc++demangle into every process so that users still have it if
|
|
|
|
// needed, but the linker won't include this unless it is actually
|
|
|
|
// called.
|
|
|
|
// http://b/138245375
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libc++demangle")
|
|
|
|
}
|
2016-11-17 10:02:25 +01:00
|
|
|
if ctx.toolchain().Bionic() {
|
2016-01-04 23:34:37 +01:00
|
|
|
if ctx.staticBinary() {
|
2020-02-13 02:13:25 +01:00
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libm", "libc", staticUnwinder(ctx))
|
|
|
|
} else {
|
|
|
|
deps.StaticUnwinderIfLegacy = true
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case "":
|
|
|
|
// None or error.
|
2020-02-13 02:13:25 +01:00
|
|
|
if ctx.toolchain().Bionic() && ctx.Module().Name() == "libc++" {
|
|
|
|
deps.StaticUnwinderIfLegacy = true
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
case "ndk_system":
|
|
|
|
// TODO: Make a system STL prebuilt for the NDK.
|
|
|
|
// 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...)
|
2023-09-06 01:02:27 +02:00
|
|
|
deps.HeaderLibs = append([]string{"ndk_system"}, deps.HeaderLibs...)
|
2018-03-27 01:30:31 +02:00
|
|
|
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")
|
|
|
|
}
|
2021-04-01 00:29:11 +02:00
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "ndk_libunwind")
|
2016-01-04 23:34:37 +01:00
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("Unknown stl: %q", stl.Properties.SelectedStl))
|
|
|
|
}
|
|
|
|
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2016-04-05 00:07:06 +02:00
|
|
|
func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags {
|
2016-01-04 23:34:37 +01:00
|
|
|
switch stl.Properties.SelectedStl {
|
|
|
|
case "libc++", "libc++_static":
|
2018-01-11 22:00:46 +01:00
|
|
|
if ctx.Darwin() {
|
|
|
|
// libc++'s headers are annotated with availability macros that
|
|
|
|
// indicate which version of Mac OS was the first to ship with a
|
|
|
|
// libc++ feature available in its *system's* libc++.dylib. We do
|
|
|
|
// not use the system's library, but rather ship our own. As such,
|
|
|
|
// these availability attributes are meaningless for us but cause
|
|
|
|
// build breaks when we try to use code that would not be available
|
|
|
|
// in the system's dylib.
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CppFlags = append(flags.Local.CppFlags,
|
2018-01-11 22:00:46 +01:00
|
|
|
"-D_LIBCPP_DISABLE_AVAILABILITY")
|
|
|
|
}
|
|
|
|
|
2016-11-17 10:02:25 +01:00
|
|
|
if !ctx.toolchain().Bionic() {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CppFlags = append(flags.Local.CppFlags, "-nostdinc++")
|
2019-10-04 00:48:34 +02:00
|
|
|
flags.extraLibFlags = append(flags.extraLibFlags, "-nostdlib++")
|
2018-08-08 19:28:12 +02:00
|
|
|
if ctx.Windows() {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CppFlags = append(flags.Local.CppFlags,
|
2024-01-19 08:57:38 +01:00
|
|
|
// These macros can also be defined by libc++'s __config
|
|
|
|
// or __config_site headers so define them the same way
|
|
|
|
// (i.e. to nothing). Disable visibility annotations since
|
|
|
|
// we're using static libc++.
|
|
|
|
"-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=",
|
|
|
|
"-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS=",
|
2018-08-08 19:28:12 +02:00
|
|
|
// Use Win32 threads in libc++.
|
2024-01-19 08:57:38 +01:00
|
|
|
"-D_LIBCPP_HAS_THREAD_API_WIN32=")
|
2018-08-08 19:28:12 +02:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
case "libstdc++":
|
2016-06-15 22:47:51 +02:00
|
|
|
// Nothing
|
2016-01-04 23:34:37 +01:00
|
|
|
case "ndk_system":
|
2023-09-06 01:02:27 +02:00
|
|
|
// Nothing: The exports of ndk_system will be added automatically to the local cflags
|
2016-01-04 23:34:37 +01:00
|
|
|
case "ndk_libc++_shared", "ndk_libc++_static":
|
2019-04-11 02:57:50 +02:00
|
|
|
if ctx.Arch().ArchType == android.Arm {
|
|
|
|
// Make sure the _Unwind_XXX symbols are not re-exported.
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--exclude-libs,libunwind.a")
|
2019-04-11 02:57:50 +02:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
case "":
|
|
|
|
// None or error.
|
2016-11-17 10:02:25 +01:00
|
|
|
if !ctx.toolchain().Bionic() {
|
2019-11-04 18:37:55 +01:00
|
|
|
flags.Local.CppFlags = append(flags.Local.CppFlags, "-nostdinc++")
|
2019-10-04 00:48:34 +02:00
|
|
|
flags.extraLibFlags = append(flags.extraLibFlags, "-nostdlib++")
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("Unknown stl: %q", stl.Properties.SelectedStl))
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|