Skip to content

Commit 03e6698

Browse files
authored
Support both Linux ABIs, legacy and C++11 (#213)
This change keeps the legacy ABI but also adds an option to build using the C++11 ABI if FIREBASE_LINUX_USE_CXX11_ABI is set during the cmake configure step. In packaging, the location of the Linux libraries is now libs/linux/$arch/$abi, where $arch is x86_64 or i386 (as before), and $abi is legacy or cxx11. For example, libs/linux/x86_64/cxx11/libfirebase_app.a. The binary package's CMakeLists.txt has been updated to choose the correct one based on whether the compiler option is enabled (it checks the actual CFLAGS for the option, not the Firebase-specific flag, so it should handle the selection automatically even if the developer's CMake project doesn't provide the Firebase-specific flag). Also any sub-builds (e.g. boringssl) will also be configured with the requested ABI option.
1 parent c3f1124 commit 03e6698

File tree

8 files changed

+74
-29
lines changed

8 files changed

+74
-29
lines changed

.github/workflows/cpp-packaging.yml

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ jobs:
220220
path: firebase-cpp-sdk-android-${{ matrix.stl }}-package.tgz
221221

222222
build_desktop:
223-
name: build-${{ matrix.sdk_platform }}-${{ matrix.architecture }}-${{ matrix.build_type }}-${{ matrix.msvc_runtime }}
223+
name: build-${{ matrix.sdk_platform }}-${{ matrix.architecture }}-${{ matrix.build_type }}-${{ matrix.msvc_runtime }}-${{ matrix.linux_abi }}
224224
runs-on: ${{ matrix.os }}
225225
if: ${{ github.event.inputs.downloadPublicVersion == '' && github.event.inputs.downloadPreviousRun == '' }}
226226
strategy:
@@ -230,6 +230,7 @@ jobs:
230230
build_type: ["Release", "Debug"]
231231
architecture: ["x64", "x86"]
232232
msvc_runtime: ["static", "dynamic"]
233+
linux_abi: ["legacy", "c++11"]
233234
python_version: [3.7]
234235
include:
235236
- os: windows-latest
@@ -251,10 +252,14 @@ jobs:
251252
sdk_platform: "darwin"
252253

253254
exclude:
255+
- os: windows-latest
256+
linux_abi: "c++11"
254257
- os: macos-latest
255258
architecture: "x86"
256259
- os: macos-latest
257260
msvc_runtime: "dynamic"
261+
- os: macos-latest
262+
linux_abi: "c++11"
258263
- os: macos-latest
259264
build_type: "Debug"
260265
- os: ubuntu-latest
@@ -276,8 +281,8 @@ jobs:
276281
shell: bash
277282
run: |
278283
echo "VCPKG_RESPONSE_FILE=external/vcpkg_${{ matrix.vcpkg_triplet }}_response_file.txt" >> $GITHUB_ENV
279-
echo "MATRIX_UNIQUE_NAME=${{ matrix.os }}-${{ matrix.build_type }}-${{ matrix.architecture }}-${{ matrix.python_version }}" >> $GITHUB_ENV
280-
echo "SDK_NAME=${{ matrix.sdk_platform }}-${{ matrix.architecture }}-${{ matrix.build_type }}-${{ matrix.msvc_runtime }}" >> $GITHUB_ENV
284+
echo "MATRIX_UNIQUE_NAME=${{ matrix.os }}-${{ matrix.build_type }}-${{ matrix.architecture }}-${{ matrix.python_version }}-${{ matrix.msvc_runtime }}-${{ matrix.linux_abi }}" >> $GITHUB_ENV
285+
echo "SDK_NAME=${{ matrix.sdk_platform }}-${{ matrix.architecture }}-${{ matrix.build_type }}-${{ matrix.msvc_runtime }}-${{ matrix.linux_abi }}" >> $GITHUB_ENV
281286
282287
- name: Add msbuild to PATH (windows)
283288
if: startsWith(matrix.os, 'windows')
@@ -288,7 +293,7 @@ jobs:
288293
uses: actions/cache@v2
289294
with:
290295
path: external/vcpkg/installed
291-
key: dev-vcpkg-${{ matrix.architecture }}-${{ matrix.vcpkg_triplet_suffix }}-${{ matrix.msvc_runtime }}-${{ hashFiles(format('{0}', env.VCPKG_RESPONSE_FILE)) }}-${{ hashFiles('.git/modules/external/vcpkg/HEAD') }}
296+
key: dev-vcpkg-${{ matrix.architecture }}-${{ matrix.vcpkg_triplet_suffix }}-${{ matrix.msvc_runtime }}-${{ matrix.linux_abi }}-${{ hashFiles(format('{0}', env.VCPKG_RESPONSE_FILE)) }}-${{ hashFiles('.git/modules/external/vcpkg/HEAD') }}
292297

293298
- name: Cache ccache files
294299
if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')
@@ -310,7 +315,7 @@ jobs:
310315
- name: Build desktop SDK
311316
shell: bash
312317
run: |
313-
python scripts/gha/build_desktop.py --arch "${{ matrix.architecture }}" --config "${{ matrix.build_type }}" --msvc_runtime_library "${{ matrix.msvc_runtime }}" --build_dir out-${{ env.SDK_NAME }} ${{ matrix.additional_build_flags }}
318+
python scripts/gha/build_desktop.py --arch "${{ matrix.architecture }}" --config "${{ matrix.build_type }}" --msvc_runtime_library "${{ matrix.msvc_runtime }}" --linux_abi "${{ matrix.linux_abi }}" --build_dir out-${{ env.SDK_NAME }} ${{ matrix.additional_build_flags }}
314319
# Make a list of all the source files, for debugging purposes.
315320
cd out-${{ env.SDK_NAME }}
316321
find .. -type f -print > src_file_list.txt
@@ -579,17 +584,19 @@ jobs:
579584
name: |
580585
packaging-tools-darwin
581586
packaging-tools-linux
582-
firebase-cpp-sdk-windows-x86-Release-dynamic-build
583-
firebase-cpp-sdk-windows-x64-Release-dynamic-build
584-
firebase-cpp-sdk-windows-x86-Debug-dynamic-build
585-
firebase-cpp-sdk-windows-x64-Debug-dynamic-build
586-
firebase-cpp-sdk-windows-x86-Release-static-build
587-
firebase-cpp-sdk-windows-x64-Release-static-build
588-
firebase-cpp-sdk-windows-x86-Debug-static-build
589-
firebase-cpp-sdk-windows-x64-Debug-static-build
590-
firebase-cpp-sdk-linux-x86-Release-static-build
591-
firebase-cpp-sdk-linux-x64-Release-static-build
592-
firebase-cpp-sdk-darwin-x64-Release-static-build
587+
firebase-cpp-sdk-windows-x86-Release-dynamic-legacy-build
588+
firebase-cpp-sdk-windows-x64-Release-dynamic-legacy-build
589+
firebase-cpp-sdk-windows-x86-Debug-dynamic-legacy-build
590+
firebase-cpp-sdk-windows-x64-Debug-dynamic-legacy-build
591+
firebase-cpp-sdk-windows-x86-Release-static-legacy-build
592+
firebase-cpp-sdk-windows-x64-Release-static-legacy-build
593+
firebase-cpp-sdk-windows-x86-Debug-static-legacy-build
594+
firebase-cpp-sdk-windows-x64-Debug-static-legacy-build
595+
firebase-cpp-sdk-linux-x86-Release-static-legacy-build
596+
firebase-cpp-sdk-linux-x64-Release-static-legacy-build
597+
firebase-cpp-sdk-linux-x86-Release-static-c++11-build
598+
firebase-cpp-sdk-linux-x64-Release-static-c++11-build
599+
firebase-cpp-sdk-darwin-x64-Release-static-legacy-build
593600
firebase-cpp-sdk-windows-x86-Release-dynamic-package
594601
firebase-cpp-sdk-windows-x64-Release-dynamic-package
595602
firebase-cpp-sdk-windows-x86-Debug-dynamic-package

CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ option(FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD
6868
"When building with Gradle, use the previously built libraries." OFF)
6969
option(FIREBASE_USE_BORINGSSL
7070
"Build against BoringSSL instead of using your system's OpenSSL." OFF)
71+
option(FIREBASE_USE_LINUX_CXX11_ABI
72+
"Build Linux SDK using the C++11 ABI instead of the legacy ABI." OFF)
7173

7274
set(FIREBASE_ANDROID_STL "" CACHE STRING "STL implementation to use.")
7375
if (NOT FIREBASE_ANDROID_STL STREQUAL "")
@@ -119,9 +121,15 @@ endif()
119121

120122
if(DESKTOP AND NOT MSVC AND NOT APPLE)
121123
# Linux-specific option.
122-
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
123-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
124-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
124+
if (FIREBASE_LINUX_USE_CXX11_ABI)
125+
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
126+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=1")
127+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=1")
128+
else()
129+
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
130+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
131+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
132+
endif()
125133
endif()
126134

127135
# Set directories needed by the Firebase subprojects

build_scripts/desktop/get_variant.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ debugmode=Release
3232
msvc_runtime_library=MD
3333
vs=VS2015
3434
stl=c++
35+
linux_abi=legacy
3536

3637
for c in $(echo "${filename}" | tr "_.-" "\n\n\n"); do
3738
case $c in
@@ -133,6 +134,15 @@ for c in $(echo "${filename}" | tr "_.-" "\n\n\n"); do
133134
stlport)
134135
stl=stlport
135136
;;
137+
cxx11)
138+
linux_abi=cxx11
139+
;;
140+
c++11)
141+
linux_abi=cxx11
142+
;;
143+
legacy)
144+
linux_abi=legacy
145+
;;
136146
esac
137147
done
138148

@@ -154,7 +164,7 @@ case ${os} in
154164
echo "Couldn't determine architecture" 1>&2
155165
exit 1
156166
fi
157-
echo -n "${arch}"
167+
echo -n "${arch}/${linux_abi}"
158168
;;
159169
windows)
160170
if [[ -z "${arch_win}" ]]; then

cmake/external_rules.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ function(build_external_dependencies)
197197
endif()
198198
else()
199199
# Propagate Linux build flags.
200-
if("${CMAKE_CXX_FLAGS}" MATCHES "-D_GLIBCXX_USE_CXX11_ABI=0")
200+
get_directory_property(CURR_DIRECTORY_DEFS COMPILE_DEFINITIONS)
201+
if("${CURR_DIRECTORY_DEFS}" MATCHES "_GLIBCXX_USE_CXX11_ABI=0" OR
202+
"${CMAKE_CXX_FLAGS}" MATCHES "-D_GLIBCXX_USE_CXX11_ABI=0")
201203
set(SUBBUILD_USE_CXX11_ABI 0)
202204
else()
203205
set(SUBBUILD_USE_CXX11_ABI 1)

cmake/toolchains/linux_32.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616

1717
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
1818
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
19-
set(CMAKE_LIBRARY_PATH "/usr/lib/i386-linux-gnu")
19+
set(CMAKE_LIBRARY_PATH "/usr/lib/i386-linux-gnu")
20+
set(INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES} "/usr/include/i386-linux-gnu")

external/vcpkg_custom_data/toolchains/linux_32.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
1717
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
1818
set(CMAKE_LIBRARY_PATH "/usr/lib/i386-linux-gnu")
19+
set(INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES} "/usr/include/i386-linux-gnu")
1920

2021
# From this line onwards, everything is a copy of the standard toolchain file
2122
# shipped with vcpkg (vcpkg/scripts/buildsystems/vcpkg.cmake). This way, we can

release_build_files/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,18 @@ elseif(MSVC)
4949
set(FIREBASE_SDK_LIBDIR
5050
${FIREBASE_CPP_SDK_DIR}/libs/windows/${MSVC_VS_VERSION}/${MSVC_RUNTIME_MODE}/${MSVC_CPU}/${MSVC_CONFIG})
5151
else()
52-
# The Firebase libraries are not built with glibcxx11, so disable the ABI.
53-
set(DISABLE_CXX11 TRUE)
52+
# Check whether we are building with CXX11 ABI.
53+
get_directory_property(CURR_DIRECTORY_DEFS COMPILE_DEFINITIONS)
54+
if ("${CURR_DIRECTORY_DEFS}" MATCHES "_GLIBCXX_USE_CXX11_ABI=0" OR
55+
"${CMAKE_CXX_FLAGS}" MATCHES "-D_GLIBCXX_USE_CXX11_ABI=0")
56+
set(DISABLE_CXX11 TRUE)
57+
set(LINUX_ABI legacy)
58+
else()
59+
set(DISABLE_CXX11 FALSE)
60+
set(LINUX_ABI cxx11)
61+
endif()
5462
set(LINUX_CPU x86_64)
55-
set(FIREBASE_SDK_LIBDIR ${FIREBASE_CPP_SDK_DIR}/libs/linux/${LINUX_CPU})
63+
set(FIREBASE_SDK_LIBDIR ${FIREBASE_CPP_SDK_DIR}/libs/linux/${LINUX_CPU}/${LINUX_ABI})
5664
endif()
5765

5866
# Defines a Firebase target, linking it with the correct prebuilt library.

scripts/gha/build_desktop.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def append_line_to_file(path, line):
5959
def install_x86_support_libraries():
6060
"""Install support libraries needed to build x86 on x86_64 hosts."""
6161
if utils.is_linux_os():
62-
packages = ['gcc-multilib', 'g++-multilib', 'libglib2.0-dev:i386', 'libsecret-1-dev:i386']
62+
packages = ['gcc-multilib', 'g++-multilib', 'libglib2.0-dev:i386',
63+
'libsecret-1-dev:i386', 'libpthread-stubs0-dev:i386',
64+
'libssl-dev:i386']
6365

6466
# First check if these packages exist on the machine already
6567
devnull = open(os.devnull, "w")
@@ -70,7 +72,7 @@ def install_x86_support_libraries():
7072
# Install them.
7173
utils.run_command(['dpkg', '--add-architecture', 'i386'], as_root=True)
7274
utils.run_command(['apt', 'update'], as_root=True)
73-
utils.run_command(['apt', 'install'] + packages, as_root=True)
75+
utils.run_command(['apt', 'install', '-y'] + packages, as_root=True)
7476

7577

7678
def _install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library):
@@ -138,7 +140,7 @@ def install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library, cleanup=True
138140
# could be several GBs and cause github runners to run out of space
139141
utils.clean_vcpkg_temp_data()
140142

141-
def cmake_configure(build_dir, arch, msvc_runtime_library='static',
143+
def cmake_configure(build_dir, arch, msvc_runtime_library='static', linux_abi='legacy',
142144
build_tests=True, config=None, target_format=None):
143145
""" CMake configure.
144146
@@ -149,6 +151,7 @@ def cmake_configure(build_dir, arch, msvc_runtime_library='static',
149151
build_dir (str): Output build directory.
150152
arch (str): Platform Architecture (example: 'x64').
151153
msvc_runtime_library (str): Runtime library for MSVC (eg: 'static', 'dynamic').
154+
linux_abi (str): Linux ABI (eg: 'legacy', 'c++11').
152155
build_tests (bool): Build cpp unit tests.
153156
config (str): Release/Debug config.
154157
If its not specified, cmake's default is used (most likely Debug).
@@ -192,6 +195,9 @@ def cmake_configure(build_dir, arch, msvc_runtime_library='static',
192195
if msvc_runtime_library == "static":
193196
cmd.append('-DMSVC_RUNTIME_LIBRARY_STATIC=ON')
194197

198+
if utils.is_linux_os() and linux_abi == 'c++11':
199+
cmd.append('-DFIREBASE_LINUX_USE_CXX11_ABI=TRUE')
200+
195201
if (target_format):
196202
cmd.append('-DFIREBASE_XCODE_TARGET_FORMAT={0}'.format(target_format))
197203

@@ -219,7 +225,7 @@ def main():
219225
return
220226

221227
# CMake configure
222-
cmake_configure(args.build_dir, args.arch, args.msvc_runtime_library,
228+
cmake_configure(args.build_dir, args.arch, args.msvc_runtime_library, args.linux_abi,
223229
args.build_tests, args.config, args.target_format)
224230

225231
# Small workaround before build, turn off -Werror=sign-compare for a specific Firestore core lib.
@@ -253,6 +259,8 @@ def parse_cmdline_args():
253259
parser.add_argument('-a', '--arch', default='x64', help='Platform architecture (x64, x86)')
254260
parser.add_argument('--msvc_runtime_library', default='static',
255261
help='Runtime library for MSVC (static(/MT) or dynamic(/MD)')
262+
parser.add_argument('--linux_abi', default='legacy',
263+
help='C++ ABI for Linux (legacy or c++11)')
256264
parser.add_argument('--build_dir', default='build', help='Output build directory')
257265
parser.add_argument('--build_tests', action='store_true', help='Build unit tests too')
258266
parser.add_argument('--vcpkg_step_only', action='store_true', help='Just install cpp packages using vcpkg and exit.')

0 commit comments

Comments
 (0)