Skip to content

Commit 5cb3db6

Browse files
JakobDegenfacebook-github-bot
authored andcommitted
oss: Add buck_build cfg (#2902)
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 599cfde commit 5cb3db6

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

shim/shims.bzl

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

8-
# @lint-ignore FBCODEBZLADDLOADS
8+
# @lint-ignore-every FBCODEBZLADDLOADS
9+
10+
prelude = native
11+
912
_SELECT_TYPE = type(select({"DEFAULT": []}))
1013

1114
def is_select(thing):
@@ -17,10 +20,9 @@ def cpp_library(
1720
undefined_symbols = None,
1821
visibility = ["PUBLIC"],
1922
**kwargs):
20-
_unused = (undefined_symbols) # @unused
23+
_unused = undefined_symbols # @unused
2124

22-
# @lint-ignore BUCKLINT: avoid "native is forbidden in fbcode"
23-
native.cxx_library(
25+
prelude.cxx_library(
2426
deps = _maybe_select_map(deps + external_deps_to_targets(external_deps), _fix_deps),
2527
visibility = visibility,
2628
preferred_linkage = "static",
@@ -49,9 +51,8 @@ def rust_library(
4951
# Reset visibility because internal and external paths are different.
5052
visibility = ["PUBLIC"]
5153

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],
54+
prelude.rust_library(
55+
rustc_flags = rustc_flags + [_CFG_BUCK_BUILD],
5556
deps = deps,
5657
visibility = visibility,
5758
mapped_srcs = mapped_srcs,
@@ -71,8 +72,8 @@ def rust_binary(
7172
deps = _maybe_select_map(deps, _fix_deps)
7273

7374
# @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],
75+
prelude.rust_binary(
76+
rustc_flags = rustc_flags + [_CFG_BUCK_BUILD],
7677
deps = deps,
7778
visibility = visibility,
7879
**kwargs
@@ -85,9 +86,8 @@ def rust_unittest(
8586
**kwargs):
8687
deps = _maybe_select_map(deps, _fix_deps)
8788

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],
89+
prelude.rust_test(
90+
rustc_flags = rustc_flags + [_CFG_BUCK_BUILD],
9191
deps = deps,
9292
visibility = visibility,
9393
**kwargs
@@ -129,8 +129,7 @@ def rust_protobuf_library(
129129
},
130130
)
131131

132-
# @lint-ignore BUCKLINT: avoid "Direct usage of native rules is not allowed."
133-
native.genrule(
132+
prelude.genrule(
134133
name = proto_name,
135134
srcs = protos + [
136135
"buck//third-party/proto:google_protobuf",
@@ -157,8 +156,7 @@ def rust_protobuf_library(
157156

158157
# For python tests only
159158
for proto in protos:
160-
# @lint-ignore BUCKLINT: avoid "Direct usage of native rules is not allowed."
161-
native.export_file(
159+
prelude.export_file(
162160
name = proto,
163161
visibility = ["PUBLIC"],
164162
)
@@ -169,17 +167,13 @@ def ocaml_binary(
169167
**kwargs):
170168
deps = _maybe_select_map(deps, _fix_deps)
171169

172-
# @lint-ignore BUCKLINT: avoid "native is forbidden in fbcode"
173-
native.ocaml_binary(
170+
prelude.ocaml_binary(
174171
deps = deps,
175172
visibility = visibility,
176173
**kwargs
177174
)
178175

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"
176+
_CFG_BUCK_BUILD = "--cfg=buck_build"
183177

184178
def _maybe_select_map(v, mapper):
185179
if is_select(v):

0 commit comments

Comments
 (0)