From 51dbf904348a226f954ad48e861b28290b8bd674 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Tue, 7 Jul 2015 16:00:06 -0700 Subject: [PATCH 1/5] Use pkg-config if possible when building the ruby extension --- src/ruby/ext/grpc/extconf.rb | 53 ++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index 6dd02344892..59fa87f8c02 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -54,31 +54,41 @@ LIB_DIRS = [ LIBDIR ] -# Check to see if GRPC_ROOT is defined or available -grpc_root = ENV['GRPC_ROOT'] -if grpc_root.nil? - r = File.expand_path(File.join(File.dirname(__FILE__), '../../../..')) - grpc_root = r if File.exist?(File.join(r, 'include/grpc/grpc.h')) +def crash(msg) + print(" extconf failure: #{msg}\n") + exit 1 +end + +def build_local_c(grpc_lib_dir, root, config) + grpc_already_built = File.exist?(File.join(grpc_lib_dir, 'libgrpc.a')) + system("make -C #{root} static_c CONFIG=#{config}") unless grpc_already_built end -# When grpc_root is available attempt to build the grpc core. -unless grpc_root.nil? +def local_fallback(msg) + # Check to see if GRPC_ROOT is defined or available + grpc_root = ENV['GRPC_ROOT'] + if grpc_root.nil? + r = File.expand_path(File.join(File.dirname(__FILE__), '../../../..')) + grpc_root = r if File.exist?(File.join(r, 'include/grpc/grpc.h')) + end + + # Stop if there is still no grpc_root + crash(msg) if grpc_root.nil? + grpc_config = ENV['GRPC_CONFIG'] || 'opt' if ENV.key?('GRPC_LIB_DIR') grpc_lib_dir = File.join(grpc_root, ENV['GRPC_LIB_DIR']) else grpc_lib_dir = File.join(File.join(grpc_root, 'libs'), grpc_config) end - unless File.exist?(File.join(grpc_lib_dir, 'libgrpc.a')) - system("make -C #{grpc_root} static_c CONFIG=#{grpc_config}") - end + build_local_c(grpc_lib_dir, grpc_root, grpc_config) HEADER_DIRS.unshift File.join(grpc_root, 'include') LIB_DIRS.unshift grpc_lib_dir -end -def crash(msg) - print(" extconf failure: #{msg}\n") - exit 1 + dir_config('grpc', HEADER_DIRS, LIB_DIRS) + have_library('grpc', 'grpc_channel_destroy') + create_makefile('grpc/grpc') + exit 0 end dir_config('grpc', HEADER_DIRS, LIB_DIRS) @@ -89,9 +99,18 @@ $CFLAGS << ' -Wno-return-type ' $CFLAGS << ' -Wall ' $CFLAGS << ' -pedantic ' -$LDFLAGS << ' -lgrpc -lgpr -lz -ldl' +grpc_pkg_config = system('pkg-config --exists grpc') + +if grpc_pkg_config + $CFLAGS << ' ' + `pkg-config --static --cflags grpc`.strip + ' ' + $LDFLAGS << ' ' + `pkg-config --static --libs grpc`.strip + ' ' +else + $LDFLAGS << ' -lgrpc -lgpr -lz -ldl' +end -crash('need grpc lib') unless have_library('grpc', 'grpc_channel_destroy') +local_fallback('need gpr lib') unless have_library('gpr', 'gpr_now') +unless have_library('grpc', 'grpc_channel_destroy') + local_fallback('need grpc lib') +end have_library('grpc', 'grpc_channel_destroy') -crash('need gpr lib') unless have_library('gpr', 'gpr_now') create_makefile('grpc/grpc') From 0b90c1e5e80cf8ad75dd7cdd3f341389686ceb1d Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Tue, 7 Jul 2015 17:44:46 -0700 Subject: [PATCH 2/5] Fixed ruby local build fallback case --- src/ruby/ext/grpc/extconf.rb | 78 +++++++++++++++--------------------- 1 file changed, 33 insertions(+), 45 deletions(-) diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index 59fa87f8c02..105689627bf 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -54,45 +54,6 @@ LIB_DIRS = [ LIBDIR ] -def crash(msg) - print(" extconf failure: #{msg}\n") - exit 1 -end - -def build_local_c(grpc_lib_dir, root, config) - grpc_already_built = File.exist?(File.join(grpc_lib_dir, 'libgrpc.a')) - system("make -C #{root} static_c CONFIG=#{config}") unless grpc_already_built -end - -def local_fallback(msg) - # Check to see if GRPC_ROOT is defined or available - grpc_root = ENV['GRPC_ROOT'] - if grpc_root.nil? - r = File.expand_path(File.join(File.dirname(__FILE__), '../../../..')) - grpc_root = r if File.exist?(File.join(r, 'include/grpc/grpc.h')) - end - - # Stop if there is still no grpc_root - crash(msg) if grpc_root.nil? - - grpc_config = ENV['GRPC_CONFIG'] || 'opt' - if ENV.key?('GRPC_LIB_DIR') - grpc_lib_dir = File.join(grpc_root, ENV['GRPC_LIB_DIR']) - else - grpc_lib_dir = File.join(File.join(grpc_root, 'libs'), grpc_config) - end - build_local_c(grpc_lib_dir, grpc_root, grpc_config) - HEADER_DIRS.unshift File.join(grpc_root, 'include') - LIB_DIRS.unshift grpc_lib_dir - - dir_config('grpc', HEADER_DIRS, LIB_DIRS) - have_library('grpc', 'grpc_channel_destroy') - create_makefile('grpc/grpc') - exit 0 -end - -dir_config('grpc', HEADER_DIRS, LIB_DIRS) - $CFLAGS << ' -Wno-implicit-function-declaration ' $CFLAGS << ' -Wno-pointer-sign ' $CFLAGS << ' -Wno-return-type ' @@ -105,12 +66,39 @@ if grpc_pkg_config $CFLAGS << ' ' + `pkg-config --static --cflags grpc`.strip + ' ' $LDFLAGS << ' ' + `pkg-config --static --libs grpc`.strip + ' ' else - $LDFLAGS << ' -lgrpc -lgpr -lz -ldl' + dir_config('grpc', HEADER_DIRS, LIB_DIRS) + raise "libdl not found" unless have_library('dl', 'dlopen') + raise "zlib not found" unless have_library('z', 'inflate') + begin + raise "Fail" unless have_library('gpr', 'gpr_now') + raise "Fail" unless have_library('grpc', 'grpc_channel_destroy') + rescue + # Check to see if GRPC_ROOT is defined or available + grpc_root = ENV['GRPC_ROOT'] + if grpc_root.nil? + r = File.expand_path(File.join(File.dirname(__FILE__), '../../../..')) + grpc_root = r if File.exist?(File.join(r, 'include/grpc/grpc.h')) + end + + # Stop if there is still no grpc_root + exit 1 if grpc_root.nil? + + grpc_config = ENV['GRPC_CONFIG'] || 'opt' + if ENV.key?('GRPC_LIB_DIR') + grpc_lib_dir = File.join(grpc_root, ENV['GRPC_LIB_DIR']) + else + grpc_lib_dir = File.join(File.join(grpc_root, 'libs'), grpc_config) + end + unless File.exist?(File.join(grpc_lib_dir, 'libgrpc.a')) + print "Building internal gRPC\n" + system("make -C #{root} static_c CONFIG=#{config}") + end + $CFLAGS << ' -I' + File.join(grpc_root, 'include') + $LDFLAGS << ' -L' + grpc_lib_dir + raise "gpr not found" unless have_library('gpr', 'gpr_now') + raise "grpc not found" unless have_library('grpc', 'grpc_channel_destroy') + end end -local_fallback('need gpr lib') unless have_library('gpr', 'gpr_now') -unless have_library('grpc', 'grpc_channel_destroy') - local_fallback('need grpc lib') -end -have_library('grpc', 'grpc_channel_destroy') + create_makefile('grpc/grpc') From fa0fa18134e95850a9a15ace8e40f5d8fcf7e4d5 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Tue, 7 Jul 2015 18:02:00 -0700 Subject: [PATCH 3/5] Check more warnings in Ruby library, add -Werror --- src/ruby/ext/grpc/extconf.rb | 11 +++++------ src/ruby/ext/grpc/rb_server.c | 6 +++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index 105689627bf..de5b0ea3362 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -54,12 +54,6 @@ LIB_DIRS = [ LIBDIR ] -$CFLAGS << ' -Wno-implicit-function-declaration ' -$CFLAGS << ' -Wno-pointer-sign ' -$CFLAGS << ' -Wno-return-type ' -$CFLAGS << ' -Wall ' -$CFLAGS << ' -pedantic ' - grpc_pkg_config = system('pkg-config --exists grpc') if grpc_pkg_config @@ -100,5 +94,10 @@ else end end +$CFLAGS << ' -std=c99 ' +$CFLAGS << ' -Wall ' +$CFLAGS << ' -Wextra ' +$CFLAGS << ' -pedantic ' +$CFLAGS << ' -Werror ' create_makefile('grpc/grpc') diff --git a/src/ruby/ext/grpc/rb_server.c b/src/ruby/ext/grpc/rb_server.c index 9c0d24bf8fd..bed3b268505 100644 --- a/src/ruby/ext/grpc/rb_server.c +++ b/src/ruby/ext/grpc/rb_server.c @@ -68,8 +68,12 @@ static void grpc_rb_server_free(void *p) { /* Deletes the wrapped object if the mark object is Qnil, which indicates that no other object is the actual owner. */ + /* grpc_server_shutdown does not exist. Change this to something that does + or delete it */ if (svr->wrapped != NULL && svr->mark == Qnil) { - grpc_server_shutdown(svr->wrapped); + // grpc_server_shutdown(svr->wrapped); + // Aborting to indicate a bug + abort(); grpc_server_destroy(svr->wrapped); } From 9e56ce034f8f9d086c25ff7987d3a097cd365d15 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 8 Jul 2015 11:31:52 -0700 Subject: [PATCH 4/5] Fixed ruby build when rebuilding C core --- src/ruby/ext/grpc/extconf.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index de5b0ea3362..f49fbdecbc9 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -85,7 +85,7 @@ else end unless File.exist?(File.join(grpc_lib_dir, 'libgrpc.a')) print "Building internal gRPC\n" - system("make -C #{root} static_c CONFIG=#{config}") + system("make -C #{grpc_root} static_c CONFIG=#{grpc_config}") end $CFLAGS << ' -I' + File.join(grpc_root, 'include') $LDFLAGS << ' -L' + grpc_lib_dir From 0f1c42e38150b5f0c075f5aa7f5b68c4dc1ccb7a Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 8 Jul 2015 12:54:31 -0700 Subject: [PATCH 5/5] Fixed Rubocop errors in extconf.rb --- src/ruby/ext/grpc/extconf.rb | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index f49fbdecbc9..7972272e2df 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -54,6 +54,15 @@ LIB_DIRS = [ LIBDIR ] +def check_grpc_root + grpc_root = ENV['GRPC_ROOT'] + if grpc_root.nil? + r = File.expand_path(File.join(File.dirname(__FILE__), '../../../..')) + grpc_root = r if File.exist?(File.join(r, 'include/grpc/grpc.h')) + end + grpc_root +end + grpc_pkg_config = system('pkg-config --exists grpc') if grpc_pkg_config @@ -61,18 +70,14 @@ if grpc_pkg_config $LDFLAGS << ' ' + `pkg-config --static --libs grpc`.strip + ' ' else dir_config('grpc', HEADER_DIRS, LIB_DIRS) - raise "libdl not found" unless have_library('dl', 'dlopen') - raise "zlib not found" unless have_library('z', 'inflate') + fail 'libdl not found' unless have_library('dl', 'dlopen') + fail 'zlib not found' unless have_library('z', 'inflate') begin - raise "Fail" unless have_library('gpr', 'gpr_now') - raise "Fail" unless have_library('grpc', 'grpc_channel_destroy') + fail 'Fail' unless have_library('gpr', 'gpr_now') + fail 'Fail' unless have_library('grpc', 'grpc_channel_destroy') rescue # Check to see if GRPC_ROOT is defined or available - grpc_root = ENV['GRPC_ROOT'] - if grpc_root.nil? - r = File.expand_path(File.join(File.dirname(__FILE__), '../../../..')) - grpc_root = r if File.exist?(File.join(r, 'include/grpc/grpc.h')) - end + grpc_root = check_grpc_root # Stop if there is still no grpc_root exit 1 if grpc_root.nil? @@ -89,8 +94,8 @@ else end $CFLAGS << ' -I' + File.join(grpc_root, 'include') $LDFLAGS << ' -L' + grpc_lib_dir - raise "gpr not found" unless have_library('gpr', 'gpr_now') - raise "grpc not found" unless have_library('grpc', 'grpc_channel_destroy') + raise 'gpr not found' unless have_library('gpr', 'gpr_now') + raise 'grpc not found' unless have_library('grpc', 'grpc_channel_destroy') end end