Skip to content
Snippets Groups Projects
Unverified Commit 78c6b88a authored by Maxim Cournoyer's avatar Maxim Cournoyer
Browse files

packaging: Limit the number of parallel jobs when building Qt.

Workaround <https://bugreports.qt.io/browse/QTBUG-94800>.

This is to avoid out of memory conditions during the build, which
requires up to about 2 GiB of memory per parallel process.  There was
also a problem with how the MAKEFLAGS was passed, which led
qtwebengine to be built using all the CPU cores even when specifying a
lesser NO_CPUS value.

* packaging/rules/debian-qt/rules (min, max): New functions.
(NO_CPUS): Express in terms of max.
(AVAILABLE_MEMORY, MEMORY_REQUIRED_PER_CORE, COMPUTED_JOB_COUNT)
(JOB_COUNT, MAX_PARALLEL_BUILDS): New variables.
(override_dh_auto_build): Override to manually control job count.
Specify NINJAFLAGS for the Chromium build.
* packaging/rules/rpm/jami-libqt.spec (min, max, cpu_count)
(available_memory, computed_job_count, job_count): New macros.
(%build): Re-indent and use the above 'job_count' variable as
the number of parallel jobs.
(%install): Likewise.

Change-Id: I9134c1e63e92104a1da8435670e2919ce692040c
parent 3725c504
No related branches found
No related tags found
No related merge requests found
...@@ -3,23 +3,43 @@ ...@@ -3,23 +3,43 @@
# export DH_VERBOSE = 1 # export DH_VERBOSE = 1
# Number of CPUS # Return the minimum value of two integer arguments.
NO_CPUS=$(shell nproc) min = $(shell echo $$(( $(1) < $(2) ? $(1) : $(2) )))
ifeq ($(NO_CPUS),0) max = $(shell echo $$(( $(1) > $(2) ? $(1) : $(2) )))
NO_CPUS=1
endif # Number of CPUs to build Qt.
NO_CPUS := $(call max,$(shell nproc),1)
# There can be multiple builds of Qt in parallel. The following
# should match the maximum number of per-machine workers used in the
# CI.
MAX_PARALLEL_BUILDS := 4
# qtwebengine (aka chromium) takes a ton of memory per build process,
# up to 2.3 GiB. Cap the number of jobs based on the amount of
# available memory to try to guard against OOM build failures.
AVAILABLE_MEMORY := $(shell free -g | grep -E '^Mem:' | awk '{print $$7}')
MEMORY_REQUIRED_PER_CORE := 2 # in GiB
COMPUTED_JOB_COUNT := \
$(call max,$(shell echo $$(( $(AVAILABLE_MEMORY) \
/ $(MEMORY_REQUIRED_PER_CORE) \
/ $(MAX_PARALLEL_BUILDS) ))),1)
JOB_COUNT = $(call min,$(NO_CPUS),$(COMPUTED_JOB_COUNT))
%: %:
dh $@ dh $@
override_dh_auto_configure: override_dh_auto_configure:
MAKEFLAGS="-j$(NO_CPUS) V=1" \ ./configure \
./configure \ -opensource \
-opensource \ -confirm-license \
-confirm-license \ -nomake examples \
-nomake examples \ -nomake tests \
-nomake tests \ -prefix "${QT_JAMI_PREFIX}"
-prefix "${QT_JAMI_PREFIX}"
override_dh_auto_build:
@echo Building Qt using $(JOB_COUNT) parallel jobs
$(MAKE) -j$(JOB_COUNT) V=1 NINJAFLAGS="-j$(JOB_COUNT)"
override_dh_auto_install: override_dh_auto_install:
dh_auto_install -Smakefile -- INSTALL_ROOT=$(CURDIR)/debian/tmp/ dh_auto_install -Smakefile -- INSTALL_ROOT=$(CURDIR)/debian/tmp/
...@@ -2,6 +2,21 @@ ...@@ -2,6 +2,21 @@
%define version RELEASE_VERSION %define version RELEASE_VERSION
%define release 0 %define release 0
# qtwebengine (aka chromium) takes a ton of memory per build process,
# up to 2.3 GiB. Cap the number of jobs based on the amount of
# available memory to try to guard against OOM build failures.
%define min(a,b) %(echo $(( %1 < %2 ? %1 : %2 )))
%define max(a,b) %(echo $(( %1 > %2 ? %1 : %2 )))
%define cpu_count %max %(nproc) 1
%define available_memory %(free -g | grep -E '^Mem:' | awk '{print $7}')
# Required memory in GiB.
%define max_parallel_builds 4
%define memory_required_per_core 2
%define computed_job_count_ %(echo $(( %available_memory / %memory_required_per_core / %max_parallel_builds )))
%define computed_job_count %max %computed_job_count_ 1
%define job_count %min %cpu_count %computed_job_count
Name: %{name} Name: %{name}
Version: %{version} Version: %{version}
Release: %{release}%{?dist} Release: %{release}%{?dist}
...@@ -31,18 +46,20 @@ This package contains Qt libraries for Jami. ...@@ -31,18 +46,20 @@ This package contains Qt libraries for Jami.
%setup -n qt-everywhere-src-%{version} %setup -n qt-everywhere-src-%{version}
%build %build
./configure \ echo "Building Qt using %{job_count} parallel jobs"
-opensource \ ./configure \
-confirm-license \ -opensource \
-nomake examples \ -confirm-license \
-nomake tests \ -nomake examples \
-prefix "%{_libdir}/qt-jami" -nomake tests \
sed -i 's,bin/python,bin/env python3,g' qtbase/mkspecs/features/uikit/devices.py -prefix "%{_libdir}/qt-jami"
make -j8 V=1 sed -i 's,bin/python,bin/env python3,g' qtbase/mkspecs/features/uikit/devices.py
# Chromium is built using Ninja, which doesn't honor MAKEFLAGS.
make -j%{job_count} V=1 NINJAFLAGS="-j%{job_count}"
%install %install
make -j8 INSTALL_ROOT=%{buildroot} V=1 install make -j%{job_count} INSTALL_ROOT=%{buildroot} V=1 install
%files %files
%defattr(-,root,root,-) %defattr(-,root,root,-)
%{_libdir}/qt-jami %{_libdir}/qt-jami
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment