Skip to content

oss: Add buck_build cfg #2902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions shim/shims.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.

# @lint-ignore FBCODEBZLADDLOADS
# @lint-ignore-every FBCODEBZLADDLOADS

prelude = native

_SELECT_TYPE = type(select({"DEFAULT": []}))

def is_select(thing):
Expand All @@ -17,10 +20,9 @@ def cpp_library(
undefined_symbols = None,
visibility = ["PUBLIC"],
**kwargs):
_unused = (undefined_symbols) # @unused
_unused = undefined_symbols # @unused

# @lint-ignore BUCKLINT: avoid "native is forbidden in fbcode"
native.cxx_library(
prelude.cxx_library(
deps = _maybe_select_map(deps + external_deps_to_targets(external_deps), _fix_deps),
visibility = visibility,
preferred_linkage = "static",
Expand Down Expand Up @@ -49,9 +51,8 @@ def rust_library(
# Reset visibility because internal and external paths are different.
visibility = ["PUBLIC"]

# @lint-ignore BUCKLINT: avoid "Direct usage of native rules is not allowed."
native.rust_library(
rustc_flags = rustc_flags + [_CFG_BUCK_OSS_BUILD],
prelude.rust_library(
rustc_flags = rustc_flags + [_CFG_BUCK_BUILD],
deps = deps,
visibility = visibility,
mapped_srcs = mapped_srcs,
Expand All @@ -71,8 +72,8 @@ def rust_binary(
deps = _maybe_select_map(deps, _fix_deps)

# @lint-ignore BUCKLINT: avoid "Direct usage of native rules is not allowed."
native.rust_binary(
rustc_flags = rustc_flags + [_CFG_BUCK_OSS_BUILD],
prelude.rust_binary(
rustc_flags = rustc_flags + [_CFG_BUCK_BUILD],
deps = deps,
visibility = visibility,
**kwargs
Expand All @@ -85,9 +86,8 @@ def rust_unittest(
**kwargs):
deps = _maybe_select_map(deps, _fix_deps)

# @lint-ignore BUCKLINT: avoid "Direct usage of native rules is not allowed."
native.rust_test(
rustc_flags = rustc_flags + [_CFG_BUCK_OSS_BUILD],
prelude.rust_test(
rustc_flags = rustc_flags + [_CFG_BUCK_BUILD],
deps = deps,
visibility = visibility,
**kwargs
Expand Down Expand Up @@ -129,8 +129,7 @@ def rust_protobuf_library(
},
)

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

# For python tests only
for proto in protos:
# @lint-ignore BUCKLINT: avoid "Direct usage of native rules is not allowed."
native.export_file(
prelude.export_file(
name = proto,
visibility = ["PUBLIC"],
)
Expand All @@ -169,17 +167,13 @@ def ocaml_binary(
**kwargs):
deps = _maybe_select_map(deps, _fix_deps)

# @lint-ignore BUCKLINT: avoid "native is forbidden in fbcode"
native.ocaml_binary(
prelude.ocaml_binary(
deps = deps,
visibility = visibility,
**kwargs
)

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

def _maybe_select_map(v, mapper):
if is_select(v):
Expand Down