And the Windows extension finally loads.

pull/4936/head
Nicolas "Pixel" Noble 9 years ago
parent 763cc08928
commit d51d121c0c
  1. 7
      Rakefile
  2. 22
      src/ruby/ext/grpc/extconf.rb
  3. 4
      src/ruby/ext/grpc/rb_byte_buffer.c
  4. 2
      src/ruby/ext/grpc/rb_call.c
  5. 2
      src/ruby/ext/grpc/rb_call_credentials.c
  6. 4
      src/ruby/ext/grpc/rb_channel.c
  7. 4
      src/ruby/ext/grpc/rb_channel_args.c
  8. 4
      src/ruby/ext/grpc/rb_channel_credentials.c
  9. 4
      src/ruby/ext/grpc/rb_completion_queue.c
  10. 2
      src/ruby/ext/grpc/rb_event_thread.c
  11. 10
      src/ruby/ext/grpc/rb_grpc.c
  12. 1
      src/ruby/ext/grpc/rb_grpc_imports.generated.c
  13. 72
      src/ruby/ext/grpc/rb_loader.c
  14. 40
      src/ruby/ext/grpc/rb_loader.h
  15. 4
      src/ruby/ext/grpc/rb_server.c
  16. 4
      src/ruby/ext/grpc/rb_server_credentials.c

@ -24,6 +24,13 @@ Rake::ExtensionTask.new('grpc_c', spec) do |ext|
ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc')
ext.cross_compile = true
ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
ext.cross_compiling do |spec|
spec.files = %w( etc/roots.pem grpc_c.32.ruby grpc_c.64.ruby )
spec.files += Dir.glob('src/ruby/bin/**/*')
spec.files += Dir.glob('src/ruby/ext/**/*')
spec.files += Dir.glob('src/ruby/lib/**/*')
spec.files += Dir.glob('src/ruby/pb/**/*')
end
end
# Define the test suites

@ -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)

@ -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>

@ -31,6 +31,8 @@
*
*/
#include <ruby/ruby.h>
#include "rb_grpc_imports.generated.h"
#include "rb_call.h"
#include <ruby/ruby.h>

@ -31,6 +31,8 @@
*
*/
#include <ruby/ruby.h>
#include "rb_grpc_imports.generated.h"
#include "rb_call_credentials.h"
#include <ruby/ruby.h>

@ -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>

@ -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>

@ -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>

@ -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>

@ -31,6 +31,8 @@
*
*/
#include <ruby/ruby.h>
#include "rb_grpc_imports.generated.h"
#include "rb_event_thread.h"
#include <stdbool.h>

@ -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 */

@ -31,6 +31,7 @@
*
*/
#include <ruby/ruby.h>
#include <grpc/support/port_platform.h>
#ifdef GPR_WIN32

@ -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

@ -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_ */

@ -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>

@ -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>

Loading…
Cancel
Save