blob: a2dbcff88e39a7b9d8d73c081f865dcd951cf65a [file] [log] [blame]
# Copyright 2021 The Cobalt Authors. 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.
import("//starboard/android/shared/toolchain/toolchain.gni")
config("platform_configuration") {
configs = [ "//starboard/build/config/sabi" ]
cflags = []
if (current_toolchain == host_toolchain) {
cflags += [ "-O2" ]
} else {
defines = []
ldflags = [
# The NDK default "ld" is actually the gold linker for all architectures
# except arm64 (aarch64) where it"s the bfd linker. Don"t use either of
# those, rather use lld everywhere. See release notes for NDK 19:
# https://developer.android.com/ndk/downloads/revision_history
"-fuse-ld=lld",
]
if (is_debug) {
cflags += [ "-O0" ]
configs += [ "//build/config/compiler:rtti" ]
} else if (is_devel) {
cflags += [ "-O2" ]
configs += [ "//build/config/compiler:rtti" ]
} else {
cflags += [ "-gline-tables-only" ]
}
libs = [
"EGL",
"GLESv2",
"OpenSLES",
"android",
"log",
"mediandk",
]
if (!cobalt_fastbuild && (is_debug || is_devel)) {
cflags += [ "-g" ]
}
if (use_asan) {
cflags += [
"-fsanitize=address",
"-fno-omit-frame-pointer",
]
ldflags += [
"-fsanitize=address",
# Force linking of the helpers in sanitizer_options.cc
"-Wl,-u_sanitizer_options_link_helper",
]
defines += [ "ADDRESS_SANITIZER" ]
} else if (use_tsan) {
cflags += [
"-fsanitize=thread",
"-fno-omit-frame-pointer",
]
ldflags += [ "-fsanitize=thread" ]
defines += [ "THREAD_SANITIZER" ]
}
cflags_cc = [ "-std=c++14" ]
cflags += [
# libwebp uses the cpufeatures library to detect ARM NEON support
"-I${android_ndk_path}/sources/android/cpufeatures",
# Mimic build/cmake/android.toolchain.cmake in the Android NDK.
"-ffunction-sections",
"-funwind-tables",
"-fstack-protector-strong",
"-no-canonical-prefixes",
# Other flags
"-fsigned-char",
"-fno-limit-debug-info",
"-fcolor-diagnostics",
"-fno-strict-aliasing", # See http://crbug.com/32204
# Default visibility is hidden to enable dead stripping.
"-fvisibility=hidden",
# Any warning will stop the build.
"-Werror",
# Disable errors for the warning till the Android NDK r19 is fixed.
# The warning is trigger when compiling .c files and complains for
# "-stdlib=libc++" which is added by the NDK.
"-Wno-error=unused-command-line-argument",
# Don"t warn about register variables (in base and net)
"-Wno-deprecated-register",
# Don"t warn about deprecated ICU methods (in googleurl and net)
"-Wno-deprecated-declarations",
# Skia doesn"t use overrides.
"-Wno-inconsistent-missing-override",
# shifting a negative signed value is undefined
"-Wno-shift-negative-value",
# Don"t warn for implicit sign conversions. (in v8 and protobuf)
"-Wno-sign-conversion",
]
defines += [
# Enable compile-time decisions based on the ABI
"ANDROID_ABI=$android_abi",
# -DANDROID is an argument to some ifdefs in the NDK"s eglplatform.h
"ANDROID",
# Cobalt on Linux flag
"COBALT_LINUX",
# So that we get the PRI* macros from inttypes.h
"__STDC_FORMAT_MACROS",
# Enable GNU extensions to get prototypes like ffsl.
"_GNU_SOURCE=1",
# Undefining __linux__ causes the system headers to make wrong
# assumptions about which C-library is used on the platform.
"__BIONIC__",
# Undefining __linux__ leaves libc++ without a threads implementation.
# TODO: See if there"s a way to make libcpp threading use Starboard.
"_LIBCPP_HAS_THREAD_API_PTHREAD",
]
ldflags += [
# Use the static LLVM libc++.
"-static-libstdc++",
# Mimic build/cmake/android.toolchain.cmake in the Android NDK, but
# force build-id to sha1, so that older lldb versions can still find
# debugsymbols, see https://github.com/android-ndk/ndk/issues/885
"-Wl,--build-id=sha1",
"-Wl,--warn-shared-textrel",
"-Wl,--fatal-warnings",
"-Wl,--gc-sections",
"-Wl,-z,nocopyreloc",
# Wrapper synchronizes punch-out video bounds with the UI frame.
"-Wl,--wrap=eglSwapBuffers",
]
}
}
config("size") {
cflags = [ "-Os" ]
}
config("speed") {
cflags = [ "-O2" ]
}
config("executable_config") {
cflags = [ "-fPIE" ]
ldflags = [ "-pie" ]
}
config("library_config") {
cflags = [ "-fPIC" ]
}
config("pedantic_warnings") {
cflags = [
"-Wall",
"-Wextra",
"-Wunreachable-code",
# Don't get pedantic about warnings from base macros. These must be
# disabled after the -Wall above, so this has to be done here rather
# than in the platform's target toolchain.
# TODO: Rebase base and use static_assert instead of COMPILE_ASSERT
"-Wno-unused-local-typedef", # COMPILE_ASSERT
"-Wno-missing-field-initializers", # LAZY_INSTANCE_INITIALIZER
# It's OK not to use some input parameters. Note that the order
# matters: Wall implies Wunused-parameter and Wno-unused-parameter
# has no effect if specified before Wall.
"-Wno-unused-parameter",
]
}