waifulib: xcompile: update to latest revision from engine repository(add support for using host clang on crosscompiling, strip support and several fixes

This commit is contained in:
Alibek Omarov 2019-09-12 17:56:52 +03:00
parent 4d33edae04
commit edd040f696

View File

@ -41,13 +41,15 @@ class Android:
def __init__(self, ctx, arch, toolchain, api): def __init__(self, ctx, arch, toolchain, api):
self.ctx = ctx self.ctx = ctx
self.api = api
for i in ['ANDROID_NDK_HOME', 'ANDROID_NDK']: for i in ['ANDROID_NDK_HOME', 'ANDROID_NDK']:
self.ndk_home = os.getenv(i) self.ndk_home = os.getenv(i)
if self.ndk_home != None: if self.ndk_home != None:
break break
if not self.ndk_home: if not self.ndk_home:
conf.fatal('Set ANDROID_NDK_HOME environment variable pointing to the root of Android NDK!') ctx.fatal('Set ANDROID_NDK_HOME environment variable pointing to the root of Android NDK!')
# TODO: this were added at some point of NDK development # TODO: this were added at some point of NDK development
# but I don't know at which version # but I don't know at which version
@ -64,7 +66,7 @@ class Android:
else: else:
self.ndk_rev = 10 self.ndk_rev = 10
if self.ndk_rev not in [10, 19]: if self.ndk_rev not in [10, 19, 20]:
ctx.fatal('Unknown NDK revision: {}'.format(self.ndk_rev)) ctx.fatal('Unknown NDK revision: {}'.format(self.ndk_rev))
self.arch = arch self.arch = arch
@ -86,13 +88,18 @@ class Android:
elif self.ndk_rev >= 19 and self.api < 16: elif self.ndk_rev >= 19 and self.api < 16:
Logs.warn('API level automatically was set to 16 due to NDK support') Logs.warn('API level automatically was set to 16 due to NDK support')
self.api = 16 self.api = 16
else: self.api = api
self.toolchain_path = self.gen_toolchain_path() self.toolchain_path = self.gen_toolchain_path()
# TODO: Crystax support? # TODO: Crystax support?
# TODO: Support for everything else than linux-x86_64? # TODO: Support for everything else than linux-x86_64?
# TODO: Determine if I actually need to implement listed above # TODO: Determine if I actually need to implement listed above
def is_host(self):
'''
Checks if we using host compiler(implies clang)
'''
return self.toolchain == 'host'
def is_arm(self): def is_arm(self):
''' '''
Checks if selected architecture is **32-bit** ARM Checks if selected architecture is **32-bit** ARM
@ -126,7 +133,16 @@ class Android:
def is_hardfp(self): def is_hardfp(self):
return self.is_hardfloat return self.is_hardfloat
def gen_toolchain_path(self): def ndk_triplet(self):
if self.is_x86():
triplet = 'i686-linux-android'
elif self.is_arm():
triplet = 'arm-linux-androideabi'
else:
triplet = self.arch + '-linux-android'
return triplet
def gen_gcc_toolchain_path(self):
path = 'toolchains' path = 'toolchains'
if sys.platform.startswith('linux'): if sys.platform.startswith('linux'):
@ -149,13 +165,6 @@ class Android:
raise Exception('Clang is not supported for this NDK') raise Exception('Clang is not supported for this NDK')
toolchain_folder = 'llvm' toolchain_folder = 'llvm'
if self.is_x86():
triplet = 'i686-linux-android{}-'.format(self.api)
elif self.is_arm():
triplet = 'armv7a-linux-androideabi{}-'.format(self.api)
else:
triplet = self.arch + '-linux-android{}-'.format(self.api)
else: else:
if self.is_x86() or self.is_amd64(): if self.is_x86() or self.is_amd64():
toolchain_folder = self.arch + '-' + self.toolchain toolchain_folder = self.arch + '-' + self.toolchain
@ -164,40 +173,79 @@ class Android:
else: else:
toolchain_folder = self.arch + '-linux-android-' + self.toolchain toolchain_folder = self.arch + '-linux-android-' + self.toolchain
if self.is_x86(): return os.path.abspath(os.path.join(self.ndk_home, path, toolchain_folder, 'prebuilt', toolchain_host))
triplet = 'i686-linux-android-'
elif self.is_arm():
triplet = 'arm-linux-androideabi-'
else:
triplet = self.arch + '-linux-android-'
return os.path.join(path, toolchain_folder, 'prebuilt', toolchain_host, 'bin', triplet) def gen_toolchain_path(self):
if self.is_clang():
if self.is_x86():
triplet = 'i686-linux-android{}-'.format(self.api)
elif self.is_arm():
triplet = 'armv7a-linux-androideabi{}-'.format(self.api)
else:
triplet = self.arch + '-linux-android{}-'.format(self.api)
else:
triplet = self.ndk_triplet() + '-'
return os.path.join(self.gen_gcc_toolchain_path(), 'bin', triplet)
def gen_binutils_path(self):
return os.path.join(self.gen_gcc_toolchain_path(), self.ndk_triplet(), 'bin')
def cc(self): def cc(self):
return os.path.abspath(os.path.join(self.ndk_home, self.toolchain_path + ('clang' if self.is_clang() else 'gcc'))) if self.is_host():
return 'clang'
return self.toolchain_path + ('clang' if self.is_clang() else 'gcc')
def cxx(self): def cxx(self):
return os.path.abspath(os.path.join(self.ndk_home, self.toolchain_path + ('clang++' if self.is_clang() else 'g++'))) if self.is_host():
return 'clang++'
return self.toolchain_path + ('clang++' if self.is_clang() else 'g++')
def strip(self):
if self.is_host():
return 'strip'
return os.path.join(self.gen_binutils_path(), 'strip')
def system_stl(self): def system_stl(self):
# TODO: proper STL support # TODO: proper STL support
return os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'system', 'include')) return os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'system', 'include'))
def libsysroot(self):
arch = self.arch
if self.is_arm():
arch = 'arm'
elif self.is_arm64():
arch = 'arm64'
path = 'platforms/android-{}/arch-{}'.format(self.api, arch)
return os.path.abspath(os.path.join(self.ndk_home, path))
def sysroot(self): def sysroot(self):
if self.ndk_rev >= 19: if self.ndk_rev >= 19 or self.is_host():
return os.path.abspath(os.path.join(self.ndk_home, 'sysroot')) return os.path.abspath(os.path.join(self.ndk_home, 'sysroot'))
else: else:
arch = self.arch return self.libsysroot()
if self.is_arm():
arch = 'arm'
elif self.is_arm64():
arch = 'arm64'
path = 'platforms/android-{}/arch-{}'.format(self.api, arch)
return os.path.abspath(os.path.join(self.ndk_home, path)) def clang_host_triplet(self):
triplet = ''
if self.is_arm():
triplet += 'arm'
elif self.is_x86():
triplet += 'i686'
else:
triplet += self.arch
triplet += '-linux-android'
return triplet
def cflags(self): def cflags(self):
cflags = ['--sysroot={0}'.format(self.sysroot()), '-DANDROID', '-D__ANDROID__'] cflags = []
if self.is_host():
cflags += ['-nostdlib', '--target=%s' % self.clang_host_triplet()]
if self.ndk_rev < 20:
cflags += ['--sysroot={0}'.format(self.sysroot())]
elif self.is_host():
cflags += ['-isysroot={0}'.format(self.sysroot())]
cflags += ['-DANDROID', '-D__ANDROID__']
cflags += ['-I{0}'.format(self.system_stl())] cflags += ['-I{0}'.format(self.system_stl())]
if self.is_arm(): if self.is_arm():
if self.arch == 'armeabi-v7a': if self.arch == 'armeabi-v7a':
@ -218,14 +266,27 @@ class Android:
# they go before object list # they go before object list
def linkflags(self): def linkflags(self):
linkflags = ['--sysroot={0}'.format(self.sysroot())] linkflags = []
if self.is_host():
linkflags += ['-fuse-ld=lld', '-nostdlib', '--target=%s' % self.clang_host_triplet(),
'--gcc-toolchain=%s' % self.gen_gcc_toolchain_path()]
if self.ndk_rev < 20 or self.is_host():
linkflags += ['--sysroot={0}'.format(self.libsysroot())]
if self.is_host():
linkflags += ['-L{0}/usr/lib/{1}'.format(self.sysroot(), self.ndk_triplet()),
'-L{0}/sysroot/usr/lib/{1}/'.format(self.gen_gcc_toolchain_path(), self.ndk_triplet())]
return linkflags return linkflags
def ldflags(self): def ldflags(self):
ldflags = ['-lgcc', '-no-canonical-prefixes'] ldflags = ['-lgcc', '-no-canonical-prefixes']
if self.is_arm(): if self.is_arm():
if self.arch == 'armeabi-v7a': if self.arch == 'armeabi-v7a':
ldflags += ['-march=armv7-a', '-Wl,--fix-cortex-a8', '-mthumb'] ldflags += ['-march=armv7-a']
if not self.is_host(): # lld only
ldflags += ['-Wl,--fix-cortex-a8']
ldflags += ['-mthumb']
if self.is_hardfloat: if self.is_hardfloat:
ldflags += ['-Wl,--no-warn-mismatch', '-lm_hard'] ldflags += ['-Wl,--no-warn-mismatch', '-lm_hard']
else: else:
@ -252,6 +313,7 @@ def configure(conf):
setattr(conf, 'android', android) setattr(conf, 'android', android)
conf.environ['CC'] = android.cc() conf.environ['CC'] = android.cc()
conf.environ['CXX'] = android.cxx() conf.environ['CXX'] = android.cxx()
conf.environ['STRIP'] = android.strip()
conf.env.CFLAGS += android.cflags() conf.env.CFLAGS += android.cflags()
conf.env.CXXFLAGS += android.cflags() conf.env.CXXFLAGS += android.cflags()
conf.env.LINKFLAGS += android.linkflags() conf.env.LINKFLAGS += android.linkflags()
@ -277,7 +339,7 @@ def configure(conf):
def post_compiler_cxx_configure(conf): def post_compiler_cxx_configure(conf):
if conf.options.ANDROID_OPTS: if conf.options.ANDROID_OPTS:
if conf.android.ndk_rev >= 19: if conf.android.ndk_rev == 19:
conf.env.CXXFLAGS_cxxshlib += ['-static-libstdc++'] conf.env.CXXFLAGS_cxxshlib += ['-static-libstdc++']
conf.env.LDFLAGS_cxxshlib += ['-static-libstdc++'] conf.env.LDFLAGS_cxxshlib += ['-static-libstdc++']
return return