SWIG support (or lack thereof)
Dear all, I have a few SWIG generated python modules, and I like distutils. distutils only sort-of supports swig. It passes very limited arguments to swig. Most importantly missing for me were macro definitions and include paths. I have attached a minimally intrusive patch that: - reuses include_dirs, define_macros and undef_macros from the C target - adds 'extra_swig_args' (which I need for at least -shadow) The patch was generated from the Python 2.3.2 and should be applied in the distutils directory. The patch solves my immediate problem, but it might be even better to add 'swig_include_dirs', 'swig_define_macros' and 'swig_undef_macros' to the Extension arguments. I volunteer for another patch if there are chances it will be accepted. - Lars --- core.orig Fri Mar 12 23:55:27 2004 +++ core.py Fri Mar 12 23:56:21 2004 @@ -54,7 +54,8 @@ 'define_macros', 'undef_macros', 'library_dirs', 'libraries', 'runtime_library_dirs', 'extra_objects', 'extra_compile_args', 'extra_link_args', - 'export_symbols', 'depends', 'language') + 'extra_swig_args', 'export_symbols', 'depends', + 'language') def setup (**attrs): """The gateway to the Distutils: do everything your setup script needs --- extension.orig Fri Mar 12 23:55:18 2004 +++ extension.py Fri Mar 12 23:57:41 2004 @@ -94,6 +94,7 @@ extra_objects=None, extra_compile_args=None, extra_link_args=None, + extra_swig_args=None, export_symbols=None, depends=None, language=None, @@ -115,6 +116,7 @@ self.extra_objects = extra_objects or [] self.extra_compile_args = extra_compile_args or [] self.extra_link_args = extra_link_args or [] + self.extra_swig_args = extra_swig_args or [] self.export_symbols = export_symbols or [] self.depends = depends or [] self.language = language --- command/build_ext.orig Fri Mar 12 20:16:24 2004 +++ command/build_ext.py Sat Mar 13 23:52:22 2004 @@ -16,6 +16,7 @@ from distutils.dep_util import newer_group from distutils.extension import Extension from distutils import log +from distutils.ccompiler import gen_preprocess_options # An extension name is just a dot-separated list of Python NAMEs (ie. # the same as a fully-qualified module name). @@ -81,6 +82,8 @@ "specify the compiler type"), ('swig-cpp', None, "make SWIG create C++ files (default is C)"), + ('extra-swig-args', None, + "extra swig options (for example -shadow)"), ] boolean_options = ['inplace', 'debug', 'force', 'swig-cpp'] @@ -108,6 +111,7 @@ self.force = None self.compiler = None self.swig_cpp = None + self.extra_swig_args = None def finalize_options (self): @@ -322,7 +326,8 @@ 'libraries', 'extra_objects', 'extra_compile_args', - 'extra_link_args'): + 'extra_link_args', + 'extra_swig_args'): val = build_info.get(key) if val is not None: setattr(ext, key, val) @@ -429,7 +434,7 @@ # First, scan the sources for SWIG definition files (.i), run # SWIG on 'em to create .c files, and modify the sources list # accordingly. - sources = self.swig_sources(sources) + sources = self.swig_sources(sources, ext) # Next, compile the source code to object files. @@ -492,7 +497,7 @@ target_lang=language) - def swig_sources (self, sources): + def swig_sources (self, sources, extension): """Walk the list of source files in 'sources', looking for SWIG interface (.i) files. Run SWIG on all that are found, and @@ -530,6 +535,16 @@ swig_cmd = [swig, "-python"] if self.swig_cpp: swig_cmd.append("-c++") + + for esa in extension.extra_swig_args: + swig_cmd.append(esa) + + opt = gen_preprocess_options(extension.define_macros + + extension.undef_macros, + extension.include_dirs) + + for o in opt: + swig_cmd.append(o) for source in swig_sources: target = swig_targets[source]
participants (1)
-
Lars Immisch