[Git][ghc/ghc][wip/romes/enable-ghc-toolchain] 4 commits: ghc-toolchain: Parse javascript and ghcjs as a Arch and OS
Rodrigo Mesquita (@alt-romes)
gitlab at gitlab.haskell.org
Mon Jul 24 11:37:38 UTC 2023
Rodrigo Mesquita pushed to branch wip/romes/enable-ghc-toolchain at Glasgow Haskell Compiler / GHC
Commits:
3e6e0b9a by Rodrigo Mesquita at 2023-07-24T12:30:47+01:00
ghc-toolchain: Parse javascript and ghcjs as a Arch and OS
- - - - -
8e82daa7 by Rodrigo Mesquita at 2023-07-24T12:31:59+01:00
ghc-toolchain: Try the C compiler as a fallback C++ compiler
It's not uncommon for users to specify a particular C compiler but not the C++
compiler.
An example of this is `configure` invoking ghc-toolchain for the HOST
target configuration, but only configuring a CC_STAGE0, not a CXX_STAGE0
We instruct ghc-toolchain to be a bit cleverer here, by trying the C
compiler as a fallback C++ compiler if none is otherwise found. It might
be that the C compiler program is a collection of compilers that also
support C++, such as gcc or clang.
- - - - -
b947472b by Rodrigo Mesquita at 2023-07-24T12:32:01+01:00
ghc-toolchain: Fix ranlib option
- - - - -
58a37221 by Rodrigo Mesquita at 2023-07-24T12:37:28+01:00
Improve handling of Cc as a fallback
- - - - -
6 changed files:
- utils/ghc-toolchain/CHANGELOG.md
- utils/ghc-toolchain/Main.hs
- utils/ghc-toolchain/src/GHC/Toolchain/ParseTriple.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cxx.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs
Changes:
=====================================
utils/ghc-toolchain/CHANGELOG.md
=====================================
@@ -2,4 +2,6 @@
## Unreleased
+* Try the C compiler as a fallback C++ compiler
+* Parse "javascript" and "ghcjs" as a valid Arch and OS
* First version. See Note [ghc-toolchain overview] in GHC.Toolchain for an overview
=====================================
utils/ghc-toolchain/Main.hs
=====================================
@@ -146,7 +146,7 @@ options =
, progOpts "cxx" "C++ compiler" _optCxx
, progOpts "cc-link" "C compiler for linking" _optCcLink
, progOpts "ar" "ar archiver" _optAr
- , progOpts "ranlib" "ranlib utility" _optAr
+ , progOpts "ranlib" "ranlib utility" _optRanlib
, progOpts "nm" "nm archiver" _optNm
, progOpts "readelf" "readelf utility" _optReadelf
, progOpts "merge-objs" "linker for merging objects" _optMergeObjs
@@ -314,7 +314,7 @@ mkTarget opts = do
-- Use Llvm target if specified, otherwise use triple as llvm target
let tgtLlvmTarget = fromMaybe (optTriple opts) (optLlvmTriple opts)
cc0 <- findCc tgtLlvmTarget (optCc opts)
- cxx <- findCxx tgtLlvmTarget (optCxx opts)
+ cxx <- findCxx tgtLlvmTarget (optCxx opts) cc0
cpp <- findCpp (optCpp opts) cc0
hsCpp <- findHsCpp (optHsCpp opts) cc0
(archOs, tgtVendor) <- parseTriple cc0 (optTriple opts)
=====================================
utils/ghc-toolchain/src/GHC/Toolchain/ParseTriple.hs
=====================================
@@ -53,6 +53,7 @@ parseArch cc arch =
"riscv64" -> pure ArchRISCV64
"hppa" -> pure ArchUnknown
"wasm32" -> pure ArchWasm32
+ "javascript" -> pure ArchJavaScript
_ -> throwE $ "Unknown architecture " ++ arch
parseOs :: String -> M OS
@@ -76,6 +77,7 @@ parseOs os =
"aix" -> pure OSAIX
"gnu" -> pure OSHurd
"wasi" -> pure OSWasi
+ "ghc-js" -> pure OSGhcjs
_ -> throwE $ "Unknown operating system " ++ os
splitOn :: Char -> String -> [String]
=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs
=====================================
@@ -23,8 +23,8 @@ newtype HsCpp = HsCpp { hsCppProgram :: Program
findHsCpp :: ProgOpt -> Cc -> M HsCpp
findHsCpp progOpt cc = checking "for Haskell C preprocessor" $ do
- -- Use the specified HS CPP or try to find one (candidate is the c compiler)
- foundHsCppProg <- findProgram "Haskell C preprocessor" progOpt [takeFileName $ prgPath $ ccProgram cc]
+ -- Use the specified HS CPP or try to use the c compiler
+ foundHsCppProg <- findProgram "Haskell C preprocessor" progOpt [] <|> pure (Program (prgPath $ ccProgram cc) [])
case poFlags progOpt of
-- If the user specified HS CPP flags don't second-guess them
Just _ -> return HsCpp{hsCppProgram=foundHsCppProg}
@@ -61,8 +61,8 @@ findHsCppArgs cpp = withTempDir $ \dir -> do
findCpp :: ProgOpt -> Cc -> M Cpp
findCpp progOpt cc = checking "for C preprocessor" $ do
- -- Use the specified CPP or try to find one (candidate is the c compiler)
- foundCppProg <- findProgram "C preprocessor" progOpt [prgPath $ ccProgram cc]
+ -- Use the specified CPP or try to use the c compiler
+ foundCppProg <- findProgram "C preprocessor" progOpt [] <|> pure (Program (prgPath $ ccProgram cc) [])
case poFlags progOpt of
-- If the user specified CPP flags don't second-guess them
Just _ -> return Cpp{cppProgram=foundCppProg}
=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cxx.hs
=====================================
@@ -11,6 +11,7 @@ import System.FilePath
import GHC.Toolchain.Prelude
import GHC.Toolchain.Program
import GHC.Toolchain.Utils
+import GHC.Toolchain.Tools.Cc
newtype Cxx = Cxx { cxxProgram :: Program
}
@@ -20,10 +21,12 @@ _cxxProgram :: Lens Cxx Program
_cxxProgram = Lens cxxProgram (\x o -> o{cxxProgram=x})
findCxx :: String -- ^ The llvm target to use if Cc supports --target
- -> ProgOpt -> M Cxx
-findCxx target progOpt = checking "for C++ compiler" $ do
+ -> ProgOpt -- ^ A user specified C++ compiler
+ -> Cc -- ^ The C compiler, to try as a fallback C++ compiler if we can't find one.
+ -> M Cxx
+findCxx target progOpt cc = checking "for C++ compiler" $ do
-- TODO: We use the search order in configure, but there could be a more optimal one
- cxxProgram <- findProgram "C++ compiler" progOpt ["g++", "clang++", "c++"]
+ cxxProgram <- findProgram "C++ compiler" progOpt ["g++", "clang++", "c++"] <|> pure (Program (prgPath $ ccProgram cc) [])
cxx <- cxxSupportsTarget target Cxx{cxxProgram}
checkCxxWorks cxx
return cxx
=====================================
utils/ghc-toolchain/src/GHC/Toolchain/Tools/Link.hs
=====================================
@@ -46,8 +46,8 @@ findCcLink :: String -- ^ The llvm target to use if CcLink supports --target
-> Bool -- ^ Whether we should search for a more efficient linker
-> ArchOS -> Cc -> Maybe Readelf -> M CcLink
findCcLink target progOpt ldOverride archOs cc readelf = checking "for C compiler for linking command" $ do
- -- Use the specified linker or try to find one
- rawCcLink <- findProgram "C compiler for linking" progOpt [takeFileName $ prgPath $ ccProgram cc]
+ -- Use the specified linker or try using the C compiler
+ rawCcLink <- findProgram "C compiler for linking" progOpt [] <|> pure (Program (prgPath $ ccProgram cc) [])
ccLinkProgram <- case poFlags progOpt of
Just _ ->
-- If the user specified linker flags don't second-guess them
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/44a9759ea0f2a80f18fa38ca43f59bf81ec2dfab...58a37221f70f573bf317d006cb9ca571cdb26dec
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/44a9759ea0f2a80f18fa38ca43f59bf81ec2dfab...58a37221f70f573bf317d006cb9ca571cdb26dec
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/20230724/46a878a7/attachment-0001.html>
More information about the ghc-commits
mailing list