Skip to content

Commit

Permalink
python: use same compiler flags than CMake
Browse files Browse the repository at this point in the history
cpp files are built before building the python extension.
  • Loading branch information
Toilal committed Mar 12, 2020
1 parent bb91537 commit d3b29f4
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,55 @@ def get_version():
return v_code


def get_cpp_extra_compile_args(compiler):
"""
Get the extra compile arguments for libjsonnet C++ compilation.
"""
if compiler.compiler_type == 'msvc':
return []
else:
return ["-Wextra", "-Woverloaded-virtual", "-pedantic", "-std=c++11"]


def get_c_extra_compile_args(compiler):
"""
Get the extra compile arguments for python jsonnet C compilation.
"""
if compiler.compiler_type == 'msvc':
return []
else:
return ["-Wextra", "-pedantic", "-std=c99"]


class custom_build_ext(build_ext):
def build_extension(self, ext):
if ext.name == '_jsonnet':
to_c_array(os.path.join(DIR, 'stdlib/std.jsonnet'), os.path.join(DIR, 'core/std.jsonnet.h'))

objects = self.compiler.compile([
'core/desugarer.cpp',
'core/formatter.cpp',
'core/libjsonnet.cpp',
'core/lexer.cpp',
'core/parser.cpp',
'core/pass.cpp',
'core/static_analysis.cpp',
'core/string_utils.cpp',
'core/vm.cpp',
'third_party/md5/md5.cpp'],
extra_postargs=get_cpp_extra_compile_args(self.compiler),
include_dirs=['include', 'third_party/md5', 'third_party/json'])

ext.extra_compile_args = get_c_extra_compile_args(self.compiler)
ext.extra_objects = objects

build_ext.build_extension(self, ext)


jsonnet_ext = Extension(
'_jsonnet',
sources=['python/_jsonnet.c',
'core/desugarer.cpp',
'core/formatter.cpp',
'core/libjsonnet.cpp',
'core/lexer.cpp',
'core/parser.cpp',
'core/pass.cpp',
'core/static_analysis.cpp',
'core/string_utils.cpp',
'core/vm.cpp',
'third_party/md5/md5.cpp'],
include_dirs=['include', 'third_party/md5', 'third_party/json'],
language='c++'
sources=['python/_jsonnet.c'],
include_dirs=['include', 'third_party/md5', 'third_party/json']
)

setup(name='jsonnet',
Expand Down

0 comments on commit d3b29f4

Please sign in to comment.