Skip to content

Commit

Permalink
Fill in missing pieces from macro layers for folly
Browse files Browse the repository at this point in the history
Summary:
I found these by repeatedly running `dotslash-oss ./buck2 targets ...` in the GitHub version of folly.

(third-party changes are in the next diff, split for reviewability)

These changes are just hacks to convert fbcode's macro layer to the buck2 prelude with the minimal work possible.

bypass-github-export-checks

Reviewed By: namanahuja

Differential Revision: D57383968

fbshipit-source-id: 825335b6650a09bc6596f4bcc36fe6af7688a7e0
  • Loading branch information
bigfootjon authored and facebook-github-bot committed May 21, 2024
1 parent ef02036 commit fc22004
Show file tree
Hide file tree
Showing 19 changed files with 1,011 additions and 22 deletions.
60 changes: 56 additions & 4 deletions shim/BUCK
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
load("@prelude//toolchains:demo.bzl", "system_demo_toolchains")
load("@prelude//toolchains:cxx.bzl", "system_cxx_toolchain")
load("@prelude//toolchains:genrule.bzl", "system_genrule_toolchain")
load("@prelude//toolchains:go.bzl", "system_go_toolchain")
load("@prelude//toolchains:haskell.bzl", "system_haskell_toolchain")
load("@prelude//toolchains:ocaml.bzl", "system_ocaml_toolchain")
load("@prelude//toolchains:python.bzl", "system_python_bootstrap_toolchain", "system_python_toolchain")
load("@prelude//toolchains:remote_test_execution.bzl", "remote_test_execution_toolchain")
load("@prelude//toolchains:rust.bzl", "system_rust_toolchain")

# All the default toolchains, suitable for a quick demo or early prototyping.
# Most real projects should copy/paste the implementation to configure them.
system_demo_toolchains()
oncall("open_source")

system_cxx_toolchain(
name = "cxx",
cxx_flags = ["-std=c++20"],
visibility = ["PUBLIC"],
)

system_genrule_toolchain(
name = "genrule",
visibility = ["PUBLIC"],
)

system_go_toolchain(
name = "go",
visibility = ["PUBLIC"],
)

system_haskell_toolchain(
name = "haskell",
visibility = ["PUBLIC"],
)

system_ocaml_toolchain(
name = "ocaml",
visibility = ["PUBLIC"],
)

system_python_toolchain(
name = "python",
visibility = ["PUBLIC"],
)

system_python_bootstrap_toolchain(
name = "python_bootstrap",
visibility = ["PUBLIC"],
)

system_rust_toolchain(
name = "rust",
default_edition = "2021",
visibility = ["PUBLIC"],
)

remote_test_execution_toolchain(
name = "remote_test_execution",
visibility = ["PUBLIC"],
)
17 changes: 17 additions & 0 deletions shim/antlir/fbpkg/fbpkg.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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.

def _builder(**_):
pass

def _buck_opts(**_):
pass

fbpkg = struct(
builder = _builder,
buck_opts = _buck_opts,
)
33 changes: 33 additions & 0 deletions shim/build_defs/auto_headers.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load("@prelude//utils:buckconfig.bzl", "read_choice")

AutoHeaders = struct(
NONE = "none",
# Uses a recursive glob to resolve all transitive headers under the given
# directory.
RECURSIVE_GLOB = "recursive_glob",
# Infer headers from sources of the rule.
SOURCES = "sources",
)

_VALUES = [
AutoHeaders.NONE,
AutoHeaders.RECURSIVE_GLOB,
AutoHeaders.SOURCES,
]

def get_auto_headers(auto_headers):
"""
Returns the level of auto-headers to apply to a rule.
Args:
auto_headers: One of the values in `AutoHeaders`
Returns:
The value passed in as auto_headers, or the value from configuration if
`auto_headers` is None
"""
if auto_headers != None:
if auto_headers not in _VALUES:
fail("unexpected `auto_headers` value: {!r}".format(auto_headers))
return auto_headers
return read_choice("cxx", "auto_headers", _VALUES, AutoHeaders.SOURCES)
13 changes: 13 additions & 0 deletions shim/build_defs/config.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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.

def _get_build_mode():
return ""

config = struct(
get_build_mode = _get_build_mode,
)
9 changes: 9 additions & 0 deletions shim/build_defs/cpp_benchmark.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 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.

def cpp_benchmark(**_):
pass
10 changes: 10 additions & 0 deletions shim/build_defs/cpp_binary.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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.

load("//:shims.bzl", _cpp_binary = "cpp_binary")

cpp_binary = _cpp_binary
10 changes: 10 additions & 0 deletions shim/build_defs/cpp_unittest.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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.

load("//:shims.bzl", _cpp_unittest = "cpp_unittest")

cpp_unittest = _cpp_unittest
9 changes: 9 additions & 0 deletions shim/build_defs/custom_rule.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 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.

def custom_rule(**_):
pass
11 changes: 11 additions & 0 deletions shim/build_defs/cython_library.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 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.

load("//build_defs:python_library.bzl", "python_library")

def cython_library(name, visibility = ["PUBLIC"], **_):
python_library(name = name, visibility = visibility)
5 changes: 5 additions & 0 deletions shim/build_defs/export_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@
def export_file(visibility = ["PUBLIC"], **kwargs):
# @lint-ignore BUCKLINT: avoid "native is forbidden in fbcode"
native.export_file(visibility = visibility, **kwargs)

def export_files(files, visibility = ["PUBLIC"], **kwargs):
# @lint-ignore BUCKLINT: avoid "native is forbidden in fbcode"
for file in files:
native.export_file(name = file, visibility = visibility, **kwargs)
4 changes: 4 additions & 0 deletions shim/build_defs/native_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ def alias(actual, visibility = ["PUBLIC"], **kwargs):
if actual.startswith("//buck2/"):
actual = "root//" + actual.removeprefix("//buck2/")
native.alias(actual = actual, visibility = visibility, **kwargs)

def buck_sh_binary(visibility = ["PUBLIC"], **kwargs):
# @lint-ignore BUCKLINT: avoid "native is forbidden in fbcode"
native.sh_binary(visibility = visibility, **kwargs)
10 changes: 10 additions & 0 deletions shim/build_defs/prebuilt_cpp_library.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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.

load("//:shims.bzl", _prebuilt_cpp_library = "prebuilt_cpp_library")

prebuilt_cpp_library = _prebuilt_cpp_library
12 changes: 12 additions & 0 deletions shim/build_defs/python_library.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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.

def python_library(srcs = [], visibility = ["PUBLIC"], **kwargs):
_unused = srcs # @unused

# @lint-ignore BUCKLINT: avoid "Direct usage of native rules is not allowed."
native.python_library(visibility = visibility, **kwargs)
12 changes: 12 additions & 0 deletions shim/build_defs/python_unittest.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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.

def python_unittest(srcs = [], **kwargs):
_unused = srcs # @unused

# @lint-ignore BUCKLINT: avoid "Direct usage of native rules is not allowed."
native.python_test(**kwargs)
41 changes: 41 additions & 0 deletions shim/lib/dicts.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Skylib module containing functions that operate on dictionaries."""

def _add(*dictionaries):
"""Returns a new `dict` that has all the entries of the given dictionaries.
If the same key is present in more than one of the input dictionaries, the
last of them in the argument list overrides any earlier ones.
This function is designed to take zero or one arguments as well as multiple
dictionaries, so that it follows arithmetic identities and callers can avoid
special cases for their inputs: the sum of zero dictionaries is the empty
dictionary, and the sum of a single dictionary is a copy of itself.
Args:
*dictionaries: Zero or more dictionaries to be added.
Returns:
A new `dict` that has all the entries of the given dictionaries.
"""
result = {}
for d in dictionaries:
result.update(d)
return result

dicts = struct(
add = _add,
)
Loading

0 comments on commit fc22004

Please sign in to comment.