Skip to content

Commit 792395e

Browse files
authored
Move x86 Linux setup to prereqs script (#945)
* Move install_x86_support_libraries to utils. * Update packaging x86 to use new prereqs script option * Fix x86 CI builds to retry prereqs as well * Add call to install_x86_support_libraries to prereqs script if needed. * Fix installation of openssl * Add option to prereqs script to skip openssl, for boringssl builds. * Use 'with' syntax for file i/o
1 parent 334254c commit 792395e

File tree

6 files changed

+126
-61
lines changed

6 files changed

+126
-61
lines changed

.github/workflows/cpp-packaging.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,13 @@ jobs:
408408
# binutils, used by older version of homebrew for hosting packages.
409409
brew update
410410
411-
- name: Install prerequisites
412-
run: |
413-
python scripts/gha/install_prereqs_desktop.py
411+
- name: Install Desktop SDK prerequisites
412+
uses: nick-invision/retry@v2
413+
with:
414+
timeout_minutes: 15
415+
max_attempts: 3
416+
command: |
417+
python scripts/gha/install_prereqs_desktop.py --gha_build --arch '${{ matrix.architecture }}' --ssl boringssl
414418
415419
- name: Export verbose flag
416420
shell: bash
@@ -538,7 +542,7 @@ jobs:
538542
- name: Install prerequisites
539543
run: |
540544
cd sdk-src
541-
python scripts/gha/install_prereqs_desktop.py
545+
python scripts/gha/install_prereqs_desktop.py --ssl boringssl
542546
cd ..
543547
544548
- name: postprocess and package built SDK

.github/workflows/desktop.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,13 @@ jobs:
176176
# binutils, used by older version of homebrew for hosting packages.
177177
brew update
178178
179-
- name: Install prerequisites
180-
run: |
181-
python scripts/gha/install_prereqs_desktop.py
179+
- name: Install Desktop SDK prerequisites
180+
uses: nick-invision/retry@v2
181+
with:
182+
timeout_minutes: 15
183+
max_attempts: 3
184+
command: |
185+
python scripts/gha/install_prereqs_desktop.py --gha_build --arch '${{ matrix.architecture }}'
182186
183187
- name: Build SDK
184188
shell: bash

.github/workflows/integration_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ jobs:
278278
timeout_minutes: 2
279279
max_attempts: 3
280280
command: |
281-
python scripts/gha/install_prereqs_desktop.py
281+
python scripts/gha/install_prereqs_desktop.py --ssl '${{ matrix.ssl_variant }}'
282282
pip install -r scripts/gha/requirements.txt
283283
python scripts/gha/restore_secrets.py --passphrase "${{ secrets.TEST_SECRET }}"
284284
- name: Install OpenSSL (Windows)

scripts/gha/build_desktop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def main():
281281

282282
# To build x86 on x86_64 linux hosts, we also need x86 support libraries
283283
if args.arch == 'x86' and utils.is_linux_os():
284-
install_x86_support_libraries(args.gha_build)
284+
utils.install_x86_support_libraries(args.gha_build)
285285

286286
# Install C++ dependencies using vcpkg
287287
if not args.disable_vcpkg:

scripts/gha/install_prereqs_desktop.py

Lines changed: 67 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -29,62 +29,77 @@
2929
3030
"""
3131

32+
import argparse
3233
import utils
3334

3435
def main():
35-
# Install protobuf on linux/mac if its not installed already
36-
if not utils.is_command_installed('protoc'):
37-
if utils.is_linux_os():
38-
# sudo apt install protobuf-compiler
39-
utils.run_command(['apt', 'install', '-y','protobuf-compiler'], as_root=True)
40-
elif utils.is_mac_os():
41-
# brew install protobuf
42-
utils.run_command(['brew', 'install', 'protobuf'])
43-
44-
# Install go on linux/mac if its not installed already
45-
if not utils.is_command_installed('go'):
46-
if utils.is_linux_os():
47-
# sudo apt install -y golang
48-
utils.run_command(['apt', 'install', '-y','golang'], as_root=True)
49-
elif utils.is_mac_os():
50-
# brew install protobuf
51-
utils.run_command(['brew', 'install', 'go'])
52-
53-
# Install openssl on linux/mac if its not installed already
54-
if not utils.is_command_installed('go'):
55-
if utils.is_linux_os():
56-
# sudo apt install -y openssl
57-
utils.run_command(['apt', 'install', '-y','openssl'], as_root=True)
58-
elif utils.is_mac_os():
59-
# brew install protobuf
60-
utils.run_command(['brew', 'install', 'openssl'])
61-
62-
# Install ccache on linux/mac if its not installed already
63-
if not utils.is_command_installed('ccache'):
64-
if utils.is_linux_os():
65-
# sudo apt install ccache
66-
utils.run_command(['apt', 'install', '-y', 'ccache'], as_root=True)
67-
elif utils.is_mac_os():
68-
# brew install ccache
69-
utils.run_command(['brew', 'install', 'ccache'])
70-
71-
# Install clang-format on linux/mac if its not installed already
72-
if not utils.is_command_installed('clang-format'):
73-
if utils.is_linux_os():
74-
# sudo apt install clang-format
75-
utils.run_command(['apt', 'install', '-y','clang-format'], as_root=True)
76-
elif utils.is_mac_os():
77-
# brew install protobuf
78-
utils.run_command(['brew', 'install', 'clang-format'])
79-
80-
# Install required python dependencies.
81-
# On Catalina, python2 in installed as default python.
82-
# Example command:
83-
# python3 -m pip install -r external/pip_requirements.txt --user
84-
utils.run_command(
85-
['python3' if utils.is_command_installed('python3') else 'python', '-m',
86-
'pip', 'install', '-r', 'external/pip_requirements.txt', '--user'] )
36+
args = parse_cmdline_args()
8737

38+
if not args.running_only:
39+
# Install protobuf on linux/mac if its not installed already
40+
if not utils.is_command_installed('protoc'):
41+
if utils.is_linux_os():
42+
# sudo apt install protobuf-compiler
43+
utils.run_command(['apt', 'install', '-y','protobuf-compiler'], as_root=True)
44+
elif utils.is_mac_os():
45+
# brew install protobuf
46+
utils.run_command(['brew', 'install', 'protobuf'])
47+
48+
# Install go on linux/mac if its not installed already
49+
if not utils.is_command_installed('go'):
50+
if utils.is_linux_os():
51+
# sudo apt install -y golang
52+
utils.run_command(['apt', 'install', '-y','golang'], as_root=True)
53+
elif utils.is_mac_os():
54+
# brew install go
55+
utils.run_command(['brew', 'install', 'go'])
56+
57+
# Install openssl on linux/mac if its not installed already
58+
if args.ssl == 'openssl' and not utils.is_command_installed('openssl'):
59+
if utils.is_linux_os():
60+
# sudo apt install -y openssl
61+
utils.run_command(['apt', 'install', '-y','openssl'], as_root=True)
62+
elif utils.is_mac_os():
63+
# brew install openssl
64+
utils.run_command(['brew', 'install', 'openssl'])
65+
66+
# Install ccache on linux/mac if its not installed already
67+
if not utils.is_command_installed('ccache'):
68+
if utils.is_linux_os():
69+
# sudo apt install ccache
70+
utils.run_command(['apt', 'install', '-y', 'ccache'], as_root=True)
71+
elif utils.is_mac_os():
72+
# brew install ccache
73+
utils.run_command(['brew', 'install', 'ccache'])
74+
75+
# Install clang-format on linux/mac if its not installed already
76+
if not utils.is_command_installed('clang-format'):
77+
if utils.is_linux_os():
78+
# sudo apt install clang-format
79+
utils.run_command(['apt', 'install', '-y','clang-format'], as_root=True)
80+
elif utils.is_mac_os():
81+
# brew install protobuf
82+
utils.run_command(['brew', 'install', 'clang-format'])
83+
84+
# Install required python dependencies.
85+
# On Catalina, python2 in installed as default python.
86+
# Example command:
87+
# python3 -m pip install -r external/pip_requirements.txt --user
88+
utils.run_command(
89+
['python3' if utils.is_command_installed('python3') else 'python', '-m',
90+
'pip', 'install', '-r', 'external/pip_requirements.txt', '--user'] )
91+
92+
if args.arch == 'x86':
93+
utils.install_x86_support_libraries(args.gha_build)
94+
95+
def parse_cmdline_args():
96+
parser = argparse.ArgumentParser(description='Install prerequisites for building cpp sdk')
97+
parser.add_argument('--arch', default=None, help='Install support libraries to build a specific architecture (currently supported: x86)')
98+
parser.add_argument('--running_only', action='store_true', help='Only install prerequisites for running, not for building')
99+
parser.add_argument('--gha_build', action='store_true', default=None, help='Set this option when building on GitHub, changing some prerequisite installation behavior')
100+
parser.add_argument('--ssl', default='openssl', help='Which SSL is this build using (supported: openssl, boringssl)')
101+
args = parser.parse_args()
102+
return args
88103

89104
if __name__ == '__main__':
90105
main()

scripts/gha/utils.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,45 @@ def clean_vcpkg_temp_data():
218218
for directory_to_remove in directories_to_remove:
219219
abspath = os.path.join(vcpkg_root_dir_path, directory_to_remove)
220220
delete_directory(abspath)
221+
222+
223+
def install_x86_support_libraries(gha_build=False):
224+
"""Install support libraries needed to build x86 on x86_64 hosts.
225+
226+
Args:
227+
gha_build: Pass in True if running on a GitHub runner; this will activate
228+
workarounds that might be undesirable on a personal system (e.g.
229+
downgrading Ubuntu packages).
230+
"""
231+
if is_linux_os():
232+
packages = ['gcc-multilib', 'g++-multilib', 'libglib2.0-dev:i386',
233+
'libsecret-1-dev:i386', 'libpthread-stubs0-dev:i386',
234+
'libssl-dev:i386']
235+
if gha_build:
236+
# Workaround for GitHub runners, which have an incompatibility between the
237+
# 64-bit and 32-bit versions of the Ubuntu package libpcre2-8-0. Downgrade
238+
# the installed 64-bit version of the library to get around this issue.
239+
# This will presumably be fixed in a future Ubuntu update. (If you remove
240+
# it, remove the workaround further down this function as well.)
241+
packages = ['--allow-downgrades'] + packages + ['libpcre2-8-0=10.34-7']
242+
243+
# First check if these packages exist on the machine already
244+
with open(os.devnull, "w") as devnull:
245+
process = subprocess.run(["dpkg", "-s"] + packages, stdout=devnull, stderr=subprocess.STDOUT)
246+
247+
if process.returncode != 0:
248+
# This implies not all of the required packages are already installed on user's machine
249+
# Install them.
250+
run_command(['dpkg', '--add-architecture', 'i386'], as_root=True, check=True)
251+
run_command(['apt', 'update'], as_root=True, check=True)
252+
run_command(['apt', 'install', '-V', '-y'] + packages, as_root=True, check=True)
253+
254+
if gha_build:
255+
# One more workaround: downgrading libpcre2-8-0 above may have uninstalled
256+
# libsecret, which is required for the Linux build. Force it to be
257+
# reinstalled, but do it as a separate command to ensure that held
258+
# packages aren't modified. (Once the workaround above is removed, this can
259+
# be removed as well.)
260+
# Note: "-f" = "fix" - let apt do what it needs to do to fix dependencies.
261+
run_command(['apt', 'install', '-f', '-V', '-y', 'libsecret-1-dev'],
262+
as_root=True, check=True)

0 commit comments

Comments
 (0)