Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that ffi-compiler loads before using it to define tasks. (#14538) #14560

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 45 additions & 37 deletions ruby/lib/google/tasks/ffi.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "ffi-compiler/compile_task"

# # @param task [FFI::Compiler::CompileTask] task to configure
def configure_common_compile_task(task)
if FileUtils.pwd.include? 'ext'
Expand Down Expand Up @@ -49,46 +47,56 @@ def with_generated_files
end
end

desc "Compile Protobuf library for FFI"
namespace "ffi-protobuf" do
with_generated_files do
# Compile Ruby UPB separately in order to limit use of -DUPB_BUILD_API to one
# compilation unit.
desc "Compile UPB library for FFI"
namespace "ffi-upb" do
with_generated_files do
FFI::Compiler::CompileTask.new('ruby-upb') do |c|
configure_common_compile_task c
c.add_define "UPB_BUILD_API"
c.exclude << "/glue.c"
c.exclude << "/shared_message.c"
c.exclude << "/shared_convert.c"
if RbConfig::CONFIG['target_os'] =~ /darwin|linux/
c.cflags << "-fvisibility=hidden"
begin
require "ffi-compiler/compile_task"

desc "Compile Protobuf library for FFI"
namespace "ffi-protobuf" do
with_generated_files do
# Compile Ruby UPB separately in order to limit use of -DUPB_BUILD_API to one
# compilation unit.
desc "Compile UPB library for FFI"
namespace "ffi-upb" do
with_generated_files do
FFI::Compiler::CompileTask.new('ruby-upb') do |c|
configure_common_compile_task c
c.add_define "UPB_BUILD_API"
c.exclude << "/glue.c"
c.exclude << "/shared_message.c"
c.exclude << "/shared_convert.c"
if RbConfig::CONFIG['target_os'] =~ /darwin|linux/
c.cflags << "-fvisibility=hidden"
end
end
end
end
end

FFI::Compiler::CompileTask.new 'protobuf_c_ffi' do |c|
configure_common_compile_task c
# Ruby UPB was already compiled with different flags.
c.exclude << "/range2-neon.c"
c.exclude << "/range2-sse.c"
c.exclude << "/naive.c"
c.exclude << "/ruby-upb.c"
end
FFI::Compiler::CompileTask.new 'protobuf_c_ffi' do |c|
configure_common_compile_task c
# Ruby UPB was already compiled with different flags.
c.exclude << "/range2-neon.c"
c.exclude << "/range2-sse.c"
c.exclude << "/naive.c"
c.exclude << "/ruby-upb.c"
end

# Setup dependencies so that the .o files generated by building ffi-upb are
# available to link here.
# TODO Can this be simplified? Can the single shared library be used
# instead of the object files?
protobuf_c_task = Rake::Task[:default]
protobuf_c_shared_lib_task = Rake::Task[protobuf_c_task.prereqs.last]
ruby_upb_shared_lib_task = Rake::Task[:"ffi-upb:default"].prereqs.first
Rake::Task[ruby_upb_shared_lib_task].prereqs.each do |dependency|
protobuf_c_shared_lib_task.prereqs.prepend dependency
# Setup dependencies so that the .o files generated by building ffi-upb are
# available to link here.
# TODO Can this be simplified? Can the single shared library be used
# instead of the object files?
protobuf_c_task = Rake::Task[:default]
protobuf_c_shared_lib_task = Rake::Task[protobuf_c_task.prereqs.last]
ruby_upb_shared_lib_task = Rake::Task[:"ffi-upb:default"].prereqs.first
Rake::Task[ruby_upb_shared_lib_task].prereqs.each do |dependency|
protobuf_c_shared_lib_task.prereqs.prepend dependency
end
end
end
rescue LoadError
desc "Compile Protobuf library for FFI"
namespace "ffi-protobuf" do
task :default do
warn "Skipping build of FFI; `gem install ffi-compiler` to enable."
end
end
end

Loading