diff --git a/build/fbcode_builder/getdeps.py b/build/fbcode_builder/getdeps.py index 647513fa5..79a5315f9 100755 --- a/build/fbcode_builder/getdeps.py +++ b/build/fbcode_builder/getdeps.py @@ -415,6 +415,11 @@ class InstallSysDepsCmd(ProjectCmdBase): packages = sorted(set(all_packages["deb"])) if packages: cmd_args = ["apt", "install", "-y"] + packages + elif manager == "homebrew": + packages = sorted(set(all_packages["homebrew"])) + if packages: + cmd_args = ["brew", "install"] + packages + else: host_tuple = loader.build_opts.host_type.as_tuple_string() print( diff --git a/build/fbcode_builder/getdeps/buildopts.py b/build/fbcode_builder/getdeps/buildopts.py index 44af5e471..05f77a6c2 100644 --- a/build/fbcode_builder/getdeps/buildopts.py +++ b/build/fbcode_builder/getdeps/buildopts.py @@ -14,7 +14,7 @@ from typing import Optional, Mapping from .copytree import containing_repo_type from .envfuncs import Env, add_path_entry -from .fetcher import get_fbsource_repo_data +from .fetcher import get_fbsource_repo_data, homebrew_package_prefix from .manifest import ContextGenerator from .platform import HostType, is_windows, get_available_ram @@ -206,6 +206,12 @@ class BuildOptions(object): sdkroot = subprocess.check_output(["xcrun", "--show-sdk-path"]) env["SDKROOT"] = sdkroot.decode().strip() + # MacOS includes a version of bison so homebrew won't automatically add + # its own version to PATH. Find where the homebrew bison is and prepend + # it to PATH. + if self.is_darwin() and self.host_type.get_package_manager() == "homebrew": + add_homebrew_package_to_path(env, "bison") + if self.fbsource_dir: env["YARN_YARN_OFFLINE_MIRROR"] = os.path.join( self.fbsource_dir, "xplat/third-party/yarn/offline-mirror" @@ -300,6 +306,14 @@ class BuildOptions(object): if os.path.isfile(cert_file): env["SSL_CERT_FILE"] = cert_file + # Try extra hard to find openssl, needed with homebrew on macOS + if ( + self.is_darwin() + and "OPENSSL_DIR" not in env + and "OPENSSL_ROOT_DIR" in os.environ + ): + env["OPENSSL_ROOT_DIR"] = os.environ["OPENSSL_ROOT_DIR"] + return env @@ -491,3 +505,9 @@ def setup_build_options(args, host_type=None): install_dir=args.install_prefix, **build_args ) + + +def add_homebrew_package_to_path(env, package): + prefix = homebrew_package_prefix(package) + if prefix and os.path.exists(os.path.join(prefix, "bin")): + add_path_entry(env, "PATH", os.path.join(prefix, "bin"), append=False) diff --git a/build/fbcode_builder/getdeps/fetcher.py b/build/fbcode_builder/getdeps/fetcher.py index c977e4c7e..50483b0f3 100644 --- a/build/fbcode_builder/getdeps/fetcher.py +++ b/build/fbcode_builder/getdeps/fetcher.py @@ -158,6 +158,7 @@ class SystemPackageFetcher(object): def __init__(self, build_options, packages): self.manager = build_options.host_type.get_package_manager() self.packages = packages.get(self.manager) + self.host_type = build_options.host_type if self.packages: self.installed = None else: @@ -172,6 +173,8 @@ class SystemPackageFetcher(object): cmd = ["rpm", "-q"] + sorted(self.packages) elif self.manager == "deb": cmd = ["dpkg", "-s"] + sorted(self.packages) + elif self.manager == "homebrew": + cmd = ["brew", "ls", "--versions"] + sorted(self.packages) if cmd: proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -181,9 +184,23 @@ class SystemPackageFetcher(object): else: # Need all packages to be present to consider us installed self.installed = False + else: self.installed = False + # Hack to make openssl discovery with homebrew work. If openssl was + # built with autoconf we could use autoconf.envcmd.OPENSSL_ROOT_DIR + # from the manifest, but it isn't, so handle the special case here. + if ( + self.installed + and self.host_type.is_darwin() + and self.manager == "homebrew" + and "openssl@1.1" in self.packages + ): + candidate = homebrew_package_prefix("openssl@1.1") + if os.path.exists(candidate): + os.environ["OPENSSL_ROOT_DIR"] = candidate + return bool(self.installed) def update(self): @@ -789,3 +806,14 @@ class ArchiveFetcher(Fetcher): def get_src_dir(self): return self.src_dir + + +def homebrew_package_prefix(package): + cmd = ["brew", "--prefix", package] + try: + proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + except FileNotFoundError: + return + + if proc.returncode == 0: + return proc.stdout.decode("utf-8").rstrip() diff --git a/build/fbcode_builder/getdeps/manifest.py b/build/fbcode_builder/getdeps/manifest.py index 0379f7ed3..0228f77d0 100644 --- a/build/fbcode_builder/getdeps/manifest.py +++ b/build/fbcode_builder/getdeps/manifest.py @@ -81,6 +81,7 @@ SCHEMA = { "autoconf.envcmd.LDFLAGS": {"optional_section": True}, "rpms": {"optional_section": True}, "debs": {"optional_section": True}, + "homebrew": {"optional_section": True}, "preinstalled.env": {"optional_section": True}, "bootstrap.args": {"optional_section": True}, "b2.args": {"optional_section": True}, @@ -112,6 +113,7 @@ ALLOWED_EXPR_SECTIONS = [ "debs", "shipit.pathmap", "shipit.strip", + "homebrew", ] @@ -358,6 +360,7 @@ class ManifestParser(object): return { "rpm": self.get_section_as_args("rpms", ctx), "deb": self.get_section_as_args("debs", ctx), + "homebrew": self.get_section_as_args("homebrew", ctx), } def _is_satisfied_by_preinstalled_environment(self, ctx): diff --git a/build/fbcode_builder/getdeps/platform.py b/build/fbcode_builder/getdeps/platform.py index eb03476dc..b454def2d 100644 --- a/build/fbcode_builder/getdeps/platform.py +++ b/build/fbcode_builder/getdeps/platform.py @@ -193,8 +193,10 @@ class HostType(object): ) def get_package_manager(self): - if not self.is_linux(): + if not self.is_linux() and not self.is_darwin(): return None + if self.is_darwin(): + return "homebrew" if self.distro in ("fedora", "centos", "centos_stream"): return "rpm" if self.distro.startswith(("debian", "ubuntu")): diff --git a/build/fbcode_builder/manifests/autoconf b/build/fbcode_builder/manifests/autoconf index 35963096c..8c8b88397 100644 --- a/build/fbcode_builder/manifests/autoconf +++ b/build/fbcode_builder/manifests/autoconf @@ -1,10 +1,13 @@ [manifest] name = autoconf -[rpms] +[debs] autoconf -[debs] +[homebrew] +autoconf + +[rpms] autoconf [download] diff --git a/build/fbcode_builder/manifests/automake b/build/fbcode_builder/manifests/automake index 71115068a..37ffb95d2 100644 --- a/build/fbcode_builder/manifests/automake +++ b/build/fbcode_builder/manifests/automake @@ -1,12 +1,15 @@ [manifest] name = automake -[rpms] +[homebrew] automake [debs] automake +[rpms] +automake + [download] url = http://ftp.gnu.org/gnu/automake/automake-1.16.1.tar.gz sha256 = 608a97523f97db32f1f5d5615c98ca69326ced2054c9f82e65bade7fc4c9dea8 diff --git a/build/fbcode_builder/manifests/bison b/build/fbcode_builder/manifests/bison index 6e355d052..a8a058263 100644 --- a/build/fbcode_builder/manifests/bison +++ b/build/fbcode_builder/manifests/bison @@ -1,10 +1,13 @@ [manifest] name = bison -[rpms] +[debs] bison -[debs] +[homebrew] +bison + +[rpms] bison [download.not(os=windows)] diff --git a/build/fbcode_builder/manifests/boost b/build/fbcode_builder/manifests/boost index b9ab0bf22..d64ac8286 100644 --- a/build/fbcode_builder/manifests/boost +++ b/build/fbcode_builder/manifests/boost @@ -15,6 +15,9 @@ BOOST_ROOT_1_78_0 [debs] libboost-all-dev +[homebrew] +boost + [rpms.all(distro=centos_stream,distro_vers=8)] boost169 boost169-math diff --git a/build/fbcode_builder/manifests/cmake b/build/fbcode_builder/manifests/cmake index 3836cb9cc..93909749a 100644 --- a/build/fbcode_builder/manifests/cmake +++ b/build/fbcode_builder/manifests/cmake @@ -1,6 +1,9 @@ [manifest] name = cmake +[homebrew] +cmake + [rpms] cmake diff --git a/build/fbcode_builder/manifests/cpptoml b/build/fbcode_builder/manifests/cpptoml index 4560e0562..124882c2a 100644 --- a/build/fbcode_builder/manifests/cpptoml +++ b/build/fbcode_builder/manifests/cpptoml @@ -1,6 +1,9 @@ [manifest] name = cpptoml +[homebrew] +cpptoml + [download] url = https://github.com/chadaustin/cpptoml/archive/refs/tags/v0.1.2.tar.gz sha256 = beda37e94f9746874436c8090c045fd80ae6f8a51f7c668c932a2b110a4fc277 diff --git a/build/fbcode_builder/manifests/double-conversion b/build/fbcode_builder/manifests/double-conversion index 2f01011bb..c9902acc6 100644 --- a/build/fbcode_builder/manifests/double-conversion +++ b/build/fbcode_builder/manifests/double-conversion @@ -5,6 +5,9 @@ name = double-conversion url = https://github.com/google/double-conversion/archive/v3.1.4.tar.gz sha256 = 95004b65e43fefc6100f337a25da27bb99b9ef8d4071a36a33b5e83eb1f82021 +[homebrew] +double-conversion + [rpms] double-conversion double-conversion-devel diff --git a/build/fbcode_builder/manifests/flex b/build/fbcode_builder/manifests/flex index f266c4033..e09464943 100644 --- a/build/fbcode_builder/manifests/flex +++ b/build/fbcode_builder/manifests/flex @@ -1,10 +1,13 @@ [manifest] name = flex -[rpms] +[debs] flex -[debs] +[homebrew] +flex + +[rpms] flex [download.not(os=windows)] diff --git a/build/fbcode_builder/manifests/libevent b/build/fbcode_builder/manifests/libevent index e102ad21a..3c96e0966 100644 --- a/build/fbcode_builder/manifests/libevent +++ b/build/fbcode_builder/manifests/libevent @@ -1,12 +1,15 @@ [manifest] name = libevent -[rpms] -libevent-devel - [debs] libevent-dev +[homebrew] +libevent + +[rpms] +libevent-devel + # Note that the CMakeLists.txt file is present only in # git repo and not in the release tarball, so take care # to use the github generated source tarball rather than diff --git a/build/fbcode_builder/manifests/libffi b/build/fbcode_builder/manifests/libffi index 386b1bd2b..0511287c2 100644 --- a/build/fbcode_builder/manifests/libffi +++ b/build/fbcode_builder/manifests/libffi @@ -1,13 +1,16 @@ [manifest] name = libffi +[debs] +libffi-dev + +[homebrew] +libffi + [rpms] libffi-devel libffi -[debs] -libffi-dev - [download] url = https://github.com/libffi/libffi/releases/download/v3.4.2/libffi-3.4.2.tar.gz sha256 = 540fb721619a6aba3bdeef7d940d8e9e0e6d2c193595bc243241b77ff9e93620 diff --git a/build/fbcode_builder/manifests/libgit2 b/build/fbcode_builder/manifests/libgit2 index 57f5cb7e3..27279d513 100644 --- a/build/fbcode_builder/manifests/libgit2 +++ b/build/fbcode_builder/manifests/libgit2 @@ -1,6 +1,9 @@ [manifest] name = libgit2 +[homebrew] +libgit2 + [rpms] libgit2-devel diff --git a/build/fbcode_builder/manifests/libsodium b/build/fbcode_builder/manifests/libsodium index d69bfcc4b..c37f4b5a6 100644 --- a/build/fbcode_builder/manifests/libsodium +++ b/build/fbcode_builder/manifests/libsodium @@ -1,13 +1,16 @@ [manifest] name = libsodium +[debs] +libsodium-dev + +[homebrew] +libsodium + [rpms] libsodium-devel libsodium-static -[debs] -libsodium-dev - [download.not(os=windows)] url = https://github.com/jedisct1/libsodium/releases/download/1.0.17/libsodium-1.0.17.tar.gz sha256 = 0cc3dae33e642cc187b5ceb467e0ad0e1b51dcba577de1190e9ffa17766ac2b1 diff --git a/build/fbcode_builder/manifests/libtool b/build/fbcode_builder/manifests/libtool index 1ec99b5f4..887a23cdf 100644 --- a/build/fbcode_builder/manifests/libtool +++ b/build/fbcode_builder/manifests/libtool @@ -1,6 +1,9 @@ [manifest] name = libtool +[homebrew] +libtool + [rpms] libtool diff --git a/build/fbcode_builder/manifests/libusb b/build/fbcode_builder/manifests/libusb index 74702d3f0..9b97c3a59 100644 --- a/build/fbcode_builder/manifests/libusb +++ b/build/fbcode_builder/manifests/libusb @@ -1,13 +1,16 @@ [manifest] name = libusb +[debs] +libusb-1.0-0-dev + +[homebrew] +libusb + [rpms] libusb-devel libusb -[debs] -libusb-1.0-0-dev - [download] url = https://github.com/libusb/libusb/releases/download/v1.0.22/libusb-1.0.22.tar.bz2 sha256 = 75aeb9d59a4fdb800d329a545c2e6799f732362193b465ea198f2aa275518157 diff --git a/build/fbcode_builder/manifests/libzmq b/build/fbcode_builder/manifests/libzmq index 4f555fa65..a36121d67 100644 --- a/build/fbcode_builder/manifests/libzmq +++ b/build/fbcode_builder/manifests/libzmq @@ -1,13 +1,16 @@ [manifest] name = libzmq +[debs] +libzmq3-dev + +[homebrew] +zeromq + [rpms] zeromq-devel zeromq -[debs] -libzmq3-dev - [download] url = https://github.com/zeromq/libzmq/releases/download/v4.3.1/zeromq-4.3.1.tar.gz sha256 = bcbabe1e2c7d0eec4ed612e10b94b112dd5f06fcefa994a0c79a45d835cd21eb diff --git a/build/fbcode_builder/manifests/lz4 b/build/fbcode_builder/manifests/lz4 index 03dbd9de4..c176b307b 100644 --- a/build/fbcode_builder/manifests/lz4 +++ b/build/fbcode_builder/manifests/lz4 @@ -1,6 +1,9 @@ [manifest] name = lz4 +[homebrew] +lz4 + [rpms] lz4-devel lz4-static diff --git a/build/fbcode_builder/manifests/lzo b/build/fbcode_builder/manifests/lzo index 342428ab5..fd474127b 100644 --- a/build/fbcode_builder/manifests/lzo +++ b/build/fbcode_builder/manifests/lzo @@ -1,12 +1,15 @@ [manifest] name = lzo -[rpms] -lzo-devel - [debs] liblzo2-dev +[homebrew] +lzo + +[rpms] +lzo-devel + [download] url = http://www.oberhumer.com/opensource/lzo/download/lzo-2.10.tar.gz sha256 = c0f892943208266f9b6543b3ae308fab6284c5c90e627931446fb49b4221a072 diff --git a/build/fbcode_builder/manifests/ninja b/build/fbcode_builder/manifests/ninja index 2b6c5dc8d..713c59d69 100644 --- a/build/fbcode_builder/manifests/ninja +++ b/build/fbcode_builder/manifests/ninja @@ -1,10 +1,13 @@ [manifest] name = ninja -[rpms] +[debs] ninja-build -[debs] +[homebrew] +ninja + +[rpms] ninja-build [download.os=windows] diff --git a/build/fbcode_builder/manifests/openssl b/build/fbcode_builder/manifests/openssl index 32700d29a..518733e7e 100644 --- a/build/fbcode_builder/manifests/openssl +++ b/build/fbcode_builder/manifests/openssl @@ -1,14 +1,17 @@ [manifest] name = openssl +[debs] +libssl-dev + +[homebrew] +openssl@1.1 + [rpms] openssl openssl-devel openssl-libs -[debs] -libssl-dev - [download] url = https://www.openssl.org/source/openssl-1.1.1l.tar.gz sha256 = 0b7a3e5e59c34827fe0c3a74b7ec8baef302b98fa80088d7f9153aa16fa76bd1 diff --git a/build/fbcode_builder/manifests/pcre b/build/fbcode_builder/manifests/pcre index 050231d5e..047f6352b 100644 --- a/build/fbcode_builder/manifests/pcre +++ b/build/fbcode_builder/manifests/pcre @@ -1,6 +1,9 @@ [manifest] name = pcre +[homebrew] +pcre + [rpms] pcre-devel pcre-static @@ -15,4 +18,3 @@ sha256 = 0b8e7465dc5e98c757cc3650a20a7843ee4c3edf50aaf60bb33fd879690d2c73 [build] builder = cmake subdir = pcre-8.43 - diff --git a/build/fbcode_builder/manifests/python b/build/fbcode_builder/manifests/python index 2dccc2cdf..f9877e783 100644 --- a/build/fbcode_builder/manifests/python +++ b/build/fbcode_builder/manifests/python @@ -1,6 +1,9 @@ [manifest] name = python +[homebrew] +python@3.8 + [rpms] python3 python3-devel diff --git a/build/fbcode_builder/manifests/re2 b/build/fbcode_builder/manifests/re2 index eb4d6a92c..945750afd 100644 --- a/build/fbcode_builder/manifests/re2 +++ b/build/fbcode_builder/manifests/re2 @@ -1,13 +1,16 @@ [manifest] name = re2 +[homebrew] +re2 + +[debs] +libre2-dev + [rpms] re2 re2-devel -[debs] -libre2-dev - [download] url = https://github.com/google/re2/archive/2019-06-01.tar.gz sha256 = 02b7d73126bd18e9fbfe5d6375a8bb13fadaf8e99e48cbb062e4500fc18e8e2e diff --git a/build/fbcode_builder/manifests/sqlite3 b/build/fbcode_builder/manifests/sqlite3 index 2463f5761..c87d4cf93 100644 --- a/build/fbcode_builder/manifests/sqlite3 +++ b/build/fbcode_builder/manifests/sqlite3 @@ -1,13 +1,16 @@ [manifest] name = sqlite3 +[debs] +libsqlite3-dev + +[homebrew] +sqlite + [rpms] sqlite-devel sqlite-libs -[debs] -libsqlite3-dev - [download] url = https://sqlite.org/2019/sqlite-amalgamation-3280000.zip sha256 = d02fc4e95cfef672b45052e221617a050b7f2e20103661cda88387349a9b1327 diff --git a/build/fbcode_builder/manifests/tree b/build/fbcode_builder/manifests/tree index 0c982f35a..ccd0180a7 100644 --- a/build/fbcode_builder/manifests/tree +++ b/build/fbcode_builder/manifests/tree @@ -1,10 +1,13 @@ [manifest] name = tree -[rpms] +[debs] tree -[debs] +[homebrew] +tree + +[rpms] tree [download.os=linux] diff --git a/build/fbcode_builder/manifests/zlib b/build/fbcode_builder/manifests/zlib index 8df0e3e48..74a0bf260 100644 --- a/build/fbcode_builder/manifests/zlib +++ b/build/fbcode_builder/manifests/zlib @@ -1,13 +1,16 @@ [manifest] name = zlib +[debs] +zlib1g-dev + +[homebrew] +zlib + [rpms] zlib-devel zlib-static -[debs] -zlib1g-dev - [download] url = http://www.zlib.net/zlib-1.2.11.tar.gz sha256 = c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1 diff --git a/build/fbcode_builder/manifests/zstd b/build/fbcode_builder/manifests/zstd index b0b3bc028..73cfbe1e1 100644 --- a/build/fbcode_builder/manifests/zstd +++ b/build/fbcode_builder/manifests/zstd @@ -1,6 +1,9 @@ [manifest] name = zstd +[homebrew] +zstd + [rpms] libzstd-devel libzstd