libshit

Just some random shit
git clone https://git.neptards.moe/neptards/libshit.git
Log | Files | Refs | Submodules | README | LICENSE

wscript (7594B)


      1 # -*- mode: python -*-
      2 
      3 from waflib import Context
      4 libshit_cross = getattr(Context.g_module, 'LIBSHIT_CROSS', False)
      5 
      6 def options(ctx):
      7     ctx.with_opt('stdlib', ['system', 'bundle-libc++'], 'system,bundle-libc++',
      8                  cross=libshit_cross,
      9                  # todo: we probably don't want this on windows with neptools
     10                  #bundle_all='bundle-libc++'
     11     )
     12 
     13 def use_libcxxabi(ctx):
     14     return ctx.env.DEST_OS != 'vita' and ctx.env.DEST_OS != 'win32'
     15 
     16 def configure(ctx):
     17     def check_system(ctx):
     18         if ctx.env.DEST_OS == 'vita':
     19             ctx.fatal("System libstdc++ doesn't work on vita")
     20 
     21     def check_bundle(ctx):
     22         ctx.env.CXXFLAGS_LIBCXX = ['-nostdinc++']
     23         ctx.env.SYSTEM_INCLUDES_LIBCXX = [
     24             ctx.path.get_bld().find_or_declare('libcxx/include'+ctx.variant).abspath(),
     25             ctx.path.get_src().find_node('libcxx/include').abspath(),
     26         ]
     27         if use_libcxxabi(ctx):
     28             ctx.env.SYSTEM_INCLUDES_LIBCXX += \
     29                 [ ctx.path.find_node('libcxxabi/include').abspath() ]
     30 
     31         if ctx.env.DEST_OS != 'vita' and ctx.env.DEST_OS != 'win32':
     32             ctx.env.LDFLAGS_LIBCXX = [
     33                 '-nodefaultlibs', '-lgcc_s', '-lm', '-lc', '-lpthread',
     34                 '-lsupc++', '-ldl', '-lrt'
     35             ]
     36 
     37     ctx.with_chk(
     38         'stdlib', {'system': check_system, 'bundle-libc++': check_bundle},
     39         cross=libshit_cross)
     40 
     41 def build(ctx):
     42     if ctx.env.WITH_STDLIB != 'bundle-libc++': return
     43 
     44     abi_defines = [
     45         '_LIBCPP_ABI_UNSTABLE', # static build, abi stability doesn't matter
     46         '_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS', # don't export symbols
     47         '_LIBCPP_NO_AUTO_LINK', # thank you I can manage the link flags myself (msvc)
     48         '_LIBCPP_ENABLE_NODISCARD', # extra warnings
     49     ]
     50     if ctx.env.DEST_OS == 'win32':
     51         abi_defines += [
     52             '_LIBCPP_SUPPORT_WCHAR',
     53             # Even with this option, the code still depends on vcruntime for
     54             # exception handling, rtti, and some cstring functions (wtf?), so
     55             # enabling this option only increases our binary's size without
     56             # decreasing the number of dependencies, so leave this off for the
     57             # time being.
     58             # '_LIBCPP_NO_VCRUNTIME'
     59         ]
     60         if ctx.env.WINVER and int(ctx.env.WINVER, 0) < 0x0600:
     61             abi_defines += ['_LIBCPP_MUTEXES_ARE_SHIT']
     62 
     63     ctx.rule_like('libcxx_gen_cfg')
     64     ctx(features = 'libcxx_gen_cfg',
     65         source   = ctx.path.get_src().find_node('libcxx/include/__config'),
     66         target   = 'libcxx/include%s/__config' % ctx.variant,
     67         defines  = abi_defines)
     68 
     69     if use_libcxxabi(ctx):
     70         src = [
     71             'libcxxabi/src/abort_message.cpp',
     72             'libcxxabi/src/cxa_aux_runtime.cpp',
     73             'libcxxabi/src/cxa_default_handlers.cpp',
     74             'libcxxabi/src/cxa_demangle.cpp',
     75             'libcxxabi/src/cxa_exception.cpp',
     76             'libcxxabi/src/cxa_exception_storage.cpp',
     77             'libcxxabi/src/cxa_guard.cpp',
     78             'libcxxabi/src/cxa_handlers.cpp',
     79             'libcxxabi/src/cxa_noexception.cpp',
     80             'libcxxabi/src/cxa_personality.cpp',
     81             'libcxxabi/src/cxa_thread_atexit.cpp',
     82             'libcxxabi/src/cxa_unexpected.cpp',
     83             'libcxxabi/src/cxa_vector.cpp',
     84             'libcxxabi/src/cxa_virtual.cpp',
     85             'libcxxabi/src/fallback_malloc.cpp',
     86             'libcxxabi/src/private_typeinfo.cpp',
     87             'libcxxabi/src/stdlib_exception.cpp',
     88             'libcxxabi/src/stdlib_new_delete.cpp',
     89             'libcxxabi/src/stdlib_stdexcept.cpp',
     90             'libcxxabi/src/stdlib_typeinfo.cpp',
     91         ]
     92         ctx.stlib(idx      = 54101,
     93                   source   = src,
     94                   defines  = ['_LIBCPP_DISABLE_EXTERN_TEMPLATE',
     95                               '_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS',
     96                               '_LIBCXXABI_BUILDING_LIBRARY',
     97                               '__STDC_CONSTANT_MACROS', '__STDC_FORMAT_MACROS',
     98                               '__STDC_LIMIT_MACROS'],
     99                   cxxflags= ['-fvisibility-inlines-hidden',
    100                              '-fstrict-aliasing', '-funwind-tables',
    101                              # https://github.com/llvm/llvm-project/issues/80
    102                              '-fno-sanitize=vptr'],
    103                   target   = 'libcxxabi',
    104                   uselib   = 'EXT LIBCXX')
    105 
    106     src = [
    107         'libcxx/src/algorithm.cpp',
    108         'libcxx/src/any.cpp',
    109         'libcxx/src/bind.cpp',
    110         'libcxx/src/charconv.cpp',
    111         'libcxx/src/chrono.cpp',
    112         'libcxx/src/condition_variable.cpp',
    113         'libcxx/src/debug.cpp',
    114         'libcxx/src/exception.cpp',
    115         'libcxx/src/functional.cpp',
    116         'libcxx/src/future.cpp',
    117         'libcxx/src/hash.cpp',
    118         'libcxx/src/ios.cpp',
    119         'libcxx/src/iostream.cpp',
    120         'libcxx/src/locale.cpp',
    121         'libcxx/src/memory.cpp',
    122         'libcxx/src/mutex.cpp',
    123         'libcxx/src/new.cpp',
    124         'libcxx/src/optional.cpp',
    125         'libcxx/src/random.cpp',
    126         'libcxx/src/regex.cpp',
    127         'libcxx/src/shared_mutex.cpp',
    128         'libcxx/src/stdexcept.cpp',
    129         'libcxx/src/string.cpp',
    130         'libcxx/src/strstream.cpp',
    131         'libcxx/src/system_error.cpp',
    132         'libcxx/src/thread.cpp',
    133         'libcxx/src/typeinfo.cpp',
    134         'libcxx/src/utility.cpp',
    135         'libcxx/src/valarray.cpp',
    136         'libcxx/src/variant.cpp',
    137         'libcxx/src/vector.cpp',
    138     ]
    139     if ctx.env.DEST_OS == 'win32':
    140         src += [
    141             'libcxx/src/support/win32/locale_win32.cpp',
    142             'libcxx/src/support/win32/support.cpp',
    143             'libcxx/src/support/win32/thread_win32.cpp',
    144         ]
    145     defines = [
    146         'NDEBUG', '_LIBCPP_BUILDING_LIBRARY',
    147         '_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER',
    148         '__STDC_CONSTANT_MACROS', '__STDC_FORMAT_MACROS', '__STDC_LIMIT_MACROS',
    149         '_WIN32_WINNT=%s' % (ctx.env.WINVER or '0x0600'),
    150     ]
    151     if use_libcxxabi(ctx): defines += ['LIBCXX_BUILDING_LIBCXXABI']
    152 
    153     ctx.stlib(idx      = 54100,
    154               source   = src,
    155               defines  = defines,
    156               cxxflags = '-fvisibility-inlines-hidden',
    157               target   = 'libcxx',
    158               uselib   = 'EXT LIBCXX',
    159               use      = 'libcxxabi')
    160 
    161 from waflib.TaskGen import feature, before_method
    162 @feature('cxx')
    163 @before_method('propagate_uselib_vars', 'process_use')
    164 def add_libcxx(self):
    165     if self.env.WITH_STDLIB != 'bundle-libc++': return
    166     name = getattr(self, 'target', None)
    167     if name == 'libcxx' or name == 'libcxxabi': return
    168 
    169     self.use = self.to_list(getattr(self, 'use', []))
    170     self.uselib = self.to_list(getattr(self, 'uselib', []))
    171     if not 'libcxx' in self.use:
    172         self.use.append('libcxx')
    173     if not 'LIBCXX' in self.uselib:
    174         self.uselib.append('LIBCXX')
    175 
    176 
    177 from waflib.Task import Task
    178 from waflib import Utils
    179 import re
    180 class libcxx_gen_cfg(Task):
    181     color = 'BLUE'
    182     before = 'c cxx'
    183     def run(self):
    184         data = self.inputs[0].read()
    185         defs = '\n'.join(map(lambda x: '#define %s' % x, self.generator.defines))
    186 
    187         replace_re = re.compile(
    188             '// CONFIG_PLACEHOLDER.*// CONFIG_PLACEHOLDER_END', re.M | re.S)
    189         if not replace_re.search(data):
    190             raise Exception('Placeholder not found')
    191         data = replace_re.sub(defs, data)
    192 
    193         warn = '// This is an auto generated file, do not edit!\n'
    194         self.outputs[0].write(warn + data)
    195 
    196     def sig_vars(self):
    197         self.m.update(Utils.h_list(self.generator.defines))