sapling/setup.py
Jun Wu 6635afb281 setup: add a function to test C compiler feature
Summary:
We are going to use some `C11` features, namely unnamed union fields.

Sadly we still have to support gcc4.4, which does not support `-std=c11` while
its `-std=gnu99` compiles the code but with the warning
`ISO C doesn't support unnamed structs/unions`.

This patch adds a feature test function to help detect compiler differences.

Test Plan:
```
make local
```

Reviewers: #mercurial, ttung

Reviewed By: ttung

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3649021

Signature: t1:3649021:1470082430:bced7bd155eb60cc8c3e1c2d950092e2abd39a00
2016-08-01 14:33:28 +01:00

95 lines
2.9 KiB
Python

from distutils.ccompiler import new_compiler
from glob import glob
import os
import shutil
import tempfile
try:
from setuptools import setup, Extensions
except ImportError:
from distutils.core import setup, Extension
def cc_has_feature(code=None, cflags=None, ldflags=None, cc=None):
"""test a C compiler feature, return True if supported, False otherwise"""
if code is None:
code = 'int main() { return 0; }'
if cflags is None:
cflags = []
if ldflags is None:
ldflags = []
if cc is None:
cc = new_compiler()
tmpdir = tempfile.mkdtemp(prefix='cc-feature-test')
try:
fname = os.path.join(tmpdir, 'a.c')
with open(fname, 'w') as f:
f.write(code)
objs = cc.compile([fname], output_dir=tmpdir, extra_postargs=cflags)
cc.link_executable(objs, os.path.join(tmpdir, 'a'),
extra_postargs=ldflags)
return True
except Exception:
return False
finally:
shutil.rmtree(tmpdir)
hgext3rd = [
p[:-3].replace('/', '.')
for p in glob('hgext3rd/*.py')
if p != 'hgext3rd/__init__.py'
]
setup(
name='fbhgext',
version='0.1.2',
author='Durham Goode',
maintainer='Durham Goode',
maintainer_email='durham@fb.com',
url='',
description='Facebook specific mercurial extensions',
long_description="",
keywords='fb hg mercurial',
license='',
packages=[
'fastmanifest',
'phabricator',
'sqldirstate',
],
py_modules=[
'statprof'
] + hgext3rd,
ext_modules = [
Extension('cfastmanifest',
sources=['cfastmanifest.c',
'cfastmanifest/bsearch.c',
'cfastmanifest/buffer.c',
'cfastmanifest/checksum.c',
'cfastmanifest/node.c',
'cfastmanifest/tree.c',
'cfastmanifest/tree_arena.c',
'cfastmanifest/tree_convert.c',
'cfastmanifest/tree_copy.c',
'cfastmanifest/tree_diff.c',
'cfastmanifest/tree_disk.c',
'cfastmanifest/tree_iterator.c',
'cfastmanifest/tree_path.c',
],
include_dirs=['cfastmanifest',
'/usr/local/include',
'/opt/local/include',
],
library_dirs=[
'/usr/local/lib',
'/opt/local/lib',
],
libraries=['crypto',
],
extra_compile_args=[
"-std=c99",
"-Wall",
"-Werror", "-Werror=strict-prototypes"],
)
],
)