[Git][ghc/ghc][wip/global-package-db] Read global package database from settings file

Matthew Pickering (@mpickering) gitlab at gitlab.haskell.org
Fri Mar 1 16:30:59 UTC 2024



Matthew Pickering pushed to branch wip/global-package-db at Glasgow Haskell Compiler / GHC


Commits:
187b4a53 by Matthew Pickering at 2024-03-01T16:30:43+00:00
Read global package database from settings file

Before this patch, the global package database was always assumed to be
in libdir </> package.conf.d.

This causes issues in GHC's build system because there are sometimes
situations where the package database you need to use is not located in
the same place as the settings file.

* The stage1 compiler needs to use stage2 libraries, so we should set
  "Global Package DB" for the stage1 compiler to the stage2 package
  database.
* Stage 2 cross compilers need to use stage3 libraries, so likewise, we
  should set to stage

* When installing we have rearranged everything so that the settings
  file and package database line up properly, so then everything should
  continue to work as before.

A reasonable question is why not generate the "right" settings files in
the right places in GHC's build system. In order to do this you would
need to engineer wrappers for all executables to point to a specific
libdir. There are also situations where the same package db is used by
two different compilers with two different settings files (think stage2
cross compiler and stage3 compiler).

In short, this 10 line patch allows for some reasonable simplifications
in Hadrian at very little cost to anything else.

- - - - -


4 changed files:

- compiler/GHC/Driver/Session.hs
- compiler/GHC/Settings/IO.hs
- hadrian/bindist/Makefile
- hadrian/src/Rules/Generate.hs


Changes:

=====================================
compiler/GHC/Driver/Session.hs
=====================================
@@ -3607,7 +3607,8 @@ compilerInfo dflags
        ("GHC Profiled",                showBool hostIsProfiled),
        ("Debug on",                    showBool debugIsOn),
        ("LibDir",                      topDir dflags),
-       -- The path of the global package database used by GHC
+       -- This is always an absolute path, unlike "Raw Global Package DB" which is
+       -- in the settings file.
        ("Global Package DB",           globalPackageDatabasePath dflags)
       ]
   where


=====================================
compiler/GHC/Settings/IO.hs
=====================================
@@ -112,8 +112,14 @@ initSettings top_dir = do
   ldIsGnuLd               <- getBooleanSetting "ld is GNU ld"
   arSupportsDashL         <- getBooleanSetting "ar supports -L"
 
-  let globalpkgdb_path = installed "package.conf.d"
-      ghc_usage_msg_path  = installed "ghc-usage.txt"
+
+  -- The package database is either a relative path to the location of the settings file
+  -- OR an absolute path.
+  -- In case the path is absolute then top_dir </> abs_path == abs_path
+  --         the path is relative then top_dir </> rel_path == top_dir </> rel_path
+  globalpkgdb_path <- installed <$> getSetting "Raw Global Package DB"
+
+  let ghc_usage_msg_path  = installed "ghc-usage.txt"
       ghci_usage_msg_path = installed "ghci-usage.txt"
 
   -- For all systems, unlit, split, mangle are GHC utilities


=====================================
hadrian/bindist/Makefile
=====================================
@@ -141,6 +141,7 @@ lib/settings : config.mk
 	@echo ',("Leading underscore", "$(LeadingUnderscore)")' >> $@
 	@echo ',("Use LibFFI", "$(UseLibffiForAdjustors)")' >> $@
 	@echo ',("RTS expects libdw", "$(GhcRtsWithLibdw)")' >> $@
+	@echo ',("Raw Global Package DB", "package.conf.d")' >> $@
 	@echo "]" >> $@
 
 # We need to install binaries relative to libraries.


=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -421,6 +421,7 @@ generateSettings = do
         , ("Leading underscore",  queryTarget (yesNo . tgtSymbolsHaveLeadingUnderscore))
         , ("Use LibFFI", expr $ yesNo <$> useLibffiForAdjustors)
         , ("RTS expects libdw", yesNo <$> getFlag UseLibdw)
+        , ("Raw Global Package DB", return "package.conf.d" )
         ]
     let showTuple (k, v) = "(" ++ show k ++ ", " ++ show v ++ ")"
     pure $ case settings of



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/187b4a5310600331c4c54177143b4c46df9d641f
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/20240301/c9d5cff3/attachment-0001.html>


More information about the ghc-commits mailing list