Skip to content

Commit 6183633

Browse files
JakobDegenfacebook-github-bot
authored andcommitted
oss: Add buck_build cfg
Summary: I'd like a simple way to check whether a build is using cargo or buck. Unfortunately, that doesn't exist right now. I suggest replacing the `buck_oss_build` cfg with a simpler `buck_build` cfg. This will be set internally via package files and externally via the OSS shim. (TBD: Should we set it in the macros internally too?) People can still recover the `#[cfg(buck_oss_build)]` behavior by checking `#[cfg(all(fbcode_build, buck_build))]`. Also, this diff cleans up some linter overrides via `prelude = native` Reviewed By: dtolnay Differential Revision: D55791957
1 parent 1e8c0ff commit 6183633

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

shim/shims.bzl

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
66
# of this source tree.
77

8+
prelude = native
9+
810
# @lint-ignore FBCODEBZLADDLOADS
911
_SELECT_TYPE = type(select({"DEFAULT": []}))
1012

@@ -19,8 +21,7 @@ def cpp_library(
1921
**kwargs):
2022
_unused = (undefined_symbols) # @unused
2123

22-
# @lint-ignore BUCKLINT: avoid "native is forbidden in fbcode"
23-
native.cxx_library(
24+
prelude.cxx_library(
2425
deps = _maybe_select_map(deps + external_deps_to_targets(external_deps), _fix_deps),
2526
visibility = visibility,
2627
preferred_linkage = "static",
@@ -49,9 +50,8 @@ def rust_library(
4950
# Reset visibility because internal and external paths are different.
5051
visibility = ["PUBLIC"]
5152

52-
# @lint-ignore BUCKLINT: avoid "Direct usage of native rules is not allowed."
53-
native.rust_library(
54-
rustc_flags = rustc_flags + [_CFG_BUCK_OSS_BUILD],
53+
prelude.rust_library(
54+
rustc_flags = rustc_flags + [_CFG_BUCK_BUILD],
5555
deps = deps,
5656
visibility = visibility,
5757
mapped_srcs = mapped_srcs,
@@ -71,8 +71,8 @@ def rust_binary(
7171
deps = _maybe_select_map(deps, _fix_deps)
7272

7373
# @lint-ignore BUCKLINT: avoid "Direct usage of native rules is not allowed."
74-
native.rust_binary(
75-
rustc_flags = rustc_flags + [_CFG_BUCK_OSS_BUILD],
74+
prelude.rust_binary(
75+
rustc_flags = rustc_flags + [_CFG_BUCK_BUILD],
7676
deps = deps,
7777
visibility = visibility,
7878
**kwargs
@@ -85,9 +85,8 @@ def rust_unittest(
8585
**kwargs):
8686
deps = _maybe_select_map(deps, _fix_deps)
8787

88-
# @lint-ignore BUCKLINT: avoid "Direct usage of native rules is not allowed."
89-
native.rust_test(
90-
rustc_flags = rustc_flags + [_CFG_BUCK_OSS_BUILD],
88+
prelude.rust_test(
89+
rustc_flags = rustc_flags + [_CFG_BUCK_BUILD],
9190
deps = deps,
9291
visibility = visibility,
9392
**kwargs
@@ -111,7 +110,7 @@ def rust_protobuf_library(
111110
build_name = name + "-build"
112111
proto_name = name + "-proto"
113112

114-
rust_binary(
113+
prelude.rust_binary(
115114
name = build_name,
116115
srcs = [build_script],
117116
crate_root = build_script,
@@ -129,8 +128,7 @@ def rust_protobuf_library(
129128
},
130129
)
131130

132-
# @lint-ignore BUCKLINT: avoid "Direct usage of native rules is not allowed."
133-
native.genrule(
131+
prelude.genrule(
134132
name = proto_name,
135133
srcs = protos + [
136134
"buck//third-party/proto:google_protobuf",
@@ -140,7 +138,7 @@ def rust_protobuf_library(
140138
env = build_env,
141139
)
142140

143-
rust_library(
141+
prelude.rust_library(
144142
name = name,
145143
srcs = srcs,
146144
doctests = doctests,
@@ -157,8 +155,7 @@ def rust_protobuf_library(
157155

158156
# For python tests only
159157
for proto in protos:
160-
# @lint-ignore BUCKLINT: avoid "Direct usage of native rules is not allowed."
161-
native.export_file(
158+
prelude.export_file(
162159
name = proto,
163160
visibility = ["PUBLIC"],
164161
)
@@ -169,17 +166,13 @@ def ocaml_binary(
169166
**kwargs):
170167
deps = _maybe_select_map(deps, _fix_deps)
171168

172-
# @lint-ignore BUCKLINT: avoid "native is forbidden in fbcode"
173-
native.ocaml_binary(
169+
prelude.ocaml_binary(
174170
deps = deps,
175171
visibility = visibility,
176172
**kwargs
177173
)
178174

179-
# Configuration that is used when building open source using Buck2 as the build system.
180-
# E.g. not applied either internally, or when using Cargo to build the open source code.
181-
# At the moment of writing, mostly used to disable jemalloc.
182-
_CFG_BUCK_OSS_BUILD = "--cfg=buck_oss_build"
175+
_CFG_BUCK_BUILD = "--cfg=buck_build"
183176

184177
def _maybe_select_map(v, mapper):
185178
if is_select(v):

0 commit comments

Comments
 (0)