Esempio n. 1
0
    def __init__(self, platform, android_abi, asan_enabled_by_default=False):
        super(AndroidConfiguration, self).__init__(platform,
                                                   asan_enabled_by_default)
        self._target_toolchain = None
        self._host_toolchain = None

        self.AppendApplicationConfigurationPath(os.path.dirname(__file__))

        self.android_abi = android_abi

        self.android_home = sdk_utils.GetSdkPath()
        self.android_ndk_home = sdk_utils.GetNdkPath()

        print('Using Android SDK at {}'.format(self.android_home))
        print('Using Android NDK at {}'.format(self.android_ndk_home))
Esempio n. 2
0
    def GetTargetToolchain(self):
        if not self._target_toolchain:
            tool_prefix = os.path.join(sdk_utils.GetNdkPath(), 'toolchains',
                                       'llvm', 'prebuilt', 'linux-x86_64',
                                       'bin', '')
            cc_path = tool_prefix + _ABI_TOOL_NAMES[self.android_abi][0]
            cxx_path = cc_path + '++'
            ar_path = tool_prefix + _ABI_TOOL_NAMES[self.android_abi][1]
            clang_flags = [
                # We'll pretend not to be Linux, but Starboard instead.
                '-U__linux__',

                # libwebp uses the cpufeatures library to detect ARM NEON support
                '-I{}/sources/android/cpufeatures'.format(self.android_ndk_home
                                                          ),

                # 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',
                '-fno-exceptions',
                '-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',
            ]
            clang_defines = [
                # Enable compile-time decisions based on the ABI
                'ANDROID_ABI={}'.format(self.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',
            ]
            linker_flags = [
                # Use the static LLVM libc++.
                '-static-libstdc++',

                # Mimic build/cmake/android.toolchain.cmake in the Android NDK.
                '-Wl,--build-id',
                '-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',
            ]
            self._target_toolchain = [
                clang.CCompiler(path=cc_path,
                                defines=clang_defines,
                                extra_flags=clang_flags),
                clang.CxxCompiler(path=cxx_path,
                                  defines=clang_defines,
                                  extra_flags=clang_flags + [
                                      '-std=c++11',
                                  ]),
                clang.AssemblerWithCPreprocessor(path=cc_path,
                                                 defines=clang_defines,
                                                 extra_flags=clang_flags),
                ar.StaticThinLinker(path=ar_path),
                ar.StaticLinker(path=ar_path),
                clangxx.SharedLibraryLinker(path=cxx_path,
                                            extra_flags=linker_flags),
                clangxx.ExecutableLinker(path=cxx_path,
                                         extra_flags=linker_flags),
            ]
        return self._target_toolchain