Sha256: 4fa9b3a8628b3de9e5df5ef600b991b92c436347025a45e9708b1f1ce69da35d
Contents?: true
Size: 1.85 KB
Versions: 115
Compression:
Stored size: 1.85 KB
Contents
#!/usr/bin/env ruby require 'rubygems' require 'ffi' base_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) GENERATOR_FILE_PATH = case when File.exists?(File.join(base_dir, "ruby_generator.bundle")) then File.join(base_dir, "ruby_generator.bundle") when File.exists?(File.join(base_dir, "ruby_generator.dll")) then File.join(base_dir, "ruby_generator.dll") else File.join(base_dir, "ruby_generator.so") end unless File.exists?(GENERATOR_FILE_PATH) $stdout << <<-WARNING Cannot locate shared object to plugin to protocol buffers generator. Thought the file would be located at #{GENERATOR_FILE_PATH} If you are running on Windows you should compile protocol buffer definitions on another VM and then use those definitions locally. Only the compiler is restricted by this. The definitions should work without issue. WARNING $stdout << $/ exit 1 end module Protobuf module RProtoC extend FFI::Library ffi_lib ::GENERATOR_FILE_PATH attach_function :_rprotoc_extern, [:int, :pointer], :int32 def self.compile_proto(args) GC.disable # Don't want strings to be GC'd while protoc has them args = args.dup args.unshift("rprotoc") args << "--help" if args.size == 1 ptr_params = [] args.each do |param| ptr_params << ::FFI::MemoryPointer.from_string(param.dup) end ptr_params << nil argv = ::FFI::MemoryPointer.new(:pointer, ptr_params.size) ptr_params.each_with_index do |param_pointer, index| argv[index].put_pointer(0, param_pointer) end self._rprotoc_extern(ptr_params.compact.size, argv) ensure GC.enable end end end ::Protobuf::RProtoC.compile_proto(ARGV)
Version data entries
115 entries across 115 versions & 1 rubygems