22490, "twesterhout", "Clang not found when trying to compile a C file", "2023-06-07T10:24:36Z"
Suppose that I don't have any of the LLVM tools or Clang on my PATH, but properly set CHPL_HOST_CC, CHPL_HOST_CXX, CHPL_TARGET_CC, and CHPL_TARGET_CXX to the absolute paths of clang and clang++. Then, if I set CHPL_LLVM=system and CHPL_HOST_COMPILER=llvm, I expect the compiler to work, and indeed it does.
However, if I now try to do something like chpl --library code.chpl code.c (i.e. I'm asking Chapel to compile a C file), this results in an error:
error in exec: No such file or directory
child process exited with code 255
error: Compile C File
The issue turns out to be that chpl can't find Clang to compile the C source. This felt weird, so after this line
I inserted a print statement to display clangCC, clangCXX, and useLinkCXX. To my surprise both clangCC and clangCXX were empty, but useLinkCXX was set correctly. So as long as only linking was required, chpl called out to useLinkCXX, and there were no errors. This can be confirmed by pre-compiling code.c into code.o and passing that to the chpl --library call -- the command works fine.
So I looked at the helpComputeClangArgs that (I guess) sets the values of clangCC and clangCXX, and saw this:
So naturally I tried setting CHPL_LLVM_CLANG_C and CHPL_LLVM_CLANG_CXX environment variables, but to no avail. E.g. printchplenv --all --internal displays:
CHPL_LLVM: system *
CHPL_LLVM_SUPPORT: system
CHPL_LLVM_CONFIG: /nix/store/f1l9dlzsrjxangh9d2l0i3mjkyrkk3r6-llvm-14.0.6-dev/bin/llvm-config *
CHPL_LLVM_VERSION: 14
CHPL_LLVM_CLANG_C: *
CHPL_LLVM_CLANG_CXX: *
CHPL_LLVM_STATIC_DYNAMIC: dynamic
CHPL_LLVM_TARGET_CPU: none
printchplenv clearly notices that I've set CHPL_LLVM_CLANG_C, but thinks it's still empty.
Anyway, I have a temporary workaround, but I have a feeling that there's a small bug somewhere.
Configuration Information
Output of chpl --version: chpl version 1.31.0 pre-release (xxxxxxxxxx) (basically main from one or two days ago)
Output of $CHPL_HOME/util/printchplenv --anonymize: