-
Notifications
You must be signed in to change notification settings - Fork 237
/
Copy pathgo_common.bzl
206 lines (177 loc) · 6.54 KB
/
go_common.bzl
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
# TODO(cjhopman): This was generated by scripts/hacks/rules_shim_with_docs.py,
# but should be manually edited going forward. There may be some errors in
# the generated docs, and so those should be verified to be accurate and
# well-formatted (and then delete this TODO)
load(":common.bzl", "LinkableDepType")
LinkMode = ["internal", "external"]
def _deps_arg():
return {
"deps": attrs.list(attrs.dep(), default = [], doc = """
The set of dependencies of this rule. Currently, this only supports go\\_library rules.
"""),
}
def _srcs_arg():
return {
"srcs": attrs.list(attrs.source(), default = [], doc = """
The set of source files to be compiled by this rule. .go files will be compiled with the Go
compiler, .s files will be compiled with the assembler, and everything else is assumed to be
files that may be `#include`d by the assembler.
"""),
}
def _package_root_arg():
return {
"package_root": attrs.option(attrs.string(), default = None, doc = """
Sets Go package direactory (relative to BUCK file).
By default (or if None passes) package_root is being detected automatically.
Empty string of Go package is on the same level as BUCK file otherwise the subdirectory name.
Example for srcs = ["foo/bar.go"], package_root = "foo"
"""),
}
def _link_style_arg():
return {
"link_style": attrs.option(attrs.enum(LinkableDepType), default = None, doc = """
Determines whether to build and link this rule's dependencies statically or dynamically. Can be
one of the following values: `static`, `static_pic` or `shared`.
This argument is relevant only if the cgo extension is enabled. Otherwise, Buck ignores this argument.
"""),
}
def _link_mode_arg():
return {
"link_mode": attrs.option(attrs.enum(LinkMode), default = None, doc = """
Determines the link mode (equivalent of `-mode`). Can be one of the following
values: `internal`, `external`.
If no value is provided, the mode is set automatically depending on the other args.
"""),
}
def _package_name_arg():
return {
"package_name": attrs.option(attrs.string(), default = None, doc = """
Sets the full name of the package being compiled. This defaults to the path from the buck root.
(e.g. given a ./.buckconfig, a rule in ./a/b/BUCK defaults to package "a/b")
"""),
}
def _compiler_flags_arg():
return {
"compiler_flags": attrs.list(attrs.string(), default = [], doc = """
The set of additional compiler flags to pass to `go tool compile`.
"""),
}
def _assembler_flags_arg():
return {
"assembler_flags": attrs.list(attrs.string(), default = [], doc = """
The set of additional assembler flags to pass to `go tool asm`.
"""),
}
def _linker_flags_arg():
return {
"linker_flags": attrs.list(attrs.arg(), default = [], doc = """
Extra linker flags passed to go link
"""),
}
def _external_linker_flags_arg():
return {
"external_linker_flags": attrs.list(attrs.arg(), default = [], doc = """
Extra external linker flags passed to go link via `-extld` argument.
"""),
}
def _embedcfg_arg():
return {
"embedcfg": attrs.option(attrs.source(), default = None, doc = """
The embedcfg.json file used by compiler to embed files defined by `//go:embed` directive.
This generation of this file is included in the `go` toolkit.
For example:
```
//go:embed *.txt
var fs embed.FS
```
If the folder contains two files (file1.txt and file2.txt), the embedcfg.json is:
```
{
"Patterns": {
"*.txt": ["file1.txt","file2.txt"]
},
"Files": {
"file1.txt": "",
"file2.txt": ""
}
}
```
"""),
}
def _cgo_enabled_arg():
return {
"cgo_enabled": attrs.option(attrs.bool(), default = None, doc = """
Analog of CGO_ENABLED env-var, applies to this target and its dependencies.
If None `go_toolchain.default_cgo_enabled` value will be applied.
"""),
}
def _override_cgo_enabled_arg():
return {
"override_cgo_enabled": attrs.option(attrs.bool(), default = None, doc = """
Per-target analog of CGO_ENABLED env-var, overrides its value for the target, but not for its dependencies.
"""),
}
def _race_arg():
return {
"race": attrs.bool(default = False, doc = """
If true, enable data race detection.
"""),
}
def _asan_arg():
return {
"asan": attrs.bool(default = False, doc = """
If true, enable ASAN.
"""),
}
def _build_tags_arg():
return {
"build_tags": attrs.list(attrs.string(), default = [], doc = """
Build tags to apply to this target and its dependencies.
"""),
}
def _cxx_compiler_flags_arg():
return {
"cxx_compiler_flags": attrs.list(attrs.arg(), default = [], doc = """
GCC/Clang flags to use when compiling any of the above C/C++ sources (which require compilation).
"""),
}
def _cxx_preprocessor_flags_arg():
return {
"cxx_preprocessor_flags": attrs.list(attrs.arg(), default = [], doc = """
GCC/Clang flags to use when preprocessing any of the above C/C++ sources (which require preprocessing).
"""),
}
def _generate_exported_header():
return {
"generate_exported_header": attrs.bool(default = False, doc = """
Generate header file with declaration for functions exported with `//export`
The header name for target `cell//foo/bar:lib` will be `foo/bar/lib.h`
"""),
}
go_common = struct(
deps_arg = _deps_arg,
srcs_arg = _srcs_arg,
package_root_arg = _package_root_arg,
link_style_arg = _link_style_arg,
link_mode_arg = _link_mode_arg,
package_name_arg = _package_name_arg,
compiler_flags_arg = _compiler_flags_arg,
assembler_flags_arg = _assembler_flags_arg,
linker_flags_arg = _linker_flags_arg,
external_linker_flags_arg = _external_linker_flags_arg,
embedcfg_arg = _embedcfg_arg,
cgo_enabled_arg = _cgo_enabled_arg,
override_cgo_enabled_arg = _override_cgo_enabled_arg,
race_arg = _race_arg,
asan_arg = _asan_arg,
build_tags_arg = _build_tags_arg,
cxx_compiler_flags_arg = _cxx_compiler_flags_arg,
cxx_preprocessor_flags_arg = _cxx_preprocessor_flags_arg,
generate_exported_header = _generate_exported_header,
)