Building GHC head with clang on Mavericks

Kazu Yamamoto (=?iso-2022-jp?B?GyRCOzNLXE9CSScbKEI=?=) kazu at iij.ad.jp
Tue Nov 19 14:02:28 UTC 2013


Hi Carter,
SimonM, please read this message.

I will answer Carter's question and show a solution of my problem.

> Kazu. This is exactly the problem I linked to.  Could you try the proposed
> patches to test if they allow builds to succeed with a wrapped clang on
> your machine?

I installed nkpart's alex and happy with GHC/clang-wrapper. With this
alex and happy, I can build GHC head with GHC/GCC42. But I cannot
build GHC head with GHC/clang-wrapper.

Moreover, I can install happy and alex with GHC/clang-wrapper without
nkpart's patches.

I think that your problem is how to build alex and happy with
GHC/clang-wrapper. But my problem is how to compile HS files created
by alex and happy with GHC/clang-wrapper.

After deep investigation, I found the source of my problem. Consider
the following file created by CPP of clang or GCC:

----
# 1 "<built-inxxx>" 1
# 1 "templates/GenericTemplatexxx.hs" 2
{-# FOO
  #-}
----

% clang -E -undef -x assembler-with-cpp this_file
generates:

----
# 1 "test"
# 1 "<built-in>" 1
# 1 "test" 2
 # 1 "<built-inxxx>" 1

 # 1 "templates/GenericTemplatexxx.hs" 2

{-# FOO
  #-}
----

So, the line started with " #" cannot be treated by GHC. This is the
problem.

% clang -E -undef -x c this_file
generates:

----
# 1 "test"
# 1 "<built-in>" 1
# 1 "<built-in>" 3



# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "test" 2
# 1 "<built-inxxx>" 1
# 1 "templates/GenericTemplatexxx.hs" 2
{-# FOO
----

And an error occurs because of "  #-}".

So, replacing "-x c" with "-x assembler-with-cpp" in a wrapper is a
MUST. And HS files generated by alex and happy should not include
lines started with "# ".

My solution so far is adding "-optP-P" to alex and happy to not
generate line markers. An example patch to alex is attached.

I can build GHC head with GHC/clang-wrapper and with alex and happy
with this hack.

--Kazu

diff --git a/Setup.lhs b/Setup.lhs
index 302a3f0..6ab62d5 100644
--- a/Setup.lhs
+++ b/Setup.lhs
@@ -44,7 +44,7 @@ myPostBuild _ flags _ lbi = do
       runProgram p = rawSystemProgramConf verbosity p (withPrograms lbi)
       cpp_template src dst opts = do
         let tmp = dst ++ ".tmp"
-        runProgram ghcProgram (["-o", tmp, "-E", "-cpp", "templates" </> src] ++ opts)
+        runProgram ghcProgram (["-o", tmp, "-E", "-cpp", "-optP-P", "templates" </> src] ++ opts)
         writeFile dst . unlines . map mungeLinePragma . lines =<< readFile tmp
         removeFile tmp
 






More information about the ghc-devs mailing list