Subject:
[ruby-ffi] [BUG] ffi 0.5.4 on OSX ?
From:
Jeremy Hinegardner
Date:
12/9/09 11:01 PM
To:
ruby-ffi@googlegroups.com

I just tried updating to 0.5.4 and ended up with this:

    http://pastie.org/736768

Doing some digging into the code reveals that in the extconf.rb it fails
to find the 'ffi.h' header, but the link tests for ffi_call and
ffi_prep_closure succeed so libffi_ok is true in extconf.rb.
When the extension builds, it fails because ffi.h is not in the include
path.

It looks to me as if ffi already exits on my OSX
(/usr/include/ffi/ffi.h), but but it is version 2.1 instead of the
shipped version 3.0.6 of ffi with gem version 0.5.4

    % grep VERSION /usr/include/ffi/ffi*
    /usr/include/ffi/fficonfig.h:#define PACKAGE_VERSION "2.1"
    /usr/include/ffi/fficonfig.h:#define VERSION "2.1-pyobjc"

Adding "/usr/include/ffi" to the find_header() call results in conflicts
on the PACKAGE_BUGREPORT, PACKAGE_NAME, PACKAGE_STRING, PACKAGE_TARNAME,
and PACKAGE_VERSION declarations.

I was able to work around the issue for me with the attached patch, but
it is probably not the correct way to deal with this issue.

enjoy,

-jeremy

-- ======================================================================== Jeremy Hinegardner jeremy@hinegardner.org

header-detection-0.5.4.patch

diff --git a/ext/ffi_c/extconf.rb b/ext/ffi_c/extconf.rb
index 08ef0b4..3786ad3 100644
--- a/ext/ffi_c/extconf.rb
+++ b/ext/ffi_c/extconf.rb
@@ -4,12 +4,13 @@ require 'rbconfig'
 dir_config("ffi_c")
 
 unless Config::CONFIG['host_os'] =~ /mswin32|mingw32/
-  pkg_config("libffi") || find_header("ffi.h", "/usr/local/include", "/opt/local/include")
-  have_ffi_call = have_library("ffi", "ffi_call", [ "ffi.h" ])
-  have_prep_closure = have_func("ffi_prep_closure")
-  libffi_ok = have_ffi_call && have_prep_closure
-  $defs << "-DHAVE_LIBFFI" if libffi_ok
-  $defs << "-DHAVE_RAW_API" if have_func("ffi_raw_call") && have_func("ffi_prep_raw_closure")
+  if pkg_config("libffi") || find_header("ffi.h", "/usr/local/include", "/opt/local/include") then
+    have_ffi_call = have_library("ffi", "ffi_call", [ "ffi.h" ])
+    have_prep_closure = have_func("ffi_prep_closure")
+    libffi_ok = have_ffi_call && have_prep_closure
+    $defs << "-DHAVE_LIBFFI" if libffi_ok
+    $defs << "-DHAVE_RAW_API" if have_func("ffi_raw_call") && have_func("ffi_prep_raw_closure")
+  end
 end
 have_func('rb_thread_blocking_region')
 

Attachments:
header-detection-0.5.4.patch1.1 KB