You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
198 lines
7.4 KiB
Python
198 lines
7.4 KiB
Python
# -*- mode: python -*-
|
|
|
|
from waflib import Context
|
|
libshit_cross = getattr(Context.g_module, 'LIBSHIT_CROSS', False)
|
|
|
|
def options(ctx):
|
|
ctx.with_opt('stdlib', ['system', 'bundle-libc++'], 'system,bundle-libc++',
|
|
cross=libshit_cross,
|
|
# todo: we probably don't want this on windows with neptools
|
|
#bundle_all='bundle-libc++'
|
|
)
|
|
|
|
def use_libcxxabi(ctx):
|
|
return ctx.env.DEST_OS != 'vita' and ctx.env.DEST_OS != 'win32'
|
|
|
|
def configure(ctx):
|
|
def check_system(ctx):
|
|
if ctx.env.DEST_OS == 'vita':
|
|
ctx.fatal("System libstdc++ doesn't work on vita")
|
|
|
|
def check_bundle(ctx):
|
|
ctx.env.CXXFLAGS_LIBCXX = ['-nostdinc++']
|
|
ctx.env.SYSTEM_INCLUDES_LIBCXX = [
|
|
ctx.path.get_bld().find_or_declare('libcxx/include'+ctx.variant).abspath(),
|
|
ctx.path.get_src().find_node('libcxx/include').abspath(),
|
|
]
|
|
if use_libcxxabi(ctx):
|
|
ctx.env.SYSTEM_INCLUDES_LIBCXX += \
|
|
[ ctx.path.find_node('libcxxabi/include').abspath() ]
|
|
|
|
if ctx.env.DEST_OS != 'vita' and ctx.env.DEST_OS != 'win32':
|
|
ctx.env.LDFLAGS_LIBCXX = [
|
|
'-nodefaultlibs', '-lgcc_s', '-lm', '-lc', '-lpthread',
|
|
'-lsupc++', '-ldl', '-lrt'
|
|
]
|
|
|
|
ctx.with_chk(
|
|
'stdlib', {'system': check_system, 'bundle-libc++': check_bundle},
|
|
cross=libshit_cross)
|
|
|
|
def build(ctx):
|
|
if ctx.env.WITH_STDLIB != 'bundle-libc++': return
|
|
|
|
abi_defines = [
|
|
'_LIBCPP_ABI_UNSTABLE', # static build, abi stability doesn't matter
|
|
'_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS', # don't export symbols
|
|
'_LIBCPP_NO_AUTO_LINK', # thank you I can manage the link flags myself (msvc)
|
|
'_LIBCPP_ENABLE_NODISCARD', # extra warnings
|
|
]
|
|
if ctx.env.DEST_OS == 'win32':
|
|
abi_defines += [
|
|
'_LIBCPP_SUPPORT_WCHAR',
|
|
# Even with this option, the code still depends on vcruntime for
|
|
# exception handling, rtti, and some cstring functions (wtf?), so
|
|
# enabling this option only increases our binary's size without
|
|
# decreasing the number of dependencies, so leave this off for the
|
|
# time being.
|
|
# '_LIBCPP_NO_VCRUNTIME'
|
|
]
|
|
if ctx.env.WINVER and int(ctx.env.WINVER, 0) < 0x0600:
|
|
abi_defines += ['_LIBCPP_MUTEXES_ARE_SHIT']
|
|
|
|
ctx.rule_like('libcxx_gen_cfg')
|
|
ctx(features = 'libcxx_gen_cfg',
|
|
source = ctx.path.get_src().find_node('libcxx/include/__config'),
|
|
target = 'libcxx/include%s/__config' % ctx.variant,
|
|
defines = abi_defines)
|
|
|
|
if use_libcxxabi(ctx):
|
|
src = [
|
|
'libcxxabi/src/abort_message.cpp',
|
|
'libcxxabi/src/cxa_aux_runtime.cpp',
|
|
'libcxxabi/src/cxa_default_handlers.cpp',
|
|
'libcxxabi/src/cxa_demangle.cpp',
|
|
'libcxxabi/src/cxa_exception.cpp',
|
|
'libcxxabi/src/cxa_exception_storage.cpp',
|
|
'libcxxabi/src/cxa_guard.cpp',
|
|
'libcxxabi/src/cxa_handlers.cpp',
|
|
'libcxxabi/src/cxa_noexception.cpp',
|
|
'libcxxabi/src/cxa_personality.cpp',
|
|
'libcxxabi/src/cxa_thread_atexit.cpp',
|
|
'libcxxabi/src/cxa_unexpected.cpp',
|
|
'libcxxabi/src/cxa_vector.cpp',
|
|
'libcxxabi/src/cxa_virtual.cpp',
|
|
'libcxxabi/src/fallback_malloc.cpp',
|
|
'libcxxabi/src/private_typeinfo.cpp',
|
|
'libcxxabi/src/stdlib_exception.cpp',
|
|
'libcxxabi/src/stdlib_new_delete.cpp',
|
|
'libcxxabi/src/stdlib_stdexcept.cpp',
|
|
'libcxxabi/src/stdlib_typeinfo.cpp',
|
|
]
|
|
ctx.stlib(idx = 54101,
|
|
source = src,
|
|
defines = ['_LIBCPP_DISABLE_EXTERN_TEMPLATE',
|
|
'_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS',
|
|
'_LIBCXXABI_BUILDING_LIBRARY',
|
|
'__STDC_CONSTANT_MACROS', '__STDC_FORMAT_MACROS',
|
|
'__STDC_LIMIT_MACROS'],
|
|
cxxflags= ['-fvisibility-inlines-hidden',
|
|
'-fstrict-aliasing', '-funwind-tables',
|
|
# https://github.com/llvm/llvm-project/issues/80
|
|
'-fno-sanitize=vptr'],
|
|
target = 'libcxxabi',
|
|
uselib = 'EXT LIBCXX')
|
|
|
|
src = [
|
|
'libcxx/src/algorithm.cpp',
|
|
'libcxx/src/any.cpp',
|
|
'libcxx/src/bind.cpp',
|
|
'libcxx/src/charconv.cpp',
|
|
'libcxx/src/chrono.cpp',
|
|
'libcxx/src/condition_variable.cpp',
|
|
'libcxx/src/debug.cpp',
|
|
'libcxx/src/exception.cpp',
|
|
'libcxx/src/functional.cpp',
|
|
'libcxx/src/future.cpp',
|
|
'libcxx/src/hash.cpp',
|
|
'libcxx/src/ios.cpp',
|
|
'libcxx/src/iostream.cpp',
|
|
'libcxx/src/locale.cpp',
|
|
'libcxx/src/memory.cpp',
|
|
'libcxx/src/mutex.cpp',
|
|
'libcxx/src/new.cpp',
|
|
'libcxx/src/optional.cpp',
|
|
'libcxx/src/random.cpp',
|
|
'libcxx/src/regex.cpp',
|
|
'libcxx/src/shared_mutex.cpp',
|
|
'libcxx/src/stdexcept.cpp',
|
|
'libcxx/src/string.cpp',
|
|
'libcxx/src/strstream.cpp',
|
|
'libcxx/src/system_error.cpp',
|
|
'libcxx/src/thread.cpp',
|
|
'libcxx/src/typeinfo.cpp',
|
|
'libcxx/src/utility.cpp',
|
|
'libcxx/src/valarray.cpp',
|
|
'libcxx/src/variant.cpp',
|
|
'libcxx/src/vector.cpp',
|
|
]
|
|
if ctx.env.DEST_OS == 'win32':
|
|
src += [
|
|
'libcxx/src/support/win32/locale_win32.cpp',
|
|
'libcxx/src/support/win32/support.cpp',
|
|
'libcxx/src/support/win32/thread_win32.cpp',
|
|
]
|
|
defines = [
|
|
'NDEBUG', '_LIBCPP_BUILDING_LIBRARY',
|
|
'_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER',
|
|
'__STDC_CONSTANT_MACROS', '__STDC_FORMAT_MACROS', '__STDC_LIMIT_MACROS',
|
|
'_WIN32_WINNT=%s' % (ctx.env.WINVER or '0x0600'),
|
|
]
|
|
if use_libcxxabi(ctx): defines += ['LIBCXX_BUILDING_LIBCXXABI']
|
|
|
|
ctx.stlib(idx = 54100,
|
|
source = src,
|
|
defines = defines,
|
|
cxxflags = '-fvisibility-inlines-hidden',
|
|
target = 'libcxx',
|
|
uselib = 'EXT LIBCXX',
|
|
use = 'libcxxabi')
|
|
|
|
from waflib.TaskGen import feature, before_method
|
|
@feature('cxx')
|
|
@before_method('propagate_uselib_vars', 'process_use')
|
|
def add_libcxx(self):
|
|
if self.env.WITH_STDLIB != 'bundle-libc++': return
|
|
name = getattr(self, 'target', None)
|
|
if name == 'libcxx' or name == 'libcxxabi': return
|
|
|
|
self.use = self.to_list(getattr(self, 'use', []))
|
|
self.uselib = self.to_list(getattr(self, 'uselib', []))
|
|
if not 'libcxx' in self.use:
|
|
self.use.append('libcxx')
|
|
if not 'LIBCXX' in self.uselib:
|
|
self.uselib.append('LIBCXX')
|
|
|
|
|
|
from waflib.Task import Task
|
|
from waflib import Utils
|
|
import re
|
|
class libcxx_gen_cfg(Task):
|
|
color = 'BLUE'
|
|
before = 'c cxx'
|
|
def run(self):
|
|
data = self.inputs[0].read()
|
|
defs = '\n'.join(map(lambda x: '#define %s' % x, self.generator.defines))
|
|
|
|
replace_re = re.compile(
|
|
'// CONFIG_PLACEHOLDER.*// CONFIG_PLACEHOLDER_END', re.M | re.S)
|
|
if not replace_re.search(data):
|
|
raise Exception('Placeholder not found')
|
|
data = replace_re.sub(defs, data)
|
|
|
|
warn = '// This is an auto generated file, do not edit!\n'
|
|
self.outputs[0].write(warn + data)
|
|
|
|
def sig_vars(self):
|
|
self.m.update(Utils.h_list(self.generator.defines))
|