[pypy-svn] r71944 - in pypy/trunk/pypy: rlib rpython/lltypesystem translator/platform translator/tool

arigo at codespeak.net arigo at codespeak.net
Tue Mar 9 13:37:06 CET 2010


Author: arigo
Date: Tue Mar  9 13:37:04 2010
New Revision: 71944

Modified:
   pypy/trunk/pypy/rlib/libffi.py
   pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py
   pypy/trunk/pypy/translator/platform/linux.py
   pypy/trunk/pypy/translator/tool/cbuild.py
Log:
Make pypy-c translations contain a static libffi on Linux.
Avoids the troubles of finding the dynamic libffi.so, and
anyway it's quite small.


Modified: pypy/trunk/pypy/rlib/libffi.py
==============================================================================
--- pypy/trunk/pypy/rlib/libffi.py	(original)
+++ pypy/trunk/pypy/rlib/libffi.py	Tue Mar  9 13:37:04 2010
@@ -53,11 +53,13 @@
     separate_module_sources = []
 
 if not _MSVC:
+    # On some platforms, we try to link statically libffi, which is small
+    # anyway and avoids endless troubles for installing.  On other platforms
+    # libffi.a is typically not there, so we link dynamically.
     if _MINGW:
         includes = ['windows.h', 'ffi.h']
     else:
         includes = ['dlfcn.h', 'ffi.h']
-    include_dirs = platform.include_dirs_for_libffi()
 
     if _MAC_OS:
         pre_include_bits = ['#define MACOSX']
@@ -65,9 +67,25 @@
         pre_include_bits = []
 
     if _FREEBSD_7 or _MINGW:
-        libraries = ['ffi']
+        libraries = []
     else:
-        libraries = ['ffi', 'dl']
+        libraries = ['dl']
+
+    def find_libffi_a():
+        dirlist = platform.library_dirs_for_libffi_a()
+        for dir in dirlist:
+            result = os.path.join(dir, 'libffi.a')
+            if os.path.exists(result):
+                return result
+        raise ImportError("'libffi.a' not found in %s" % (dirlist,))
+
+    if hasattr(platform, 'library_dirs_for_libffi_a'):
+        # platforms on which we want static linking
+        link_files = [find_libffi_a()]
+    else:
+        # platforms on which we want dynamic linking
+        libraries = ['ffi'] + libraries
+        link_files = []
 
     eci = ExternalCompilationInfo(
         pre_include_bits = pre_include_bits,
@@ -76,6 +94,8 @@
         separate_module_sources = separate_module_sources,
         include_dirs = platform.include_dirs_for_libffi(),
         library_dirs = platform.library_dirs_for_libffi(),
+        link_files = link_files,
+        testonly_libraries = ['ffi'],
     )
 else:
     libffidir = py.path.local(pypydir).join('translator', 'c', 'src', 'libffi_msvc')

Modified: pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/ll2ctypes.py	Tue Mar  9 13:37:04 2010
@@ -853,7 +853,7 @@
             eci = old_eci.compile_shared_lib()
             _eci_cache[old_eci] = eci
 
-    libraries = list(eci.libraries + eci.frameworks)
+    libraries = eci.testonly_libraries + eci.libraries + eci.frameworks
 
     FUNCTYPE = lltype.typeOf(funcptr).TO
     if not libraries:

Modified: pypy/trunk/pypy/translator/platform/linux.py
==============================================================================
--- pypy/trunk/pypy/translator/platform/linux.py	(original)
+++ pypy/trunk/pypy/translator/platform/linux.py	Tue Mar  9 13:37:04 2010
@@ -24,6 +24,10 @@
     def library_dirs_for_libffi(self):
         return ['/usr/lib/libffi']
 
+    def library_dirs_for_libffi_a(self):
+        # places where we need to look for libffi.a
+        return self.library_dirs_for_libffi() + ['/usr/lib']
+
 
 class Linux64(Linux):
     shared_only = ['-fPIC']

Modified: pypy/trunk/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/trunk/pypy/translator/tool/cbuild.py	(original)
+++ pypy/trunk/pypy/translator/tool/cbuild.py	Tue Mar  9 13:37:04 2010
@@ -18,7 +18,7 @@
                    'post_include_bits', 'libraries', 'library_dirs',
                    'separate_module_sources', 'separate_module_files',
                    'export_symbols', 'compile_extra', 'link_extra',
-                   'frameworks', 'link_files']
+                   'frameworks', 'link_files', 'testonly_libraries']
     _DUPLICATES_OK = ['compile_extra', 'link_extra']
     _EXTRA_ATTRIBUTES = ['use_cpp_linker', 'platform']
 
@@ -36,6 +36,7 @@
                  link_extra              = [],
                  frameworks              = [],
                  link_files              = [],
+                 testonly_libraries      = [],
                  use_cpp_linker          = False,
                  platform                = None):
         """
@@ -82,6 +83,10 @@
         link_files: list of file names which will be directly passed to the
         linker
 
+        testonly_libraries: list of libraries that are searched for during
+        testing only, by ll2ctypes.  Useful to search for a name in a dynamic
+        library during testing but use the static library for compilation.
+
         use_cpp_linker: a flag to tell if g++ should be used instead of gcc
         when linking (a bit custom so far)
 



More information about the Pypy-commit mailing list