2016-01-05 06:34:37 +08: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 (
|
2016-05-19 06:37:25 +08:00
|
|
|
"android/soong/android"
|
2016-01-05 06:34:37 +08:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2019-10-19 05:49:46 +08:00
|
|
|
func getNdkStlFamily(m LinkableInterface) string {
|
2018-09-05 07:28:17 +08:00
|
|
|
family, _ := getNdkStlFamilyAndLinkType(m)
|
|
|
|
return family
|
|
|
|
}
|
|
|
|
|
2019-10-19 05:49:46 +08:00
|
|
|
func getNdkStlFamilyAndLinkType(m LinkableInterface) (string, string) {
|
|
|
|
stl := m.SelectedStl()
|
2017-12-16 05:56:59 +08:00
|
|
|
switch stl {
|
2018-09-05 07:28:17 +08:00
|
|
|
case "ndk_libc++_shared":
|
|
|
|
return "libc++", "shared"
|
|
|
|
case "ndk_libc++_static":
|
|
|
|
return "libc++", "static"
|
2017-12-16 05:56:59 +08:00
|
|
|
case "ndk_system":
|
2018-09-05 07:28:17 +08:00
|
|
|
return "system", "shared"
|
2017-12-16 05:56:59 +08:00
|
|
|
case "":
|
2018-09-05 07:28:17 +08:00
|
|
|
return "none", "none"
|
2017-12-16 05:56:59 +08:00
|
|
|
default:
|
2018-09-05 07:28:17 +08:00
|
|
|
panic(fmt.Errorf("stl: %q is not a valid STL", stl))
|
2017-12-16 05:56:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 06:34:37 +08:00
|
|
|
type StlProperties struct {
|
2018-01-05 06:21:14 +08: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 07:57:46 +08:00
|
|
|
Stl *string `android:"arch_variant"`
|
2016-01-05 06:34:37 +08:00
|
|
|
|
|
|
|
SelectedStl string `blueprint:"mutated"`
|
|
|
|
}
|
|
|
|
|
2016-04-05 06:07:06 +08:00
|
|
|
type stl struct {
|
2016-01-05 06:34:37 +08:00
|
|
|
Properties StlProperties
|
|
|
|
}
|
|
|
|
|
2016-04-05 06:07:06 +08:00
|
|
|
func (stl *stl) props() []interface{} {
|
2016-01-05 06:34:37 +08:00
|
|
|
return []interface{}{&stl.Properties}
|
|
|
|
}
|
|
|
|
|
2016-04-05 06:07:06 +08:00
|
|
|
func (stl *stl) begin(ctx BaseModuleContext) {
|
2016-01-05 06:34:37 +08:00
|
|
|
stl.Properties.SelectedStl = func() string {
|
2016-07-13 04:12:33 +08:00
|
|
|
s := ""
|
|
|
|
if stl.Properties.Stl != nil {
|
|
|
|
s = *stl.Properties.Stl
|
|
|
|
}
|
2017-09-28 08:01:44 +08:00
|
|
|
if ctx.useSdk() && ctx.Device() {
|
2016-07-13 04:12:33 +08:00
|
|
|
switch s {
|
2019-03-25 05:17:56 +08:00
|
|
|
case "", "system":
|
2016-01-05 06:34:37 +08:00
|
|
|
return "ndk_system"
|
2018-01-05 06:21:14 +08:00
|
|
|
case "c++_shared", "c++_static":
|
2016-07-13 04:12:33 +08:00
|
|
|
return "ndk_lib" + s
|
2017-01-26 03:10:04 +08:00
|
|
|
case "libc++":
|
|
|
|
return "ndk_libc++_shared"
|
|
|
|
case "libc++_static":
|
|
|
|
return "ndk_libc++_static"
|
2016-04-22 06:53:42 +08:00
|
|
|
case "none":
|
|
|
|
return ""
|
2016-01-05 06:34:37 +08:00
|
|
|
default:
|
2016-07-13 04:12:33 +08:00
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL with sdk_version set", s)
|
2016-01-05 06:34:37 +08:00
|
|
|
return ""
|
|
|
|
}
|
2017-04-05 03:59:48 +08:00
|
|
|
} else if ctx.Windows() {
|
2016-07-13 04:12:33 +08:00
|
|
|
switch s {
|
2018-08-09 01:28:12 +08:00
|
|
|
case "libc++", "libc++_static", "":
|
|
|
|
// Only use static libc++ for Windows.
|
|
|
|
return "libc++_static"
|
2016-01-05 06:34:37 +08:00
|
|
|
case "none":
|
|
|
|
return ""
|
|
|
|
default:
|
2016-07-13 04:12:33 +08:00
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL for windows", s)
|
2016-01-05 06:34:37 +08:00
|
|
|
return ""
|
|
|
|
}
|
2019-01-18 06:44:05 +08:00
|
|
|
} else if ctx.Fuchsia() {
|
|
|
|
switch s {
|
|
|
|
case "c++_static":
|
|
|
|
return "libc++_static"
|
|
|
|
case "c++_shared":
|
|
|
|
return "libc++"
|
|
|
|
case "libc++", "libc++_static":
|
|
|
|
return s
|
|
|
|
case "none":
|
|
|
|
return ""
|
|
|
|
case "":
|
|
|
|
if ctx.static() {
|
|
|
|
return "libc++_static"
|
|
|
|
} else {
|
|
|
|
return "libc++"
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL on Fuchsia", s)
|
|
|
|
return ""
|
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
} else {
|
2016-07-13 04:12:33 +08:00
|
|
|
switch s {
|
2016-06-16 04:47:51 +08:00
|
|
|
case "libc++", "libc++_static":
|
2016-07-13 04:12:33 +08:00
|
|
|
return s
|
2020-04-08 00:50:32 +08:00
|
|
|
case "c++_shared":
|
|
|
|
return "libc++"
|
|
|
|
case "c++_static":
|
|
|
|
return "libc++_static"
|
2016-01-05 06:34:37 +08:00
|
|
|
case "none":
|
|
|
|
return ""
|
2020-04-08 00:50:32 +08:00
|
|
|
case "", "system":
|
2016-01-05 06:34:37 +08:00
|
|
|
if ctx.static() {
|
|
|
|
return "libc++_static"
|
|
|
|
} else {
|
|
|
|
return "libc++"
|
|
|
|
}
|
|
|
|
default:
|
2016-07-13 04:12:33 +08:00
|
|
|
ctx.ModuleErrorf("stl: %q is not a supported STL", s)
|
2016-01-05 06:34:37 +08:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2018-11-16 03:29:28 +08:00
|
|
|
func needsLibAndroidSupport(ctx BaseModuleContext) bool {
|
Replace stringly-typed API levels.
Handling of API levels within Soong is currently fairly difficult
since it isn't always clear based on context what kind of API level a
given string represents, how much canonicalizing and error checking
the code receiving the string are expected to do, or how those errors
should be treated.
The API level struct does not export its raw data, so as to keep its
"constructor" private to the android package, and to prevent misuse of
the `number` field, which is only an implementation detail for preview
API levels. API levels can be parsed with either
`android.ApiLevelFromUser`, which returns any errors to the caller, or
`android.ApiLevelOrPanic`, which is used in the case where the input
is trusted and any errors in parsing should panic. Even within the
`android` package, these APIs should be preferred over direct
construction.
For cases where there are context specific parsing requirements, such
as handling the "minimum" alias in the cc module,
`nativeApiLevelFromUser` and `nativeApiLevelOrPanic` should be used
instead.
Test: treehugger
Bug: http://b/154667674
Change-Id: Id52921fda32cb437fb1775ac2183299dedc0cf20
2020-07-07 05:49:35 +08:00
|
|
|
version := nativeApiLevelOrPanic(ctx, ctx.sdkVersion())
|
|
|
|
return version.LessThan(android.FirstNonLibAndroidSupportVersion)
|
2018-11-16 03:29:28 +08:00
|
|
|
}
|
|
|
|
|
2020-02-13 09:13:25 +08:00
|
|
|
func staticUnwinder(ctx android.BaseModuleContext) string {
|
|
|
|
if ctx.Arch().ArchType == android.Arm {
|
|
|
|
return "libunwind_llvm"
|
|
|
|
} else {
|
|
|
|
return "libgcc_stripped"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-05 06:07:06 +08:00
|
|
|
func (stl *stl) deps(ctx BaseModuleContext, deps Deps) Deps {
|
2016-01-05 06:34:37 +08:00
|
|
|
switch stl.Properties.SelectedStl {
|
|
|
|
case "libstdc++":
|
2016-06-16 04:47:51 +08:00
|
|
|
// Nothing
|
2016-01-05 06:34:37 +08: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-25 03:17:40 +08: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 17:02:25 +08:00
|
|
|
if ctx.toolchain().Bionic() {
|
2016-01-05 06:34:37 +08:00
|
|
|
if ctx.staticBinary() {
|
2020-02-13 09:13:25 +08:00
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libm", "libc", staticUnwinder(ctx))
|
|
|
|
} else {
|
|
|
|
deps.StaticUnwinderIfLegacy = true
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case "":
|
|
|
|
// None or error.
|
2020-02-13 09:13:25 +08:00
|
|
|
if ctx.toolchain().Bionic() && ctx.Module().Name() == "libc++" {
|
|
|
|
deps.StaticUnwinderIfLegacy = true
|
|
|
|
}
|
2016-01-05 06:34:37 +08: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...)
|
2018-03-27 07:30:31 +08: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")
|
|
|
|
}
|
2018-11-16 03:29:28 +08:00
|
|
|
if needsLibAndroidSupport(ctx) {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "ndk_libandroid_support")
|
|
|
|
}
|
2018-03-27 07:30:31 +08:00
|
|
|
if ctx.Arch().ArchType == android.Arm {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "ndk_libunwind")
|
2019-12-11 10:37:45 +08:00
|
|
|
} else {
|
|
|
|
deps.StaticLibs = append(deps.StaticLibs, "libgcc_stripped")
|
2018-03-27 07:30:31 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("Unknown stl: %q", stl.Properties.SelectedStl))
|
|
|
|
}
|
|
|
|
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2016-04-05 06:07:06 +08:00
|
|
|
func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags {
|
2016-01-05 06:34:37 +08:00
|
|
|
switch stl.Properties.SelectedStl {
|
|
|
|
case "libc++", "libc++_static":
|
2018-01-12 05:00:46 +08: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-05 01:37:55 +08:00
|
|
|
flags.Local.CppFlags = append(flags.Local.CppFlags,
|
2018-01-12 05:00:46 +08:00
|
|
|
"-D_LIBCPP_DISABLE_AVAILABILITY")
|
|
|
|
}
|
|
|
|
|
2016-11-17 17:02:25 +08:00
|
|
|
if !ctx.toolchain().Bionic() {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CppFlags = append(flags.Local.CppFlags, "-nostdinc++")
|
2019-10-04 06:48:34 +08:00
|
|
|
flags.extraLibFlags = append(flags.extraLibFlags, "-nostdlib++")
|
2018-08-09 01:28:12 +08:00
|
|
|
if ctx.Windows() {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CppFlags = append(flags.Local.CppFlags,
|
2018-08-09 01:28:12 +08:00
|
|
|
// Disable visiblity annotations since we're using static
|
|
|
|
// libc++.
|
|
|
|
"-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
|
|
|
|
"-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
|
|
|
|
// Use Win32 threads in libc++.
|
|
|
|
"-D_LIBCPP_HAS_THREAD_API_WIN32")
|
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
} else {
|
2016-05-19 06:37:25 +08:00
|
|
|
if ctx.Arch().ArchType == android.Arm {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--exclude-libs,libunwind_llvm.a")
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
case "libstdc++":
|
2016-06-16 04:47:51 +08:00
|
|
|
// Nothing
|
2016-01-05 06:34:37 +08:00
|
|
|
case "ndk_system":
|
2016-05-19 06:37:25 +08:00
|
|
|
ndkSrcRoot := android.PathForSource(ctx, "prebuilts/ndk/current/sources/cxx-stl/system/include")
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CFlags = append(flags.Local.CFlags, "-isystem "+ndkSrcRoot.String())
|
2016-01-05 06:34:37 +08:00
|
|
|
case "ndk_libc++_shared", "ndk_libc++_static":
|
2019-04-11 08:57:50 +08:00
|
|
|
if ctx.Arch().ArchType == android.Arm {
|
|
|
|
// Make sure the _Unwind_XXX symbols are not re-exported.
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,--exclude-libs,libunwind.a")
|
2019-04-11 08:57:50 +08:00
|
|
|
}
|
2016-01-05 06:34:37 +08:00
|
|
|
case "":
|
|
|
|
// None or error.
|
2016-11-17 17:02:25 +08:00
|
|
|
if !ctx.toolchain().Bionic() {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.CppFlags = append(flags.Local.CppFlags, "-nostdinc++")
|
2019-10-04 06:48:34 +08:00
|
|
|
flags.extraLibFlags = append(flags.extraLibFlags, "-nostdlib++")
|
2016-01-05 06:34:37 +08:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("Unknown stl: %q", stl.Properties.SelectedStl))
|
|
|
|
}
|
|
|
|
|
|
|
|
return flags
|
|
|
|
}
|