Skip to content

Commit 65f3068

Browse files
authored
Workaround for Linux x86 build: downgrade libraries on GitHub runners (#764)
When installing 32-bit Linux dependencies on GitHub runners, downgrade libpcre2-8-0 to an earlier version to ensure compatibility with the i386 version of the package. This is something that should be fixed in a subsequent Ubuntu release and so is a temporary workaround. This also adds checks to the various prerequisite commands run by build_desktop.py, which was previously just silently ignoring errors (making this much harder to track down). Now it will error out as soon as a command fails.
1 parent 56c49c7 commit 65f3068

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

scripts/gha/build_desktop.py

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,25 @@ def append_line_to_file(path, line):
5656
file.write("\n" + line + "\n")
5757

5858

59-
def install_x86_support_libraries():
60-
"""Install support libraries needed to build x86 on x86_64 hosts."""
59+
def install_x86_support_libraries(gha_build=False):
60+
"""Install support libraries needed to build x86 on x86_64 hosts.
61+
62+
Args:
63+
gha_build: Pass in True if running on a GitHub runner; this will activate
64+
workarounds that might be undesirable on a personal system (e.g.
65+
downgrading Ubuntu packages).
66+
"""
6167
if utils.is_linux_os():
6268
packages = ['gcc-multilib', 'g++-multilib', 'libglib2.0-dev:i386',
6369
'libsecret-1-dev:i386', 'libpthread-stubs0-dev:i386',
6470
'libssl-dev:i386']
71+
if gha_build:
72+
# Workaround for GitHub runners, which have an incompatibility between the
73+
# 64-bit and 32-bit versions of the Ubuntu package libpcre2-8-0. Downgrade
74+
# the installed 64-bit version of the library to get around this issue.
75+
# This will presumably be fixed in a future Ubuntu update. (If you remove
76+
# it, remove the workaround further down this function as well.)
77+
packages = ['--allow-downgrades'] + packages + ['libpcre2-8-0=10.34-7']
6578

6679
# First check if these packages exist on the machine already
6780
devnull = open(os.devnull, "w")
@@ -70,9 +83,19 @@ def install_x86_support_libraries():
7083
if process.returncode != 0:
7184
# This implies not all of the required packages are already installed on user's machine
7285
# Install them.
73-
utils.run_command(['dpkg', '--add-architecture', 'i386'], as_root=True)
74-
utils.run_command(['apt', 'update'], as_root=True)
75-
utils.run_command(['apt', 'install', '-y'] + packages, as_root=True)
86+
utils.run_command(['dpkg', '--add-architecture', 'i386'], as_root=True, check=True)
87+
utils.run_command(['apt', 'update'], as_root=True, check=True)
88+
utils.run_command(['apt', 'install', '-V', '-y'] + packages, as_root=True, check=True)
89+
90+
if gha_build:
91+
# One more workaround: downgrading libpcre2-8-0 above may have uninstalled
92+
# libsecret, which is required for the Linux build. Force it to be
93+
# reinstalled, but do it as a separate command to ensure that held
94+
# packages aren't modified. (Once the workaround above is removed, this can
95+
# be removed as well.)
96+
# Note: "-f" = "fix" - let apt do what it needs to do to fix dependencies.
97+
utils.run_command(['apt', 'install', '-f', '-V', '-y', 'libsecret-1-dev'],
98+
as_root=True, check=True)
7699

77100

78101
def _install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library, use_openssl=False):
@@ -94,7 +117,7 @@ def _install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library, use_openssl
94117
if not found_vcpkg_executable:
95118
script_absolute_path = utils.get_vcpkg_installation_script_path()
96119
# Example: ./external/vcpkg/bootstrap-sh
97-
utils.run_command([script_absolute_path])
120+
utils.run_command([script_absolute_path], check=True)
98121

99122
# Copy any of our custom defined vcpkg data to vcpkg submodule directory
100123
utils.copy_vcpkg_custom_data()
@@ -113,7 +136,9 @@ def _install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library, use_openssl
113136
# Eg: ./external/vcpkg/vcpkg install @external/vcpkg_x64-osx_response_file.txt
114137
# --disable-metrics
115138
utils.run_command([vcpkg_executable_file_path, 'install',
116-
'@' + vcpkg_response_file_path, '--disable-metrics'])
139+
'@' + vcpkg_response_file_path, '--disable-metrics'],
140+
check=True)
141+
117142

118143
def install_cpp_dependencies_with_vcpkg(arch, msvc_runtime_library, cleanup=True,
119144
use_openssl=False):
@@ -243,12 +268,12 @@ def main():
243268
# Ensure that the submodules are initialized and updated
244269
# Example: vcpkg is a submodule (external/vcpkg)
245270
if not args.disable_vcpkg:
246-
utils.run_command(['git', 'submodule', 'init'])
247-
utils.run_command(['git', 'submodule', 'update'])
271+
utils.run_command(['git', 'submodule', 'init'], check=True)
272+
utils.run_command(['git', 'submodule', 'update'], check=True)
248273

249274
# To build x86 on x86_64 linux hosts, we also need x86 support libraries
250275
if args.arch == 'x86' and utils.is_linux_os():
251-
install_x86_support_libraries()
276+
install_x86_support_libraries(args.gha_build)
252277

253278
# Install C++ dependencies using vcpkg
254279
if not args.disable_vcpkg:
@@ -293,7 +318,7 @@ def parse_cmdline_args():
293318
parser.add_argument('--target', nargs='+', help='A list of CMake build targets (eg: firebase_app firebase_auth)')
294319
parser.add_argument('--target_format', default=None, help='(Mac only) whether to output frameworks (default) or libraries.')
295320
parser.add_argument('--use_openssl', action='store_true', default=None, help='Use openssl for build instead of boringssl')
296-
parser.add_argument('--gha_build', action='store_true', default=None, help='Set to true when building on GitHub, for metric tracking purposes')
321+
parser.add_argument('--gha_build', action='store_true', default=None, help='Set to true when building on GitHub, for metric tracking purposes (also changes some prerequisite installation behavior).')
297322
args = parser.parse_args()
298323
return args
299324

0 commit comments

Comments
 (0)