From 8c2a48742a00670fb05752fb34d72ba7f2ba3150 Mon Sep 17 00:00:00 2001 From: Yi Wu Date: Wed, 7 Nov 2018 22:08:35 -0800 Subject: [PATCH] Use -Os for lite release build (#4652) Summary: Set `-Os` for lite release build to minimize binary size. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4652 Differential Revision: D12965427 Pulled By: yiwu-arbug fbshipit-source-id: c8b647642c24b3e5df6a2cd13112e452a08e8398 --- CMakeLists.txt | 2 +- Makefile | 17 ++++++++++++++++- build_tools/rocksdb-lego-determinator | 7 +++---- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cb80cd10..2a4bdb6b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -366,7 +366,7 @@ endif() option(ROCKSDB_LITE "Build RocksDBLite version" OFF) if(ROCKSDB_LITE) add_definitions(-DROCKSDB_LITE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -Os") endif() if(CMAKE_SYSTEM_NAME MATCHES "Cygwin") diff --git a/Makefile b/Makefile index 176ad1217..2b3274f7a 100644 --- a/Makefile +++ b/Makefile @@ -93,9 +93,24 @@ ifeq ($(MAKECMDGOALS),rocksdbjavastaticpublish) DEBUG_LEVEL=0 endif +# Lite build flag. +LITE ?= 0 +ifneq ($(LITE), 0) + OPT += -DROCKSDB_LITE +endif + +# Figure out optimize level. +ifneq ($(DEBUG_LEVEL), 2) +ifeq ($(LITE), 0) + OPT += -O2 +else + OPT += -Os +endif +endif + # compile with -O2 if debug level is not 2 ifneq ($(DEBUG_LEVEL), 2) -OPT += -O2 -fno-omit-frame-pointer +OPT += -fno-omit-frame-pointer # Skip for archs that don't support -momit-leaf-frame-pointer ifeq (,$(shell $(CXX) -fsyntax-only -momit-leaf-frame-pointer -xc /dev/null 2>&1)) OPT += -momit-leaf-frame-pointer diff --git a/build_tools/rocksdb-lego-determinator b/build_tools/rocksdb-lego-determinator index 1365f7fe9..90ff38556 100755 --- a/build_tools/rocksdb-lego-determinator +++ b/build_tools/rocksdb-lego-determinator @@ -85,7 +85,6 @@ NON_SHM="TMPD=/tmp/rocksdb_test_tmp" GCC_481="ROCKSDB_FBCODE_BUILD_WITH_481=1" ASAN="COMPILE_WITH_ASAN=1" CLANG="USE_CLANG=1" -LITE="OPT=\"-DROCKSDB_LITE -g\"" TSAN="COMPILE_WITH_TSAN=1" UBSAN="COMPILE_WITH_UBSAN=1" TSAN_CRASH='CRASH_TEST_EXT_ARGS="--compression_type=zstd --log2_keys_per_lock=22"' @@ -345,7 +344,7 @@ LITE_BUILD_COMMANDS="[ $CLEANUP_ENV, { 'name':'Build RocksDB debug version', - 'shell':'$LITE make J=1 all check || $CONTRUN_NAME=lite $TASK_CREATION_TOOL', + 'shell':'make J=1 LITE=1 all check || $CONTRUN_NAME=lite $TASK_CREATION_TOOL', 'user':'root', $PARSER }, @@ -663,12 +662,12 @@ run_regression() # === lite build === make clean - OPT=-DROCKSDB_LITE make -j$(nproc) static_lib + make LITE=1 -j$(nproc) static_lib send_size_to_ods static_lib_lite $(stat --printf="%s" librocksdb.a) strip librocksdb.a send_size_to_ods static_lib_lite_stripped $(stat --printf="%s" librocksdb.a) - OPT=-DROCKSDB_LITE make -j$(nproc) shared_lib + make LITE=1 -j$(nproc) shared_lib send_size_to_ods shared_lib_lite $(stat --printf="%s" `readlink -f librocksdb.so`) strip `readlink -f librocksdb.so` send_size_to_ods shared_lib_lite_stripped $(stat --printf="%s" `readlink -f librocksdb.so`)