1load("@build_bazel_rules_apple//apple:apple_binary.bzl", "apple_binary") 2load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix") 3load("//upb/cmake:build_defs.bzl", "staleness_test") 4 5package(default_visibility = ["//ruby:__subpackages__"]) 6 7PROTOBUF_C_SOURCES = [ 8 "convert.c", 9 "convert.h", 10 "defs.c", 11 "defs.h", 12 "map.c", 13 "map.h", 14 "message.c", 15 "message.h", 16 "protobuf.c", 17 "protobuf.h", 18 "repeated_field.c", 19 "repeated_field.h", 20 "shared_convert.c", 21 "shared_convert.h", 22 "shared_message.c", 23 "shared_message.h", 24 "wrap_memcpy.c", 25] 26 27# We copy everything into a copy/ subdirectory so that we can use the 28# up-to-date Bazel-generated amalgamation files without conflicting with the 29# possibly stale checked-in amalgamations. 30genrule( 31 name = "copy_sources", 32 srcs = PROTOBUF_C_SOURCES + [ 33 "glue.c", 34 "//upb:gen_ruby_amalgamation", 35 ], 36 outs = ["copy/%s" % src for src in PROTOBUF_C_SOURCES] + [ 37 "copy/glue.c", 38 "copy/ruby-upb.h", 39 "copy/ruby-upb.c", 40 ], 41 cmd = "cp $(SRCS) $(RULEDIR)/copy", 42) 43 44cc_library( 45 name = "protobuf_c", 46 srcs = ["copy/%s" % src for src in PROTOBUF_C_SOURCES] + [ 47 "copy/ruby-upb.c", 48 "copy/ruby-upb.h", 49 ], 50 linkstatic = True, 51 target_compatible_with = select({ 52 "@rules_ruby//ruby/runtime:config_jruby": ["@platforms//:incompatible"], 53 "//conditions:default": [], 54 }), 55 deps = [ 56 "//third_party/utf8_range", 57 "@rules_ruby//ruby/runtime:headers", 58 ], 59 alwayslink = True, 60) 61 62# Needs to be compiled with UPB_BUILD_API in order to expose functions called 63# via FFI directly by Ruby. 64cc_library( 65 name = "upb_api", 66 srcs = [ 67 "copy/ruby-upb.c", 68 ], 69 hdrs = [ 70 "copy/ruby-upb.h", 71 ], 72 copts = ["-fvisibility=hidden"], 73 linkstatic = False, 74 local_defines = [ 75 "UPB_BUILD_API", 76 ], 77 target_compatible_with = select({ 78 "//ruby:ffi_disabled": ["@platforms//:incompatible"], 79 "//conditions:default": [], 80 }), 81 deps = [ 82 "//third_party/utf8_range", 83 ], 84) 85 86cc_library( 87 name = "protobuf_c_ffi", 88 srcs = ["copy/%s" % src for src in [ 89 "glue.c", 90 "shared_convert.c", 91 "shared_convert.h", 92 "shared_message.c", 93 "shared_message.h", 94 ]], 95 copts = [ 96 "-std=gnu99", 97 "-O3", 98 "-Wall", 99 "-Wsign-compare", 100 "-Wno-declaration-after-statement", 101 ], 102 linkstatic = True, 103 local_defines = [ 104 "NDEBUG", 105 ], 106 target_compatible_with = select({ 107 "//ruby:ffi_disabled": ["@platforms//:incompatible"], 108 "//conditions:default": [], 109 }), 110 deps = [":upb_api"], 111 alwayslink = 1, 112) 113 114apple_binary( 115 name = "ffi_bundle", 116 binary_type = "loadable_bundle", 117 linkopts = [ 118 "-undefined,dynamic_lookup", 119 "-multiply_defined,suppress", 120 ], 121 minimum_os_version = "10.11", 122 platform_type = "macos", 123 tags = ["manual"], 124 deps = [ 125 ":protobuf_c_ffi", 126 ], 127) 128 129apple_binary( 130 name = "bundle", 131 binary_type = "loadable_bundle", 132 linkopts = [ 133 "-undefined,dynamic_lookup", 134 "-multiply_defined,suppress", 135 ], 136 minimum_os_version = "10.11", 137 platform_type = "macos", 138 tags = ["manual"], 139 deps = [ 140 ":protobuf_c", 141 ], 142) 143 144pkg_files( 145 name = "dist_files", 146 srcs = glob([ 147 "*.h", 148 "*.c", 149 "*.rb", 150 "Rakefile", 151 ]), 152 strip_prefix = strip_prefix.from_root(""), 153 visibility = ["//ruby:__pkg__"], 154) 155 156genrule( 157 name = "copy_ruby_amalgamation_h", 158 srcs = ["//upb:ruby-upb.h"], 159 outs = ["generated-in/ruby-upb.h"], 160 cmd = "cp $< $@", 161) 162 163genrule( 164 name = "copy_ruby_amalgamation_c", 165 srcs = ["//upb:ruby-upb.c"], 166 outs = ["generated-in/ruby-upb.c"], 167 cmd = "cp $< $@", 168) 169 170staleness_test( 171 name = "test_amalgamation_staleness", 172 outs = [ 173 "ruby-upb.c", 174 "ruby-upb.h", 175 ], 176 generated_pattern = "generated-in/%s", 177 tags = ["manual"], 178) 179