1load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix") 2load("@rules_ruby//ruby:defs.bzl", "ruby_library") 3 4config_setting( 5 name = "requires_bundle", 6 constraint_values = ["@platforms//os:osx"], 7) 8 9cc_binary( 10 name = "protobuf_c.so", 11 linkshared = 1, 12 tags = ["manual"], 13 deps = ["//ruby/ext/google/protobuf_c"], 14) 15 16cc_binary( 17 name = "libprotobuf_c_ffi.so", 18 linkshared = 1, 19 tags = ["manual"], 20 deps = ["//ruby/ext/google/protobuf_c:protobuf_c_ffi"], 21) 22 23# Move the bundle to the location expected by our Ruby files. 24genrule( 25 name = "copy_bundle", 26 srcs = ["//ruby/ext/google/protobuf_c:bundle"], 27 outs = ["protobuf_c.bundle"], 28 cmd = "cp $< $@", 29 tags = ["manual"], 30) 31 32# Move the bundle to the location expected by our Ruby files. 33genrule( 34 name = "copy_ffi_bundle", 35 srcs = ["//ruby/ext/google/protobuf_c:ffi_bundle"], 36 outs = ["libprotobuf_c_ffi.bundle"], 37 cmd = "cp $< $@", 38 tags = ["manual"], 39 visibility = [ 40 "//ruby:__subpackages__", 41 ], 42) 43 44java_binary( 45 name = "protobuf_java_bin", 46 create_executable = False, 47 deploy_env = ["@rules_ruby//ruby/runtime:jruby_binary"], 48 runtime_deps = [ 49 "//ruby/src/main/java:protobuf_java", 50 ], 51) 52 53# Move the jar to the location expected by our Ruby files. 54genrule( 55 name = "copy_jar", 56 srcs = ["protobuf_java_bin_deploy.jar"], 57 outs = ["protobuf_java.jar"], 58 cmd = "cp $< $@", 59 tags = ["manual"], 60 visibility = ["//ruby:__subpackages__"], 61) 62 63ruby_library( 64 name = "protobuf_lib", 65 srcs = glob([ 66 "**/*.rb", 67 ]), 68 data = select({ 69 # Platform native implementations 70 "@rules_ruby//ruby/runtime:config_jruby": ["protobuf_java.jar"], 71 "@platforms//os:osx": ["protobuf_c.bundle"], 72 "//conditions:default": ["protobuf_c.so"], 73 }) + select({ 74 # FFI Implementations 75 "//ruby:macos_ffi_enabled": ["libprotobuf_c_ffi.bundle"], 76 "//ruby:linux_ffi_enabled": ["libprotobuf_c_ffi.so"], 77 "//conditions:default": [], 78 }), 79 includes = [ 80 "ruby", 81 "ruby/lib", 82 ], 83 visibility = ["//ruby:__pkg__"], 84 deps = [ 85 "//ruby:well_known_ruby_protos", 86 "@protobuf_bundle//:bigdecimal", 87 ] + select({ 88 "//ruby:ffi_enabled": [ 89 "@protobuf_bundle//:ffi", 90 "@protobuf_bundle//:ffi-compiler", 91 ], 92 "//conditions:default": [], 93 }), 94) 95 96pkg_files( 97 name = "dist_files", 98 srcs = glob([ 99 "**/*.rb", 100 "**/*.rake", 101 ]), 102 strip_prefix = strip_prefix.from_root(""), 103 visibility = ["//ruby:__pkg__"], 104) 105