Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CHPL_LLVM_GCC_INSTALL_DIR as an alternative to CHPL_LLVM_GCC_PREFIX #25913

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions doc/rst/usingchapel/chplenv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,52 @@ 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
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:

* ``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``. 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.

mppf marked this conversation as resolved.
Show resolved Hide resolved
.. _readme-chplenv.CHPL_UNWIND:

CHPL_UNWIND
Expand Down
26 changes: 22 additions & 4 deletions util/chplenv/chpl_llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -710,6 +710,20 @@ def get_gcc_prefix():

return gcc_prefix

@memoize
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


# 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.
Expand Down Expand Up @@ -808,9 +822,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)
mppf marked this conversation as resolved.
Show resolved Hide resolved
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:
Expand Down