Example #1
0
def config_sys_socket_h(ctx, builder):
    '''
    Test for the posix sys/socket.h header, which provides network sockets.

    @param builder: C builder
    '''

    if not builder.check_header_exists('sys/socket.h'):
        raise MissingHeader('sys/socket.h')

    socket_h = Record()

    code = '''
        #include <sys/types.h>
        #include <sys/socket.h>

        extern int accept(int s, struct sockaddr* addr, %s* addrlen);
    '''

    logger.check('determing type of socklen_t')
    for t in 'socklen_t', 'unsigned int', 'int':
        if builder.try_compile(code % t):
            logger.passed('ok ' + t)
            socket_h.socklen_t = t
            break
    else:
        logger.failed()
        raise ConfigFailed('failed to detect type of socklen_t')

    return socket_h
Example #2
0
def config_host(ctx, build):
    ctx.logger.log('configuring host phase', color='cyan')

    platform = call('fbuild.builders.platform.guess_platform', ctx,
        ctx.options.build_platform)

    if platform == build.platform:
        ctx.logger.log("using build's c and cxx compiler", color='cyan')
        phase = build
    else:
        phase = Record(
            ctx=ctx,
            platform=platform,
            c=make_c_builder(ctx, exe=fbuild.builders.host_cc,
                platform=platform,
                debug=ctx.options.debug or ctx.options.host_c_debug,
                optimize=not (ctx.options.debug or ctx.options.host_c_debug),
                includes=ctx.options.host_includes,
                libpaths=ctx.options.host_libpaths,
                flags=ctx.options.host_c_flags),
            cxx=make_cxx_builder(ctx, exe=fbuild.builders.host_cxx,
                platform=platform,
                debug=ctx.options.debug or ctx.options.host_c_debug,
                optimize=not (ctx.options.debug or ctx.options.host_c_debug),
                includes=ctx.options.host_includes,
                libpaths=ctx.options.host_libpaths,
                flags=ctx.options.host_cxx_flags))

    phase.ocaml = call('fbuild.builders.ocaml.Ocaml', ctx,
        debug=ctx.options.debug or ctx.options.host_ocaml_debug,
        ocamlc=ctx.options.host_ocamlc,
        ocamlopt=ctx.options.host_ocamlopt,
        flags=['-w', 'yzex', '-warn-error', 'FPSU'],
        linker=phase.c.static.lib_linker,
        requires_at_least_version=(3, 11))

    phase.ocamllex = call('fbuild.builders.ocaml.Ocamllex', ctx,
        ctx.options.host_ocamllex)

    # we prefer the native ocaml as it's much faster
    if hasattr(phase.ocaml, 'ocamlopt'):
        phase.ocaml = phase.ocaml.ocamlopt
    else:
        phase.ocaml = phase.ocaml.ocamlc

    # We optionally support llvm
    try:
        llvm_config = call('fbuild.builders.llvm.LlvmConfig', ctx,
            ctx.options.host_llvm_config,
            requires_at_least_version=(2, 7))
    except fbuild.ConfigFailed:
        phase.llvm_config = None
    else:
        if llvm_config.ocaml_libdir().exists():
            #phase.llvm_config = llvm_config
            phase.llvm_config = None
        else:
            phase.llvm_config = None

    return phase
Example #3
0
def config_host(ctx, build):
    ctx.logger.log('configuring host phase', color='cyan')

    platform = call('fbuild.builders.platform.guess_platform', ctx,
        ctx.options.build_platform)

    if platform == build.platform:
        ctx.logger.log("using build's c and cxx compiler", color='cyan')
        phase = build
    else:
        phase = Record(
            ctx=ctx,
            platform=platform,
            c=make_c_builder(ctx, exe=fbuild.builders.host_cc,
                platform=platform,
                debug=ctx.options.debug or ctx.options.host_c_debug,
                optimize=not (ctx.options.debug or ctx.options.host_c_debug),
                includes=ctx.options.host_includes,
                libpaths=ctx.options.host_libpaths,
                flags=ctx.options.host_c_flags),
            cxx=make_cxx_builder(ctx, exe=fbuild.builders.host_cxx,
                platform=platform,
                debug=ctx.options.debug or ctx.options.host_c_debug,
                optimize=not (ctx.options.debug or ctx.options.host_c_debug),
                includes=ctx.options.host_includes,
                libpaths=ctx.options.host_libpaths,
                flags=ctx.options.host_cxx_flags))

    phase.ocaml = call('fbuild.builders.ocaml.Ocaml', ctx,
        debug=ctx.options.debug or ctx.options.host_ocaml_debug,
        ocamlc=ctx.options.host_ocamlc,
        ocamlopt=ctx.options.host_ocamlopt,
        flags=['-w', 'yzex', '-warn-error', 'FPSU'],
        linker=phase.c.static.lib_linker,
        requires_at_least_version=(3, 11))

    phase.ocamllex = call('fbuild.builders.ocaml.Ocamllex', ctx,
        ctx.options.host_ocamllex)

    # we prefer the native ocaml as it's much faster
    if hasattr(phase.ocaml, 'ocamlopt'):
        phase.ocaml = phase.ocaml.ocamlopt
    else:
        phase.ocaml = phase.ocaml.ocamlc

    # We optionally support llvm
    try:
        llvm_config = call('fbuild.builders.llvm.LlvmConfig', ctx,
            ctx.options.host_llvm_config,
            requires_at_least_version=(2, 7))
    except fbuild.ConfigFailed:
        phase.llvm_config = None
    else:
        if llvm_config.ocaml_libdir().exists():
            #phase.llvm_config = llvm_config
            phase.llvm_config = None
        else:
            phase.llvm_config = None

    return phase
Example #4
0
def make_c_builder(*args, **kwargs):
    static = call('fbuild.builders.c.guess_static', *args, **kwargs)
    shared = call('fbuild.builders.c.guess_shared', *args, **kwargs)

    return Record(
        static=static,
        shared=shared)
Example #5
0
def build_flx_drivers(ctx, phase):
    libs = [
        call('buildsystem.ocs.build_lib', phase),
        call('buildsystem.sex.build', phase),
        call('buildsystem.dypgen.build_lib', phase),
        build_flx_version(phase),
        build_flx_lex(phase),
        build_flx_parse(phase),
        build_flx_misc(phase),
        build_flx_file(phase),
        build_flx_core(phase),
        build_flx_desugar(phase),
        build_flx_bind(phase),
        build_flx_frontend(phase),
        build_flx_opt(phase),
        build_flx_lower(phase),
        build_flx_backend(phase),
        build_flx_cpp_backend(phase),
        build_flx_version_hook(phase),
    ]

    external_libs = ['unix', 'str']

    flxg = phase.ocaml.build_exe('host/bin/flxg',
                                 Path.glob('src/compiler/flxg/*.ml{,i}'),
                                 libs=libs,
                                 external_libs=external_libs)

    return Record(flxg=flxg, )
Example #6
0
def build_runtime(phase):
    path = Path('src/exceptions')

    buildsystem.copy_hpps_to_rtl(
        phase.ctx,
        path / 'flx_exceptions.hpp',
        path / 'flx_eh.hpp',
    )

    srcs = [
        copy(ctx=phase.ctx, src=f, dst=phase.ctx.buildroot / f) for f in [
            path / 'flx_exceptions.cpp',
            path / 'flx_eh.cpp',
        ]
    ]
    includes = [
        'src/rtl', phase.ctx.buildroot / 'host/lib/rtl',
        phase.ctx.buildroot / 'share/lib/rtl'
    ]
    macros = ['BUILD_FLX_EXCEPTIONS']

    dst = 'host/lib/rtl/flx_exceptions'
    return Record(static=buildsystem.build_cxx_static_lib(phase,
                                                          dst,
                                                          srcs,
                                                          includes=includes,
                                                          macros=macros),
                  shared=buildsystem.build_cxx_shared_lib(phase,
                                                          dst,
                                                          srcs,
                                                          includes=includes,
                                                          macros=macros))
Example #7
0
def config_build(ctx):
    ctx.logger.log('configuring build phase', color='cyan')

    platform = call('fbuild.builders.platform.guess_platform', ctx,
                    ctx.options.build_platform)
    return Record(
        ctx=ctx,
        platform=platform,
        c=make_c_builder(
            ctx,
            exe=ctx.options.build_cc,
            platform=platform,
            debug=ctx.options.debug or ctx.options.build_c_debug,
            optimize=not (ctx.options.debug or ctx.options.build_c_debug),
            includes=ctx.options.build_includes,
            libpaths=ctx.options.build_libpaths,
            flags=ctx.options.build_c_flags),
        cxx=make_cxx_builder(
            ctx,
            exe=ctx.options.build_cxx,
            platform=platform,
            debug=ctx.options.debug or ctx.options.build_c_debug,
            optimize=not (ctx.options.debug or ctx.options.build_c_debug),
            includes=ctx.options.build_includes,
            libpaths=ctx.options.build_libpaths,
            flags=ctx.options.build_cxx_flags))
Example #8
0
def make_c_builder(ctx, *args, includes=[], libpaths=[], flags=[], **kwargs):
    flags = list(chain(ctx.options.c_flags, flags))

    kwargs['platform_options'] = [
        # GRRR .. for clang
        ({'darwin'},
            {'warnings': ['all', 'fatal-errors',
                'no-constant-logical-operand',
                'no-array-bounds',
                ],
            'flags': ['-fno-common','-fvisibility=hidden'] + flags,
            'optimize_flags': ['-fomit-frame-pointer']}),
        ({'bsd'}, {
            'warnings': ['all', 'fatal-errors', 'no-constant-logical-operand', 'no-array-bounds', ],
            'flags': ['-std=c++11', '-fno-common','-fvisibility=hidden'] + flags,
            'link_flags' : ['-lpthread'],
            'link_flags-': ['-ldl'],
            'optimize_flags': ['-fomit-frame-pointer']}),
        ({'posix'},
            {'warnings': ['all', 'fatal-errors'],
            'flags': ['-std=gnu89', '-fno-common', '-fvisibility=hidden', '-fno-strict-aliasing'] + flags,
            'optimize_flags': ['-fomit-frame-pointer']}),
        ({'windows'}, {
            'link_flags' : ['/DEBUG'],
            'flags': ['/GR', '/MDd', '/EHs', '/Zi', '/wd4291'] + flags,
            'optimize_flags': ['/Ox']}),
    ]
    kwargs['includes'] = list(chain(ctx.options.includes, includes))
    kwargs['libpaths'] = list(chain(ctx.options.libpaths, libpaths))

    return Record(
        static=call('fbuild.builders.c.guess_static', ctx, *args, **kwargs),
        shared=call('fbuild.builders.c.guess_shared', ctx, *args, **kwargs))
Example #9
0
def build_libtsm(ctx, c, xkbcommon):
    base = Path('deps/libtsm')
    src = base / 'src'
    shl = src / 'shared'
    tsm = src / 'tsm'

    sources = Path.glob(
        tsm / '*.c') + [shl / 'shl-htable.c', base / 'external' / 'wcwidth.c']
    includes = [shl, tsm, base]

    if xkbcommon is not None:
        cflags = xkbcommon.cflags
    else:
        cflags = []

    macros = ['_GNU_SOURCE=1']
    if not ctx.options.release:
        macros.append('BUILD_ENABLE_DEBUG')

    return Record(includes=includes,
                  lib=c.build_lib('tsm',
                                  sources,
                                  includes=includes,
                                  macros=macros,
                                  cflags=cflags))
Example #10
0
def config_build(ctx, *, platform, cc, cxx):
    ctx.logger.log('configuring build phase', color='cyan')

    return Record(
        platform=call('fbuild.builders.platform.guess_platform', ctx, platform),
        c=make_c_builder(ctx, exe=cc),
        cxx=make_cxx_builder(ctx, exe=cxx),
    )
Example #11
0
def config_compiler_bugs(ctx, builder):
    """
    Test for common c++ bugs.
    """

    bugs = Record()
    bugs.class_member_intialization = builder.check_compile('''
        struct X {
            static const int i = 1;
        };

        int main(int argc, char** argv) {
            return 0;
        }
    ''', 'checking class member initialization')

    return bugs
Example #12
0
def configure(ctx):
    flags = ['-Wall', '-Werror'] + ctx.options.cflag
    testflags = []
    defs = []
    kw = {}
    if ctx.options.use_color:
        flags.append('-fdiagnostics-color')

    if ctx.options.release:
        kw['optimize'] = True
        kw['macros'] = ['NDEBUG']
    else:
        kw['debug'] = True
        kw['macros'] = ['DEBUG']

    c = guess_static(ctx,
                     exe=ctx.options.cc,
                     flags=flags,
                     includes=['utf'],
                     platform_options=[
                         ({'posix'}, {
                             'external_libs+': ['rt']
                         }),
                         ({'gcc'}, {
                             'flags+': ['-Wno-maybe-uninitialized']
                         }),
                         ({'clang'}, {
                             'flags+': ['-Wno-unknown-warning-option']
                         }),
                     ],
                     **kw)
    arch = get_target_arch(ctx, c)
    if arch == 'x86_64':
        defs.append('X64')
    elif re.match('i\d86', arch):
        # X86 is implemented in the x86_64.dasc file.
        arch = 'x86_64'
    else:
        assert 0, "get_target_arch returned invalid architecture '%s'" % arch

    dasm = DynAsmBuilder(ctx, exe=ctx.options.lua, defs=defs)

    if Libcut_h(c).libcut_h:
        ctx.logger.passed('found libcut.h; will build tests')
        tests = True
        testflags.append('-std=gnu11')
    else:
        ctx.logger.failed('cannot find libcut.h; will not build tests')
        tests = False

    headerdoc = find_headerdoc(ctx)

    return Record(dasm=dasm,
                  c=c,
                  arch=arch,
                  tests=tests,
                  testflags=testflags,
                  headerdoc=headerdoc)
Example #13
0
def make_cxx_builder(ctx, *args, includes=[], libpaths=[], flags=[], **kwargs):
    flags = list(chain(ctx.options.cxx_flags, flags))

    kwargs['platform_options'] = [
        # GRRR .. for clang++
        ({'darwin'}, {
            'warnings': [
                'fatal-errors',
                'no-invalid-offsetof',
                'no-logical-op-parentheses',
                'no-bitwise-op-parentheses',
                'no-parentheses-equality',
                'no-parentheses',
                'no-return-stack-address',
                'no-tautological-compare',
                'no-return-type-c-linkage',
                'no-unused-variable',
                'no-unused-function',
                'no-c++11-narrowing',
                'no-missing-braces',
                'no-return-type-c-linkage',
            ],
            'flags': [
                '-w', '-fno-common', '-fno-strict-aliasing',
                '-fvisibility=hidden', '-std=c++11'
            ] + flags,
            'optimize_flags': ['-fomit-frame-pointer']
        }),
        #({'cygwin'}, {
        #    'warnings': ['fatal-errors', 'no-invalid-offsetof','no-parentheses'],
        #    'flags': ['-std=gnu++11', '-w',
        #     '-fno-common', '-fvisibility=hidden', '-fno-strict-aliasing'] + flags,
        #    'optimize_flags': ['-fomit-frame-pointer']}),
        ({'posix'}, {
            'warnings':
            ['fatal-errors', 'no-invalid-offsetof', 'no-parentheses'],
            'flags': [
                '-std=gnu++11', '-D_POSIX', '-w', '-fno-common',
                '-fvisibility=hidden', '-fno-strict-aliasing'
            ] + flags,
            'optimize_flags': ['-fomit-frame-pointer']
        }),
        ({'windows'}, {
            'link_flags': ['/DEBUG'],
            'flags':
            ['/GR', '/MDd', '/EHs', '/Zi', '/wd4291', '/wd4190'] + flags,
            'optimize_flags': ['/Ox']
        }),
    ]
    kwargs['includes'] = list(chain(ctx.options.includes, includes))
    kwargs['libpaths'] = list(chain(ctx.options.libpaths, libpaths))

    return Record(static=call('fbuild.builders.cxx.guess_static', ctx, *args,
                              **kwargs),
                  shared=call('fbuild.builders.cxx.guess_shared', ctx, *args,
                              **kwargs))
Example #14
0
def find_headerdoc(ctx):
    try:
        headerdoc2html = find_program(ctx, ['headerdoc2html'])
        gatherheaderdoc = find_program(ctx, ['gatherheaderdoc'])
    except fbuild.ConfigFailed:
        ctx.logger.failed('cannot find headerdoc; will not generate docs')
        return None
    else:
        return Record(headerdoc2html=headerdoc2html,
                      gatherheaderdoc=gatherheaderdoc)
Example #15
0
def build_runtime(host_phase, target_phase):
    path = Path('src/faio')

    buildsystem.copy_hpps_to_rtl(
        target_phase.ctx,
        path / 'faio_job.hpp',
        path / 'faio_timer.hpp',
        path / 'faio_posixio.hpp',
        path / 'faio_winio.hpp',
    )

    dst = 'host/lib/rtl/faio'
    srcs = [
        path / 'faio_job.cpp',
        path / 'faio_timer.cpp',
    ]
    includes = [
        target_phase.ctx.buildroot / 'host/lib/rtl',
        Path('src', 'flx_async'),
        Path('src', 'pthread'),
        Path('src', 'demux'),
        Path('src', 'rtl'),
        Path('src', 'exceptions'),
        Path('src', 'gc'),
        path,
    ]
    macros = ['BUILD_FAIO']
    libs = [
        call('buildsystem.flx_pthread.build_runtime', target_phase),
        call('buildsystem.flx_async.build_runtime', host_phase, target_phase),
        call('buildsystem.demux.build_runtime', target_phase),
    ]

    if 'win32' in target_phase.platform:
        srcs.append(path / 'faio_winio.cpp')
        includes.append(Path('src', 'demux', 'win'))

    if 'posix' in target_phase.platform:
        srcs.append(path / 'faio_posixio.cpp')
        includes.append(Path('src', 'demux', 'posix'))

    return Record(static=buildsystem.build_cxx_static_lib(
        target_phase,
        dst,
        srcs,
        includes=includes,
        macros=macros,
        libs=[lib.static for lib in libs]),
                  shared=buildsystem.build_cxx_shared_lib(
                      target_phase,
                      dst,
                      srcs,
                      includes=includes,
                      macros=macros,
                      libs=[lib.shared for lib in libs]))
Example #16
0
def config_target(ctx, host):
    ctx.logger.log('configuring target phase', color='cyan')

    platform = call('fbuild.builders.platform.guess_platform', ctx,
                    ctx.options.target_platform)

    if platform == host.platform:
        ctx.logger.log("using host's c and cxx compiler", color='cyan')
        phase = host
    else:
        phase = Record(
            ctx=ctx,
            platform=platform,
            c=make_c_builder(
                ctx,
                exe=ctx.options.target_cc,
                platform=platform,
                debug=ctx.options.debug or ctx.options.target_c_debug,
                optimize=not (ctx.options.debug or ctx.options.target_c_debug),
                includes=ctx.options.target_includes,
                libpaths=ctx.options.target_libpaths,
                flags=ctx.options.target_c_flags),
            cxx=make_cxx_builder(
                ctx,
                exe=ctx.options.target_cxx,
                platform=platform,
                debug=ctx.options.debug or ctx.options.target_c_debug,
                optimize=not (ctx.options.debug or ctx.options.target_c_debug),
                includes=ctx.options.target_includes,
                libpaths=ctx.options.target_libpaths,
                flags=ctx.options.target_cxx_flags))

    # We optionally support sdl
    try:
        phase.sdl_config = call('fbuild.builders.sdl.SDLConfig',
                                ctx,
                                ctx.options.target_sdl_config,
                                requires_at_least_version=(1, 3))
    except (fbuild.ConfigFailed, OSError):
        phase.sdl_config = None

    return phase
Example #17
0
def build_runtime(host_phase, target_phase):
    """
    Builds the judy runtime library, and returns the static and shared
    library versions.
    """

    path = Path('src/judy/src')

    # Copy the header into the runtime library.
    buildsystem.copy_to(target_phase.ctx,
                        target_phase.ctx.buildroot / 'share/lib/rtl',
                        [path / 'Judy.h'])

    types = config_call('fbuild.config.c.c99.types', target_phase.platform,
                        target_phase.c.static)

    if types.voidp.size == 8:
        macros = ['JU_64BIT']
    else:
        macros = ['JU_32BIT']

    if 'windows' in target_phase.platform:
        macros.append('BUILD_JUDY')  #Apply this to all source files.

    srcs = [
        copy(target_phase.ctx, p, target_phase.ctx.buildroot / 'share' / p)
        for p in [
            path / 'JudyCommon/JudyMalloc.c', path / 'JudySL/JudySL.c', path /
            'JudyHS/JudyHS.c'
        ] + (path / 'Judy1' / '*.c').glob() + (path / 'JudyL' / '*.c').glob()
    ]

    # Copy all the common judy sources we need so people can rebuild the RTL without a source distro
    for p in ((path / 'JudyCommon' / '*.c').glob() +
              (path / 'Judy*' / '*.h').glob()):
        if p not in ('JudyMalloc.c', 'JudyPrintJP.c'):
            copy(target_phase.ctx, p, target_phase.ctx.buildroot / 'share' / p)

    includes = [path, path / 'JudyCommon', path / 'JudyL', path / 'Judy1']

    static = buildsystem.build_c_static_lib(target_phase,
                                            'host/lib/rtl/judy',
                                            srcs=srcs,
                                            macros=macros,
                                            includes=includes)

    shared = buildsystem.build_c_shared_lib(target_phase,
                                            'host/lib/rtl/judy',
                                            srcs=srcs,
                                            macros=macros,
                                            includes=includes)

    return Record(static=static, shared=shared)
Example #18
0
def config_target(ctx, host):
    ctx.logger.log('configuring target phase', color='cyan')

    platform = call('fbuild.builders.platform.platform', ctx,
        ctx.options.target_platform)

    if platform == host.platform:
        ctx.logger.log("using host's c and cxx compiler", color='cyan')
        phase = host
    else:
        phase = Record(
            ctx=ctx,
            platform=platform,
            c=make_c_builder(ctx, ctx.options.target_cc,
                platform=platform,
                debug=ctx.options.debug or ctx.options.target_c_debug,
                profile=ctx.options.profile or ctx.options.target_c_profile,
                optimize=ctx.options.optimize or
                    ctx.options.target_c_optimize,
                includes=ctx.options.target_includes,
                libpaths=ctx.options.target_libpaths,
                flags=ctx.options.target_c_flags),
            cxx=make_cxx_builder(ctx, ctx.options.target_cxx,
                platform=platform,
                debug=ctx.options.debug or ctx.options.target_c_debug,
                optimize=ctx.options.optimize or
                    ctx.options.target_c_optimize,
                includes=ctx.options.target_includes,
                libpaths=ctx.options.target_libpaths,
                flags=ctx.options.target_c_flags))

    # We optionally support sdl
    try:
        phase.sdl_config = call('fbuild.builders.sdl.SDLConfig', ctx,
            ctx.options.target_sdl_config,
            requires_at_least_version=(1, 3))
    except fbuild.ConfigFailed:
        phase.sdl_config = None

    return phase
Example #19
0
def build_abseil(ctx, cxx):
    abseil = Record(includes=['deps/abseil'])

    abseil.base = cxx.build_lib('abseil_base',
                                abseil_sources('base/*.cc',
                                               'base/internal/*.cc'),
                                includes=abseil.includes,
                                include_source_dirs=False)

    abseil.numeric = cxx.build_lib('abseil_numeric',
                                   abseil_sources('numeric/int128.cc'),
                                   includes=abseil.includes,
                                   libs=[abseil.base])

    abseil.strings = cxx.build_lib('abseil_strings',
                                   abseil_sources('strings/*.cc',
                                                  'strings/internal/*.cc'),
                                   includes=abseil.includes,
                                   libs=[abseil.base, abseil.numeric])

    abseil.stacktrace = cxx.build_lib('abseil_stacktrace',
                                      abseil_sources(
                                          'debugging/stacktrace.cc',
                                          'debugging/internal/*.cc'),
                                      includes=abseil.includes)

    return abseil
Example #20
0
def config_sys_mman_h(ctx, builder):
    '''
    Test for the posix sys/mman.h header, which provides memory mapped files.

    @param builder: C builder
    '''

    if not builder.check_header_exists('sys/mman.h'):
        raise MissingHeader('sys/mman.h')

    mman_h = Record()
    mman_h.macros = {}

    for macro in (
            'PROT_EXEC', 'PROT_READ', 'PROT_WRITE', 'MAP_DENYWRITE',
            'MAP_ANON', 'MAP_FILE', 'MAP_FIXED', 'MAP_HASSEMAPHORE',
            'MAP_SHARED', 'MAP_PRIVATE', 'MAP_NORESERVE', 'MAP_LOCKED',
            'MAP_GROWSDOWN', 'MAP_32BIT', 'MAP_POPULATE', 'MAP_NONBLOCK'):
        mman_h.macros[macro] = builder.check_macros_exist(macro,
            headers=['sys/mman.h'])

    return mman_h
Example #21
0
def run_pkg_config(ctx, package):
    pkg = PkgConfig(ctx, package, exe=ctx.options.pkg_config)

    try:
        ctx.logger.check('checking for %s' % package)
        cflags = pkg.cflags()
        ldlibs = pkg.libs()
    except fbuild.ExecutionError:
        ctx.logger.failed()
        raise fbuild.ConfigFailed('%s is required.' % package)

    ctx.logger.passed()
    return Record(cflags=cflags, ldlibs=ldlibs)
Example #22
0
def config_pthread_h(ctx, builder):
    '''
    Test for the posix pthread.h header, which provides posix threads.

    @param builder: C builder
    '''

    if not builder.check_header_exists('pthread.h'):
        raise MissingHeader('pthread.h')

    pthread_h = Record()

    code = '''
        #include <pthread.h>

        void* start(void* data) { return NULL; }

        int main(int argc, char** argv) {
            pthread_t thr;
            pthread_attr_t attr;
            pthread_attr_init(&attr);
            pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
            int res = pthread_create(&thr, &attr, start, NULL);
            pthread_attr_destroy(&attr);
            return res;
        }
    '''

    logger.check('detecting pthread link flags')
    for flags in [], ['-lpthread'], ['-pthread'], ['-pthreads']:
        if builder.try_run(code, lkwargs={'flags': flags}):
            logger.passed('ok %r' % ' '.join(flags))
            pthread_h.flags = flags
            break
    else:
        logger.failed()
        raise ConfigFailed('failed to link pthread program')

    return pthread_h
Example #23
0
def configure(ctx):
    kw = dict(debug=ctx.options.buildtype == 'debug',
              optimize=ctx.options.buildtype == 'release',
              flags=['-fdiagnostics-color'] if ctx.options.use_color else [],
              platform_options=[
                  ({'posix'}, {
                      'external_libs': ['m']
                  }),
              ])
    kw['flags'].extend(ctx.options.cflag)
    static = guess_static(ctx, **kw)
    shared = guess_shared(ctx, **kw)
    return Record(static=static, shared=shared)
Example #24
0
def config_target(ctx, host, *, platform, cc, cxx):
    ctx.logger.log('configuring target phase', color='cyan')

    platform = call('fbuild.builders.platform.platform', ctx, platform)

    if platform == host.platform:
        ctx.logger.log("using host's c and cxx compiler")
        phase = host
    else:
        phase = Record(platform=platform,
                       c=make_c_builder(ctx, exe=cc),
                       cxx=make_cxx_builder(ctx, exe=cxx))

    return phase
Example #25
0
def config_host(ctx, build, *,
        platform, cc, cxx, ocamlc, ocamlopt, ocamllex, ocamlyacc):
    ctx.logger.log('configuring host phase', color='cyan')

    platform = call('fbuild.builders.platform.guess_platform', ctx, platform)

    if platform == build.platform:
        ctx.logger.log("using build's c and cxx compiler")
        phase = build
    else:
        phase = Record(
            platform=platform,
            c=make_c_builder(ctx, exe=cc),
            cxx=make_cxx_builder(ctx, exe=cxx))

    phase.ocaml = call('fbuild.builders.ocaml.Ocaml', ctx,
        ocamlc=ocamlc,
        ocamlopt=ocamlopt,
    )
    phase.ocamllex = call('fbuild.builders.ocaml.Ocamllex', ctx, ocamllex)
    phase.ocamlyacc = call('fbuild.builders.ocaml.Ocamlyacc', ctx, ocamlyacc)

    return phase
Example #26
0
def make_cxx_builder(*args, **kwargs):
    static = call('fbuild.builders.cxx.guess_static', *args,
        platform_options=[
            ({'windows'}, {'flags': ['/EHsc']}),
        ],
        **kwargs)
    shared = call('fbuild.builders.cxx.guess_shared', *args,
        platform_options=[
            ({'windows'}, {'flags': ['/EHsc']}),
        ],
        **kwargs)

    return Record(
        static=static,
        shared=shared)
Example #27
0
def configure(ctx):
    """Configure Felix."""

    build = config_build(ctx)
    host = config_host(ctx, build)
    target = config_target(ctx, host)

    types = config_call('fbuild.config.c.c99.types', target.platform,
                        target.c.static)

    compiler = hack_toolchain_name(str(target.c.static))
    os = hack_os_name(target.platform)
    bits = hack_size(types.voidp.size)

    target_config(ctx, target, os, bits, compiler)
    return Record(build=build, host=host, target=target)
Example #28
0
def pkg_config(ctx, package, *, name=None, optional=False, suffix=''):
    name = name or package
    if suffix:
        suffix = ' %s' % suffix

    pkg = PkgConfig(ctx, package)
    ctx.logger.check('checking for %s' % name)
    try:
        rec = Record(cflags=truthy(pkg.cflags()), ldlibs=truthy(pkg.libs()))
    except fbuild.Error:
        ctx.logger.failed()
        if not optional:
            raise fbuild.Error('%s is required%s.' % (name, suffix))
    else:
        ctx.logger.passed()
        return rec
Example #29
0
def configure(ctx):
    if ctx.options.platform:
        platform = ast.literal_eval(ctx.options.platform)
    else:
        platform = guess_platform(ctx)

    flags = ctx.options.cflag
    posix_flags = ['-Wall', '-Werror']
    clang_flags = []

    if ctx.options.use_color:
        posix_flags.append('-fdiagnostics-color')
    if ctx.options.release:
        debug = False
        optimize = True
    else:
        debug = True
        optimize = False
        clang_flags.append('-fno-limit-debug-info')

    c = guess.static(ctx,
                     platform=platform,
                     exe=ctx.options.cc,
                     flags=flags,
                     debug=debug,
                     optimize=optimize,
                     platform_options=[
                         ({'clang'}, {
                             'flags+': clang_flags
                         }),
                         ({'posix'}, {
                             'flags+': posix_flags,
                             'external_libs+': ['m'],
                             'cross_compiler': True
                         }),
                     ])

    external_libs = []

    if platform & {'posix'} and not platform & {'mingw'}:
        libelf_test = libelf(c)
        if not libelf_test.libelf_h or not libelf_test.gelf_h:
            raise fbuild.ConfigFailed('libelf is required')
        external_libs.append('elf')

    return Record(c=c, external_libs=external_libs)
Example #30
0
def build(ctx):
    rec = configure(ctx)
    ctx.install_destdir = ctx.options.destdir
    ctx.install_prefix = ctx.options.prefix

    dtweaks = rec.c.build_exe('dtweaks', ['src/dtweaks.c'],
                              cflags=rec.glib.cflags + rec.gio.cflags,
                              ldlibs=rec.glib.ldlibs + rec.gio.ldlibs)

    ctx.install(dtweaks, 'bin')
    ctx.install('misc/dtweaks.hook', 'share/libalpm/hooks')

    if rec.mrkd is not None:
        roff = []
        for man in Path.glob('man/*.md'):
            roff = rec.mrkd.convert(man, format='roff')
            rec.mrkd.convert(man, format='html', index='man/index.ini')
            ctx.install(roff, 'share/man/man%s' % roff.ext[1:])

    return Record(dtweaks=dtweaks, **rec)
Example #31
0
def configure(ctx, release):
    config_kw = {}
    wcxxflags = []
    if release:
        config_kw['optimize'] = True
        wcxxflags.append('/MT')
    else:
        config_kw['debug'] = True
        wcxxflags.append('/LDd')
    felix = Felix(ctx, flags=ctx.options.flxflag, **config_kw)
    extra = felix.platform_extra
    kw = dict(platform_extra=extra, platform_options=[
        ({'windows'}, {'flags+': ['/EHsc']+wcxxflags}),
        ({'posix'}, {'flags+': ['-std=c++11']}),
    ], flags=ctx.options.cxxflag, **config_kw)
    static = guess_static(ctx, **kw)
    shared = guess_shared(ctx, **kw)
    gen_fpc(ctx, static)
    linker = static.lib_linker if 'windows' in extra else shared.lib_linker
    fluidsynth = check_fluid(linker)
    return Record(static=static, shared=shared, felix=felix, fluidsynth=fluidsynth)
Example #32
0
def build_runtime(host_phase, target_phase):
    path = Path('src/gc')

    buildsystem.copy_hpps_to_rtl(target_phase.ctx,
        path / 'flx_gc.hpp',
        path / 'flx_judy_scanner.hpp',
        path / 'flx_serialisers.hpp',
        path / 'flx_collector.hpp',
        path / 'flx_gc_private.hpp',
        path / 'flx_ts_collector.hpp',
        path / 'pthread_bound_queue.hpp',
        path / 'pthread_work_fifo.hpp',
    )

    dst = 'host/lib/rtl/flx_gc'
    srcs = [copy(ctx=target_phase.ctx, src=f, dst=target_phase.ctx.buildroot / f) for f in Path.glob(path / '*.cpp')]
    includes = [
        target_phase.ctx.buildroot / 'host/lib/rtl',
        target_phase.ctx.buildroot / 'share/lib/rtl',
        'src/rtl',
        'src/pthread',
        'src/exceptions',
        'src/judy/src',
    ]
    macros = ['BUILD_FLX_GC']
    libs = [
        call('buildsystem.judy.build_runtime', host_phase, target_phase),
        call('buildsystem.flx_exceptions.build_runtime', target_phase),
        call('buildsystem.flx_pthread.build_runtime', target_phase),
    ]

    return Record(
        static=buildsystem.build_cxx_static_lib(target_phase, dst, srcs,
            includes=includes,
            macros=macros,
            libs=[lib.static for lib in libs]),
        shared=buildsystem.build_cxx_shared_lib(target_phase, dst, srcs,
            includes=includes,
            macros=macros,
            libs=[lib.shared for lib in libs]))
Example #33
0
def configure(ctx):
    flags = ctx.options.cflag
    posix_flags = ['-Wall', '-Werror']
    clang_flags = []

    if not ctx.options.disable_color:
        posix_flags.append('-fdiagnostics-color')
    if ctx.options.release:
        debug = False
        optimize = True
    else:
        debug = True
        optimize = False
        clang_flags.append('-fno-limit-debug-info')

    c = guess.static(ctx,
                     exe=ctx.options.cc,
                     flags=flags,
                     debug=debug,
                     optimize=optimize,
                     platform_options=[
                         ({'clang'}, {
                             'flags+': clang_flags
                         }),
                         ({'posix'}, {
                             'flags+': posix_flags,
                             'external_libs+': ['dl']
                         }),
                     ])

    glib = run_pkg_config(ctx, 'glib-2.0')
    gio = run_pkg_config(ctx, 'gio-2.0')

    try:
        mrkd = MrkdBuilder(ctx, ctx.options.mrkd)
    except fbuild.ConfigFailed:
        mrkd = None

    return Record(c=c, glib=glib, gio=gio, mrkd=mrkd)
Example #34
0
def configure(ctx):
    flags = ['-Wall', '-Werror']+ctx.options.cflag
    testflags = []
    defs = []
    kw = {}
    if ctx.options.use_color:
        flags.append('-fdiagnostics-color')

    if ctx.options.release:
        kw['optimize'] = True
        kw['macros'] = ['NDEBUG']
    else:
        kw['debug'] = True
        kw['macros'] = ['DEBUG']

    c = guess_static(ctx, exe=ctx.options.cc, flags=flags, includes=['utf'],
        platform_options=[
            ({'posix'}, {'external_libs+': ['rt']})
        ],
        **kw)
    arch = get_target_arch(ctx, c)
    if arch == 'x86_64':
        defs.append('X64')
    elif re.match('i\d86', arch):
        # X86 is implemented in the x86_64.dasc file.
        arch = 'x86_64'
    else:
        raise fbuild.ConfigFailed('unsupported target architecture ' + arch)

    dasm = DynAsmBuilder(ctx, exe=ctx.options.lua, defs=defs)

    if Libcut_h(c).libcut_h:
        ctx.logger.passed('found libcut.h; will build tests')
        tests = True
        testflags.append('-std=gnu11')
    else:
        ctx.logger.failed('cannot find libcut.h; will not build tests')
        tests = False
    return Record(dasm=dasm, c=c, arch=arch, tests=tests, testflags=testflags)
Example #35
0
def configure(ctx):
    posix_flags = ['-std=c++11', '-Wno-unused-command-line-argument']
    clang_flags = []
    nonclang_flags = []
    kw = {}

    if ctx.options.release:
        kw['optimize'] = True
        posix_flags.append('-flto')
        # clang_flags.append('-fuse-ld=lld')
        posix_flags.append('-fuse-ld=lld')
        # nonclang_flags.append('-fuse-ld=gold')
    else:
        kw['debug'] = True
        clang_flags.append('-fno-limit-debug-info')

    if ctx.options.use_color:
        posix_flags.append('-fdiagnostics-color')

    cxx = guess.static(
        ctx,
        exe=ctx.options.cxx,
        flags=ctx.options.cxxflag,
        includes=['deps/abseil'],
        platform_options=[
            ({'posix'}, {
                'flags+': posix_flags
            }),
            ({'clang'}, {
                'flags+': clang_flags,
                'macros': ['__CLANG_SUPPORT_DYN_ANNOTATION__']
            }),
            # ({'!clang'}, {'flags+': nonclang_flags}),
        ],
        **kw)

    return Record(cxx=cxx)
Example #36
0
def config_omp_h(ctx, builder):
    if not builder.check_header_exists('omp.h'):
        raise MissingHeader('omp.h')

    code = r'''
        #include <omp.h>
        #include <stdio.h>
        #include <stdlib.h>

        int main (int argc, char *argv[]) {
            int nthreads, tid;

            #pragma omp parallel private(nthreads, tid)
            {
                tid = omp_get_thread_num();
                printf("Hello World from thread = %d\n", tid);

                /* Only master thread does this */
                if (tid == 0) {
                    nthreads = omp_get_num_threads();
                    printf("Number of threads = %d\n", nthreads);
                }
            }

            return 0;
        }
    '''

    ctx.logger.check('checking if supports omp_get_thread_num')
    for flags in [], ['-openmp'], ['-fopenmp'], ['/openmp']:
        if builder.try_run(code, lkwargs={'flags': flags}):
            ctx.logger.passed('ok %r' % ' '.join(flags))

            return Record(flags=flags)
    else:
        ctx.logger.failed()
        raise fbuild.ConfigFailed('failed to link openmp program')
Example #37
0
def config_host(ctx, build):
    ctx.logger.log('configuring host phase', color='cyan')

    platform = call('fbuild.builders.platform.platform', ctx,
        ctx.options.build_platform)

    if platform == build.platform:
        ctx.logger.log("using build's c and cxx compiler", color='cyan')
        phase = build
    else:
        phase = Record(
            ctx=ctx,
            platform=platform,
            c=make_c_builder(ctx, fbuild.builders.host_cc,
                platform=platform,
                debug=ctx.options.debug or ctx.options.host_c_debug,
                profile=ctx.options.profile or ctx.options.host_c_profile,
                optimize=ctx.options.optimize or
                    ctx.options.host_c_optimize,
                includes=ctx.options.host_includes,
                libpaths=ctx.options.host_libpaths,
                flags=ctx.options.host_c_flags),
            cxx=make_cxx_builder(ctx, fbuild.buildesr.host_cxx,
                platform=platform,
                debug=ctx.options.debug or ctx.options.host_c_debug,
                profile=ctx.options.profile or ctx.options.host_c_profile,
                optimize=ctx.options.optimize or
                    ctx.options.host_c_optimize,
                includes=ctx.options.host_includes,
                libpaths=ctx.options.host_libpaths,
                flags=ctx.options.host_c_flags))

    ocaml = call('fbuild.builders.ocaml.ocamlfind.Ocaml', ctx,
        debug=ctx.options.debug or ctx.options.host_ocaml_debug,
        profile=ctx.options.profile or ctx.options.host_ocaml_profile,
        ocamlc=ctx.options.host_ocamlc,
        ocamlcp=ctx.options.host_ocamlcp,
        ocamlopt=ctx.options.host_ocamlopt,
        flags=['-w', 'exYz', '-warn-error', 'FDPSU'],
        requires_at_least_version=(3, 12))

    phase.ocamlc = ocaml.ocamlc
    phase.ocamlcp = ocaml.ocamlcp
    phase.ocamlopt = ocaml.ocamlopt

    phase.ocamllex = call('fbuild.builders.ocaml.Ocamllex', ctx,
        ctx.options.host_ocamllex)

    # we prefer the native ocaml as it's much faster
    if not ctx.options.host_use_ocamlc and hasattr(ocaml, 'ocamlopt'):
        phase.ocaml = phase.ocamlopt
    elif ctx.options.profile or ctx.options.host_ocaml_profile:
        phase.ocaml = phase.ocamlcp
    else:
        phase.ocaml = phase.ocamlc

    # We optionally support llvm
    try:
        llvm_config = call('fbuild.builders.llvm.LlvmConfig', ctx,
            ctx.options.host_llvm_config,
            requires_at_least_version=(2, '7'))
    except fbuild.ConfigFailed:
        phase.llvm_config = None
    else:
        if llvm_config.ocaml_libdir().exists():
            phase.llvm_config = llvm_config
        else:
            phase.llvm_config = None

    return phase