diff --git a/setup.py b/setup.py index 96ef6c565..d4be378cb 100644 --- a/setup.py +++ b/setup.py @@ -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',