[Chapel Merge] Fix problem running 'make' with CC and CXX set

Branch: refs/heads/main
Revision: 4112d47eae48cbb9b8dbdcf934f4e7f5822f3835
Author: mppf
Link: Fix problem running 'make' with CC and CXX set by mppf · Pull Request #21985 · chapel-lang/chapel · GitHub
Log Message:
Fix problem running 'make' with CC and CXX set (#21985)

This PR is intended to resolve the build issue discussed in

When building Chapel with something like CC=clang CXX=clang++ make,
several things were going wrong:

  1. There was an error from printchplenv
  2. That error did not stop the build & later there were linker errors

Why was there an error at all? it was this sequence of events:

  • the Makefile invoking cmake set CMAKE_C_COMPILER and
    CMAKE_CXX_COMPILER based on CHPL_MAKE_HOST_CC etc to communicate this
    setting to cmake (so cmake does not infer it based upon CC or use its
    favorite compiler)
  • the cmake script invoked printchplenv while setting CHPL_HOST_CC and
    CHPL_HOST_CXX in the environment (so that printchplenv will be
    considering the same configuration that cmake is using)
  • printchplenv supports inferring CHPL_HOST_COMPILER from CC and
    CXX but not from CHPL_HOST_CC and CHPL_HOST_CXX. So, it failed,
    because the default value CHPL_HOST_COMPILER=gnu was inconsistent with
    CHPL_HOST_CC=clang / CHPL_HOST_CXX=clang++.

This PR:

  • It adjusts the cmake script to check for the return code from
    printchplenv and fail with an error if it is nonzero.
  • Enables inferring CHPL_HOST_COMPILER from CHPL_HOST_CC /
    CHPL_HOST_CXX
  • Enables inferring CHPL_TARGET_COMPILER from CHPL_TARGET_CC /
    CHPL_TARGET_CXX (but this does not happen when LLVM would be the
    default or when using a PrgEnv).

An alternative solution to the issue of inferring CHPL_HOST_COMPILER
would be to pass it as an environment variable from make to cmake
and from cmake to printchplenv.

Reviewed by @arezaii - thanks!

  • verified that CC=clang-14 CXX=clang++-14 make works on an Ubuntu
    22.10 system where it did not work before
  • full local testing

Compare: Comparing b70551a006503b4c41ed40cd167e40ca8fe81542...7fd061595cc11b04e00d54288e9480655ec8e97d · chapel-lang/chapel · GitHub

Diff:
M CMakeLists.txt
M util/chplenv/chpl_compiler.py
https://github.com/chapel-lang/chapel/pull/21985.diff