Compile C with Clang, not gcc, when building with Haskell stack

I’m trying to build a Haskell project that includes C source files, but I want to compile the C source files with Clang instead of the default GCC. Is there a way to configure this in the package.yaml or stack.yaml?

# package.yaml
# ...
# stack.yaml
# ...

Yes, you can configure the compiler to be used for C source files in the stack.yaml file.

In the stack.yaml file, you can specify the gcc-options or clang-options field under the ghc-options section to pass specific options to the C compiler.

Here’s an example of how you can configure Clang as the compiler for C source files:

# stack.yaml
# ...

    gcc-options: "-pgmP clang"

In the above example, the gcc-options field is used to specify the Clang compiler (-pgmP clang) for all C source files.

Make sure you have Clang installed on your system before using it as the compiler.

Note that this configuration will apply to all Haskell projects managed by Stack on your system. If you want to apply this configuration only to a specific project, you can create a separate stack.yaml file in the project directory and specify the desired options there.