[Git][ghc/ghc][wip/hadrian-windows-bindist-cross] 3 commits: ghc-toolchain: Check for C99 support with -std=c99

Matthew Pickering (@mpickering) gitlab at gitlab.haskell.org
Wed Aug 23 15:16:14 UTC 2023



Matthew Pickering pushed to branch wip/hadrian-windows-bindist-cross at Glasgow Haskell Compiler / GHC


Commits:
f241486e by Ben Gamari at 2023-08-23T15:53:36+01:00
ghc-toolchain: Check for C99 support with -std=c99

Previously we failed to try enabling C99 support with `-std=c99`, as
`autoconf` attempts. This broke on older compilers (e.g. CentOS 7) which
don't enable C99 by default.

Fixes #23879.

- - - - -
b1fd16f0 by Matthew Pickering at 2023-08-23T16:15:56+01:00
Endian

- - - - -
6fb968c8 by Matthew Pickering at 2023-08-23T16:16:04+01:00
fix ben

- - - - -


2 changed files:

- utils/ghc-toolchain/src/GHC/Toolchain/PlatformDetails.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cc.hs


Changes:

=====================================
utils/ghc-toolchain/src/GHC/Toolchain/PlatformDetails.hs
=====================================
@@ -46,7 +46,7 @@ checkWordSize cc = checking "word size" $ do
 
 checkEndianness :: Cc -> M Endianness
 checkEndianness cc = do
-    checkEndiannessParamH cc <|> checkEndiannessLimitsH cc
+    checkEndiannessParamH cc <|> checkEndiannessLimitsH cc <|> checkEndianness__BYTE_ORDER__ cc
 
 checkEndiannessParamH :: Cc -> M Endianness
 checkEndiannessParamH cc = checking "endianness (param.h)" $ do
@@ -92,6 +92,28 @@ checkEndiannessLimitsH cc = checking "endianness (limits.h)" $ do
         , "#endif"
         ]
 
+checkEndianness__BYTE_ORDER__ :: Cc -> M Endianness
+checkEndianness__BYTE_ORDER__ cc = checking "endianness (__BYTE_ORDER__)" $ do
+    out <- preprocess cc prog
+    case reverse $ lines out of
+      "big":_ -> return BigEndian
+      "little":_ -> return LittleEndian
+      "unknown":_ -> throwE "unknown endianness"
+      _ -> throwE "unrecognized output"
+  where
+    prog = unlines
+        [ "#include <sys/param.h>"
+        , "#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__"
+        , "little"
+        , "#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__"
+        , "big"
+        , "#else"
+        , "unknown"
+        , "#endif"
+        ]
+
+
+
 checkLeadingUnderscore :: Cc -> Nm -> M Bool
 checkLeadingUnderscore cc nm = checking ctxt $ withTempDir $ \dir -> do
     let test_o = dir </> "test.o"


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cc.hs
=====================================
@@ -39,12 +39,15 @@ findCc llvmTarget progOpt = checking "for C compiler" $ do
     -- there's a more optimal one
     ccProgram <- findProgram "C compiler" progOpt ["gcc", "clang", "cc"]
 
-    cc' <- ignoreUnusedArgs $ Cc {ccProgram}
-    cc  <- ccSupportsTarget llvmTarget cc'
-    checking "whether Cc works" $ checkCcWorks cc
-    checkC99Support cc
-    checkCcSupportsExtraViaCFlags cc
-    return cc
+    cc0 <- ignoreUnusedArgs $ Cc {ccProgram}
+    cc1 <- ccSupportsTarget llvmTarget cc0
+    checking "whether Cc works" $ checkCcWorks cc1
+    cc2 <- oneOf "cc doesn't support C99" $ map checkC99Support
+        [ cc1
+        , cc1 & _ccFlags %++ "-std=c99"
+        ]
+    checkCcSupportsExtraViaCFlags cc2
+    return cc2
 
 checkCcWorks :: Cc -> M ()
 checkCcWorks cc = withTempDir $ \dir -> do
@@ -75,7 +78,7 @@ ccSupportsTarget :: String -> Cc -> M Cc
 ccSupportsTarget target cc = checking "whether Cc supports --target" $
                              supportsTarget _ccProgram checkCcWorks target cc
 
-checkC99Support :: Cc -> M ()
+checkC99Support :: Cc -> M Cc
 checkC99Support cc = checking "for C99 support" $ withTempDir $ \dir -> do
     let test_o = dir </> "test.o"
     compileC cc test_o $ unlines
@@ -84,6 +87,7 @@ checkC99Support cc = checking "for C99 support" $ withTempDir $ \dir -> do
         , "# error \"Compiler does not advertise C99 conformance\""
         , "#endif"
         ]
+    return cc
 
 checkCcSupportsExtraViaCFlags :: Cc -> M ()
 checkCcSupportsExtraViaCFlags cc = checking "whether cc supports extra via-c flags" $ withTempDir $ \dir -> do



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c5b9fe24ebbb195ac58dec1fc0fe7f443f9ecec3...6fb968c866641f2da0efc64a2ff657e20719dbd3

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/c5b9fe24ebbb195ac58dec1fc0fe7f443f9ecec3...6fb968c866641f2da0efc64a2ff657e20719dbd3
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230823/e33de671/attachment-0001.html>


More information about the ghc-commits mailing list