consume fizz as an external project in cmake
Summary: Favor standalone cmake config than relying on custom script
MODIFY
CMakeLists.txt
CMakeLists.txt
@@ -27,7 +27,6 @@ find_package(Boost 1.62
context
)
find_package(folly REQUIRED)
-find_package(Fizz REQUIRED)
find_package(Glog REQUIRED)
find_package(Threads)
@@ -75,6 +74,7 @@ list(APPEND
-Wnon-virtual-dtor
)
+include(BuildFizz)
if(BUILD_TESTS)
enable_testing()
include(QuicTest)

MODIFY
build_helper.sh
build_helper.sh
@@ -55,13 +55,9 @@ mkdir -p "$MVFST_BUILD_DIR"
if [ -z "${INSTALL_PREFIX-}" ]; then
FOLLY_INSTALL_DIR=$DEPS_DIR
- FIZZ_INSTALL_DIR=$DEPS_DIR
- GTEST_INSTALL_DIR=$DEPS_DIR
MVFST_INSTALL_DIR=$BWD
else
FOLLY_INSTALL_DIR=$INSTALL_PREFIX
- FIZZ_INSTALL_DIR=$INSTALL_PREFIX
- GTEST_INSTALL_DIR=$INSTALL_PREFIX
MVFST_INSTALL_DIR=$INSTALL_PREFIX
fi
@@ -143,27 +139,6 @@ function setup_folly() {
cd "$BWD" || exit
}
-function setup_fizz() {
- FIZZ_DIR=$DEPS_DIR/fizz
- FIZZ_BUILD_DIR=$DEPS_DIR/fizz/build/
- if [ ! -d "$FIZZ_DIR" ] ; then
- echo -e "${COLOR_GREEN}[ INFO ] Cloning fizz repo ${COLOR_OFF}"
- git clone https://github.com/facebookincubator/fizz "$FIZZ_DIR"
- echo -e "${COLOR_GREEN}[ INFO ] install dependencies ${COLOR_OFF}"
- fi
- echo -e "${COLOR_GREEN}Building Fizz ${COLOR_OFF}"
- mkdir -p "$FIZZ_BUILD_DIR"
- cd "$FIZZ_BUILD_DIR" || exit
- cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
- -DCMAKE_PREFIX_PATH="$FIZZ_INSTALL_DIR" \
- -DCMAKE_INSTALL_PREFIX="$FIZZ_INSTALL_DIR" \
- "$FIZZ_DIR/fizz"
- make -j "$(nproc)"
- make install
- echo -e "${COLOR_GREEN}Folly is installed ${COLOR_OFF}"
- cd "$BWD" || exit
-}
-
function detect_platform() {
unameOut="$(uname -s)"
case "${unameOut}" in
@@ -176,7 +151,6 @@ function detect_platform() {
detect_platform
setup_folly
-setup_fizz
# build mvfst:
cd "$MVFST_BUILD_DIR" || exit
@@ -184,7 +158,6 @@ cmake -DCMAKE_PREFIX_PATH="$FOLLY_INSTALL_DIR" \
-DCMAKE_INSTALL_PREFIX="$MVFST_INSTALL_DIR" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_TESTS=On \
- -DFIZZ_PROJECT="$DEPS_DIR/fizz" \
../..
make -j "$(nproc)"
echo -e "${COLOR_GREEN}MVFST build is complete. To run unit test: \

ADD
cmake/BuildFizz.cmake
+# Copyright (c) Facebook, Inc. and its affiliates.
+#
+# This source code is licensed under the MIT license found in the
+# LICENSE file in the root directory of this source tree.
+
+include(ExternalProject)
+# Construct platform aware cmake args since on OSX
+# it requires path to the openssl libs
+list(APPEND CMAKE_ARGS
+ -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo
+ -DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}
+)
+if(UNIX AND APPLE)
+ list(APPEND CMAKE_ARGS
+ -DOPENSSL_ROOT_DIR:STRING=${OPENSSL_ROOT_DIR}
+ -DOPENSSL_LIBRARIES:STRING=${OPENSSL_LIBRARIES}
+)
+endif()
+
+# Consume Fizz as an external project
+ExternalProject_Add(
+ fizz_project
+ GIT_REPOSITORY https://github.com/facebookincubator/fizz
+ PREFIX fizz_project
+ SOURCE_SUBDIR fizz
+ # Disable install step
+ INSTALL_COMMAND ""
+ LOG_DOWNLOAD ON
+ LOG_UPDATE 1
+ LOG_CONFIGURE ON
+ LOG_BUILD ON
+ LOG_TEST 1
+ LOG_INSTALL 1
+ CMAKE_CACHE_ARGS ${CMAKE_ARGS}
+)
+set(FIZZ_TARGET fizz_project)
+ExternalProject_Get_Property(fizz_project source_dir)
+set(FIZZ_SOURCE_DIR ${source_dir})
+set(FIZZ_PROJECT ${source_dir})
+ExternalProject_Get_Property(fizz_project binary_dir)
+set(FIZZ_BINARY_DIR ${binary_dir})
+
+# Setup fizz libraries and include dirs
+set(LIBFIZZ_LIBRARY
+ "${FIZZ_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}fizz${CMAKE_STATIC_LIBRARY_SUFFIX}"
+)
+set(LIBFIZZ_INCLUDE_DIR "${source_dir}")

MODIFY
cmake/QuicTest.cmake
cmake/QuicTest.cmake
@@ -70,7 +70,8 @@ function(quic_add_test)
# implementation of 'main()' that calls folly::init
"${QUIC_FBCODE_ROOT}/quic/common/test/TestMain.cpp"
)
- add_dependencies(${QUIC_TEST_TARGET} googletest) # make sure googletest is built first
+ # make sure googletest and fizz are built first
+ add_dependencies(${QUIC_TEST_TARGET} googletest ${FIZZ_TARGET})
target_compile_options(
${QUIC_TEST_TARGET} PRIVATE
${_QUIC_BASE_COMPILE_OPTIONS}

MODIFY
quic/api/CMakeLists.txt
quic/api/CMakeLists.txt
@@ -15,6 +15,7 @@ add_library(
target_include_directories(
mvfst_transport PUBLIC
$<BUILD_INTERFACE:${QUIC_FBCODE_ROOT}>
+ $<BUILD_INTERFACE:${LIBFIZZ_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include/>
)
@@ -26,6 +27,7 @@ target_compile_options(
add_dependencies(
mvfst_transport
+ ${FIZZ_TARGET}
mvfst_cc_algo
mvfst_codec
mvfst_codec_pktbuilder
@@ -48,7 +50,7 @@ add_dependencies(
target_link_libraries(
mvfst_transport PUBLIC
Folly::folly
- fizz::fizz
+ ${LIBFIZZ_LIBRARY}
mvfst_cc_algo
mvfst_codec
mvfst_codec_pktbuilder

ADD
quic/common/test/AeadTestUtil.cpp
+/*
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ *
+ */
+
+// Copied from
+// https://github.com/facebookincubator/fizz/blob/master/fizz/crypto/aead/test/TestUtil.cpp
+#include <fizz/crypto/aead/test/TestUtil.h>
+
+#include <fizz/crypto/aead/IOBufUtil.h>
+
+using namespace folly;
+
+namespace fizz {
+namespace test {
+
+std::unique_ptr<folly::IOBuf> defaultCreator(size_t len, size_t) {
+ return IOBuf::create(len);
+}
+
+// Converts the hex encoded string to an IOBuf.
+std::unique_ptr<folly::IOBuf>
+toIOBuf(std::string hexData, size_t headroom, size_t tailroom) {
+ std::string out;
+ CHECK(folly::unhexlify(hexData, out));
+ return folly::IOBuf::copyBuffer(out, headroom, tailroom);
+}
+
+std::unique_ptr<IOBuf>
+chunkIOBuf(std::unique_ptr<IOBuf> input, size_t chunks, BufCreator creator) {
+ if (!creator) {
+ creator = defaultCreator;
+ }
+ // create IOBuf chunks
+ size_t inputLen = input->computeChainDataLength();
+ size_t chunkLen = floor((double)inputLen / (double)chunks);
+ std::unique_ptr<IOBuf> chunked;
+
+ for (size_t i = 0; i < chunks - 1; ++i) {
+ auto buf = creator(chunkLen, i);
+ buf->append(chunkLen);
+ if (!chunked) {
+ chunked = std::move(buf);
+ } else {
+ chunked->prependChain(std::move(buf));
+ }
+ }
+
+ size_t remainLen = inputLen - (chunks - 1) * chunkLen;
+ auto remain = creator(remainLen, chunks - 1);
+ remain->append(remainLen);
+ chunked->prependChain(std::move(remain));
+
+ transformBuffer(
+ *input, *chunked, [](uint8_t* out, const uint8_t* in, size_t len) {
+ memcpy(out, in, len);
+ });
+
+ CHECK_EQ(chunks, chunked->countChainElements());
+ return chunked;
+}
+} // namespace test
+} // namespace fizz

MODIFY
quic/common/test/CMakeLists.txt
quic/common/test/CMakeLists.txt
@@ -10,13 +10,14 @@ endif()
add_library(
mvfst_test_utils STATIC
TestUtils.cpp
- ${FIZZ_PROJECT}/fizz/crypto/aead/test/TestUtil.cpp
- ${FIZZ_PROJECT}/fizz/crypto/test/TestUtil.cpp
+ AeadTestUtil.cpp
+ CryptoTestUtil.cpp
)
+
target_include_directories(
mvfst_test_utils PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
- $<BUILD_INTERFACE:${FIZZ_PROJECT}>
+ $<BUILD_INTERFACE:${LIBFIZZ_INCLUDE_DIR}>
${LIBGMOCK_INCLUDE_DIR}
${LIBGTEST_INCLUDE_DIR}
)
@@ -29,6 +30,7 @@ target_compile_options(
add_dependencies(
mvfst_test_utils
+ ${FIZZ_TARGET}
mvfst_client
mvfst_codec_pktbuilder
mvfst_codec_types
@@ -41,7 +43,7 @@ add_dependencies(
target_link_libraries(
mvfst_test_utils PUBLIC
Folly::folly
- fizz::fizz
+ ${LIBFIZZ_LIBRARY}
${LIBGMOCK_LIBRARIES}
${LIBGTEST_LIBRARIES}
mvfst_client
@@ -62,7 +64,7 @@ quic_add_test(TARGET QuicCommonUtilTest SOURCES
IntervalSetTest.cpp
DEPENDS
Folly::folly
- fizz::fizz
+ ${LIBFIZZ_LIBRARY}
mvfst_client
mvfst_codec_pktbuilder
mvfst_codec_types

ADD
quic/common/test/CryptoTestUtil.cpp
+/*
+ * Copyright (c) Facebook, Inc. and its affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ *
+ */
+
+// Copied from
+// https://github.com/facebookincubator/fizz/blob/master/fizz/crypto/test/TestUtil.cpp
+#include <fizz/crypto/test/TestUtil.h>
+
+#include <folly/String.h>
+#include <folly/ssl/OpenSSLCertUtils.h>
+#include <sodium/randombytes.h>
+
+using namespace folly;
+using namespace folly::ssl;
+
+namespace fizz {
+namespace test {
+
+EvpPkeyUniquePtr getPrivateKey(StringPiece key) {
+ BioUniquePtr bio(BIO_new(BIO_s_mem()));
+ CHECK(bio);
+ CHECK_EQ(BIO_write(bio.get(), key.data(), key.size()), key.size());
+ EvpPkeyUniquePtr pkey(
+ PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, nullptr));
+ CHECK(pkey);
+ return pkey;
+}
+
+EvpPkeyUniquePtr getPublicKey(StringPiece key) {
+ BioUniquePtr bio(BIO_new(BIO_s_mem()));
+ CHECK(bio);
+ CHECK_EQ(BIO_write(bio.get(), key.data(), key.size()), key.size());
+ EvpPkeyUniquePtr pkey(
+ PEM_read_bio_PUBKEY(bio.get(), nullptr, nullptr, nullptr));
+ CHECK(pkey);
+ return pkey;
+}
+
+// Converts the hex encoded string to an IOBuf.
+std::unique_ptr<folly::IOBuf> toIOBuf(folly::StringPiece hexData) {
+ std::string out;
+ CHECK(folly::unhexlify(hexData, out));
+ return folly::IOBuf::copyBuffer(out);
+}
+
+folly::ssl::X509UniquePtr getCert(folly::StringPiece cert) {
+ BioUniquePtr bio(BIO_new(BIO_s_mem()));
+ CHECK(bio);
+ CHECK_EQ(BIO_write(bio.get(), cert.data(), cert.size()), cert.size());
+ X509UniquePtr x509(PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr));
+ CHECK(x509);
+ return x509;
+}
+
+std::unique_ptr<folly::IOBuf> getCertData(folly::StringPiece cert) {
+ return OpenSSLCertUtils::derEncode(*getCert(cert));
+}
+
+static struct randombytes_implementation mockRandom = {
+ []() { return "test"; }, // implementation_name
+ []() { return (uint32_t)0x44444444; }, // random
+ nullptr, // stir
+ nullptr, // uniform
+ [](void* const buf, const size_t size) { memset(buf, 0x44, size); }, // buf
+ nullptr}; // close
+
+void useMockRandom() {
+ randombytes_set_implementation(&mockRandom);
+}
+} // namespace test
+} // namespace fizz

MODIFY
quic/congestion_control/CMakeLists.txt
quic/congestion_control/CMakeLists.txt
@@ -15,6 +15,7 @@ add_library(
target_include_directories(
mvfst_cc_algo PUBLIC
$<BUILD_INTERFACE:${QUIC_FBCODE_ROOT}>
+ $<BUILD_INTERFACE:${LIBFIZZ_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include/>
)
@@ -26,6 +27,7 @@ target_compile_options(
add_dependencies(
mvfst_cc_algo
+ ${FIZZ_TARGET}
mvfst_constants
mvfst_exception
mvfst_state_machine
@@ -35,7 +37,7 @@ add_dependencies(
target_link_libraries(
mvfst_cc_algo PUBLIC
Folly::folly
- fizz::fizz
+ ${LIBFIZZ_LIBRARY}
mvfst_constants
mvfst_exception
mvfst_state_machine

MODIFY
quic/handshake/CMakeLists.txt
quic/handshake/CMakeLists.txt
@@ -13,6 +13,7 @@ add_library(
target_include_directories(
mvfst_handshake PUBLIC
$<BUILD_INTERFACE:${QUIC_FBCODE_ROOT}>
+ $<BUILD_INTERFACE:${LIBFIZZ_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include/>
)
@@ -24,6 +25,7 @@ target_compile_options(
add_dependencies(
mvfst_handshake
+ ${FIZZ_TARGET}
mvfst_constants
mvfst_exception
mvfst_codec_types
@@ -33,7 +35,7 @@ add_dependencies(
target_link_libraries(
mvfst_handshake PUBLIC
Folly::folly
- fizz::fizz
+ ${LIBFIZZ_LIBRARY}
mvfst_constants
mvfst_exception
mvfst_codec_types

MODIFY
quic/happyeyeballs/CMakeLists.txt
quic/happyeyeballs/CMakeLists.txt
@@ -11,6 +11,7 @@ add_library(
target_include_directories(
mvfst_happyeyeballs PUBLIC
$<BUILD_INTERFACE:${QUIC_FBCODE_ROOT}>
+ $<BUILD_INTERFACE:${LIBFIZZ_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include/>
)
@@ -22,13 +23,14 @@ target_compile_options(
add_dependencies(
mvfst_happyeyeballs
+ ${FIZZ_TARGET}
mvfst_state_machine
)
target_link_libraries(
mvfst_happyeyeballs PUBLIC
Folly::folly
- fizz::fizz
+ ${LIBFIZZ_LIBRARY}
mvfst_state_machine
)

MODIFY
quic/server/CMakeLists.txt
quic/server/CMakeLists.txt
@@ -19,6 +19,7 @@ add_library(
target_include_directories(
mvfst_server PUBLIC
$<BUILD_INTERFACE:${QUIC_FBCODE_ROOT}>
+ $<BUILD_INTERFACE:${LIBFIZZ_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include/>
)
@@ -30,6 +31,7 @@ target_compile_options(
add_dependencies(
mvfst_server
+ ${FIZZ_TARGET}
mvfst_constants
mvfst_codec
mvfst_codec_types
@@ -40,7 +42,7 @@ add_dependencies(
target_link_libraries(
mvfst_server PUBLIC
Folly::folly
- fizz::fizz
+ ${LIBFIZZ_LIBRARY}
mvfst_constants
mvfst_codec
mvfst_codec_types

MODIFY
quic/server/handshake/test/CMakeLists.txt
quic/server/handshake/test/CMakeLists.txt
@@ -16,7 +16,7 @@ quic_add_test(TARGET ServerHandshakeTest
StatelessResetGeneratorTest.cpp
DEPENDS
Folly::folly
- fizz::fizz
+ ${LIBFIZZ_LIBRARY}
mvfst_client
mvfst_codec_types
mvfst_constants

consume fizz as an external project in cmake

Summary: Favor standalone cmake config than relying on custom script

Reviewed By: siyengar

Differential Revision: D15227020

fbshipit-source-id: 949885b06daeef5e496bf5f1b67a2a3a89750ebf