Subject: [PATCH 0/5] Add '--with-toolchain' package transformation option
From: Ludovic Courtès <[email-masked]>
To: [email-masked]
Cc: Ludovic Courtès <[email-masked]>
Date: Mon, 28 Sep 2020 21:53:05 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

From: Ludovic Courtès <[email-masked]>

Hello!

This patch series adds the ‘--with-toolchain’ option.  I’ve
tested it with gcc-toolchain@10 and clang-toolchain, and I can say
it works as advertised.  :-)

One thing I wasn’t entirely sure about: ‘--with-toolchain’ changes
the toolchain of the specified package, not that of its dependents.
This assumes that the toolchains all follow the same ABI.  This is
the case for C, apparently, maybe not for C++.  Should it instead
change to toolchain of the package’s dependents as well?

Something like:

  guix build guile --with-toolchain=[email-masked]=clang-toolchain 

generates working code.

Another issue is that since we use ‘package-input-rewriting/spec’,
we can’t change the toolchain of core packages like Guile or Perl
without rebuilding the world.  For example, if we omit “@3.0.4”
in the example above, we rebuild a “guile” package deep down and
everything that follows (aka. “the world”).

Another option I considered was to graft the package that
‘--with-toolchain’ targets instead of rebuilding its dependents.
Again that’d only work if the resulting binaries are ABI-compatible,
but maybe that’s a reasonable assumption.  It would definitely save
build time.  Should it be grafted, or should there be a separate
option to do that?  Thoughts?

Last, when doing ‘--with-toolchain=foo=gcc-toolchain’, I noticed
that ‘foo’ would keep a reference to ‘gcc-toolchain’ for some obscure
reasons:

--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env guix build hello --with-toolchain=hello=gcc-toolchain
/gnu/store/qi7pqqsxhbwmy75hl43j7l0aw1xr7r42-hello-2.10
$ grep -r $(guix build gcc-toolchain | head -2 |tail -1) /gnu/store/qi7pqqsxhbwmy75hl43j7l0aw1xr7r42-hello-2.10
Duuma dosiero /gnu/store/qi7pqqsxhbwmy75hl43j7l0aw1xr7r42-hello-2.10/bin/hello kongruas
$ strings /gnu/store/qi7pqqsxhbwmy75hl43j7l0aw1xr7r42-hello-2.10/bin/hello | grep $(guix build gcc-toolchain | head -2 |tail -1)
/gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib:/gnu/store/qj38f3vi4q1d7z30hkpaxyajv49rwamb-gcc-10.2.0-lib/lib:/gnu/store/qj38f3vi4q1d7z30hkpaxyajv49rwamb-gcc-10.2.0-lib/lib/gcc/x86_64-unknown-linux-gnu/10.2.0/../../..:/gnu/store/pknm43xsza6nlc7bn27djip8fis92akd-gcc-toolchain-10.2.0/lib
--8<---------------cut here---------------end--------------->8---

Not a showstopper but would be nice to address.

Feedback welcome!

Ludo’.

Ludovic Courtès (5):
  gnu: gcc-toolchain: Add 'GUIX_LOCPATH' to the search paths.
  gnu: clang-toolchain: Add 'GUIX_LOCPATH' to the search paths.
  gnu: clang-toolchain: Create 'cc' and 'c++' symlinks.
  packages: Add 'package-with-toolchain'.
  guix build: Add '--with-toolchain'.

 doc/guix.texi                 | 61 +++++++++++++++++++++++++++++++++++
 gnu/packages/commencement.scm |  8 +++--
 gnu/packages/llvm.scm         | 12 ++++++-
 guix/build-system.scm         | 35 ++++++++++++++++++--
 guix/packages.scm             |  9 ++++++
 guix/scripts/build.scm        | 40 +++++++++++++++++++++++
 tests/packages.scm            | 20 ++++++++++++
 tests/scripts-build.scm       | 30 +++++++++++++++++
 8 files changed, 210 insertions(+), 5 deletions(-)

-- 
2.28.0