[sdk/kdesrc-build/auto-detect-nr-cpus] /: rc-file: Add "num-cpus" option by default and use it in default setup.
Michael Pyne
null at kde.org
Tue Jul 7 03:08:31 BST 2020
Git commit 57e6c0c3b9299b136fc20c02846563bea49e3cf4 by Michael Pyne.
Committed on 07/07/2020 at 02:07.
Pushed by mpyne into branch 'auto-detect-nr-cpus'.
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.
M +40 -2 doc/index.docbook
M +1 -4 kdesrc-build-setup
M +3 -1 kdesrc-buildrc-kf5-sample
M +4 -0 modules/ksb/BuildContext.pm
M +1 -3 modules/ksb/FirstRun.pm
M +1 -1 qt5-build-include
https://invent.kde.org/sdk/kdesrc-build/commit/57e6c0c3b9299b136fc20c02846563bea49e3cf4
diff --git a/doc/index.docbook b/doc/index.docbook
index 75b8587..bc60de9 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -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.
</para>
+<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.
+</para></tip>
+
<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>
<screen>
global
- 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>
+<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
+<replaceable>option-value</replaceable>.</para>
+
+<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
+&kdesrc-build;.</para>
+
+<para>
+To see an example of this in use, see
+<xref linkend="make-options-example"/>.</para>
+
+</sect3>
+
<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>
+<row id="conf-num-cpus">
+<entry>num-cpus</entry>
+<entry>Cannot be overridden</entry>
+<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>
+</entry>
+</row>
+
<row id="conf-override-build-system">
<entry>override-build-system</entry>
<entry>Module setting overrides global</entry>
diff --git a/kdesrc-build-setup b/kdesrc-build-setup
index c72d17e..838165a 100755
--- a/kdesrc-build-setup
+++ b/kdesrc-build-setup
@@ -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,
diff --git a/kdesrc-buildrc-kf5-sample b/kdesrc-buildrc-kf5-sample
index aaa0619..823b1bf 100644
--- a/kdesrc-buildrc-kf5-sample
+++ b/kdesrc-buildrc-kf5-sample
@@ -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
diff --git a/modules/ksb/BuildContext.pm b/modules/ksb/BuildContext.pm
index 80172d4..3ceaf01 100644
--- a/modules/ksb/BuildContext.pm
+++ b/modules/ksb/BuildContext.pm
@@ -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;
}
diff --git a/modules/ksb/FirstRun.pm b/modules/ksb/FirstRun.pm
index 2a2f9cd..04ec9ac 100644
--- a/modules/ksb/FirstRun.pm
+++ b/modules/ksb/FirstRun.pm
@@ -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
diff --git a/qt5-build-include b/qt5-build-include
index ae19108..d756301 100644
--- a/qt5-build-include
+++ b/qt5-build-include
@@ -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
More information about the kde-doc-english
mailing list