Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 55 additions & 41 deletions .github/workflows/cpp-packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,21 @@ jobs:
tar -xvzf artifacts/packaging-tools-${tools_platform}/packaging-tools.tgz -C bin
rm -rf artifacts/packaging-tools-*.tgz
chmod -R u+x bin
if [[ "${{ matrix.sdk_platform }}" != "darwin" ]]; then
# Use llvm-objcopy rather than GNU objcopy to rename symbols on
# Linux and Windows. GNU objcopy does a linear search of the symbol
# redefinition list for every symbol, which is extremely slow for
# large (especially Debug) libraries; llvm-objcopy uses a hash table.
# The Ubuntu runners come with several versions of LLVM installed,
# so use the newest one available.
llvm_objcopy=$(ls /usr/bin/llvm-objcopy-* 2>/dev/null | sort -V | tail -n 1)
if [[ -z "${llvm_objcopy}" ]]; then
sudo apt-get install -y llvm
llvm_objcopy=$(command -v llvm-objcopy)
fi
echo "Using ${llvm_objcopy}: $(${llvm_objcopy} --version | head -n 2 | tr '\n' ' ')"
ln -sf "${llvm_objcopy}" bin/llvm-objcopy
fi
# To save space, delete any artifacts that we don't need for packaging.
for pkg in artifacts/firebase-cpp-sdk-*; do
if [[ "${pkg}" != "artifacts/firebase-cpp-sdk-${{ matrix.sdk_platform }}${{ matrix.suffix }}"* ]]; then
Expand All @@ -608,11 +623,16 @@ jobs:
# MacOS: use LLVM binutils for both X64 and ARM64
additional_flags+=(-L)
elif [[ "${{ matrix.sdk_platform }}" == "windows" && "${variant}" == *"/x64/"* ]]; then
# Windows x64: force input and output target format
additional_flags+=(-f pe-x86-64,pe-bigobj-x86-64)
# Windows x64: force input and output target format (for GNU
# nm and ar; llvm-objcopy autodetects the format).
additional_flags+=(-O -f pe-x86-64,pe-bigobj-x86-64)
elif [[ "${{ matrix.sdk_platform }}" == "windows" && "${variant}" == *"/x86/"* ]]; then
# Windows x86: force input and output target format
additional_flags+=(-f pe-i386,pe-bigobj-i386)
# Windows x86: force input and output target format (for GNU
# nm and ar; llvm-objcopy autodetects the format).
additional_flags+=(-O -f pe-i386,pe-bigobj-i386)
else
# Linux: use llvm-objcopy, GNU nm and ar.
additional_flags+=(-O)
fi
sdk-src/build_scripts/desktop/package.sh -D -b ${pkg} -o firebase-cpp-sdk-${{ matrix.sdk_platform }}${{ matrix.suffix }}-package -p ${{ matrix.sdk_platform }} -t bin -d ${variant} -P python3 -j ${additional_flags[*]}
done
Expand Down Expand Up @@ -783,15 +803,38 @@ jobs:
# Save the hash of every file into the SDK package.
find firebase_cpp_sdk -type f -print0 | xargs -0 ${{ env.hashCommand }} --tag > file_hashes.txt
mv file_hashes.txt firebase_cpp_sdk/
# Zip up the SDK package recursively, preserving symlinks.
zip -9 -r -y ../firebase_cpp_sdk.zip firebase_cpp_sdk

# Create the Windows-only SDK package, using hard links to avoid
# copying the files.
mkdir -p ../windows-sdk
cp -al firebase_cpp_sdk ../windows-sdk/firebase_cpp_sdk_windows
pushd ../windows-sdk/firebase_cpp_sdk_windows
# Remove all non-Windows files.
rm -rf xcframeworks frameworks libs/linux libs/ios libs/tvos libs/darwin libs/android Android
cat > readme_windows.md <<EOF
# Firebase C++ SDK - Windows only

This package contains only the subset of the Firebase C++ SDK needed for use on
Windows. For general SDK information, see the accompanying readme.md file.
EOF
popd

# Zip up both SDK packages recursively (in parallel), preserving symlinks.
../sdk-src/build_scripts/other/zip_package.sh ../firebase_cpp_sdk.zip firebase_cpp_sdk &
full_zip_pid=$!
(cd ../windows-sdk && ../sdk-src/build_scripts/other/zip_package.sh ../firebase_cpp_sdk_windows.zip firebase_cpp_sdk_windows) &
windows_zip_pid=$!
wait ${full_zip_pid}
wait ${windows_zip_pid}
cd ..

- name: compute SDK hash
shell: bash
run: |
${{ env.hashCommand }} --tag firebase_cpp_sdk.zip > firebase_cpp_sdk_hash.txt
echo "::warning ::$(cat firebase_cpp_sdk_hash.txt)"
${{ env.hashCommand }} --tag firebase_cpp_sdk_windows.zip > firebase_cpp_sdk_windows_hash.txt
echo "::warning ::$(cat firebase_cpp_sdk_windows_hash.txt)"

- name: Print final package contents
shell: bash
Expand All @@ -810,51 +853,22 @@ jobs:
with:
name: firebase_cpp_sdk.zip
path: firebase_cpp_sdk.zip
# Already compressed, don't waste time compressing it again.
compression-level: 0

create_windows_only_package:
name: create-windows-only-package
runs-on: ubuntu-22.04
needs: [merge_packages]
steps:
- name: download SDK zip
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # ratchet:actions/download-artifact@v8
with:
name: firebase_cpp_sdk.zip
- name: unzip SDK and remove non-Windows files
run: |
set -x
unzip -q firebase_cpp_sdk.zip -d windows-sdk
cd windows-sdk
# Rename the top-level directory.
mv firebase_cpp_sdk firebase_cpp_sdk_windows
cd firebase_cpp_sdk_windows
# Remove all non-Windows files.
rm -rf xcframeworks frameworks libs/linux libs/ios libs/tvos libs/darwin libs/android Android
cat > readme_windows.md <<EOF
# Firebase C++ SDK - Windows only

This package contains only the subset of the Firebase C++ SDK needed for use on
Windows. For general SDK information, see the accompanying readme.md file.
EOF
cd ..
zip -9 -r -y ../firebase_cpp_sdk_windows.zip firebase_cpp_sdk_windows
cd ..
- name: compute Windows SDK hash
shell: bash
run: |
${{ env.hashCommand }} --tag firebase_cpp_sdk_windows.zip > firebase_cpp_sdk_windows_hash.txt
echo "::warning ::$(cat firebase_cpp_sdk_windows_hash.txt)"
- name: upload Windows hash
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # ratchet:actions/upload-artifact@v7
with:
name: firebase_cpp_sdk_windows_hash.txt
path: firebase_cpp_sdk_windows_hash.txt

- name: upload Windows SDK zip
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # ratchet:actions/upload-artifact@v7
with:
name: firebase_cpp_sdk_windows.zip
path: firebase_cpp_sdk_windows.zip

# Already compressed, don't waste time compressing it again.
compression-level: 0

cleanup_packaging_artifacts:
# Clean up intermediate artifacts from packaging step.
Expand All @@ -879,7 +893,7 @@ jobs:

trigger_integration_tests:
# Trigger the integration_tests workflow.
needs: [merge_packages, download_sdk_package, create_windows_only_package, cleanup_packaging_artifacts]
needs: [merge_packages, download_sdk_package, cleanup_packaging_artifacts]
if: (github.event.inputs.skipIntegrationTests == 0 || github.event.inputs.skipIntegrationTests == '') && !cancelled() && !failure()
runs-on: ubuntu-22.04
steps:
Expand Down
14 changes: 12 additions & 2 deletions build_scripts/desktop/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ options:
-j, run merge_libraries jobs in parallel
-v, enable verbose mode
-L, use LLVM binutils
-O, use llvm-objcopy (from the tools directory) for objcopy only, but keep
using GNU nm and ar. Much faster than GNU objcopy when renaming many symbols.
-R, print rename prefix and exit
-N, print allowed namespaces and exit
-D, delete package files after using them to save disk space
Expand All @@ -41,6 +43,7 @@ binutils_format=
temp_dir=
run_in_parallel=0
use_llvm_binutils=0
use_llvm_objcopy=0

. "${root_dir}/build_scripts/packaging.conf"

Expand All @@ -59,7 +62,7 @@ abspath(){
fi
}

while getopts "f:b:o:p:d:m:P:t:NRhjLDv" opt; do
while getopts "f:b:o:p:d:m:P:t:NRhjLODv" opt; do
case $opt in
f)
binutils_format=$OPTARG
Expand Down Expand Up @@ -90,6 +93,9 @@ while getopts "f:b:o:p:d:m:P:t:NRhjLDv" opt; do
L)
use_llvm_binutils=1
;;
O)
use_llvm_objcopy=1
;;
d)
variant=$OPTARG
;;
Expand Down Expand Up @@ -235,7 +241,11 @@ if [[ ${use_llvm_binutils} -eq 1 ]]; then
readonly binutils_nm=${tools_path}/llvm-nm
readonly binutils_ar=${tools_path}/llvm-ar
else
readonly binutils_objcopy=${tools_path}/objcopy
if [[ ${use_llvm_objcopy} -eq 1 ]]; then
readonly binutils_objcopy=${tools_path}/llvm-objcopy
else
readonly binutils_objcopy=${tools_path}/objcopy
fi
if [[ -x ${tools_path}/nm-new ]] ; then
readonly binutils_nm=${tools_path}/nm-new
else
Expand Down
91 changes: 91 additions & 0 deletions build_scripts/other/zip_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash

# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Zip up a directory recursively, preserving symlinks (e.g. inside
# frameworks), as fast as possible.
#
# Info-ZIP's "zip" is single-threaded, which makes zipping the multi-gigabyte
# SDK package very slow. If 7-Zip is available, use it to create the zip file
# with multithreaded compression instead. After creating the archive, verify
# that it contains the same number of regular files and symlinks as the
# source directory; if it doesn't (for example, if this version of 7-Zip
# doesn't support storing symlinks in zip files), fall back to Info-ZIP.
#
# Usage: zip_package.sh <output.zip> <directory>
# The directory is added to the archive using the given (relative) path,
# so run this from the parent of <directory>.
#
# Environment variables:
# ZIP_PACKAGE_LEVEL: Compression level, 0-9 (default: 6).
# ZIP_PACKAGE_FORCE_INFOZIP: If set to 1, always use Info-ZIP.

set -e

if [[ $# -ne 2 ]]; then
echo "Usage: $0 <output.zip> <directory>" 1>&2
exit 2
fi

readonly output_zip="$1"
readonly input_dir="$2"
readonly level="${ZIP_PACKAGE_LEVEL:-6}"

if [[ ! -d "${input_dir}" ]]; then
echo "Directory not found: ${input_dir}" 1>&2
exit 2
fi

# Count the regular files and symlinks in the source directory.
expected_files=$(find "${input_dir}" -type f | wc -l)
expected_links=$(find "${input_dir}" -type l | wc -l)

verify_zip() {
# zipinfo prints one line per entry, starting with the Unix mode string.
local listing actual_files actual_links
listing=$(zipinfo "$1" 2>/dev/null) || return 1
actual_files=$(echo "${listing}" | grep -c '^-' || true)
actual_links=$(echo "${listing}" | grep -c '^l' || true)
echo "Zip contains ${actual_files} files and ${actual_links} symlinks" \
"(expected ${expected_files} and ${expected_links})."
[[ "${actual_files}" -eq "${expected_files}" &&
"${actual_links}" -eq "${expected_links}" ]]
}

sevenzip=
for cmd in 7zz 7z 7za; do
if command -v "${cmd}" > /dev/null; then
sevenzip="${cmd}"
break
fi
done

rm -f "${output_zip}"
if [[ -n "${sevenzip}" && "${ZIP_PACKAGE_FORCE_INFOZIP}" != "1" ]]; then
echo "Creating ${output_zip} with ${sevenzip} (multithreaded, level ${level})..."
# -snl: store symlinks as links. -mmt=on: multithreaded compression.
# -bso0 -bsp0: suppress the per-file output and progress indicator.
if "${sevenzip}" a -tzip -mx="${level}" -mmt=on -snl -bso0 -bsp0 \
"${output_zip}" "${input_dir}" && verify_zip "${output_zip}"; then
exit 0
fi
echo "Warning: ${sevenzip} failed or produced an unexpected archive," \
"falling back to Info-ZIP." 1>&2
rm -f "${output_zip}"
fi

echo "Creating ${output_zip} with Info-ZIP (level ${level})..."
zip -q -"${level}" -r -y "${output_zip}" "${input_dir}"
verify_zip "${output_zip}"
12 changes: 12 additions & 0 deletions scripts/gha/build_desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@ def main():
cmd = ['cmake', '--build', args.build_dir, '-j', str(os.cpu_count()),
'--config', args.config]

if utils.is_windows_os():
# "-j" above only makes MSBuild build multiple *projects* at once; each
# project's source files are still compiled one at a time unless /MP is
# passed to the compiler. Our own targets pass /MP, but external projects
# (gRPC, Abseil, Protobuf, Firestore, etc.) don't, and the external
# projects' nested builds don't get "-j" either. Large projects like
# grpc.vcxproj and firestore_core.vcxproj are at the end of the dependency
# chain, so they end up compiling on a single core for most of the build.
# The compiler reads extra options from the CL environment variable, which
# is inherited by every cl.exe invocation, including the external projects.
os.environ['CL'] = ('/MP ' + os.environ.get('CL', '')).strip()
print('Setting CL=%s to enable parallel compilation.' % os.environ['CL'])
if args.target:
# Example: cmake --build build -j 8 --target firebase_app firebase_auth
cmd.append('--target')
Expand Down
Loading
Loading