Skip to content

Commit

Permalink
build mimic-dev1 with gcc 7
Browse files Browse the repository at this point in the history
    ceph/ceph#19548

cmake: check gcc version not release date for libstdc++ saneness
cmake: bail out if GCC version is less than 5.1

    ceph/ceph#18938
    ceph/ceph#19344

build/ops: use devtoolset-7 on centos/rhel-7
ceph.spec: use devtoolset-6-gcc-c++ on aarch64

    ceph/ceph#18863
    ceph/ceph#19341

install-deps: use DTS-7 on aarch64 and only download mirrored package indexes

    ceph/ceph#19645

Signed-off-by: luo.runbing <luo.runbing@zte.com.cn>
  • Loading branch information
runsisi committed Jan 5, 2018
1 parent fb16edd commit b84480c
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 20 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Expand Up @@ -16,6 +16,9 @@ endif (POLICY CMP0022)
if (POLICY CMP0023)
cmake_policy(SET CMP0023 OLD)
endif (POLICY CMP0023)
if(POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()
if(POLICY CMP0056)
cmake_policy(SET CMP0056 NEW)
endif()
Expand Down Expand Up @@ -175,6 +178,13 @@ else(ENABLE_SHARED)
endif(ENABLE_SHARED)
set(CMAKE_POSITION_INDEPENDENT_CODE ${ENABLE_SHARED})

option(WITH_STATIC_LIBSTDCXX "Link against libstdc++ statically" OFF)
if(WITH_STATIC_LIBSTDCXX)
if(NOT CMAKE_COMPILER_IS_GNUCXX)
message(FATAL_ERROR "Please use GCC to enable WITH_STATIC_LIBSTDCXX")
endif()
endif()

option(WITH_RDMA "Enable RDMA in async messenger" ON)
if(WITH_RDMA)
find_package(rdma REQUIRED)
Expand Down
11 changes: 11 additions & 0 deletions ceph.spec.in
Expand Up @@ -120,7 +120,13 @@ BuildRequires: gperf
BuildRequires: cmake
BuildRequires: cryptsetup
BuildRequires: fuse-devel
%if 0%{?rhel} == 7
# devtoolset offers newer make and valgrind-devel, but the old ones are good
# enough.
BuildRequires: devtoolset-7-gcc-c++
%else
BuildRequires: gcc-c++
%endif
BuildRequires: gdbm
%if 0%{with tcmalloc}
BuildRequires: gperftools-devel >= 2.4
Expand Down Expand Up @@ -778,6 +784,11 @@ python-rbd, python-rgw or python-cephfs instead.
%autosetup -p1 -n @TARBALL_BASENAME@

%build

%if 0%{?rhel} == 7
. /opt/rh/devtoolset-7/enable
%endif

%if 0%{with cephfs_java}
# Find jni.h
for i in /usr/{lib64,lib}/jvm/java/include{,/linux}; do
Expand Down
18 changes: 12 additions & 6 deletions cmake/modules/Distutils.cmake
Expand Up @@ -56,7 +56,18 @@ function(distutils_add_cython_module name src)
endfunction(distutils_add_cython_module)

function(distutils_install_cython_module name)
get_property(compiler_launcher GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
get_property(link_launcher GLOBAL PROPERTY RULE_LAUNCH_LINK)
set(PY_CC "${compiler_launcher} ${CMAKE_C_COMPILER}")
set(PY_LDSHARED "${link_launcher} ${CMAKE_C_COMPILER} -shared")
install(CODE "
set(ENV{CC} \"${PY_CC}\")
set(ENV{LDSHARED} \"${PY_LDSHARED}\")
set(ENV{CPPFLAGS} \"-iquote${CMAKE_SOURCE_DIR}/src/include\")
set(ENV{LDFLAGS} \"-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")
set(ENV{CYTHON_BUILD_DIR} \"${CMAKE_CURRENT_BINARY_DIR}\")
set(ENV{CEPH_LIBDIR} \"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\")
set(options --prefix=${CMAKE_INSTALL_PREFIX})
if(DEFINED ENV{DESTDIR})
if(EXISTS /etc/debian_version)
Expand All @@ -67,12 +78,7 @@ function(distutils_install_cython_module name)
list(APPEND options --root=/)
endif()
execute_process(
COMMAND env
CYTHON_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}
CEPH_LIBDIR=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
CC=${CMAKE_C_COMPILER}
CPPFLAGS=\"-iquote${CMAKE_SOURCE_DIR}/src/include\"
LDFLAGS=\"-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}\"
COMMAND
${PYTHON${PYTHON_VERSION}_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/setup.py
build --verbose --build-base ${CYTHON_MODULE_DIR}
--build-platlib ${CYTHON_MODULE_DIR}/lib.${PYTHON${PYTHON_VERSION}_VERSION_MAJOR}
Expand Down
118 changes: 112 additions & 6 deletions install-deps.sh
@@ -1,4 +1,5 @@
#!/bin/bash -e
#!/usr/bin/env bash
# -*- mode:sh; tab-width:8; indent-tabs-mode:t -*-
#
# Ceph distributed storage system
#
Expand All @@ -11,6 +12,7 @@
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
set -e
DIR=/tmp/install-deps.$$
trap "rm -fr $DIR" EXIT
mkdir -p $DIR
Expand All @@ -24,6 +26,80 @@ function munge_ceph_spec_in {
sed -e 's/@//g' -e 's/%bcond_with make_check/%bcond_without make_check/g' < ceph.spec.in > $OUTFILE
}

function ensure_decent_gcc_on_deb {
# point gcc to the one offered by g++-7 if the used one is not
# new enough
local old=$(gcc -dumpversion)
local new=$1
if dpkg --compare-versions $old ge 7.0; then
return
fi

local dist=$(lsb_release --short --codename)

if [ ! -f /usr/bin/g++-${new} ]; then
$SUDO tee /etc/apt/sources.list.d/ubuntu-toolchain-r.list <<EOF
deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu $dist main
deb [arch=amd64] http://mirror.cs.uchicago.edu/ubuntu-toolchain-r $dist main
deb [arch=amd64,i386] http://mirror.yandex.ru/mirrors/launchpad/ubuntu-toolchain-r $dist main
EOF
# import PPA's signing key into APT's keyring
$SUDO apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1E9377A2BA9EF27F
$SUDO apt-get -y update -o Acquire::Languages=none -o Acquire::Translation=none || true
$SUDO apt-get install -y g++-7
fi

case $dist in
trusty)
old=4.8;;
xenial)
old=5;;
esac
$SUDO update-alternatives --remove-all gcc || true
$SUDO update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-${new} 20 \
--slave /usr/bin/g++ g++ /usr/bin/g++-${new}

$SUDO update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-${old} 10 \
--slave /usr/bin/g++ g++ /usr/bin/g++-${old}

$SUDO update-alternatives --auto gcc

# cmake uses the latter by default
$SUDO ln -nsf /usr/bin/gcc /usr/bin/x86_64-linux-gnu-gcc
$SUDO ln -nsf /usr/bin/g++ /usr/bin/x86_64-linux-gnu-g++
}

function version_lt {
test $1 != $(echo -e "$1\n$2" | sort -rV | head -n 1)
}

function ensure_decent_gcc_on_rh {
local old=$(gcc -dumpversion)
local expected=5.1
local dts_ver=$1
if version_lt $old $expected; then
if test -t 1; then
# interactive shell
cat <<EOF
Your GCC is too old. Please run following command to add DTS to your environment:
scl enable devtoolset-7 bash
Or add following line to the end of ~/.bashrc to add it permanently:
source scl_source enable devtoolset-7
see https://www.softwarecollections.org/en/scls/rhscl/devtoolset-7/ for more details.
EOF
else
# non-interactive shell
source /opt/rh/devtoolset-$dts_ver/enable
fi
fi
}

if [ x`uname`x = xFreeBSDx ]; then
$SUDO pkg install -yq \
devel/babeltrace \
Expand Down Expand Up @@ -79,7 +155,15 @@ else
debian|ubuntu|devuan)
echo "Using apt-get to install dependencies"
$SUDO apt-get install -y lsb-release devscripts equivs
$SUDO apt-get install -y dpkg-dev gcc
$SUDO apt-get install -y dpkg-dev
case "$VERSION" in
*Trusty*|*Xenial*)
ensure_decent_gcc_on_deb 7
;;
*)
$SUDO apt-get install -y gcc
;;
esac
if ! test -r debian/control ; then
echo debian/control is not a readable file
exit 1
Expand Down Expand Up @@ -111,6 +195,12 @@ else
builddepcmd="dnf -y builddep --allowerasing"
fi
echo "Using $yumdnf to install dependencies"
if [ $(lsb_release -si) = CentOS -a $(uname -m) = aarch64 ]; then
$SUDO yum-config-manager --disable centos-sclo-sclo || true
$SUDO yum-config-manager --disable centos-sclo-rh || true
$SUDO yum remove centos-release-scl || true
fi

$SUDO $yumdnf install -y redhat-lsb-core
case $(lsb_release -si) in
Fedora)
Expand All @@ -122,23 +212,39 @@ else
$SUDO yum install -y yum-utils
MAJOR_VERSION=$(lsb_release -rs | cut -f1 -d.)
if test $(lsb_release -si) = RedHatEnterpriseServer ; then
$SUDO yum install subscription-manager
$SUDO subscription-manager repos --enable=rhel-$MAJOR_VERSION-server-optional-rpms
$SUDO yum-config-manager --enable rhel-$MAJOR_VERSION-server-optional-rpms
fi
$SUDO yum-config-manager --add-repo https://dl.fedoraproject.org/pub/epel/$MAJOR_VERSION/x86_64/
$SUDO yum install --nogpgcheck -y epel-release
$SUDO rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$MAJOR_VERSION
$SUDO rm -f /etc/yum.repos.d/dl.fedoraproject.org*
if test $(lsb_release -si) = CentOS -a $MAJOR_VERSION = 7 ; then
$SUDO yum-config-manager --enable cr
fi
if test $(lsb_release -si) = VirtuozzoLinux -a $MAJOR_VERSION = 7 ; then
case $(uname -m) in
x86_64)
$SUDO yum -y install centos-release-scl
dts_ver=7
;;
aarch64)
$SUDO yum -y install centos-release-scl-rh
$SUDO yum-config-manager --disable centos-sclo-rh
$SUDO yum-config-manager --enable centos-sclo-rh-testing
dts_ver=7
;;
esac
elif test $(lsb_release -si) = RedHatEnterpriseServer -a $MAJOR_VERSION = 7 ; then
$SUDO yum-config-manager --enable rhel-server-rhscl-7-rpms
dts_ver=7
elif test $(lsb_release -si) = VirtuozzoLinux -a $MAJOR_VERSION = 7 ; then
$SUDO yum-config-manager --enable cr
fi
;;
esac
munge_ceph_spec_in $DIR/ceph.spec
$SUDO $builddepcmd $DIR/ceph.spec 2>&1 | tee $DIR/yum-builddep.out
if [ -n dts_ver ]; then
ensure_decent_gcc_on_rh $dts_ver
fi
! grep -q -i error: $DIR/yum-builddep.out || exit 1
;;
opensuse|suse|sles)
Expand Down
4 changes: 2 additions & 2 deletions run-make-check.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#
# Ceph distributed storage system
#
Expand Down Expand Up @@ -60,7 +60,7 @@ function run() {
fi

if test -f ./install-deps.sh ; then
$DRY_RUN ./install-deps.sh || return 1
$DRY_RUN source ./install-deps.sh || return 1
fi

# Init defaults after deps are installed. get_processors() depends on coreutils nproc.
Expand Down
25 changes: 20 additions & 5 deletions src/CMakeLists.txt
Expand Up @@ -158,6 +158,18 @@ else()
set(C_STANDARD_REQUIRED ON)
endif()


if(CMAKE_COMPILER_IS_GNUCXX AND
CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
# this is not always correct, as one can use clang with libstdc++ or
# use old gcc with new libstdc++, but it covers the most cases.
#
# libstdc++ 4.9 has O(n) list::size(), and its regex is buggy
message(SEND_ERROR "performance regression is expected due to an O(n) "
"implementation of 'std::list::size()' in libstdc++ older than 5.1.0, "
"Please use GCC 5.1 and up.")
endif()

## Handle diagnostics color if compiler supports them.
CHECK_C_COMPILER_FLAG("-fdiagnostics-color=always"
COMPILER_SUPPORTS_DIAGNOSTICS_COLOR)
Expand Down Expand Up @@ -662,6 +674,12 @@ target_link_libraries(ceph-common dmclock ${ceph_common_deps})
set_target_properties(ceph-common PROPERTIES
SOVERSION 0
INSTALL_RPATH "")
if(WITH_STATIC_LIBSTDCXX)
set_target_properties(ceph-common PROPERTIES
LINK_FLAGS "-static-libstdc++ -static-libgcc")
set_target_properties(common PROPERTIES
LINK_FLAGS "-static-libstdc++ -static-libgcc")
endif()
install(TARGETS ceph-common DESTINATION ${CMAKE_INSTALL_PKGLIBDIR})

add_library(common_utf8 STATIC common/utf8.c)
Expand Down Expand Up @@ -797,7 +815,7 @@ set(ceph_mon_srcs
add_executable(ceph-mon ${ceph_mon_srcs}
$<TARGET_OBJECTS:common_texttable_obj>)
add_dependencies(ceph-mon erasure_code_plugins)
target_link_libraries(ceph-mon mon common os global-static common
target_link_libraries(ceph-mon mon os global-static common
${EXTRALIBS}
${CMAKE_DL_LIBS})
install(TARGETS ceph-mon DESTINATION bin)
Expand All @@ -823,10 +841,7 @@ if (NOT WITH_SYSTEM_ROCKSDB)
# rocksdb/util/crc32c.cc.
list(APPEND ROCKSDB_CMAKE_ARGS -DCMAKE_AR=${CMAKE_AR})
list(APPEND ROCKSDB_CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})

if (CMAKE_CXX_COMPILER_ID STREQUAL Clang)
list(APPEND ROCKSDB_CMAKE_ARGS -DFAIL_ON_WARNINGS=OFF)
endif()
list(APPEND ROCKSDB_CMAKE_ARGS -DFAIL_ON_WARNINGS=OFF)

# we use an external project and copy the sources to bin directory to ensure
# that object files are built outside of the source tree.
Expand Down
3 changes: 2 additions & 1 deletion src/global/CMakeLists.txt
Expand Up @@ -10,8 +10,9 @@ add_library(libglobal_objs OBJECT ${libglobal_srcs})
add_library(global-static STATIC
$<TARGET_OBJECTS:libglobal_objs>
$<TARGET_OBJECTS:global_common_objs>)
target_link_libraries(global-static common)

add_library(global STATIC
$<TARGET_OBJECTS:libglobal_objs>
$<TARGET_OBJECTS:global_common_objs>)
target_link_libraries(global ceph-common ${DPDK_LIBRARIES} ${EXTRALIBS})
target_link_libraries(global ceph-common ${EXTRALIBS})

0 comments on commit b84480c

Please sign in to comment.