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