redis-rb / redis-client

Simple low level client for Redis 6+
MIT License
124 stars 60 forks source link

`hiredis-client` failed to compile on FreeBSD #71

Closed N0xFF closed 1 year ago

N0xFF commented 1 year ago

OS: FreeBSD 13.1-RELEASE amd64. Ruby: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-freebsd13.1].

current directory: /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/hiredis-client-0.11.2/ext/redis_client/hiredis
make DESTDIR\=
compiling hiredis_connection.c
linking shared-object redis_client/hiredis_connection.so
ld: error: /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/hiredis-client-0.11.2/ext/redis_client/hiredis/export.clang:1: unexpected
EOF
>>> _Init_hiredis_connection
>>> ^
clang: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1
Full log ``` Installing hiredis-client 0.11.2 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/hiredis-client-0.11.2/ext/redis_client/hiredis /root/.rbenv/versions/3.1.2/bin/ruby -I /root/.rbenv/versions/3.1.2/lib/ruby/3.1.0 -r ./siteconf20221122-34326-szp23j.rb extconf.rb checking for rb_hash_new_capa() in ruby.h... no checking for openssl/ssl.h... yes cc -std=c99 -pedantic -c -O3 -fPIC -DHIREDIS_TEST_SSL -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb alloc.c cc -std=c99 -pedantic -c -O3 -fPIC -DHIREDIS_TEST_SSL -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb net.c cc -std=c99 -pedantic -c -O3 -fPIC -DHIREDIS_TEST_SSL -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb hiredis.c cc -std=c99 -pedantic -c -O3 -fPIC -DHIREDIS_TEST_SSL -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb sds.c cc -std=c99 -pedantic -c -O3 -fPIC -DHIREDIS_TEST_SSL -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb async.c cc -std=c99 -pedantic -c -O3 -fPIC -DHIREDIS_TEST_SSL -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb read.c cc -std=c99 -pedantic -c -O3 -fPIC -DHIREDIS_TEST_SSL -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb sockcompat.c ar rcs libhiredis.a alloc.o net.o hiredis.o sds.o async.o read.o sockcompat.o cc -std=c99 -pedantic -c -O3 -fPIC -DHIREDIS_TEST_SSL -I/usr/local/opt/openssl/include -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb ssl.c ar rcs libhiredis_ssl.a ssl.o creating Makefile current directory: /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/hiredis-client-0.11.2/ext/redis_client/hiredis make DESTDIR\= clean current directory: /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/hiredis-client-0.11.2/ext/redis_client/hiredis make DESTDIR\= compiling hiredis_connection.c linking shared-object redis_client/hiredis_connection.so ld: error: /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/hiredis-client-0.11.2/ext/redis_client/hiredis/export.clang:1: unexpected EOF >>> _Init_hiredis_connection >>> ^ clang: error: linker command failed with exit code 1 (use -v to see invocation) *** Error code 1 Stop. make: stopped in /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/hiredis-client-0.11.2/ext/redis_client/hiredis make failed, exit code 1 Gem files will remain installed in /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/hiredis-client-0.11.2 for inspection. Results logged to /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/extensions/x86_64-freebsd-13/3.1.0/hiredis-client-0.11.2/gem_make.out /root/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:95:in `run' /root/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:44:in `block in make' /root/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:36:in `each' /root/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:36:in `make' /root/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:63:in `block in build' /root/.rbenv/versions/3.1.2/lib/ruby/3.1.0/tempfile.rb:317:in `open' /root/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/ext_conf_builder.rb:26:in `build' /root/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:161:in `build_extension' /root/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:195:in `block in build_extensions' /root/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:192:in `each' /root/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/ext/builder.rb:192:in `build_extensions' /root/.rbenv/versions/3.1.2/lib/ruby/3.1.0/rubygems/installer.rb:853:in `build_extensions' /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/rubygems_gem_installer.rb:72:in `build_extensions' /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/rubygems_gem_installer.rb:28:in `install' /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/source/rubygems.rb:207:in `install' /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/installer/gem_installer.rb:54:in `install' /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/installer/gem_installer.rb:16:in `install_from_spec' /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/installer/parallel_installer.rb:186:in `do_install' /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/installer/parallel_installer.rb:177:in `block in worker_pool' /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/worker.rb:62:in `apply_func' /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/worker.rb:57:in `block in process_queue' /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/worker.rb:54:in `loop' /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/worker.rb:54:in `process_queue' /root/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.26/lib/bundler/worker.rb:91:in `block (2 levels) in create_threads' An error occurred while installing hiredis-client (0.11.2), and Bundler cannot continue. In Gemfile: hiredis-client ```
irb(main):001:0> RbConfig::CONFIG['CC']
=> "clang"
# clang -v
FreeBSD clang version 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)
Target: x86_64-unknown-freebsd13.1
Thread model: posix
InstalledDir: /usr/bin
stanhu commented 1 year ago

I seem to remember we ran into something similar in pg_query where FreeBSD had to be treated differently here: https://github.com/pganalyze/pg_query/pull/222/files#diff-8e5f1c8bbc2ab74598f30b99a2798a7354372f46a4340bfa93815cd615825e30R17-R21

clang on FreeBSD might not support -Wl,-exported_symbols_list. It's listed as a Darwin-specific option in https://www.freebsd.org/cgi/man.cgi?query=gcc10&apropos=0&sektion=0&manpath=FreeBSD+12.2-RELEASE+and+Ports&arch=default&format=html. pg_query uses -Wl,--retain-symbols-file and a different symbol file.

https://github.com/emersion/mrsh/pull/82/files#diff-30d8f6be6320feeacf686be94f48c70869b52630e01ea625f0f15adc0d57c3e4R45-R55 uses -Wl,--version-script.

stanhu commented 1 year ago

@N0xFF Would you be able to see if this patch fixes the problem?

diff --git a/hiredis-client/ext/redis_client/hiredis/extconf.rb b/hiredis-client/ext/redis_client/hiredis/extconf.rb
index f88f184..c26d6a5 100644
--- a/hiredis-client/ext/redis_client/hiredis/extconf.rb
+++ b/hiredis-client/ext/redis_client/hiredis/extconf.rb
@@ -55,7 +55,7 @@ if RUBY_ENGINE == "ruby" && !RUBY_PLATFORM.match?(/mswin/)
   end

   cc_version = `#{RbConfig.expand("$(CC) --version".dup)}`
-  if cc_version.match?(/clang/i)
+  if cc_version.match?(/clang/i) && RUBY_PLATFORM =~ /darwin/
     $LDFLAGS << ' -Wl,-exported_symbols_list,"' << File.join(__dir__, 'export.clang') << '"'
     if RUBY_VERSION >= "3.2"
       $LDFLAGS << " -Wl,-exported_symbol,_ruby_abi_version"
N0xFF commented 1 year ago

Without changes:

# ruby extconf.rb
checking for rb_hash_new_capa() in ruby.h... no
checking for openssl/ssl.h... yes
gmake: Nothing to be done for 'static'.
creating Makefile

# make
linking shared-object redis_client/hiredis_connection.so
ld: error: /root/Ruby/redis-client/hiredis-client/ext/redis_client/hiredis/export.clang:1: unexpected EOF
>>> _Init_hiredis_connection
>>> ^
clang: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop.
make: stopped in /root/Ruby/redis-client/hiredis-client/ext/redis_client/hiredis

With changes:

# ruby extconf.rb
checking for rb_hash_new_capa() in ruby.h... no
checking for openssl/ssl.h... yes
gmake: Nothing to be done for 'static'.
creating Makefile

# make
linking shared-object redis_client/hiredis_connection.so