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

feat: add ability to build the extension over system library #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions ext/hiredis_ext/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
require 'mkmf'

def config_system_libraries?
enable_config("system-libraries", ENV.key?("USE_SYSTEM_LIBRARIES")) do |_, default|
arg_config("--use-system-libraries", default)
end
end

build_hiredis = true
unless have_header('sys/socket.h')
puts "Could not find <sys/socket.h> (Likely Windows)."
Expand Down Expand Up @@ -27,15 +33,21 @@
end

if build_hiredis
# Make sure hiredis is built...
Dir.chdir(hiredis_dir) do
success = system("#{make_program} static")
raise "Building hiredis failed" if !success
end
if config_system_libraries?
# Make sure that hiredis development modules are installed ...
find_header("hiredis.h", *["", "hiredis"].map {|p| File.join(RbConfig::CONFIG["includedir"], p) })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we expect hiredis.h to be installed in the Ruby include dir? I'm wondering why we wouldn't just keep things simple and leave this as find_header("hiredis.h").

have_library("hiredis")
else
# Make sure hiredis is built...
Dir.chdir(hiredis_dir) do
success = system("#{make_program} static")
raise "Building hiredis failed" if !success
end

# Statically link to hiredis (mkmf can't do this for us)
$CFLAGS << " -I#{hiredis_dir}"
$LDFLAGS << " #{hiredis_dir}/libhiredis.a"
# Statically link to hiredis (mkmf can't do this for us)
$CFLAGS << " -I#{hiredis_dir}"
$LDFLAGS << " #{hiredis_dir}/libhiredis.a"
end

have_func("rb_thread_fd_select")
create_makefile('hiredis/ext/hiredis_ext')
Expand Down