From a0c3babe7bc948cced25fdeb61f8646eabfdc02f Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Mon, 9 Sep 2024 15:42:50 -0400 Subject: [PATCH 1/5] Add CHPL_LLVM_GCC_INSTALL_DIR as an alternative to CHPL_LLVM_GCC_PREFIX --- Signed-off-by: Michael Ferguson --- util/chplenv/chpl_llvm.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/util/chplenv/chpl_llvm.py b/util/chplenv/chpl_llvm.py index c29da81c40e6..7f898b5adfde 100755 --- a/util/chplenv/chpl_llvm.py +++ b/util/chplenv/chpl_llvm.py @@ -649,7 +649,7 @@ def llvm_enabled(): return False @memoize -def get_gcc_prefix(): +def get_gcc_prefix_dir(): gcc_prefix = overrides.get('CHPL_LLVM_GCC_PREFIX', '') # allow CHPL_LLVM_GCC_PREFIX=none to disable inferring it @@ -710,6 +710,12 @@ def get_gcc_prefix(): return gcc_prefix +@memoize +def get_gcc_install_dir(): + gcc_dir = overrides.get('CHPL_LLVM_GCC_INSTALL_DIR', '') + + return gcc_dir + # The bundled LLVM does not currently know to look in a particular Mac OS X SDK # so we provide a -isysroot arg to indicate which is used. @@ -808,9 +814,13 @@ def get_system_llvm_built_sdkroot(): def get_clang_basic_args(): clang_args = [ ] - gcc_prefix = get_gcc_prefix() - if gcc_prefix: - clang_args.append('--gcc-toolchain=' + gcc_prefix) + gcc_install_dir = get_gcc_install_dir(); + if gcc_install_dir: + clang_args.append('--gcc-install-dir=' + gcc_install_dir) + else: + gcc_prefix = get_gcc_prefix_dir() + if gcc_prefix: + clang_args.append('--gcc-toolchain=' + gcc_prefix) sysroot_args = get_sysroot_resource_dir_args() if sysroot_args: From a4fbe0eae07023da7d366b4063df5d708279a473 Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Mon, 9 Sep 2024 15:57:56 -0400 Subject: [PATCH 2/5] Add docs --- Signed-off-by: Michael Ferguson --- doc/rst/usingchapel/chplenv.rst | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/doc/rst/usingchapel/chplenv.rst b/doc/rst/usingchapel/chplenv.rst index eade2b960759..f8ed0fcbe8a3 100644 --- a/doc/rst/usingchapel/chplenv.rst +++ b/doc/rst/usingchapel/chplenv.rst @@ -860,6 +860,42 @@ CHPL_LLVM_GCC_PREFIX ``--gcc-toolchain`` flag; or you can set it to a particular directory to pass to ``clang`` with the ``--gcc-toolchain`` flag. + Please note that, on some systems, it's possible to install multiple + versions of gcc to ``/usr``. In that event, ``CHPL_LLVM_GCC_PREFIX`` + and ``--gcc-toolchain`` cannot distinguish between these multiple versions. + Use the next option, ``CHPL_LLVM_GCC_INSTALL_DIR``, instead for such + cases. + +.. _readme-chplenv.CHPL_LLVM_GCC_INSTALL_DIR: + +CHPL_LLVM_GCC_INSTALL_DIR +~~~~~~~~~~~~~~~~~~~~~~~~~ + + Sometimes it's necessary to request that ``clang`` work with a + particular version of GCC. If many versions are installed at the same + prefix (e.g. ``/usr``) then ``CHPL_LLVM_GCC_PREFIX`` won't be able to + do that. That is where ``CHPL_LLVM_GCC_INSTALL_DIR`` comes in! + + To understand what to set ``CHPL_LLVM_GCC_INSTALL_DIR`` to in such + cases, try a test compile: + + * ``echo int main() { return 0; } > hello.cc`` + * ``clang++ -v hello.cc`` + + This will print out lines along these lines: + + .. + + Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11 + Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12 + Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13 + Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/14 + Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/14 + + The paths printed here are suitable for use with + ``CHPL_LLVM_GCC_INSTALL_DIR``. + + .. _readme-chplenv.CHPL_UNWIND: CHPL_UNWIND From d24925c4d7d1fad904b52be445c5bcb5bdd1645d Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Tue, 10 Sep 2024 09:53:35 -0400 Subject: [PATCH 3/5] Add more to docs --- Signed-off-by: Michael Ferguson --- doc/rst/usingchapel/chplenv.rst | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/rst/usingchapel/chplenv.rst b/doc/rst/usingchapel/chplenv.rst index f8ed0fcbe8a3..636bfd3545a7 100644 --- a/doc/rst/usingchapel/chplenv.rst +++ b/doc/rst/usingchapel/chplenv.rst @@ -893,8 +893,19 @@ CHPL_LLVM_GCC_INSTALL_DIR Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/14 The paths printed here are suitable for use with - ``CHPL_LLVM_GCC_INSTALL_DIR``. + ``CHPL_LLVM_GCC_INSTALL_DIR``. Choose the path that corresponds to the + ``g++`` version that you are trying to use. If you are not sure which + ``g++`` version to use -- the version that comes with your system is a + good starting point. You can use + ``/usr/bin/g++ --version`` or just ``g++ --version`` to find that + version. + .. note:: + + ``CHPL_LLVM_GCC_INSTALL_DIR`` works with the clang flag + ``--gcc-install-dir`` which was added in LLVM / clang 16. As a + result, ``CHPL_LLVM_GCC_INSTALL_DIR`` will not work for earlier + versions of LLVM / clang. .. _readme-chplenv.CHPL_UNWIND: From 94e179cc7b6a12134aca67c6254357c67eab9480 Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Tue, 10 Sep 2024 09:59:03 -0400 Subject: [PATCH 4/5] Check LLVM / clang version --- Signed-off-by: Michael Ferguson --- util/chplenv/chpl_llvm.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/util/chplenv/chpl_llvm.py b/util/chplenv/chpl_llvm.py index 7f898b5adfde..b2e6735b3b1b 100755 --- a/util/chplenv/chpl_llvm.py +++ b/util/chplenv/chpl_llvm.py @@ -714,6 +714,14 @@ def get_gcc_prefix_dir(): def get_gcc_install_dir(): gcc_dir = overrides.get('CHPL_LLVM_GCC_INSTALL_DIR', '') + if gcc_dir: + llvm_version = get_llvm_version() + if llvm_version in ('11', '12', '13', '14', '15'): + warning("This LLVM / clang version {0} is too old to use " + "CHPL_LLVM_GCC_INSTALL_DIR -- " + "it will be ignored".format(llvm_version)) + return '' + return gcc_dir From bf9e120ffabfcee7a96fee945c22e5bfd41edf32 Mon Sep 17 00:00:00 2001 From: Michael Ferguson Date: Tue, 10 Sep 2024 10:19:04 -0400 Subject: [PATCH 5/5] Improve docs wording and formatting --- Signed-off-by: Michael Ferguson --- doc/rst/usingchapel/chplenv.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/rst/usingchapel/chplenv.rst b/doc/rst/usingchapel/chplenv.rst index 636bfd3545a7..117aea978c79 100644 --- a/doc/rst/usingchapel/chplenv.rst +++ b/doc/rst/usingchapel/chplenv.rst @@ -874,7 +874,8 @@ CHPL_LLVM_GCC_INSTALL_DIR Sometimes it's necessary to request that ``clang`` work with a particular version of GCC. If many versions are installed at the same prefix (e.g. ``/usr``) then ``CHPL_LLVM_GCC_PREFIX`` won't be able to - do that. That is where ``CHPL_LLVM_GCC_INSTALL_DIR`` comes in! + differentate between them. That is where ``CHPL_LLVM_GCC_INSTALL_DIR`` + comes in! To understand what to set ``CHPL_LLVM_GCC_INSTALL_DIR`` to in such cases, try a test compile: @@ -882,9 +883,7 @@ CHPL_LLVM_GCC_INSTALL_DIR * ``echo int main() { return 0; } > hello.cc`` * ``clang++ -v hello.cc`` - This will print out lines along these lines: - - .. + This will print out lines along these lines:: Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12