Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extconf: add sdk helper, primarily for macOS #757

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion ext/ffi_c/extconf.rb
Expand Up @@ -4,11 +4,26 @@
require 'mkmf'
require 'rbconfig'

# Recent versions of macOS have removed /usr/include, which without this
# would break the logic below around finding/using the perfectly usable
# system libffi.
def sdk_path_if_needed
if File.exist?("/usr/include")
""
elsif File.exist?("/Applications/Xcode.app")
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
elsif File.exist?("/Library/Developer/CommandLineTools")
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
else
""
end
end

def system_libffi_usable?
# We need pkg_config or ffi.h
libffi_ok = pkg_config("libffi") ||
have_header("ffi.h") ||
find_header("ffi.h", "/usr/local/include", "/usr/include/ffi")
find_header("ffi.h", "/usr/local/include", "#{sdk_path_if_needed}/usr/include/ffi")

# Ensure we can link to ffi_call
libffi_ok &&= have_library("ffi", "ffi_call", [ "ffi.h" ]) ||
Expand Down