Skip to content
Permalink
Browse files

buildsys: use meson as build system

  • Loading branch information...
Snaipe committed Sep 15, 2019
1 parent c47a9c9 commit 0766b7cf386cb6016bce7be7ca18b556a7438e2d
Showing with 344 additions and 42 deletions.
  1. +4 −14 .gitignore
  2. +18 −0 ci/cram-env.patch
  3. +4 −0 ci/isdir.py
  4. +204 −0 meson.build
  5. +19 −0 sample/meson.build
  6. +26 −28 src/config.h.in
  7. +54 −0 src/meson.build
  8. +15 −0 test/meson.build
@@ -1,15 +1,5 @@
*
!*/
build/

!src/*.c
!src/*.h
!src/asm/*.S
!src/asm/*.asm
!sample/*.c
!test/*.t
!.cmake/*/*.cmake
!CMakeLists.txt
!*.rst
!*.md

config.h
*.swp
*.swo
*~
@@ -0,0 +1,18 @@
--- _test.py.orig 2016-09-03 00:50:27.505527300 +0200
+++ "/c/Program Files/Python35/lib/site-packages/cram/_test.py" 2016-09-03 00:48:48.708932100 +0200
@@ -143,11 +143,15 @@
after.setdefault(pos, []).append(line)
stdin.append(b('echo %s %s $?\n' % (usalt, i + 1)))

+ env = {k: v.decode('utf-8') if isinstance(v, bytes) else v for k, v in env.items()}
+
output, retcode = execute(shell + ['-'], stdin=b('').join(stdin),
stdout=PIPE, stderr=STDOUT, env=env)
if retcode == 80:
return (refout, None, [])

+ output = output.replace(b'\r\n', b'\n').replace(b'\r', b'\n')
+
pos = -1
ret = 0
for i, line in enumerate(output[:-1].splitlines(True)):
@@ -0,0 +1,4 @@
#!/usr/bin/env python3
import os, sys
os.chdir(os.environ['MESON_SOURCE_ROOT'])
sys.exit(0 if os.path.isdir(sys.argv[1]) else 1)
@@ -0,0 +1,204 @@
project('boxfort', 'c',
meson_version : '>= 0.48.0',
license : 'MIT',
version : '0.0.1',
default_options : ['c_std=c99', 'warning_level=3', 'b_lundef=false'])

# standard install directories
prefix = get_option('prefix')

# Helper scripts
auxdir = join_paths(meson.source_root(), 'ci')
isdir = join_paths(auxdir, 'isdir.py')

python3 = find_program('python3')
git = find_program('git', required: false)

# Get the right version

is_git_repo = run_command([isdir, '.git']).returncode() == 0

version = 'v' + meson.project_version()
if git.found() and is_git_repo
version = run_command([git.path(), 'describe', '--dirty', '--tags']).stdout().strip()
branch = run_command([git.path(), 'rev-parse', '--abbrev-ref', 'HEAD']).stdout().strip()

if branch != 'master'
version = '@0@ (@1@)'.format(version, branch)
endif
endif

cc = meson.get_compiler('c')

add_project_arguments(
cc.get_supported_arguments([
'-Wno-unused-parameter',
'-Wno-unused-value',
'-fvisibility=hidden',

# MSVC-specific stuff
'/SAFESEH:NO',
'/source-charset:utf-8',
]),
'-DBXF_BUILDING_LIB',
'-D_GNU_SOURCE',
language: ['c', 'cpp'])

if host_machine.system() == 'windows'
add_project_arguments(
'-DVC_EXTRALEAN',
'-DWIN32_LEAN_AND_MEAN',
'-D_CRT_SECURE_NO_WARNINGS',
'-D_WIN32_WINNT=0x600',
language: ['c', 'cpp'])
endif

boxfort_includedir = include_directories(
'include',
'src',
)

threads = dependency('threads')

# optional platform-dependent standard libs
librt = cc.find_library('rt', required: false)
libm = cc.find_library('m', required: false)

config = configuration_data()
config.set('package', meson.project_name())
config.set('version', version)

os = host_machine.system()
arch = host_machine.cpu_family()

mangling = 'none'
if cc.symbols_have_underscore_prefix()
mangling = 'leading-underscore'
endif

if arch == 'x86'
bitness = 32
elif arch == 'x86_64'
bitness = 64
elif arch == 'arm'
bitness = 32
elif arch == 'aarch64'
bitness = 64
else
error('Architecture "@0@" is not supported.'.format(arch))
endif

binfmt = 'elf'
os_family = 'posix'
if os == 'windows'
binfmt = 'pe'
os_family = 'windows'
elif os == 'darwin'
binfmt = 'mach-o'
endif

config.set('BXF_EXE_FORMAT', binfmt)
config.set('BXF_EXE_FMT_@0@'.format(binfmt.to_upper()), 1)
config.set('BXF_OS_FAMILY', os_family)
config.set('BXF_ARCH', '"' + arch + '"')
config.set('BXF_ARCH_@0@'.format(arch), 1)
config.set('BXF_MANGLING', mangling)
config.set('BXF_BITS', bitness)

checks = [
{'fn': 'clock_gettime'},
{'fn': 'gettimeofday'},
{'fn': 'mincore'},
{'fn': 'prctl'},
{'fn': 'shm_open'},

# some platforms define mincore with an unsigned vector
{
'fn': 'mincore',
'proto': 'int _(void *, size_t, unsigned char *)',
'headers': ['unistd.h', 'sys/mman.h'],
'var': 'HAVE_UNSIGNED_MINCORE_VEC',
},

{'sym': 'PR_SET_PDEATHSIG', 'header': 'sys/prctl.h'},
{'sym': 'CLOCK_MONOTONIC_RAW', 'header': 'time.h'},
{'sym': 'environ', 'header': 'unistd.h'},
]

if binfmt == 'elf'
checks += [
{'sym': '_r_debug', 'header': 'link.h'},
{'sym': '_DYNAMIC', 'header': 'link.h'},
]
endif

check_prelude = '''
#define _GNU_SOURCE
'''

prototype_check = '''
@0@
typedef @1@;
static _ *check = @2@;
'''

foreach check : checks
chk_prefix = check.get('prefix', '')
if chk_prefix != ''
chk_prefix = chk_prefix + '_'
endif

result = false
if check.has_key('proto')
includes = ''
foreach hdr : check.get('headers')
includes += '#include <@0@>\n'.format(hdr)
endforeach
result = cc.compiles(prototype_check.format(includes, check.get('proto'), check.get('fn')))
elif check.has_key('fn')
name = check.get('fn')
libs = ['c']
if librt.found()
libs += 'rt'
endif
if libm.found()
libs += 'm'
endif
if check.has_key('libs')
libs += check.get('libs')
endif
args = []
foreach lib : libs
args += '-l' + lib
endforeach
result = cc.has_function(name, prefix: check_prelude, args: args)
elif check.has_key('sym')
name = check.get('sym')
result = cc.has_header_symbol(check.get('header'), name, prefix: check_prelude)
elif check.has_key('hdr')
name = check.get('hdr')
result = cc.has_header(name)
endif

name = 'HAVE_@1@@0@'.format(name.to_upper(), chk_prefix.to_upper())
config.set(name, result)
endforeach

api = files('include/boxfort.h')

install_headers(api)

includedir = include_directories(
'include',
'src',
)

if target_machine.system() == 'windows'
config.set10('HAVE_WIN32_THREADS', true)
else
config.set10('HAVE_PTHREADS', true)
endif

subdir('src')
subdir('sample')
subdir('test')
@@ -0,0 +1,19 @@
samples = [
'nested.c',
'callback.c',
'timeout.c',
'context.c',
]

foreach sample : samples
e = executable(sample + '.bin', sample,
include_directories: includedir,
dependencies: [libm],
link_with: boxfort,
c_args: [
cc.get_supported_arguments([
'-fvisibility=default',
])
])
test(sample, e)
endforeach
@@ -24,39 +24,37 @@
#ifndef CONFIG_H_IN_
# define CONFIG_H_IN_

#cmakedefine BXF_ARCH "@BXF_ARCH@"
#cmakedefine BXF_BITS @BXF_BITS@
#cmakedefine BXF_MANGLING @BXF_MANGLING@
#cmakedefine BXF_OS_FAMILY @BXF_OS_FAMILY@
#mesondefine BXF_ARCH
#mesondefine BXF_BITS
#mesondefine BXF_MANGLING
#mesondefine BXF_OS_FAMILY

# ifdef BXF_OS_FAMILY
# define BXF_OS_FAMILY_STR #BXF_OS_FAMILY
# endif

#cmakedefine BXF_ARCH_x86 @BXF_ARCH_x86@
#cmakedefine BXF_ARCH_x86_64 @BXF_ARCH_x86_64@
#cmakedefine BXF_ARCH_ARM @BXF_ARCH_ARM@
#cmakedefine BXF_ARCH_ARM64 @BXF_ARCH_ARM64@

#cmakedefine BXF_EXE_FMT_ELF @BXF_EXE_FMT_ELF@
#cmakedefine BXF_EXE_FMT_PE @BXF_EXE_FMT_PE@
#cmakedefine BXF_EXE_FMT_MACH_O @BXF_EXE_FMT_MACH_O@

#cmakedefine BXF_ARENA_REOPEN_SHM @BXF_ARENA_REOPEN_SHM@
#cmakedefine BXF_ARENA_FILE_BACKED @BXF_ARENA_FILE_BACKED@
#cmakedefine BXF_FORK_RESILIENCE @BXF_FORK_RESILIENCE@

#cmakedefine HAVE__R_DEBUG @HAVE__R_DEBUG@
#cmakedefine HAVE__DYNAMIC @HAVE__DYNAMIC@
#cmakedefine HAVE_PR_SET_PDEATHSIG @HAVE_PR_SET_PDEATHSIG@
#cmakedefine HAVE_CLOCK_GETTIME @HAVE_CLOCK_GETTIME@
#cmakedefine HAVE_CLOCK_MONOTONIC_RAW @HAVE_CLOCK_MONOTONIC_RAW@
#cmakedefine HAVE_GETTIMEOFDAY @HAVE_GETTIMEOFDAY@
#cmakedefine HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP \
@HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP@
#cmakedefine HAVE_ENVIRON @HAVE_ENVIRON@

#cmakedefine ASSEMBLER_SUPPORTS_HIDDEN @ASSEMBLER_SUPPORTS_HIDDEN@
#mesondefine BXF_ARCH_x86
#mesondefine BXF_ARCH_x86_64
#mesondefine BXF_ARCH_ARM
#mesondefine BXF_ARCH_ARM64

#mesondefine BXF_EXE_FMT_ELF
#mesondefine BXF_EXE_FMT_PE
#mesondefine BXF_EXE_FMT_MACH_O

#mesondefine BXF_ARENA_REOPEN_SHM
#mesondefine BXF_ARENA_FILE_BACKED
#mesondefine BXF_FORK_RESILIENCE

#mesondefine HAVE__R_DEBUG
#mesondefine HAVE__DYNAMIC
#mesondefine HAVE_PR_SET_PDEATHSIG
#mesondefine HAVE_CLOCK_GETTIME
#mesondefine HAVE_CLOCK_MONOTONIC_RAW
#mesondefine HAVE_GETTIMEOFDAY
#mesondefine HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP
#mesondefine HAVE_ENVIRON
#mesondefine ASSEMBLER_SUPPORTS_HIDDEN

# define BXFI_STR_(x) #x
# define BXFI_STR(x) BXFI_STR_(x)
@@ -0,0 +1,54 @@
sources = files(
'addr.c',
'addr.h',
'arena.c',
'arena.h',
'context.c',
'context.h',
'exe.h',
'exe-@0@.c'.format(binfmt),
'exe-@0@.h'.format(binfmt),
'sandbox-@0@.c'.format(os_family),
'sandbox-@0@.h'.format(os_family),
'sandbox.c',
'sandbox.h',
'timeout-@0@.c'.format(os_family),
'timeout.h',
'timestamp.c',
'timestamp.h',
)

asm_extension = '.S'
asm = files('asm/trampoline-@0@@1@'.format(arch, asm_extension))
if target_machine.system() == 'windows'
asm += 'asm/setjmp-@0@@1@'.format(arch, asm_extension)
endif

sources += asm

configure_file(input : 'config.h.in',
output : 'config.h',
configuration : config)

deps = [
threads,
librt,
libm,
]

boxfort = library('boxfort', sources,
include_directories: [boxfort_includedir],
version: '3.1.0',
dependencies: deps,
install: true,
link_args: cc.get_supported_arguments([
'-Wl,--exclude-libs,ALL',
]),
)

pkgconfig = import('pkgconfig')
pkgconfig.generate(
name: meson.project_name(),
description: 'A portable process sandboxing library',
url: 'https://snai.pe/git/boxfort',
)

0 comments on commit 0766b7c

Please sign in to comment.
You can’t perform that action at this time.