Check it out in the intro video
Logical Design
Folly is a collection of relatively independent components, some as simple as a few symbols. There is no restriction on internal dependencies, meaning that a given folly module may use any other folly components.
All symbols are defined in the top-level namespace folly
, except of
course macros. Macro names are ALL_UPPERCASE and should be prefixed
with FOLLY_
. Namespace folly
defines other internal namespaces
such as internal
or detail
. User code should not depend on symbols
in those namespaces.
Folly has an experimental
directory as well. This designation connotes
primarily that we feel the API may change heavily over time. This code,
typically, is still in heavy use and is well tested.
What’s in it?
Because of folly’s fairly flat structure, the best way to see what’s in it
is to look at the headers in top level folly/
directory. You can also
check the docs
folder for documentation, starting with the
overview.
Folly is published on GitHub at https://github.com/facebook/folly.
getdeps.py
This script is used by many of Meta’s OSS tools. It will download and build all of the necessary dependencies first, and will then invoke cmake etc to build folly. This will help ensure that you build with relevant versions of all of the dependent libraries, taking into account what versions are installed locally on your system.
It’s written in python so you’ll need python3.6 or later on your PATH. It works on Linux, macOS and Windows.
The settings for folly’s cmake build are held in its getdeps manifest build/fbcode_builder/manifests/folly
, which you can edit locally if desired.
Run tests
By default getdeps.py
will build the tests for folly. To run them:
cd folly
python3 ./build/fbcode_builder/getdeps.py --allow-system-packages test
build.sh
/build.bat
wrapper
build.sh
can be used on Linux and MacOS, on Windows use
the build.bat
script instead. Its a wrapper around getdeps.py
.
Build with cmake directly
If you don’t want to let getdeps invoke cmake for you then by default, building the tests is disabled as part of the CMake all
target.
To build the tests, specify -DBUILD_TESTS=ON
to CMake at configure time.
NB if you want to invoke cmake
again to iterate on a getdeps.py
build, there is a helpful run_cmake.py
script output in the scratch-path build directory. You can find the scratch build directory from logs or with python3 ./build/fbcode_builder/getdeps.py show-build-dir
.
Running tests with ctests also works if you cd to the build dir, e.g.
(cd $(python3 ./build/fbcode_builder/getdeps.py show-build-dir) && ctest)
Finding dependencies in non-default locations
If you have boost, gtest, or other dependencies installed in a non-default
location, you can use the CMAKE_INCLUDE_PATH
and CMAKE_LIBRARY_PATH
variables to make CMAKE look also look for header files and libraries in
non-standard locations. For example, to also search the directories
/alt/include/path1
and /alt/include/path2
for header files and the
directories /alt/lib/path1
and /alt/lib/path2
for libraries, you can invoke
cmake
as follows:
cmake \
-DCMAKE_INCLUDE_PATH=/alt/include/path1:/alt/include/path2 \
-DCMAKE_LIBRARY_PATH=/alt/lib/path1:/alt/lib/path2 ...
Ubuntu LTS, CentOS Stream, Fedora
Use the getdeps.py
approach above. We test in CI on Ubuntu LTS, and occasionally on other distros.
If you find the set of system packages is not quite right for your chosen distro, you can specify distro version specific overrides in the dependency manifests (e.g. https://github.com/facebook/folly/blob/main/build/fbcode_builder/manifests/boost ). You could probably make it work on most recent Ubuntu/Debian or Fedora/Redhat derived distributions.
At time of writing (Dec 2021) there is a build break on GCC 11.x based systems in lang_badge_test. If you don’t need badge functionality you can work around by commenting it out from CMakeLists.txt (unfortunately fbthrift does need it)
Windows (Vcpkg)
Note that many tests are disabled for folly Windows builds, you can see them in the log from the cmake configure step, or by looking for WINDOWS_DISABLED in CMakeLists.txt
That said, getdeps.py
builds work on Windows and are tested in CI.
If you prefer, you can try Vcpkg. folly is available in Vcpkg and releases may be built via vcpkg install folly:x64-windows
.
You may also use vcpkg install folly:x64-windows --head
to build against main
.
macOS
getdeps.py
builds work on macOS and are tested in CI, however if you prefer, you can try one of the macOS package managers
Homebrew
folly is available as a Formula and releases may be built via brew install folly
.
You may also use folly/build/bootstrap-osx-homebrew.sh
to build against main
:
./folly/build/bootstrap-osx-homebrew.sh
This will create a build directory _build
in the top-level.
MacPorts
Install the required packages from MacPorts:
sudo port install \
boost \
cmake \
gflags \
git \
google-glog \
libevent \
libtool \
lz4 \
lzma \
openssl \
snappy \
xz \
zlib
Download and install double-conversion:
git clone https://github.com/google/double-conversion.git
cd double-conversion
cmake -DBUILD_SHARED_LIBS=ON .
make
sudo make install
Download and install folly with the parameters listed below:
git clone https://github.com/facebook/folly.git
cd folly
mkdir _build
cd _build
cmake ..
make
sudo make install