-
-
Notifications
You must be signed in to change notification settings - Fork 167
/
Copy pathobjc.go
135 lines (125 loc) · 4.45 KB
/
objc.go
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
package main
var objcLibraryRuleTemplateString = `load("@rules_cc//cc:defs.bzl", "objc_library")
load("@rules_proto_grpc//:defs.bzl", "bazel_build_rule_common_attrs", "filter_files", "proto_compile_attrs")
load("//:{{ .Lang.Name }}_{{ .Rule.Kind }}_compile.bzl", "{{ .Lang.Name }}_{{ .Rule.Kind }}_compile")
def {{ .Rule.Name }}(name, **kwargs): # buildifier: disable=function-docstring
# Compile protos
name_pb = name + "_pb"
{{ .Lang.Name }}_{{ .Rule.Kind }}_compile(
name = name_pb,
{{ .Common.CompileArgsForwardingSnippet }}
)
# Filter files to sources and headers
filter_files(
name = name_pb + "_srcs",
target = name_pb,
extensions = ["m"],
)
filter_files(
name = name_pb + "_hdrs",
target = name_pb,
extensions = ["h"],
)
`
var objcProtoLibraryRuleTemplate = mustTemplate(objcLibraryRuleTemplateString + `
# Create {{ .Lang.Name }} library
objc_library(
name = name,
non_arc_srcs = [name_pb + "_srcs"],
deps = PROTO_DEPS + kwargs.get("deps", []),
hdrs = [name_pb + "_hdrs"],
includes = [name_pb],
**{
k: v
for (k, v) in kwargs.items()
if k in bazel_build_rule_common_attrs + [
"alwayslink",
"copts",
"defines",
"include_prefix",
"linkopts",
"linkstatic",
"local_defines",
"nocopts",
"strip_include_prefix",
]
}
)
PROTO_DEPS = [
Label("@protobuf//:protobuf_objc"),
]`)
var objcGrpcLibraryRuleTemplate = mustTemplate(objcLibraryRuleTemplateString + `
# Create {{ .Lang.Name }} library
objc_library(
name = name,
non_arc_srcs = [name_pb],
deps = GRPC_DEPS + kwargs.get("deps", []),
includes = [name_pb],
**{
k: v
for (k, v) in kwargs.items()
if k in bazel_build_rule_common_attrs + [
"alwayslink",
"copts",
"defines",
"include_prefix",
"linkopts",
"linkstatic",
"local_defines",
"nocopts",
"strip_include_prefix",
]
}
)
GRPC_DEPS = [
Label("@protobuf//:protobuf_objc"),
Label("@grpc//src/objective-c:proto_objc_rpc"),
]`)
var objcModulePrefixLines = `bazel_dep(name = "apple_support", version = "1.15.1")` // Need apple_support loaded as early as possible for toolchain
func makeObjc() *Language {
return &Language{
Name: "objc",
DisplayName: "Objective-C",
Notes: mustTemplate("Rules for generating Objective-C protobuf and gRPC ``.m`` & ``.h`` files and libraries using standard Protocol Buffers and gRPC. Libraries are created with the Bazel native ``objc_library``"),
SkipTestPlatforms: []string{"linux", "windows"},
ModulePrefixLines: objcModulePrefixLines,
Rules: []*Rule{
&Rule{
Name: "objc_proto_compile",
Kind: "proto",
Implementation: compileRuleTemplate,
Plugins: []string{"//:proto_plugin"},
BuildExample: protoCompileExampleTemplate,
Doc: "Generates Objective-C protobuf ``.m`` & ``.h`` files",
Attrs: compileRuleAttrs,
},
&Rule{
Name: "objc_grpc_compile",
Kind: "grpc",
Implementation: compileRuleTemplate,
Plugins: []string{"//:proto_plugin", "//:grpc_plugin"},
BuildExample: grpcCompileExampleTemplate,
Doc: "Generates Objective-C protobuf and gRPC ``.m`` & ``.h`` files",
Attrs: compileRuleAttrs,
},
&Rule{
Name: "objc_proto_library",
Kind: "proto",
Implementation: objcProtoLibraryRuleTemplate,
BuildExample: protoLibraryExampleTemplate,
Doc: "Generates an Objective-C protobuf library using ``objc_library``",
Attrs: cppLibraryRuleAttrs,
},
&Rule{
Name: "objc_grpc_library",
Kind: "grpc",
Implementation: objcGrpcLibraryRuleTemplate,
SkipTestPlatforms: []string{"all"}, // Current gRPC in BCR is broken due to missing rules_apple
BuildExample: grpcLibraryExampleTemplate,
Doc: "Generates an Objective-C protobuf and gRPC library using ``objc_library``",
Attrs: cppLibraryRuleAttrs,
Experimental: true,
},
},
}
}