Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions .github/workflows/build.yml

This file was deleted.

635 changes: 635 additions & 0 deletions .github/workflows/getdeps_linux.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
compile_commands.json
109 changes: 109 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the LICENSE file
# in the root directory of this source tree.

cmake_minimum_required(VERSION 3.19)

project(mcrouter VERSION 1.0.0)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build/fbcode_builder/CMake"
${CMAKE_MODULE_PATH})

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_OPTIMIZE_DEPENDENCIES ON)

option(BUILD_TESTS "If enabled, compile the tests." OFF)
option(USE_CCACHE "Use ccache for compiler caching, if available" OFF)
option(PROFILE_BUILD "Profile build times (requires clang)" OFF)

# Opt out of using the upstream BoostConfig module with CMake >= 3.30,
# since GitHub Actions provides Boost < 1.70 and therefore is missing the upstream module.
if(POLICY CMP0167)
cmake_policy(SET CMP0167 OLD)
endif()

# Disable Meta-specific functionality for the OSS build.
add_compile_definitions(LIBMC_FBTRACE_DISABLE DISABLE_COMPRESSION
MCROUTER_OSS_BUILD)

# Allow using a compiler cache locally on an opt-in basis.
if(USE_CCACHE)
find_program(CCACHE_EXECUTABLE ccache)
if(CCACHE_EXECUTABLE)
set(ccacheEnv CCACHE_SLOPPINESS=pch_defines,time_macros)

foreach(lang IN ITEMS C CXX)
set(CMAKE_${lang}_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E env ${ccacheEnv}
${CCACHE_EXECUTABLE})
endforeach()
endif()
endif()

# Allow profiling build performance with clang.
if(PROFILE_BUILD)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:-ftime-trace>)
message("Enabling build time profiling")
else()
message(
"${CMAKE_CXX_COMPILER_ID} compiler detected, cannot enable build time profiling"
)
endif()
endif()

if(WIN32)
include(FBCompilerSettingsMSVC)
else()
include(FBCompilerSettingsUnix)

# Create symlink to compile_commands.json for IDE to pick it up
execute_process(
COMMAND
${CMAKE_COMMAND} -E create_symlink
${CMAKE_BINARY_DIR}/compile_commands.json
${CMAKE_CURRENT_SOURCE_DIR}/compile_commands.json)
endif()

# Set up options for generated Thrift client code
include(FBThriftLibrary)
set(THRIFT_OPTIONS stack_arguments sync_methods_return_try
deprecated_terse_writes)

find_package(Boost 1.65.1 REQUIRED COMPONENTS system thread filesystem regex
context program_options)

find_package(fmt REQUIRED)
find_package(folly REQUIRED)
find_package(Fizz REQUIRED)
find_package(Glog REQUIRED)
find_package(gflags REQUIRED)
find_package(wangle REQUIRED)
find_package(FBThrift REQUIRED)

include_directories(.)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
Comment on lines +87 to +88
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super sure about this, but this seems like the best way to support the current #include style.


if(BUILD_TESTS)
enable_testing()
include(CTest)

find_package(GTest MODULE REQUIRED)

include(GoogleTest)
endif()

add_subdirectory(mcrouter)

install(TARGETS mcrouter mcpiper)

# Provide a basic CPack integration to allow easily creating packages for Linux
# distributions.
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"mcrouter - a memcached protocol router for scaling memcached deployments.")
set(CPACK_PACKAGE_VENDOR "Meta Platforms, Inc.")
set(CPACK_VERBATIM_VARIABLES ON)
include(CPack)
47 changes: 19 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Mcrouter [![Build Status](https://github.com/facebook/mcrouter/workflows/build/badge.svg)](https://github.com/facebook/mcrouter/actions?workflow=build)
# Mcrouter [![Build Status](https://github.com/facebook/mcrouter/actions/workflows/getdeps_linux.yml/badge.svg)](https://github.com/facebook/mcrouter/actions/workflows/getdeps_linux.yml)
[![Support Ukraine](https://img.shields.io/badge/Support-Ukraine-FFD500?style=flat&labelColor=005BBB)](https://opensource.fb.com/support-ukraine) [![License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/facebook/mcrouter/blob/master/LICENSE)

Mcrouter (pronounced mc router) is a memcached protocol router for scaling [memcached](https://memcached.org/)
Expand All @@ -12,42 +12,33 @@ See https://github.com/facebook/mcrouter/wiki to get started.

## Quick start guide

### New! Ubuntu package available
### Building

Currently, we support Ubuntu Bionic (18.04) amd64.
Here is how to install it:
Mcrouter depends on [folly](https://github.com/facebook/folly), [wangle](https://github.com/facebook/wangle), [fizz](https://github.com/facebookincubator/fizz), [fbthrift](https://github.com/facebook/fbthrift)
and [mvfst](https://github.com/facebook/mvfst).

Add the repo key:
The `getdeps.py` tool, shared between many open source C++ projects at Meta, may be used to build mcrouter and its dependencies:

$ wget -O - https://facebook.github.io/mcrouter/debrepo/bionic/PUBLIC.KEY | sudo apt-key add
# Clone the repo
git clone https://github.com/facebook/mcrouter.git
cd mcrouter

Add the following line to apt sources file /etc/apt/sources.list
# Build, using system dependencies if available, including tests
./build/fbcode_builder/getdeps.py --allow-system-packages build mcrouter

deb https://facebook.github.io/mcrouter/debrepo/bionic bionic contrib
# Build, using system dependencies if available, without tests
./build/fbcode_builder/getdeps.py --allow-system-packages --no-tests build mcrouter

Update the local repo cache:
Once built, you may use `getdeps.py` to run the tests as well:

$ sudo apt-get update
# Run the tests
./build/fbcode_builder/getdeps.py --allow-system-packages test

Install mcrouter:
### Packaging
mcrouter ships with a basic `CPack` configuration that may be used to package it for your Linux distribution.
After building the project, change to its `getdeps.py` scratch dir, and run `cpack` with the appropriate generator.

$ sudo apt-get install mcrouter


### Installing From Source

See https://github.com/facebook/mcrouter/wiki/mcrouter-installation for more
detailed installation instructions.

Mcrouter depends on [folly](https://github.com/facebook/folly), [wangle](https://github.com/facebook/wangle), [fizz](https://github.com/facebookincubator/fizz), and [fbthrift](https://github.com/facebook/fbthrift).

The installation is a standard autotools flow:

$ autoreconf --install
$ ./configure
$ make
$ sudo make install
$ mcrouter --help
### Running mcrouter

Assuming you have a memcached instance on the local host running on port 5001,
the simplest mcrouter setup is:
Expand Down
1 change: 1 addition & 0 deletions build/.cmake/api/v1/query/client-neocmake/query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"requests":[{"kind":"codemodel","version":[{"major":2,"minor":7}]},{"kind":"configureLog","version":[{"major":1,"minor":0}]},{"kind":"cache","version":[{"major":2,"minor":0}]},{"kind":"cmakeFiles","version":[{"major":1,"minor":1}]},{"kind":"toolchains","version":[{"major":1,"minor":0}]}]}
5 changes: 5 additions & 0 deletions build/fbcode_builder/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Facebook-internal CI builds don't have write permission outside of the
# source tree, so we install all projects into this directory.
/facebook_ci
__pycache__/
*.pyc
27 changes: 27 additions & 0 deletions build/fbcode_builder/CMake/FBBuildOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) Facebook, Inc. and its affiliates.

function (fb_activate_static_library_option)
option(USE_STATIC_DEPS_ON_UNIX
"If enabled, use static dependencies on unix systems. This is generally discouraged."
OFF
)
# Mark USE_STATIC_DEPS_ON_UNIX as an "advanced" option, since enabling it
# is generally discouraged.
mark_as_advanced(USE_STATIC_DEPS_ON_UNIX)

if(UNIX AND USE_STATIC_DEPS_ON_UNIX)
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a" PARENT_SCOPE)
endif()

option(PREFER_STATIC_DEPS_ON_UNIX
"If enabled, use static dependencies on unix systems as possible as we can. This is generally discouraged."
OFF
)
# Mark PREFER_STATIC_DEPS_ON_UNIX as an "advanced" option, since enabling it
# is generally discouraged.
mark_as_advanced(PREFER_STATIC_DEPS_ON_UNIX)

if(UNIX AND PREFER_STATIC_DEPS_ON_UNIX)
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".so" PARENT_SCOPE)
endif()
endfunction()
141 changes: 141 additions & 0 deletions build/fbcode_builder/CMake/FBCMakeParseArgs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#
# Copyright (c) Facebook, Inc. and its affiliates.
#
# Helper function for parsing arguments to a CMake function.
#
# This function is very similar to CMake's built-in cmake_parse_arguments()
# function, with some improvements:
# - This function correctly handles empty arguments. (cmake_parse_arguments()
# ignores empty arguments.)
# - If a multi-value argument is specified more than once, the subsequent
# arguments are appended to the original list rather than replacing it. e.g.
# if "SOURCES" is a multi-value argument, and the argument list contains
# "SOURCES a b c SOURCES x y z" then the resulting value for SOURCES will be
# "a;b;c;x;y;z" rather than "x;y;z"
# - This function errors out by default on unrecognized arguments. You can
# pass in an extra "ALLOW_UNPARSED_ARGS" argument to make it behave like
# cmake_parse_arguments(), and return the unparsed arguments in a
# <prefix>_UNPARSED_ARGUMENTS variable instead.
#
# It does look like cmake_parse_arguments() handled empty arguments correctly
# from CMake 3.0 through 3.3, but it seems like this was probably broken when
# it was turned into a built-in function in CMake 3.4. Here is discussion and
# patches that fixed this behavior prior to CMake 3.0:
# https://cmake.org/pipermail/cmake-developers/2013-November/020607.html
#
# The one downside to this function over the built-in cmake_parse_arguments()
# is that I don't think we can achieve the PARSE_ARGV behavior in a non-builtin
# function, so we can't properly handle arguments that contain ";". CMake will
# treat the ";" characters as list element separators, and treat it as multiple
# separate arguments.
#
function(fb_cmake_parse_args PREFIX OPTIONS ONE_VALUE_ARGS MULTI_VALUE_ARGS ARGS)
foreach(option IN LISTS ARGN)
if ("${option}" STREQUAL "ALLOW_UNPARSED_ARGS")
set(ALLOW_UNPARSED_ARGS TRUE)
else()
message(
FATAL_ERROR
"unknown optional argument for fb_cmake_parse_args(): ${option}"
)
endif()
endforeach()

# Define all options as FALSE in the parent scope to start with
foreach(var_name IN LISTS OPTIONS)
set("${PREFIX}_${var_name}" "FALSE" PARENT_SCOPE)
endforeach()

# TODO: We aren't extremely strict about error checking for one-value
# arguments here. e.g., we don't complain if a one-value argument is
# followed by another option/one-value/multi-value name rather than an
# argument. We also don't complain if a one-value argument is the last
# argument and isn't followed by a value.

list(APPEND all_args ${ONE_VALUE_ARGS})
list(APPEND all_args ${MULTI_VALUE_ARGS})
set(current_variable)
set(unparsed_args)
foreach(arg IN LISTS ARGS)
list(FIND OPTIONS "${arg}" opt_index)
if("${opt_index}" EQUAL -1)
list(FIND all_args "${arg}" arg_index)
if("${arg_index}" EQUAL -1)
# This argument does not match an argument name,
# must be an argument value
if("${current_variable}" STREQUAL "")
list(APPEND unparsed_args "${arg}")
else()
# Ugh, CMake lists have a pretty fundamental flaw: they cannot
# distinguish between an empty list and a list with a single empty
# element. We track our own SEEN_VALUES_arg setting to help
# distinguish this and behave properly here.
if ("${SEEN_${current_variable}}" AND "${${current_variable}}" STREQUAL "")
set("${current_variable}" ";${arg}")
else()
list(APPEND "${current_variable}" "${arg}")
endif()
set("SEEN_${current_variable}" TRUE)
endif()
else()
# We found a single- or multi-value argument name
set(current_variable "VALUES_${arg}")
set("SEEN_${arg}" TRUE)
endif()
else()
# We found an option variable
set("${PREFIX}_${arg}" "TRUE" PARENT_SCOPE)
set(current_variable)
endif()
endforeach()

foreach(arg_name IN LISTS ONE_VALUE_ARGS)
if(NOT "${SEEN_${arg_name}}")
unset("${PREFIX}_${arg_name}" PARENT_SCOPE)
elseif(NOT "${SEEN_VALUES_${arg_name}}")
# If the argument was seen but a value wasn't specified, error out.
# We require exactly one value to be specified.
message(
FATAL_ERROR "argument ${arg_name} was specified without a value"
)
else()
list(LENGTH "VALUES_${arg_name}" num_args)
if("${num_args}" EQUAL 0)
# We know an argument was specified and that we called list(APPEND).
# If CMake thinks the list is empty that means there is really a single
# empty element in the list.
set("${PREFIX}_${arg_name}" "" PARENT_SCOPE)
elseif("${num_args}" EQUAL 1)
list(GET "VALUES_${arg_name}" 0 arg_value)
set("${PREFIX}_${arg_name}" "${arg_value}" PARENT_SCOPE)
else()
message(
FATAL_ERROR "too many arguments specified for ${arg_name}: "
"${VALUES_${arg_name}}"
)
endif()
endif()
endforeach()

foreach(arg_name IN LISTS MULTI_VALUE_ARGS)
# If this argument name was never seen, then unset the parent scope
if (NOT "${SEEN_${arg_name}}")
unset("${PREFIX}_${arg_name}" PARENT_SCOPE)
else()
# TODO: Our caller still won't be able to distinguish between an empty
# list and a list with a single empty element. We can tell which is
# which, but CMake lists don't make it easy to show this to our caller.
set("${PREFIX}_${arg_name}" "${VALUES_${arg_name}}" PARENT_SCOPE)
endif()
endforeach()

# By default we fatal out on unparsed arguments, but return them to the
# caller if ALLOW_UNPARSED_ARGS was specified.
if (DEFINED unparsed_args)
if ("${ALLOW_UNPARSED_ARGS}")
set("${PREFIX}_UNPARSED_ARGUMENTS" "${unparsed_args}" PARENT_SCOPE)
else()
message(FATAL_ERROR "unrecognized arguments: ${unparsed_args}")
endif()
endif()
endfunction()
13 changes: 13 additions & 0 deletions build/fbcode_builder/CMake/FBCompilerSettings.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) Facebook, Inc. and its affiliates.

# This file applies common compiler settings that are shared across
# a number of Facebook opensource projects.
# Please use caution and your best judgement before making changes
# to these shared compiler settings in order to avoid accidentally
# breaking a build in another project!

if (WIN32)
include(FBCompilerSettingsMSVC)
else()
include(FBCompilerSettingsUnix)
endif()
Loading
Loading