aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2016-01-31 11:33:19 +0100
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2016-01-31 11:37:13 +0100
commitd51d121c0c52205393ae607ebfab5e50b5c9a491 (patch)
tree4962ddb1949b6814251d6d479e898f103b2a4fdb /src
parent763cc089284b47b0a8fffc14b5e143fa90b2743b (diff)
And the Windows extension finally loads.
Diffstat (limited to 'src')
-rw-r--r--src/ruby/ext/grpc/extconf.rb22
-rw-r--r--src/ruby/ext/grpc/rb_byte_buffer.c4
-rw-r--r--src/ruby/ext/grpc/rb_call.c2
-rw-r--r--src/ruby/ext/grpc/rb_call_credentials.c2
-rw-r--r--src/ruby/ext/grpc/rb_channel.c4
-rw-r--r--src/ruby/ext/grpc/rb_channel_args.c4
-rw-r--r--src/ruby/ext/grpc/rb_channel_credentials.c4
-rw-r--r--src/ruby/ext/grpc/rb_completion_queue.c4
-rw-r--r--src/ruby/ext/grpc/rb_event_thread.c2
-rw-r--r--src/ruby/ext/grpc/rb_grpc.c10
-rw-r--r--src/ruby/ext/grpc/rb_grpc_imports.generated.c1
-rw-r--r--src/ruby/ext/grpc/rb_loader.c72
-rw-r--r--src/ruby/ext/grpc/rb_loader.h40
-rw-r--r--src/ruby/ext/grpc/rb_server.c4
-rw-r--r--src/ruby/ext/grpc/rb_server_credentials.c4
15 files changed, 153 insertions, 26 deletions
diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb
index 84ee3f8364..b259f8146f 100644
--- a/src/ruby/ext/grpc/extconf.rb
+++ b/src/ruby/ext/grpc/extconf.rb
@@ -54,6 +54,8 @@ LIB_DIRS = [
LIBDIR
]
+windows = RUBY_PLATFORM =~ /mingw|mswin/
+
grpc_root = File.expand_path(File.join(File.dirname(__FILE__), '../../../..'))
grpc_config = ENV['GRPC_CONFIG'] || 'opt'
@@ -64,27 +66,16 @@ else
grpc_lib_dir = File.join(grpc_root, 'libs', grpc_config)
end
-unless File.exist?(File.join(grpc_lib_dir, 'libgrpc.a'))
+unless File.exist?(File.join(grpc_lib_dir, 'libgrpc.a')) or windows
for var in %w( CC AR ) do
ENV[var] = RbConfig::CONFIG[var]
end
ENV['LD'] = ENV['CC']
- if RUBY_PLATFORM =~ /mingw|mswin/
- ENV['SYSTEM'] = 'MINGW32'
- end
-
ENV['EMBED_OPENSSL'] = 'true'
ENV['EMBED_ZLIB'] = 'true'
- grpc_cppflags = ''
- grpc_cppflags << ' -D_WIN32_WINNT=0x600 '
- grpc_cppflags << ' -DUNICODE '
- grpc_cppflags << ' -D_UNICODE '
-
- ENV['CPPFLAGS'] = grpc_cppflags
-
output_dir = File.expand_path(RbConfig::CONFIG['topdir'])
grpc_lib_dir = File.join(output_dir, 'libs', grpc_config)
ENV['BUILDDIR'] = output_dir
@@ -95,7 +86,7 @@ unless File.exist?(File.join(grpc_lib_dir, 'libgrpc.a'))
end
$CFLAGS << ' -I' + File.join(grpc_root, 'include')
-$LDFLAGS << ' ' + File.join(grpc_lib_dir, 'libgrpc.a')
+$LDFLAGS << ' ' + File.join(grpc_lib_dir, 'libgrpc.a') unless windows
if grpc_config == 'gcov'
$CFLAGS << ' -O0 -fprofile-arcs -ftest-coverage'
$LDFLAGS << ' -fprofile-arcs -ftest-coverage -rdynamic'
@@ -108,11 +99,6 @@ $CFLAGS << ' -pedantic '
$CFLAGS << ' -Werror '
$CFLAGS << ' -Wno-format '
-case RUBY_PLATFORM
-when /mingw|mswin/
- $LDFLAGS << ' -static '
-end
-
output = File.join('grpc', 'grpc_c')
puts 'Generating Makefile for ' + output
create_makefile(output)
diff --git a/src/ruby/ext/grpc/rb_byte_buffer.c b/src/ruby/ext/grpc/rb_byte_buffer.c
index 0aa34c844e..db7cac363a 100644
--- a/src/ruby/ext/grpc/rb_byte_buffer.c
+++ b/src/ruby/ext/grpc/rb_byte_buffer.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,8 @@
*
*/
+#include <ruby/ruby.h>
+#include "rb_grpc_imports.generated.h"
#include "rb_byte_buffer.h"
#include <ruby/ruby.h>
diff --git a/src/ruby/ext/grpc/rb_call.c b/src/ruby/ext/grpc/rb_call.c
index 07864ebf59..af05ddf6e7 100644
--- a/src/ruby/ext/grpc/rb_call.c
+++ b/src/ruby/ext/grpc/rb_call.c
@@ -31,6 +31,8 @@
*
*/
+#include <ruby/ruby.h>
+#include "rb_grpc_imports.generated.h"
#include "rb_call.h"
#include <ruby/ruby.h>
diff --git a/src/ruby/ext/grpc/rb_call_credentials.c b/src/ruby/ext/grpc/rb_call_credentials.c
index ebcc6592c2..2426f106a9 100644
--- a/src/ruby/ext/grpc/rb_call_credentials.c
+++ b/src/ruby/ext/grpc/rb_call_credentials.c
@@ -31,6 +31,8 @@
*
*/
+#include <ruby/ruby.h>
+#include "rb_grpc_imports.generated.h"
#include "rb_call_credentials.h"
#include <ruby/ruby.h>
diff --git a/src/ruby/ext/grpc/rb_channel.c b/src/ruby/ext/grpc/rb_channel.c
index 2fb8a5cdf0..d1e48753f2 100644
--- a/src/ruby/ext/grpc/rb_channel.c
+++ b/src/ruby/ext/grpc/rb_channel.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,8 @@
*
*/
+#include <ruby/ruby.h>
+#include "rb_grpc_imports.generated.h"
#include "rb_channel.h"
#include <ruby/ruby.h>
diff --git a/src/ruby/ext/grpc/rb_channel_args.c b/src/ruby/ext/grpc/rb_channel_args.c
index 37dd981925..69827cea1c 100644
--- a/src/ruby/ext/grpc/rb_channel_args.c
+++ b/src/ruby/ext/grpc/rb_channel_args.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,8 @@
*
*/
+#include <ruby/ruby.h>
+#include "rb_grpc_imports.generated.h"
#include "rb_channel_args.h"
#include <ruby/ruby.h>
diff --git a/src/ruby/ext/grpc/rb_channel_credentials.c b/src/ruby/ext/grpc/rb_channel_credentials.c
index 3530081c6b..8c6fc3b7eb 100644
--- a/src/ruby/ext/grpc/rb_channel_credentials.c
+++ b/src/ruby/ext/grpc/rb_channel_credentials.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,8 @@
*
*/
+#include <ruby/ruby.h>
+#include "rb_grpc_imports.generated.h"
#include "rb_channel_credentials.h"
#include <ruby/ruby.h>
diff --git a/src/ruby/ext/grpc/rb_completion_queue.c b/src/ruby/ext/grpc/rb_completion_queue.c
index a7de96d718..1eb5a28750 100644
--- a/src/ruby/ext/grpc/rb_completion_queue.c
+++ b/src/ruby/ext/grpc/rb_completion_queue.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,8 @@
*
*/
+#include <ruby/ruby.h>
+#include "rb_grpc_imports.generated.h"
#include "rb_completion_queue.h"
#include <ruby/ruby.h>
diff --git a/src/ruby/ext/grpc/rb_event_thread.c b/src/ruby/ext/grpc/rb_event_thread.c
index 516f0bdad2..2649a1087f 100644
--- a/src/ruby/ext/grpc/rb_event_thread.c
+++ b/src/ruby/ext/grpc/rb_event_thread.c
@@ -31,6 +31,8 @@
*
*/
+#include <ruby/ruby.h>
+#include "rb_grpc_imports.generated.h"
#include "rb_event_thread.h"
#include <stdbool.h>
diff --git a/src/ruby/ext/grpc/rb_grpc.c b/src/ruby/ext/grpc/rb_grpc.c
index 9514d54c17..eefdb93d67 100644
--- a/src/ruby/ext/grpc/rb_grpc.c
+++ b/src/ruby/ext/grpc/rb_grpc.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,8 @@
*
*/
+#include <ruby/ruby.h>
+#include "rb_grpc_imports.generated.h"
#include "rb_grpc.h"
#include <math.h>
@@ -45,6 +47,7 @@
#include "rb_channel.h"
#include "rb_channel_credentials.h"
#include "rb_completion_queue.h"
+#include "rb_loader.h"
#include "rb_server.h"
#include "rb_server_credentials.h"
@@ -298,6 +301,11 @@ VALUE sym_details = Qundef;
VALUE sym_metadata = Qundef;
void Init_grpc_c() {
+ if (!grpc_rb_load_core()) {
+ rb_raise(rb_eLoadError, "Couldn't find or load gRPC's dynamic C core");
+ return;
+ }
+
grpc_init();
/* TODO: find alternative to ruby_vm_at_exit that is ok in Ruby 2.0 */
diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c
index a278b2ba99..23fc51b4e8 100644
--- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c
+++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c
@@ -31,6 +31,7 @@
*
*/
+#include <ruby/ruby.h>
#include <grpc/support/port_platform.h>
#ifdef GPR_WIN32
diff --git a/src/ruby/ext/grpc/rb_loader.c b/src/ruby/ext/grpc/rb_loader.c
new file mode 100644
index 0000000000..242535f164
--- /dev/null
+++ b/src/ruby/ext/grpc/rb_loader.c
@@ -0,0 +1,72 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "rb_grpc_imports.generated.h"
+
+#if GPR_WIN32
+#include <tchar.h>
+
+int grpc_rb_load_core() {
+#if GPR_ARCH_64
+ TCHAR fname[] = _T("grpc_c.64.ruby");
+#else
+ TCHAR fname[] = _T("grpc_c.32.ruby");
+#endif
+ HMODULE module = GetModuleHandle(_T("grpc_c.so"));
+ TCHAR path[2048 + 32] = _T("");
+ LPTSTR seek_back = NULL;
+ GetModuleFileName(module, path, 2048);
+
+ seek_back = _tcsrchr(path, _T('\\'));
+
+ while (seek_back) {
+ HMODULE grpc_c;
+ _tcscpy(seek_back + 1, fname);
+ grpc_c = LoadLibrary(path);
+ if (grpc_c) {
+ grpc_rb_load_imports(grpc_c);
+ return 1;
+ } else {
+ *seek_back = _T('\0');
+ seek_back = _tcsrchr(path, _T('\\'));
+ }
+ }
+
+ return 0;
+}
+
+#else
+
+int grpc_rb_load_core() { return 1; }
+
+#endif
diff --git a/src/ruby/ext/grpc/rb_loader.h b/src/ruby/ext/grpc/rb_loader.h
new file mode 100644
index 0000000000..d0c1613a64
--- /dev/null
+++ b/src/ruby/ext/grpc/rb_loader.h
@@ -0,0 +1,40 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPC_RB_LOADER_H_
+#define GRPC_RB_LOADER_H_
+
+/* Attempts to load the core if necessary, and return non-zero upon succes. */
+int grpc_rb_load_core();
+
+#endif /* GRPC_RB_BYTE_BUFFER_H_ */
diff --git a/src/ruby/ext/grpc/rb_server.c b/src/ruby/ext/grpc/rb_server.c
index ebdd7e1a34..37cc55a651 100644
--- a/src/ruby/ext/grpc/rb_server.c
+++ b/src/ruby/ext/grpc/rb_server.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,8 @@
*
*/
+#include <ruby/ruby.h>
+#include "rb_grpc_imports.generated.h"
#include "rb_server.h"
#include <ruby/ruby.h>
diff --git a/src/ruby/ext/grpc/rb_server_credentials.c b/src/ruby/ext/grpc/rb_server_credentials.c
index de57585e0b..f866aecd28 100644
--- a/src/ruby/ext/grpc/rb_server_credentials.c
+++ b/src/ruby/ext/grpc/rb_server_credentials.c
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,8 @@
*
*/
+#include <ruby/ruby.h>
+#include "rb_grpc_imports.generated.h"
#include "rb_server_credentials.h"
#include <ruby/ruby.h>