
Rodrigo Mesquita pushed to branch wip/romes/24212 at Glasgow Haskell Compiler / GHC Commits: 84763b70 by Rodrigo Mesquita at 2025-07-10T14:48:45+01:00 SettingsLdCommand - - - - - 02d8d9e5 by Rodrigo Mesquita at 2025-07-10T17:23:46+01:00 Doing it - - - - - f2ac37e0 by Rodrigo Mesquita at 2025-07-10T18:14:17+01:00 Doing - - - - - 12 changed files: - compiler/GHC/Driver/Session.hs - compiler/GHC/Settings.hs - compiler/GHC/Settings/IO.hs - compiler/GHC/SysTools/BaseDir.hs - configure.ac - distrib/configure.ac.in - hadrian/bindist/Makefile - hadrian/src/Rules/BinaryDist.hs - hadrian/src/Rules/Generate.hs - m4/fp_setup_windows_toolchain.m4 - m4/fp_settings.m4 → m4/subst_tooldir.m4 - utils/ghc-toolchain/exe/Main.hs Changes: ===================================== compiler/GHC/Driver/Session.hs ===================================== @@ -3513,9 +3513,8 @@ compilerInfo dflags showBool False = "NO" platform = targetPlatform dflags isWindows = platformOS platform == OSMinGW32 - useInplaceMinGW = toolSettings_useInplaceMinGW $ toolSettings dflags expandDirectories :: FilePath -> Maybe FilePath -> String -> String - expandDirectories topd mtoold = expandToolDir useInplaceMinGW mtoold . expandTopDir topd + expandDirectories topd mtoold = expandToolDir mtoold . expandTopDir topd -- Note [Special unit-ids] -- ~~~~~~~~~~~~~~~~~~~~~~~ ===================================== compiler/GHC/Settings.hs ===================================== @@ -23,7 +23,6 @@ module GHC.Settings , sMergeObjsSupportsResponseFiles , sLdIsGnuLd , sGccSupportsNoPie - , sUseInplaceMinGW , sArSupportsDashL , sPgm_L , sPgm_P @@ -102,7 +101,6 @@ data ToolSettings = ToolSettings , toolSettings_mergeObjsSupportsResponseFiles :: Bool , toolSettings_ldIsGnuLd :: Bool , toolSettings_ccSupportsNoPie :: Bool - , toolSettings_useInplaceMinGW :: Bool , toolSettings_arSupportsDashL :: Bool , toolSettings_cmmCppSupportsG0 :: Bool @@ -221,8 +219,6 @@ sLdIsGnuLd :: Settings -> Bool sLdIsGnuLd = toolSettings_ldIsGnuLd . sToolSettings sGccSupportsNoPie :: Settings -> Bool sGccSupportsNoPie = toolSettings_ccSupportsNoPie . sToolSettings -sUseInplaceMinGW :: Settings -> Bool -sUseInplaceMinGW = toolSettings_useInplaceMinGW . sToolSettings sArSupportsDashL :: Settings -> Bool sArSupportsDashL = toolSettings_arSupportsDashL . sToolSettings ===================================== compiler/GHC/Settings/IO.hs ===================================== @@ -68,16 +68,10 @@ initSettings top_dir = do getBooleanSetting key = either pgmError pure $ getRawBooleanSetting settingsFile mySettings key - -- On Windows, by mingw is often distributed with GHC, - -- so we look in TopDir/../mingw/bin, - -- as well as TopDir/../../mingw/bin for hadrian. - -- But we might be disabled, in which we we don't do that. - useInplaceMinGW <- getBooleanSetting "Use inplace MinGW toolchain" - -- see Note [topdir: How GHC finds its files] -- NB: top_dir is assumed to be in standard Unix -- format, '/' separated - mtool_dir <- liftIO $ findToolDir useInplaceMinGW top_dir + mtool_dir <- liftIO $ findToolDir top_dir -- see Note [tooldir: How GHC finds mingw on Windows] let getSetting_raw key = either pgmError pure $ @@ -85,11 +79,11 @@ initSettings top_dir = do getSetting_topDir top key = either pgmError pure $ getRawFilePathSetting top settingsFile mySettings key getSetting_toolDir top tool key = - expandToolDir useInplaceMinGW tool <$> getSetting_topDir top key + expandToolDir tool <$> getSetting_topDir top key getSetting key = getSetting_topDir top_dir key getToolSetting key = getSetting_toolDir top_dir mtool_dir key - expandDirVars top tool = expandToolDir useInplaceMinGW tool . expandTopDir top + expandDirVars top tool = expandToolDir tool . expandTopDir top getToolPath :: (Target -> Program) -> String getToolPath key = expandDirVars top_dir mtool_dir (prgPath . key $ target) @@ -189,7 +183,6 @@ initSettings top_dir = do , toolSettings_mergeObjsSupportsResponseFiles = maybe False mergeObjsSupportsResponseFiles $ tgtMergeObjs target - , toolSettings_useInplaceMinGW = useInplaceMinGW , toolSettings_arSupportsDashL = arSupportsDashL $ tgtAr target , toolSettings_cmmCppSupportsG0 = cmmCppSupportsG0 $ tgtCmmCPreprocessor target ===================================== compiler/GHC/SysTools/BaseDir.hs ===================================== @@ -119,15 +119,14 @@ play nice with the system compiler instead. -- | Expand occurrences of the @$tooldir@ interpolation in a string -- on Windows, leave the string untouched otherwise. expandToolDir - :: Bool -- ^ whether we use the ambient mingw toolchain - -> Maybe FilePath -- ^ tooldir + :: Maybe FilePath -- ^ tooldir -> String -> String #if defined(mingw32_HOST_OS) -expandToolDir False (Just tool_dir) s = expandPathVar "tooldir" tool_dir s -expandToolDir False Nothing _ = panic "Could not determine $tooldir" -expandToolDir True _ s = s +expandToolDir (Just tool_dir) s = expandPathVar "tooldir" tool_dir s +expandToolDir Nothing _ = panic "Could not determine $tooldir" +expandToolDir _ s = s #else -expandToolDir _ _ s = s +expandToolDir _ s = s #endif -- | Returns a Unix-format path pointing to TopDir. @@ -161,13 +160,13 @@ tryFindTopDir Nothing -- Returns @Nothing@ when not on Windows. -- When called on Windows, it either throws an error when the -- tooldir can't be located, or returns @Just tooldirpath@. --- If the distro toolchain is being used we treat Windows the same as Linux +-- If the distro toolchain is being used, there will be no variables to +-- substitute for anyway, so this is a no-op. findToolDir - :: Bool -- ^ whether we use the ambient mingw toolchain - -> FilePath -- ^ topdir + :: FilePath -- ^ topdir -> IO (Maybe FilePath) #if defined(mingw32_HOST_OS) -findToolDir False top_dir = go 0 (top_dir > "..") [] +findToolDir top_dir = go 0 (top_dir > "..") [] where maxDepth = 3 go :: Int -> FilePath -> [FilePath] -> IO (Maybe FilePath) go k path tried @@ -180,7 +179,7 @@ findToolDir False top_dir = go 0 (top_dir > "..") [] if oneLevel then return (Just path) else go (k+1) (path > "..") tried' -findToolDir True _ = return Nothing +findToolDir _ = return Nothing #else -findToolDir _ _ = return Nothing +findToolDir _ = return Nothing #endif ===================================== configure.ac ===================================== @@ -132,6 +132,7 @@ AC_ARG_ENABLE(distro-toolchain, [FP_CAPITALIZE_YES_NO(["$enableval"], [EnableDistroToolchain])], [EnableDistroToolchain=NO] ) +AC_SUBST([EnableDistroToolchain]) if test "$EnableDistroToolchain" = "YES"; then TarballsAutodownload=NO @@ -752,8 +753,6 @@ FP_PROG_AR_NEEDS_RANLIB dnl ** Check to see whether ln -s works AC_PROG_LN_S -FP_SETTINGS - dnl ** Find the path to sed AC_PATH_PROGS(SedCmd,gsed sed,sed) ===================================== distrib/configure.ac.in ===================================== @@ -91,6 +91,7 @@ AC_ARG_ENABLE(distro-toolchain, [FP_CAPITALIZE_YES_NO(["$enableval"], [EnableDistroToolchain])], [EnableDistroToolchain=@EnableDistroToolchain@] ) +AC_SUBST([EnableDistroToolchain]) if test "$HostOS" = "mingw32" -a "$EnableDistroToolchain" = "NO"; then FP_SETUP_WINDOWS_TOOLCHAIN([$hardtop/mingw/], [\$\$topdir/../mingw/]) @@ -384,8 +385,6 @@ fi AC_SUBST(BaseUnitId) -FP_SETTINGS - # We get caught by # http://savannah.gnu.org/bugs/index.php?1516 # $(eval ...) inside conditionals causes errors @@ -418,6 +417,32 @@ AC_OUTPUT VALIDATE_GHC_TOOLCHAIN([default.target],[default.target.ghc-toolchain]) +if test "$EnableDistroToolchain" = "YES"; then + # If the user specified --enable-distro-toolchain then we just use the + # executable names, not paths. We do this by finding strings of paths to + # programs and keeping the basename only: + cp Target.hs Target.hs.bak + + while IFS= read -r line; do + if echo "$line" | grep -q 'prgPath = "'; then + path=$(echo "$line" | sed -E 's/.*prgPath = "([^"]+)".*/\1/') + base=$(basename "$path") + echo "$line" | sed "s|$path|$base|" + else + echo "$line" + fi + done < Target.hs.bak > Target.hs +fi + +if test "$windows" = YES -a "$EnableDistroToolchain" = "NO"; then + # Handle the Windows toolchain installed in FP_SETUP_WINDOWS_TOOLCHAIN. + # We need to issue a substitution to use $tooldir, + # See Note [tooldir: How GHC finds mingw on Windows] + SUBST_TOOLDIR([default.target]) + echo "Applied tooldir substitution to default.target:" + cat default.target +fi + rm -Rf acargs acghc-toolchain actmp-ghc-toolchain echo "****************************************************" ===================================== hadrian/bindist/Makefile ===================================== @@ -87,8 +87,8 @@ lib/settings : config.mk @rm -f $@ @echo '[("target os", "$(HaskellTargetOs)")' >> $@ @echo ',("target arch", "$(HaskellTargetArch)")' >> $@ + @echo ',("target has libm", "$(TargetHasLibm)")' >> $@ @echo ',("unlit command", "$$topdir/../bin/$(CrossCompilePrefix)unlit")' >> $@ - @echo ',("Use inplace MinGW toolchain", "$(EnableDistroToolchain)")' >> $@ @echo ',("target RTS linker only supports shared libraries", "$(TargetRTSLinkerOnlySupportsSharedLibs)")' >> $@ @echo ',("Use interpreter", "$(GhcWithInterpreter)")' >> $@ @echo ',("Support SMP", "$(GhcWithSMP)")' >> $@ @@ -98,6 +98,11 @@ lib/settings : config.mk @echo ',("base unit-id", "$(BaseUnitId)")' >> $@ @echo "]" >> $@ +lib/targets/default.target : config.mk default.target + @rm -f $@ + @echo "Copying the bindist-configured default.target to lib/targets/default.target" + cp default.target $@ + # We need to install binaries relative to libraries. BINARIES = $(wildcard ./bin/*) .PHONY: install_bin_libdir ===================================== hadrian/src/Rules/BinaryDist.hs ===================================== @@ -141,7 +141,6 @@ bindistRules = do installPrefix <- fromMaybe (error prefixErr) <$> cmdPrefix installTo NotRelocatable installPrefix - -- TODO: ROMES: TOUCH HERE? phony "binary-dist-dir" $ do version <- setting ProjectVersion targetPlatform <- setting TargetPlatformFull ===================================== hadrian/src/Rules/Generate.hs ===================================== @@ -487,7 +487,6 @@ generateSettings settingsFile = do , ("target arch", queryTarget (show . archOS_arch . tgtArchOs)) , ("unlit command", ("$topdir/../bin/" <>) <$> expr (programName (ctx { Context.package = unlit }))) , ("target has libm", expr $ lookupSystemConfig "target-has-libm") - , ("Use inplace MinGW toolchain", expr $ lookupSystemConfig "settings-use-distro-mingw") , ("target RTS linker only supports shared libraries", expr $ yesNo <$> targetRTSLinkerOnlySupportsSharedLibs) , ("Use interpreter", expr $ yesNo <$> ghcWithInterpreter (predStage stage)) , ("Support SMP", expr $ yesNo <$> targetSupportsSMP) ===================================== m4/fp_setup_windows_toolchain.m4 ===================================== @@ -77,6 +77,7 @@ AC_DEFUN([FP_INSTALL_WINDOWS_TOOLCHAIN],[ # $2 the location that the windows toolchain will be installed in relative to the libdir AC_DEFUN([FP_SETUP_WINDOWS_TOOLCHAIN],[ + # TODO: UPDATE COMMENT # N.B. The parameters which get plopped in the `settings` file used by the # resulting compiler are computed in `FP_SETTINGS`. Specifically, we use # $$topdir-relative paths instead of fullpaths to the toolchain, by replacing ===================================== m4/fp_settings.m4 → m4/subst_tooldir.m4 ===================================== @@ -16,13 +16,11 @@ dnl dnl * FP_SETUP_WINDOWS_TOOLCHAIN will set the toolchain variables to paths dnl to the bundled toolchain (e.g. CFLAGS=/full/path/to/mingw/bin/gcc) dnl -dnl * Later on, in FP_SETTINGS, we substitute occurrences of the path to the +dnl * Later on, at the end of distrib/configure.ac, we substitute occurrences of the path to the dnl mingw tooldir by $tooldir (see SUBST_TOOLDIR). dnl The reason is the Settings* variants of toolchain variables are used by the bindist configure to dnl create the settings file, which needs the windows bundled toolchain to be relative to $tooldir. dnl -dnl * Finally, hadrian will also substitute the mingw prefix by $tooldir before writing the toolchain to the settings file (see generateSettings) -dnl dnl The ghc-toolchain program isn't concerned with any of these complications: dnl it is passed either the full paths to the toolchain executables, or the bundled dnl mingw path is set first on $PATH before invoking it. And ghc-toolchain @@ -35,7 +33,7 @@ dnl ghc-toolchain. # SUBST_TOOLDIR # ---------------------------------- -# $1 - the variable where to search for occurrences of the path to the +# $1 - the filepath where to search for occurrences of the path to the # inplace mingw, and update by substituting said occurrences by # the value of $mingw_install_prefix, where the mingw toolchain will be at # install time @@ -43,30 +41,5 @@ dnl ghc-toolchain. # See Note [How we configure the bundled windows toolchain] AC_DEFUN([SUBST_TOOLDIR], [ - dnl and Note [How we configure the bundled windows toolchain] - $1=`echo "$$1" | sed 's%'"$mingw_prefix"'%'"$mingw_install_prefix"'%g'` -]) - -# FP_SETTINGS -# ---------------------------------- -# Set the variables used in the settings file -AC_DEFUN([FP_SETTINGS], -[ - # LLVM backend tools - - if test "$EnableDistroToolchain" = "YES"; then - # If the user specified --enable-distro-toolchain then we just use the - # executable names, not paths. - dnl XXX="$(basename XXX)" - SettingsLdCommand="$(basename $SettingsLdCommand)" - fi - - if test "$windows" = YES -a "$EnableDistroToolchain" = "NO"; then - # Handle the Windows toolchain installed in FP_SETUP_WINDOWS_TOOLCHAIN. - # We need to issue a substitution to use $tooldir, - # See Note [tooldir: How GHC finds mingw on Windows] - dnl SUBST_TOOLDIR([XXX]) - fi - - AC_SUBST(EnableDistroToolchain) + sed -i.bkp $1 's%'"$mingw_prefix"'%'"$mingw_install_prefix"'%g' ]) ===================================== utils/ghc-toolchain/exe/Main.hs ===================================== @@ -534,4 +534,3 @@ mkTarget opts = do } return t ---- ROMES:TODO: fp_settings.m4 in general which I don't think was ported completely (e.g. the basenames and windows llvm-XX and such) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/656841725bc1ed58fc2789e3e1a4879... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/656841725bc1ed58fc2789e3e1a4879... You're receiving this email because of your account on gitlab.haskell.org.