diff --git a/build/buck2/README.md b/build/buck2/README.md new file mode 100644 index 00000000..c4237b1a --- /dev/null +++ b/build/buck2/README.md @@ -0,0 +1,16 @@ +# Easy buck2 builds for Facebook projects + +This directory contains buck2 targets designed to simplify buck2 builds of +Meta open source projects. + +The most notable target is `//build/buck2/install_deps`, which will attempt to +discover and install necessary third party packages from apt / dnf / etc. +See the "repos" directory for the currently supported platforms. + +## Deployment + +This directory is copied literally into a number of different Facebook open +source repositories. Any change made to code in this directory will be +automatically be replicated by our open source tooling into all GitHub hosted +repositories that use `buck2`. Typically this directory is copied +into the open source repositories as `build/buck2/`. diff --git a/build/buck2/install_deps/BUCK b/build/buck2/install_deps/BUCK new file mode 100644 index 00000000..99bab33a --- /dev/null +++ b/build/buck2/install_deps/BUCK @@ -0,0 +1,15 @@ +# 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("@fbcode_macros//build_defs:native_rules.bzl", "buck_sh_binary") + +oncall("open_source") + +buck_sh_binary( + name = "install_deps", + main = "install_deps.sh", + resources = glob(["repos/*"]), +) diff --git a/build/buck2/install_deps/install_deps.sh b/build/buck2/install_deps/install_deps.sh new file mode 100755 index 00000000..9cb370e5 --- /dev/null +++ b/build/buck2/install_deps/install_deps.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. + +if [ -z "$INSTALL_COMMAND" ]; then + if [ -f /etc/os-release ]; then + . /etc/os-release; + fi + + if command -v brew >/dev/null; then + ID="homebrew"; + fi + + if [ -f "$BUCK_DEFAULT_RUNTIME_RESOURCES/repos/$ID" ]; then + # shellcheck disable=SC1090 + . "$BUCK_DEFAULT_RUNTIME_RESOURCES/repos/$ID"; + else + echo "Unable to determine platform id / install commands"; + return 1; + fi +fi + +if [ -z "${BUCK2_COMMAND}" ]; then + if command -v buck2 >/dev/null; then + BUCK2_COMMAND="buck2" + elif command -v dotslash >/dev/null && [ -f ./buck2 ]; then + BUCK2_COMMAND="dotslash ./buck2" + else + echo "Unable to determine buck2 command"; + return 1; + fi +fi + +PKG_FILE=$(mktemp /tmp/buck2-install-pkgs.XXXXXX) + +eval "$BUCK2_COMMAND \\ + cquery \"attrregexfilter(labels, 'third-party:$ID:', deps(//...))\" \\ + --json --output-attribute=labels 2>/dev/null \\ + | grep -o \"third-party:$ID:[^\\\"]*\" \\ + | sort \\ + | uniq \\ + | sed \"s/third-party:$ID://\" \\ + > $PKG_FILE" + +echo "About to install the project dependencies with the following command:" +echo +eval "cat $PKG_FILE | xargs echo $INSTALL_COMMAND" +echo +echo "Press \"y\" to continue" +read -r REPLY +echo + +if expr "X$REPLY" : '^X[Yy]$' >/dev/null; then + eval "cat $PKG_FILE | xargs -r $INSTALL_COMMAND" +else + echo "Not installing dependencies" +fi + +rm "$PKG_FILE" diff --git a/build/buck2/install_deps/repos/fedora b/build/buck2/install_deps/repos/fedora new file mode 100755 index 00000000..6182343b --- /dev/null +++ b/build/buck2/install_deps/repos/fedora @@ -0,0 +1 @@ +INSTALL_COMMAND="sudo -E dnf install -y" diff --git a/build/buck2/install_deps/repos/homebrew b/build/buck2/install_deps/repos/homebrew new file mode 100755 index 00000000..5d1dafb8 --- /dev/null +++ b/build/buck2/install_deps/repos/homebrew @@ -0,0 +1 @@ +INSTALL_COMMAND="brew install" diff --git a/build/buck2/install_deps/repos/ubuntu b/build/buck2/install_deps/repos/ubuntu new file mode 100755 index 00000000..b1ce6800 --- /dev/null +++ b/build/buck2/install_deps/repos/ubuntu @@ -0,0 +1 @@ +INSTALL_COMMAND="sudo -E apt-get install -y"