Commit 57e6c0c3 authored by Michael Pyne's avatar Michael Pyne

rc-file: Add "num-cpus" option by default and use it in default setup.

This change introduces a "num-cpus" option that is inherently present in
the build context.

This permits config file reading code to refer to this option (due to an
existing kdesrc-build feature). So I also update the various available
methods of generating a default configuration to use this option instead
of hardcoding a -j value for make-options (or leaving it blank).

This should provide maximum performance for most users (who aren't using
or can't use the existing Ninja support, anyways), as long as they are
able to start from a generated configuration.

Users with existing configuration files would need to regenerate it or
edit it to add "make-options -j ${num-cpus}" (including separately to
their Qt5 options if applicable, as global options are ignored for
non-KDE modules).

See issue #39.
parent 36975cfe
Pipeline #26152 passed with stage
in 2 minutes and 16 seconds
......@@ -503,11 +503,16 @@ compile jobs you wish to allow. A higher number (up to the number of logical CP
your system has available) leads to quicker builds, but requires more system resources.
<tip><para>&kdesrc-build; sets the option <option><link linkend="conf-num-cpus">num-cpus</link></option> to
the detected number of available processing cores. You can use this value
in your own configuration file to avoid having to set it manually.
<example id="make-options-example">
<title>Configuring Make for 4 compiles at once, with exceptions</title>
<title>Configuring Make to use all available CPUs, with exceptions</title>
make-options -j4
make-options -j <literal>${num-cpus}</literal>
end global
......@@ -1599,6 +1604,25 @@ linkend="conf-use-modules">use-modules</link> for more information.
<sect3 id="kdesrc-buildrc-option-values">
<title>Processing of option values</title>
<para>In general, the entire line contents after the
<replaceable>option-name</replaceable> is used as the
<para>One modification that &kdesrc-build; performs is that a sequence
<userinput>${<replaceable>name-of-option</replaceable>}</userinput> is replaced
with the value of that option from the global configuration. This allows you
to reference the value of existing options, including options already set by
To see an example of this in use, see
<xref linkend="make-options-example"/>.</para>
<sect3 id="kdesrc-buildrc-options-groups">
<title><quote>options</quote> modules</title>
......@@ -2598,6 +2622,20 @@ module if it normally would have tried anyways.</entry>
due to fixes in the underlying build system.</entry>
<row id="conf-num-cpus">
<entry>Cannot be overridden</entry>
<para>This option is automatically set by &kdesrc-build; to the number of
available CPUs (as indicated by the external application
<application>nproc</application>). If &kdesrc-build; cannot detect the
number of CPUs, this value is set to 4.</para>
<para>See <xref linkend="make-options-example"/> for an example of this
option's usage. This option was added in version 20.07.</para>
<row id="conf-override-build-system">
<entry>Module setting overrides global</entry>
......@@ -280,9 +280,6 @@ my @chosenModules = getListOptions(
my $numCpus = getUserInput(
'How many CPU cores do you wish to use for building?', '4');
my $outputFileName = "$ENV{HOME}/.kdesrc-buildrc";
my $output; # Will be output filehandle.
......@@ -371,7 +368,7 @@ print $output <<EOF;
# Use multiple cores for building. Other options to GNU make may also be
# set.
make-options -j$numCpus
make-options -j \${num-cpus}
# kdesrc-build can install a sample .xsession file for "Custom"
# (or "XSession") logins,
......@@ -12,7 +12,9 @@ global
# Where to download source code. By default the build directory and
# logs will be kept under this directory as well.
source-dir ~/kdesrc
source-dir ~/kde/src
make-options -j ${num-cpus}
end global
# Instead of specifying modules here, the current best practice is to refer to
......@@ -172,6 +172,10 @@ sub new
assert_isa($self, 'ksb::Module');
assert_isa($self, 'ksb::BuildContext');
# Make the number of CPUs available to the rc-file by turning it into a pre-set option
my $nproc = int (eval { (filter_program_output(undef, 'nproc'))[0] } // 4);
$self->setOption('num-cpus', $nproc);
return $self;
......@@ -142,8 +142,6 @@ DONE
my $sampleRc = $packages{'sample-rc'} or
_throw("Embedded sample file missing!");
my $numCpus = `nproc 2>/dev/null` || 4;
$sampleRc =~ s/%\{num_cpus}/$numCpus/g;
$sampleRc =~ s/%\{base_dir}/$baseDir/g;
open my $sampleFh, '>', "$ENV{HOME}/.kdesrc-buildrc"
......@@ -529,7 +527,7 @@ global
include-dependencies true
cmake-options -DCMAKE_BUILD_TYPE=RelWithDebInfo
make-options -j%{num_cpus}
make-options -j ${num-cpus}
end global
# With base options set, the remainder of the file is used to define modules to build, in the
......@@ -16,7 +16,7 @@ module-set qt5-set
prefix ${qtdir}
configure-flags -release -reduce-relocations -force-debug-info -separate-debug-info
# make-options -j7
make-options -j ${num-cpus}
end module-set
# qtwebengine is essentially the Chromium Embedded Framework with Qt bindings
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment