Skip to content

Commit a6ff671

Browse files
Yuhong Guowesm
authored andcommitted
Support offline build of glog
1 parent 14865ee commit a6ff671

10 files changed

Lines changed: 156 additions & 36 deletions

File tree

ci/travis_install_toolchain.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ if [ ! -e $CPP_TOOLCHAIN ]; then
3939
snappy \
4040
thrift-cpp=0.11.0 \
4141
zlib \
42+
glog \
4243
zstd
4344
fi

cpp/CMakeLists.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ Pass multiple labels by dividing with semicolons")
257257
OFF)
258258

259259
option(ARROW_USE_GLOG
260-
"Build the Plasma logging system using glog"
260+
"Build libraries with glog support for pluggable logging"
261261
ON)
262262

263263
if (MSVC)
@@ -652,9 +652,14 @@ if (ARROW_ORC)
652652
endif()
653653
654654
if (ARROW_USE_GLOG)
655-
SET(ARROW_STATIC_LINK_LIBS
656-
glog
657-
${ARROW_STATIC_LINK_LIBS})
655+
#SET(ARROW_SHARED_PRIVATE_LINK_LIBS
656+
# glog_static
657+
# ${ARROW_SHARED_PRIVATE_LINK_LIBS})
658+
#SET(ARROW_SHARED_PRIVATE_LINK_LIBS
659+
# glog_static
660+
# ${ARROW_SHARED_PRIVATE_LINK_LIBS})
661+
SET(ARROW_STATIC_LINK_LIBS glog_static ${ARROW_STATIC_LINK_LIBS})
662+
#add_dependencies(arrow_dependencies glog_static)
658663
add_definitions(-DARROW_USE_GLOG)
659664
endif()
660665
@@ -679,6 +684,9 @@ set(ARROW_STATIC_PRIVATE_LINK_LIBS
679684
${BOOST_FILESYSTEM_LIBRARY}
680685
${BOOST_REGEX_LIBRARY})
681686
687+
if (ARROW_USE_GLOG)
688+
set(ARROW_STATIC_PRIVATE_LINK_LIBS glog_static ${ARROW_STATIC_PRIVATE_LINK_LIBS})
689+
endif()
682690
if (NOT MSVC)
683691
set(ARROW_LINK_LIBS
684692
${ARROW_LINK_LIBS}

cpp/cmake_modules/FindGLOG.cmake

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
#
14+
# Tries to find GLog headers and libraries.
15+
#
16+
# Usage of this module as follows:
17+
#
18+
# find_package(GLOG)
19+
#
20+
# Variables used by this module, they can change the default behaviour and need
21+
# to be set before calling find_package:
22+
#
23+
# GLOG_HOME - When set, this path is inspected instead of standard library
24+
# locations as the root of the GLog installation.
25+
# The environment variable GLOG_HOME overrides this veriable.
26+
#
27+
# This module defines
28+
# GLOG_INCLUDE_DIR, directory containing headers
29+
# GLOG_STATIC_LIB, path to libglog.a
30+
# GLOG_FOUND, whether glog has been found
31+
32+
if( NOT "${GLOG_HOME}" STREQUAL "")
33+
file( TO_CMAKE_PATH "${GLOG_HOME}" _native_path )
34+
list( APPEND _glog_roots ${_native_path} )
35+
endif()
36+
37+
# Try the parameterized roots, if they exist
38+
if ( _glog_roots )
39+
find_path( GLOG_INCLUDE_DIR NAMES glog/logging.h
40+
PATHS ${_glog_roots} NO_DEFAULT_PATH
41+
PATH_SUFFIXES "include" )
42+
find_library( GLOG_LIBRARIES NAMES glog
43+
PATHS ${_glog_roots} NO_DEFAULT_PATH
44+
PATH_SUFFIXES "lib" )
45+
else ()
46+
find_path( GLOG_INCLUDE_DIR NAMES glog/logging.h )
47+
find_library( GLOG_LIBRARIES NAMES glog )
48+
endif ()
49+
50+
51+
if (GLOG_INCLUDE_DIR AND GLOG_LIBRARIES)
52+
set(GLOG_FOUND TRUE)
53+
get_filename_component( GLOG_LIBS ${GLOG_LIBRARIES} PATH )
54+
set(GLOG_LIB_NAME glog)
55+
set(GLOG_STATIC_LIB ${GLOG_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${GLOG_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
56+
set(GLOG_MAIN_STATIC_LIB ${GLOG_LIBS}/${CMAKE_STATIC_LIBRARY_PREFIX}${GLOG_LIB_NAME}_main${CMAKE_STATIC_LIBRARY_SUFFIX})
57+
set(GLOG_SHARED_LIB ${GLOG_LIBS}/${CMAKE_SHARED_LIBRARY_PREFIX}${GLOG_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
58+
else ()
59+
set(GLOG_FOUND FALSE)
60+
endif ()
61+
62+
if (GLOG_FOUND)
63+
if (NOT GLOG_FIND_QUIETLY)
64+
message(STATUS "Found the GLog library: ${GLOG_LIBRARIES}")
65+
endif ()
66+
else ()
67+
if (NOT GLOG_FIND_QUIETLY)
68+
set(GLOG_ERR_MSG "Could not find the GLog library. Looked in ")
69+
if ( _glog_roots )
70+
set(GLOG_ERR_MSG "${GLOG_ERR_MSG} ${_glog_roots}.")
71+
else ()
72+
set(GLOG_ERR_MSG "${GLOG_ERR_MSG} system search paths.")
73+
endif ()
74+
if (GLOG_FIND_REQUIRED)
75+
message(FATAL_ERROR "${GLOG_ERR_MSG}")
76+
else (GLOG_FIND_REQUIRED)
77+
message(STATUS "${GLOG_ERR_MSG}")
78+
endif (GLOG_FIND_REQUIRED)
79+
endif ()
80+
endif ()
81+
82+
mark_as_advanced(
83+
GLOG_INCLUDE_DIR
84+
GLOG_LIBS
85+
GLOG_LIBRARIES
86+
GLOG_STATIC_LIB
87+
)

cpp/cmake_modules/ThirdpartyToolchain.cmake

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ if (NOT "$ENV{ARROW_BUILD_TOOLCHAIN}" STREQUAL "")
4040
set(THRIFT_HOME "$ENV{ARROW_BUILD_TOOLCHAIN}")
4141
set(ZLIB_HOME "$ENV{ARROW_BUILD_TOOLCHAIN}")
4242
set(ZSTD_HOME "$ENV{ARROW_BUILD_TOOLCHAIN}")
43+
set(GLOG_HOME "$ENV{ARROW_BUILD_TOOLCHAIN}")
4344

4445
if (NOT DEFINED ENV{BOOST_ROOT})
4546
# Since we have to set this in the environment, we check whether
@@ -106,6 +107,10 @@ if (DEFINED ENV{ZSTD_HOME})
106107
set(ZSTD_HOME "$ENV{ZSTD_HOME}")
107108
endif()
108109

110+
if (DEFINED ENV{GLOG_HOME})
111+
set(GLOG_HOME "$ENV{GLOG_HOME}")
112+
endif()
113+
109114
# ----------------------------------------------------------------------
110115
# Some EP's require other EP's
111116

@@ -238,6 +243,12 @@ else()
238243
set(ZSTD_SOURCE_URL "https://github.com/facebook/zstd/archive/v${ZSTD_VERSION}.tar.gz")
239244
endif()
240245

246+
if (DEFINED ENV{ARROW_GLOG_URL})
247+
set(GLOG_SOURCE_URL "$ENV{ARROW_GLOG_URL}")
248+
else()
249+
set(GLOG_SOURCE_URL "https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz")
250+
endif()
251+
241252
# ----------------------------------------------------------------------
242253
# ExternalProject options
243254

@@ -1261,42 +1272,51 @@ endif()
12611272

12621273
endif() # ARROW_HIVESERVER2
12631274

1264-
if(ARROW_USE_GLOG)
1265-
message(STATUS "Starting to build glog")
1266-
set(GLOG_VERSION "0.3.5")
1267-
set(GLOG_CMAKE_CXX_FLAGS "${EP_CXX_FLAGS} -fPIC")
1268-
if(APPLE)
1269-
# If we don't set this flag, the binary built with 10.13 cannot be used in 10.12.
1270-
set(GLOG_CMAKE_CXX_FLAGS "${GLOG_CMAKE_CXX_FLAGS} -mmacosx-version-min=10.12")
1271-
endif()
1275+
if (ARROW_USE_GLOG)
1276+
# ----------------------------------------------------------------------
1277+
# GLOG
12721278

1273-
set(GLOG_URL "https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz")
1274-
set(GLOG_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/glog_ep/src/glog_ep-install")
1275-
set(GLOG_HOME "${GLOG_PREFIX}")
1276-
set(GLOG_INCLUDE_DIR "${GLOG_PREFIX}/include")
1277-
set(GLOG_STATIC_LIB "${GLOG_PREFIX}/lib/libglog.a")
1279+
if("${GLOG_HOME}" STREQUAL "")
1280+
set(GLOG_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/glog_ep-prefix/src/glog_ep")
1281+
set(GLOG_INCLUDE_DIR "${GLOG_BUILD_DIR}/include")
1282+
set(GLOG_STATIC_LIB "${GLOG_BUILD_DIR}/lib/libglog.a")
1283+
set(GLOG_CMAKE_CXX_FLAGS "${GLOG_CMAKE_CXX_FLAGS} -fPIC")
1284+
1285+
if(APPLE)
1286+
# If we don't set this flag, the binary built with 10.13 cannot be used in 10.12.
1287+
set(GLOG_CMAKE_CXX_FLAGS "${GLOG_CMAKE_CXX_FLAGS} -mmacosx-version-min=10.12")
1288+
endif()
12781289

1279-
set(GLOG_CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
1280-
-DCMAKE_INSTALL_PREFIX=${GLOG_PREFIX}
1290+
set(GLOG_CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
1291+
-DCMAKE_INSTALL_PREFIX=${GLOG_BUILD_DIR}
12811292
-DBUILD_SHARED_LIBS=OFF
12821293
-DBUILD_TESTING=OFF
12831294
-DWITH_GFLAGS=OFF
12841295
-DCMAKE_CXX_FLAGS_${UPPERCASE_BUILD_TYPE}=${GLOG_CMAKE_CXX_FLAGS}
12851296
-DCMAKE_C_FLAGS_${UPPERCASE_BUILD_TYPE}=${EP_C_FLAGS}
12861297
-DCMAKE_CXX_FLAGS=${GLOG_CMAKE_CXX_FLAGS})
1298+
message(STATUS "Glog version: ${GLOG_VERSION}")
1299+
ExternalProject_Add(glog_ep
1300+
URL ${GLOG_SOURCE_URL}
1301+
#BUILD_IN_SOURCE 1
1302+
BUILD_BYPRODUCTS "${GLOG_STATIC_LIB}"
1303+
CMAKE_ARGS ${GLOG_CMAKE_ARGS}
1304+
${EP_LOG_OPTIONS})
12871305

1288-
ExternalProject_Add(glog_ep
1289-
URL ${GLOG_URL}
1290-
${EP_LOG_OPTIONS}
1291-
BUILD_IN_SOURCE 1
1292-
BUILD_BYPRODUCTS "${GLOG_STATIC_LIB}"
1293-
CMAKE_ARGS ${GLOG_CMAKE_ARGS})
1306+
set(GLOG_VENDORED 1)
1307+
else()
1308+
find_package(GLOG REQUIRED)
1309+
set(GLOG_VENDORED 0)
1310+
endif()
1311+
1312+
message(STATUS "Glog include dir: ${GLOG_INCLUDE_DIR}")
1313+
message(STATUS "Glog static library: ${GLOG_STATIC_LIB}")
12941314

1295-
message(STATUS "GLog include dir: ${GLOG_INCLUDE_DIR}")
1296-
message(STATUS "GLog static library: ${GLOG_STATIC_LIB}")
12971315
include_directories(SYSTEM ${GLOG_INCLUDE_DIR})
1298-
ADD_THIRDPARTY_LIB(glog
1316+
ADD_THIRDPARTY_LIB(glog_static
12991317
STATIC_LIB ${GLOG_STATIC_LIB})
13001318

1301-
add_dependencies(glog glog_ep)
1302-
endif() # ARROW_USE_GLOG
1319+
if (GLOG_VENDORED)
1320+
add_dependencies(glog_static glog_ep)
1321+
endif()
1322+
endif()

cpp/src/arrow/util/logging-test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ TEST(PrintLogTest, LogTestWithInit) {
6767
TEST(LogPerfTest, PerfTest) {
6868
ArrowLog::StartArrowLog("/fake/path/to/appdire/LogPerfTest", ArrowLogLevel::ARROW_ERROR,
6969
"/tmp/");
70-
int rounds = 100000;
70+
int rounds = 10000;
7171

7272
int64_t start_time = current_time_ms();
7373
for (int i = 0; i < rounds; ++i) {

cpp/src/arrow/util/logging.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ typedef arrow::CerrLog LoggingProvider;
7979
#endif
8080

8181
ArrowLogLevel ArrowLog::severity_threshold_ = ArrowLogLevel::ARROW_INFO;
82-
std::unique_ptr<char[]> ArrowLog::app_name_;
82+
std::unique_ptr<std::string> ArrowLog::app_name_;
8383

8484
#ifdef ARROW_USE_GLOG
8585

@@ -109,11 +109,10 @@ void ArrowLog::StartArrowLog(const std::string& app_name,
109109
ArrowLogLevel severity_threshold,
110110
const std::string& log_dir) {
111111
severity_threshold_ = severity_threshold;
112-
app_name_.reset(new char[app_name.length() + 1]);
113-
snprintf(app_name_.get(), app_name.length() + 1, "%s", app_name.c_str());
112+
app_name_.reset(new std::string(app_name));
114113
#ifdef ARROW_USE_GLOG
115114
int mapped_severity_threshold = GetMappedSeverity(severity_threshold_);
116-
google::InitGoogleLogging(app_name_.get());
115+
google::InitGoogleLogging(app_name_->c_str());
117116
google::SetStderrLogging(mapped_severity_threshold);
118117
// Enble log file if log_dir is not empty.
119118
if (!log_dir.empty()) {

cpp/src/arrow/util/logging.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class ArrowLog : public ArrowLogBase {
158158
static ArrowLogLevel severity_threshold_;
159159
// In InitGoogleLogging, it simply keeps the pointer.
160160
// We need to make sure the app name passed to InitGoogleLogging exist.
161-
static std::unique_ptr<char[]> app_name_;
161+
static std::unique_ptr<std::string> app_name_;
162162

163163
protected:
164164
virtual std::ostream& Stream();

cpp/thirdparty/download_dependencies.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ wget -c -O $_DST/orc.tar.gz https://github.com/apache/orc/archive/rel/release-$O
6767

6868
wget -c -O $_DST/thrift.tar.gz http://archive.apache.org/dist/thrift/${THRIFT_VERSION}/thrift-${THRIFT_VERSION}.tar.gz
6969

70+
wget -c -O $_DST/glog.tar.gz https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz
71+
7072
echo "
7173
# Environment variables for offline Arrow build
7274
export ARROW_BOOST_URL=$_DST/boost.tar.gz
@@ -84,4 +86,5 @@ export ARROW_PROTOBUF_URL=$_DST/protobuf.tar.gz
8486
export ARROW_GRPC_URL=$_DST/grpc.tar.gz
8587
export ARROW_ORC_URL=$_DST/orc.tar.gz
8688
export ARROW_THRIFT_URL=$_DST/thrift.tar.gz
89+
export ARROW_GLOG_URL=$_DST/glog.tar.gz
8790
"

cpp/thirdparty/versions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ PROTOBUF_VERSION=2.6.0
3333
GRPC_VERSION=1.12.1
3434
ORC_VERSION=1.5.1
3535
THRIFT_VERSION=0.11.0
36+
GLOG_VERSION=0.3.5

python/testing/setup_toolchain.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ conda create -y -q -p $CPP_TOOLCHAIN python=3.6 \
5656
curl \
5757
thrift-cpp \
5858
libhdfs3 \
59+
glog \
5960
ninja
6061

6162
if [ $BUILD_OS_NAME == "osx" ]; then

0 commit comments

Comments
 (0)