Updating capnproto bundling code to use CMake and ninja
- Must faster - Also showing output by default (easier to diagnose errors) * ninja has minimal verbosity (unless there are errors)
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
def build_libcapnp(bundle_dir, build_dir, verbose=False):
|
def build_libcapnp(bundle_dir, build_dir, verbose=False):
|
||||||
@@ -11,23 +13,46 @@ def build_libcapnp(bundle_dir, build_dir, verbose=False):
|
|||||||
bundle_dir = os.path.abspath(bundle_dir)
|
bundle_dir = os.path.abspath(bundle_dir)
|
||||||
capnp_dir = os.path.join(bundle_dir, 'capnproto-c++')
|
capnp_dir = os.path.join(bundle_dir, 'capnproto-c++')
|
||||||
build_dir = os.path.abspath(build_dir)
|
build_dir = os.path.abspath(build_dir)
|
||||||
|
tmp_dir = os.path.join(capnp_dir, 'build')
|
||||||
|
if not os.path.exists(tmp_dir):
|
||||||
|
os.mkdir(tmp_dir)
|
||||||
|
|
||||||
with tempfile.TemporaryFile() as f:
|
cxxflags = os.environ.get('CXXFLAGS', None)
|
||||||
stdout = f
|
os.environ['CXXFLAGS'] = (cxxflags or '') + ' -O2 -DNDEBUG'
|
||||||
if verbose:
|
|
||||||
stdout = None
|
|
||||||
cxxflags = os.environ.get('CXXFLAGS', None)
|
|
||||||
os.environ['CXXFLAGS'] = (cxxflags or '') + ' -fPIC -O2 -DNDEBUG'
|
|
||||||
conf = subprocess.Popen(['./configure', '--disable-shared', '--prefix', build_dir], cwd=capnp_dir, stdout=stdout)
|
|
||||||
returncode = conf.wait()
|
|
||||||
if returncode != 0:
|
|
||||||
raise RuntimeError('Configure failed')
|
|
||||||
|
|
||||||
make = subprocess.Popen(['make', '-j4', 'install'], cwd=capnp_dir, stdout=stdout)
|
# Enable ninja for compilation if available
|
||||||
returncode = make.wait()
|
build_type = []
|
||||||
if cxxflags is None:
|
if shutil.which('ninja'):
|
||||||
del os.environ['CXXFLAGS']
|
build_type = ['-G', 'Ninja']
|
||||||
else:
|
|
||||||
os.environ['CXXFLAGS'] = cxxflags
|
# TODO Determine VS version
|
||||||
if returncode != 0:
|
|
||||||
raise RuntimeError('Make failed')
|
args = [
|
||||||
|
'cmake',
|
||||||
|
'-DCMAKE_POSITION_INDEPENDENT_CODE=1',
|
||||||
|
'-DBUILD_TESTING=OFF',
|
||||||
|
'-DBUILD_SHARED_LIBS=OFF',
|
||||||
|
'-DCMAKE_INSTALL_PREFIX:PATH={}'.format(build_dir),
|
||||||
|
capnp_dir,
|
||||||
|
]
|
||||||
|
args.extend(build_type)
|
||||||
|
conf = subprocess.Popen(args, cwd=tmp_dir, stdout=sys.stdout)
|
||||||
|
returncode = conf.wait()
|
||||||
|
if returncode != 0:
|
||||||
|
raise RuntimeError('CMake failed')
|
||||||
|
|
||||||
|
# Run build through cmake
|
||||||
|
build = subprocess.Popen([
|
||||||
|
'cmake',
|
||||||
|
'--build',
|
||||||
|
'.',
|
||||||
|
'--target',
|
||||||
|
'install',
|
||||||
|
], cwd=tmp_dir, stdout=sys.stdout)
|
||||||
|
returncode = build.wait()
|
||||||
|
if cxxflags is None:
|
||||||
|
del os.environ['CXXFLAGS']
|
||||||
|
else:
|
||||||
|
os.environ['CXXFLAGS'] = cxxflags
|
||||||
|
if returncode != 0:
|
||||||
|
raise RuntimeError('capnproto compilation failed')
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ pjoin = os.path.join
|
|||||||
# Constants
|
# Constants
|
||||||
#
|
#
|
||||||
|
|
||||||
bundled_version = (0, 7, 4)
|
bundled_version = (0, 7, 0)
|
||||||
libcapnp_name = "capnproto-c++-%i.%i.%i.tar.gz" % (bundled_version)
|
libcapnp_name = "capnproto-c++-%i.%i.%i.tar.gz" % (bundled_version)
|
||||||
libcapnp_url = "https://capnproto.org/" + libcapnp_name
|
libcapnp_url = "https://capnproto.org/" + libcapnp_name
|
||||||
|
|
||||||
@@ -92,10 +92,6 @@ def fetch_libcapnp(savedir, url=None):
|
|||||||
shutil.move(with_version, dest)
|
shutil.move(with_version, dest)
|
||||||
else:
|
else:
|
||||||
cpp_dir = os.path.join(with_version, 'c++')
|
cpp_dir = os.path.join(with_version, 'c++')
|
||||||
conf = Popen(['autoreconf', '-i'], cwd=cpp_dir)
|
|
||||||
returncode = conf.wait()
|
|
||||||
if returncode != 0:
|
|
||||||
raise RuntimeError('Autoreconf failed. Make sure autotools are installed on your system.')
|
|
||||||
shutil.move(cpp_dir, dest)
|
shutil.move(cpp_dir, dest)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user