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

Version Path
protobuf-2.7.12 bin/rprotoc
protobuf-2.8.0.beta9-java bin/rprotoc
protobuf-2.8.0.beta9 bin/rprotoc
protobuf-2.8.0.beta8-java bin/rprotoc
protobuf-2.8.0.beta8 bin/rprotoc
protobuf-2.8.0.beta6-java bin/rprotoc
protobuf-2.8.0.beta6 bin/rprotoc
protobuf-2.8.0.beta5-java bin/rprotoc
protobuf-2.8.0.beta5 bin/rprotoc
protobuf-2.8.0.beta4-java bin/rprotoc
protobuf-2.8.0.beta4 bin/rprotoc
protobuf-2.8.0.beta3-java bin/rprotoc
protobuf-2.8.0.beta3 bin/rprotoc
protobuf-2.8.0.beta2-java bin/rprotoc
protobuf-2.8.0.beta2 bin/rprotoc
protobuf-2.7.11-java bin/rprotoc
protobuf-2.7.11 bin/rprotoc
protobuf-2.8.0.beta1-java bin/rprotoc
protobuf-2.8.0.beta1 bin/rprotoc
protobuf-2.7.10-java bin/rprotoc