Skip to content

Commit

Permalink
Merge pull request #12 from senior7515/build-oss
Browse files Browse the repository at this point in the history
build: first pass builds all deps.
  • Loading branch information
emaxerrno authored Nov 4, 2020
2 parents a240e37 + 77daa25 commit b83198c
Show file tree
Hide file tree
Showing 10 changed files with 430 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .clang_complete
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-std=gnu++17
-std=c++17
-Isrc
141 changes: 141 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
cmake_minimum_required(VERSION 3.9.0)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
project(REDPANDA VERSION "0.1.0" LANGUAGES CXX)
# https://cmake.org/cmake/help/v3.4/policy/CMP0065.html
cmake_policy(SET CMP0065 OLD)

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

# CCACHE_DIR is initially provided by vtools
set(CCACHE_DIR $ENV{CCACHE_DIR} CACHE PATH "ccache directory")
set(ENV{CCACHE_DIR} ${CCACHE_DIR})
set(REDPANDA_DEPS_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/deps_install
CACHE STRING "Managed dependencies install directory")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
list(APPEND BASE_LD_FLAGS_LIST
-L${REDPANDA_DEPS_INSTALL_DIR}/lib
-L${REDPANDA_DEPS_INSTALL_DIR}/lib64
)
set(PKG_CONFIG_PATH_LIST
${REDPANDA_DEPS_INSTALL_DIR}/lib64/pkgconfig
${REDPANDA_DEPS_INSTALL_DIR}/share/pkgconfig
${REDPANDA_DEPS_INSTALL_DIR}/lib/pkgconfig
)

list(APPEND BASE_CXX_FLAGS_LIST -fPIC)
list(APPEND BASE_C_FLAGS_LIST -fPIC)
if ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
list(APPEND BASE_CXX_FLAGS_LIST
-fsanitize=undefined
-fsanitize=address
)
list(APPEND BASE_C_FLAGS_LIST
-fsanitize=undefined
-fsanitize=address
)
list(APPEND BASE_LD_FLAGS_LIST
-fsanitize=undefined
-fsanitize=address
)
endif()

# join flag lists
string(JOIN " " BASE_C_FLAGS ${BASE_C_FLAGS_LIST})
string(JOIN " " BASE_CXX_FLAGS ${BASE_CXX_FLAGS_LIST})
string(JOIN " " BASE_LD_FLAGS ${BASE_LD_FLAGS_LIST})
string(JOIN ":" PKG_CONFIG_PATH ${PKG_CONFIG_PATH_LIST})
find_package(PkgConfig REQUIRED)
set(ENV{PKG_CONFIG_PATH} "${PKG_CONFIG_PATH}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${BASE_C_FLAGS}")

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
"Choose: Debug, Release, RelWithDebInfo, MinSizeRel." FORCE)
endif()

if(REDPANDA_DEPS_ONLY AND NOT V_MANAGE_DEPS)
message(FATAL_ERROR
"To build managed dependencies V_MANAGE_DEPS must be enabled")
endif()

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${BASE_LD_FLAGS} -pie")
set(CMAKE_SHARED_LINKER_FLAGS "${BASE_LD_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${BASE_LD_FLAGS}")

# don't export() the contents to registry
set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY ON CACHE INTERNAL "" FORCE)
# disable system level registry /usr/local/share/cmake/*
set(CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY ON CACHE INTERNAL "" FORCE)
# disable user package registry ~/.cmake/*
set(CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY ON CACHE INTERNAL "" FORCE)
set(REDPANDA_DEPS_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/deps_build)
# build type specific flags
string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
set(CMAKE_C_FLAGS_BUILD_TYPE ${CMAKE_C_FLAGS_${BUILD_TYPE}})
set(CMAKE_CXX_FLAGS_BUILD_TYPE ${CMAKE_CXX_FLAGS_${BUILD_TYPE}})
configure_file(oss.cmake.in ${REDPANDA_DEPS_BUILD_DIR}/CMakeLists.txt @ONLY)
# wire up dependency search paths.
list(APPEND CMAKE_PREFIX_PATH "${REDPANDA_DEPS_INSTALL_DIR}")
set(BASE_LD_FLAGS "${BASE_LD_FLAGS} -L${REDPANDA_DEPS_INSTALL_DIR}/lib")
if(NOT REDPANDA_DEPS_SKIP_BUILD)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
RESULT_VARIABLE result
WORKING_DIRECTORY ${REDPANDA_DEPS_BUILD_DIR})
if(result)
message(FATAL_ERROR "CMake step for v::deps failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${REDPANDA_DEPS_BUILD_DIR})
if(result)
message(FATAL_ERROR "Build step for v::build failed: ${result}")
endif()
endif()

# from seastar/CMakeLists.txt. unfortunately this snippet doesn't appear to be
# installed along with the rest of seastar.
function (seastar_generate_swagger)
set (one_value_args TARGET VAR IN_FILE OUT_FILE)
cmake_parse_arguments (args "" "${one_value_args}" "" ${ARGN})
get_filename_component (out_dir ${args_OUT_FILE} DIRECTORY)
if(REDPANDA_DEPS_ONLY)
set (generator "${REDPANDA_DEPS_INSTALL_DIR}/bin/seastar-json2code.py")
else()
find_program(GENERATOR "seastar-json2code.py")
set (generator "${GENERATOR}")
endif()

add_custom_command (
DEPENDS
${args_IN_FILE}
${generator}
OUTPUT ${args_OUT_FILE}
COMMAND ${CMAKE_COMMAND} -E make_directory ${out_dir}
COMMAND ${generator} -f ${args_IN_FILE} -o ${args_OUT_FILE})

add_custom_target (${args_TARGET}
DEPENDS ${args_OUT_FILE})

set (${args_VAR} ${args_OUT_FILE} PARENT_SCOPE)
endfunction ()

if(REDPANDA_DEPS_ONLY)
message("Finished building/installing external project dependencies.")
return()
endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# add code
include(ccache)
include(testing)
include(set_option)
include(v_library)
add_subdirectory(src)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ all built from source. The only thing we do not build yet is the Linux Kernel, b
For hackers, here is the short and sweet:

```
./install-dependencies.sh && ./build.sh
sudo ./install-dependencies.sh && ./build.sh
```

See the [contributing docs](./CONTRIBUTING.md)
16 changes: 16 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -x
root=$(git rev-parse --show-toplevel)
if [[ -z ${CC} ]]; then export CC=/usr/bin/gcc; fi
if [[ -z ${CXX} ]]; then export CXX=/usr/bin/g++; fi
if [[ ! -z ${CCACHE_DIR} && -e /dev/shm ]]; then export CCACHE_DIR=/dev/shm/redpanda; fi

# Change Debug via -DCMAKE_BUILD_TYPE=Debug
cmake -DCMAKE_BUILD_TYPE=Release \
-B$root/build \
-H$root \
-GNinja \
-DCMAKE_C_COMPILER=$CC \
-DCMAKE_CXX_COMPILER=$CXX

(cd $root/build && ninja && ctest -R _rpunit)
14 changes: 6 additions & 8 deletions cmake/FindBase64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ include (FindPackageHandleStandardArgs REQUIRED)

find_path (Base64_IMPORTED_OBJECT
NAMES libbase64.o
HINTS
${V_DEPS_INSTALL_DIR}/lib)

HINTS ${REDPANDA_DEPS_INSTALL_DIR}/lib)

find_path (Base64_INCLUDE_DIR
NAMES libbase64.h
HINTS
${V_DEPS_INSTALL_DIR}/include)
HINTS ${REDPANDA_DEPS_INSTALL_DIR}/include)

mark_as_advanced (
Base64_IMPORTED_OBJECT
Expand All @@ -23,9 +21,9 @@ if (Base64_FOUND)
set (Base64_INCLUDE_DIRS ${Base64_INCLUDE_DIR})
endif ()

if (Base64_FOUND AND NOT (TARGET Zstd::zstd))
add_library(Base64 OBJECT IMPORTED)
set_target_properties(Base64
if (Base64_FOUND AND NOT (TARGET Base64::base64))
add_library(Base64::base64 OBJECT IMPORTED)
set_target_properties(Base64::base64
PROPERTIES
IMPORTED_OBJECTS ${Base64_IMPORTED_OBJECT}/libbase64.o
INTERFACE_INCLUDE_DIRECTORIES ${Base64_INCLUDE_DIR})
Expand Down
50 changes: 50 additions & 0 deletions install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

echo "installing seastar dependencies"
if [ -f "/etc/os-release" ]; then
. /etc/os-release
elif [ -f "/etc/arch-release" ]; then
export ID=arch
else
echo "/etc/os-release missing."
exit 1
fi

deb_deps=(
curl
libzstd-dev
libsnappy-dev
libsystemd-dev
rapidjson-dev
libxxhash-dev
python3-venv
python3-jinja2
)
fedora_deps=(
curl
libzstd-static
libzstd-devel
snappy-devel
systemd-devel
rapidjson-devel
xxhash-devel
python3-virtualenv
python3-jinja2
)


case "$ID" in
ubuntu|debian)
apt-get install -y "${deb_deps[@]}"
;;
fedora)
dnf install -y "${fedora_deps[@]}"
;;
*)
echo "Please help us make the script better by sending patches with your OS $ID"
exit 1
;;
esac
# needed for unit tests
sudo sysctl -w fs.aio-max-nr=10485760
curl -1sLf "https://raw.githubusercontent.com/vectorizedio/seastar/master/install-dependencies.sh" | sudo -E bash
Loading

0 comments on commit b83198c

Please sign in to comment.