[Git][ghc/ghc][wip/hadrian-windows-bindist-cross] ghc-toolchain: Normalise triple via config.sub

Matthew Pickering (@mpickering) gitlab at gitlab.haskell.org
Mon Aug 21 10:09:47 UTC 2023



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


Commits:
c444a7c4 by Matthew Pickering at 2023-08-21T11:09:34+01:00
ghc-toolchain: Normalise triple via config.sub

We were not normalising the target triple anymore like we did with the
old make build system.

TODO: Should the target prefix use the normalised or unnormalised
platform?

- - - - -


4 changed files:

- utils/ghc-toolchain/exe/Main.hs
- utils/ghc-toolchain/ghc-toolchain.cabal
- + utils/ghc-toolchain/src/GHC/Toolchain/NormaliseTriple.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Program.hs


Changes:

=====================================
utils/ghc-toolchain/exe/Main.hs
=====================================
@@ -31,6 +31,7 @@ import GHC.Toolchain.Tools.Ranlib
 import GHC.Toolchain.Tools.Nm
 import GHC.Toolchain.Tools.MergeObjs
 import GHC.Toolchain.Tools.Readelf
+import GHC.Toolchain.NormaliseTriple (normaliseTriple)
 
 data Opts = Opts
     { optTriple    :: String
@@ -367,15 +368,17 @@ ldOverrideWhitelist a =
     _ -> False
 
 
+
 mkTarget :: Opts -> M Target
 mkTarget opts = do
+    normalised_triple <- normaliseTriple (optTriple opts)
     -- Use Llvm target if specified, otherwise use triple as llvm target
-    let tgtLlvmTarget = fromMaybe (optTriple opts) (optLlvmTriple opts)
+    let tgtLlvmTarget = fromMaybe normalised_triple (optLlvmTriple opts)
     cc0 <- findCc tgtLlvmTarget (optCc opts)
     cxx <- findCxx tgtLlvmTarget (optCxx opts)
     cpp <- findCpp (optCpp opts) cc0
     hsCpp <- findHsCpp (optHsCpp opts) cc0
-    (archOs, tgtVendor) <- parseTriple cc0 (optTriple opts)
+    (archOs, tgtVendor) <- parseTriple cc0 normalised_triple
     cc <- addPlatformDepCcFlags archOs cc0
     readelf <- optional $ findReadelf (optReadelf opts)
     ccLink <- findCcLink tgtLlvmTarget (optCcLink opts) (ldOverrideWhitelist archOs && fromMaybe True (optLdOverride opts)) archOs cc readelf


=====================================
utils/ghc-toolchain/ghc-toolchain.cabal
=====================================
@@ -17,6 +17,7 @@ library
                       GHC.Toolchain.Prelude,
                       GHC.Toolchain.Program,
                       GHC.Toolchain.ParseTriple,
+                      GHC.Toolchain.NormaliseTriple,
                       GHC.Toolchain.CheckArm,
                       GHC.Toolchain.Target,
                       GHC.Toolchain.Tools.Ar,


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/NormaliseTriple.hs
=====================================
@@ -0,0 +1,12 @@
+module GHC.Toolchain.NormaliseTriple where
+
+import GHC.Toolchain.Prelude
+import GHC.Toolchain.Program
+import Data.Text (strip, pack, unpack)
+
+normaliseTriple :: String -> M String
+normaliseTriple triple = do
+  let norm = unpack . strip . pack
+  normalised_triple <- norm <$> readProgramStdout shProgram ["config.sub", triple]
+  logInfo $ unwords ["Normalised triple:", triple, "~>", normalised_triple]
+  return normalised_triple


=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Program.hs
=====================================
@@ -1,5 +1,6 @@
 module GHC.Toolchain.Program
     ( Program(..)
+    , shProgram
     , _prgPath
     , _prgFlags
     , addFlagIfNew
@@ -37,6 +38,9 @@ data Program = Program { prgPath :: FilePath
                        }
     deriving (Read, Eq, Ord)
 
+shProgram :: Program
+shProgram = Program "sh" []
+
 instance Show Program where
   -- Normalise filepaths before showing to aid with diffing the target files.
   show (Program p f) = unwords



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c444a7c43af903b261e0a3a53b75ce8eb0ae9988

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/c444a7c43af903b261e0a3a53b75ce8eb0ae9988
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/20230821/42d5194f/attachment-0001.html>


More information about the ghc-commits mailing list