Commit d6cecde5 authored by Tamar Christina's avatar Tamar Christina

Remove the Windows GCC driver.

This patch drops the GCC driver and instead moves
the only remaining path that we need to keep for
backwards compatibility to the settings file.

It also generalizes the code that expands `$TopDir`
so it can expand it within any location in the string
and also changes it so `$TopDir` is expanded only
after the words call because `$TopDir` can contains
spaces which would be horribly broken.

Test Plan: ./validate

Reviewers: austin, hvr, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, erikd

GHC Trac Issues: #13709

Differential Revision:
parent fda094d0
......@@ -464,6 +464,7 @@ AC_DEFUN([FP_SETTINGS],
SettingsCCompilerFlags="$CONF_CC_OPTS_STAGE2 -B\$topdir/../mingw/bin/ -B\$topdir/../mingw/lib/"
......@@ -486,6 +487,7 @@ AC_DEFUN([FP_SETTINGS],
......@@ -523,7 +525,6 @@ AC_DEFUN([FP_SETTINGS],
......@@ -202,17 +202,10 @@ initSysTools mbMinusB
Nothing ->
pgmError ("Can't parse " ++
show platformConstantsFile)
let getSetting key = case lookup key mySettings of
Just xs ->
return $ case stripPrefix "$topdir" xs of
Just [] ->
Just xs'@(c:_)
| isPathSeparator c ->
top_dir ++ xs'
_ ->
let getSettingRaw key = case lookup key mySettings of
Just xs -> return xs
Nothing -> pgmError ("No entry for " ++ show key ++ " in " ++ show settingsFile)
getSetting key = resolveTopDir top_dir <$> getSettingRaw key
getBooleanSetting key = case lookup key mySettings of
Just "YES" -> return True
Just "NO" -> return False
......@@ -239,7 +232,11 @@ initSysTools mbMinusB
-- with the settings file, but it would be a little fiddly
-- to make that possible, so for now you can't.
gcc_prog <- getSetting "C compiler command"
gcc_args_str <- getSetting "C compiler flags"
-- TopDir can expand to something that contains spaces
-- for the argument string we apply words to the string in order to
-- break it up. So defer the expansion of $TopDir till after the words
-- call here.
gcc_args_str <- getSettingRaw "C compiler flags"
gccSupportsNoPie <- getBooleanSetting "C compiler supports -no-pie"
cpp_prog <- getSetting "Haskell CPP command"
cpp_args_str <- getSetting "Haskell CPP flags"
......@@ -252,7 +249,7 @@ initSysTools mbMinusB
| otherwise = []
cpp_args= map Option (words cpp_args_str)
gcc_args = map Option (words gcc_args_str
gcc_args = map (Option . resolveTopDir top_dir) (words gcc_args_str
++ unreg_gcc_args
++ tntc_gcc_args)
ldSupportsCompactUnwind <- getBooleanSetting "ld supports compact unwind"
......@@ -363,6 +360,21 @@ initSysTools mbMinusB
sPlatformConstants = platformConstants
-- | This function will replace any usage of $TopDir in the given string
-- regardless of it's location within the string.
resolveTopDir :: String -- ^ The value of $TopDir
-> String -- ^ The string to perform substitutions in
-> String -- ^ The resulting string with all subs done.
resolveTopDir top_dir str
= case break (=='$') str of
(_, []) -> str
(x, xs) -> let rst = case stripPrefix "$topdir" xs of
Just [] -> top_dir
Just xs'@(c:_) | isPathSeparator c
-> top_dir ++ xs'
_ -> xs
in x ++ resolveTopDir top_dir rst
-- returns a Unix-format path (relying on getBaseDir to do so too)
findTopDir :: Maybe String -- Maybe TopDir path (without the '-B' prefix).
-> IO String -- TopDir (in Unix format '/' separated)
......@@ -302,8 +302,6 @@ fail() {
if test "$HostOS" = "mingw32"
# Find the mingw-w64 7z file to extract.
# NB. If you update the tarballs to a new version of gcc, don't
# forget to tweak the paths in driver/gcc/gcc.c.
if test "$HostArch" = "i386"
......@@ -366,12 +364,6 @@ set_up_tarballs() {
mv "inplace/${tarball_mingw_dir}" inplace/mingw &&
touch inplace/mingw
# NB. Now since the GCC is hardcoded to use /mingw32 we need to
# make a wrapper around it to give it the proper paths
mv inplace/mingw/bin/gcc.exe inplace/mingw/bin/realgcc.exe
inplace/mingw/bin/realgcc.exe driver/gcc/gcc.c driver/utils/cwrapper.c driver/utils/getLocation.c -Idriver/utils -o inplace/mingw/bin/gcc.exe
AC_MSG_NOTICE([In-tree MingW-w64 tree created])
......@@ -80,6 +80,9 @@ Now we generate ::
used to build a GHC using compilers on your ``PATH`` instead of using the
bundled bindist. See :ghc-ticket:`13792`
- Windows no longer uses an intermediate GCC driver and instead calls GCC
directly. See :ghc-ticket:`13709`.
- Lots of other bugs. See `Trac <>`_
for a complete list.
/* gcc on mingw is hardcoded to use /mingw (which is c:/mingw) to
find various files. If this is a different version of mingw to the
one that we have in the GHC tree then things can go wrong. We
therefore need to add various -B flags to the gcc commandline,
so that it uses our in-tree mingw. Hence this wrapper. */
#include "cwrapper.h"
#include "getLocation.h"
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
char *binDir;
char *exePath;
char *preArgv[4];
char *oldPath;
char *newPath;
char *base;
char *version;
int n;
binDir = getExecutablePath();
exePath = mkString("%s/realgcc.exe", binDir);
/* We need programs like
to be able to find the DLLs in inplace/mingw/bin, so we need to
add it to $PATH */
oldPath = getenv("PATH");
if (!oldPath) {
die("Couldn't read PATH\n");
n = snprintf(NULL, 0, "PATH=%s;%s", binDir, oldPath);
newPath = malloc(n);
if (!newPath) {
die("Couldn't allocate space for PATH\n");
snprintf(newPath, n, "PATH=%s;%s", binDir, oldPath);
n = putenv(newPath);
if (n) {
die("putenv failed\n");
/* GCC Version. */
version = mkString("%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
/* Without these -B args, gcc will still work. However, if you
have a mingw installation in c:/mingw then it will use files
from that in preference to the in-tree files. */
preArgv[0] = mkString("-B%s", binDir);
preArgv[1] = mkString("-B%s/../lib", binDir);
#if defined(__MINGW64__)
base = mkString("x86_64-w64-mingw32");
base = mkString("i686-w64-mingw32");
preArgv[2] = mkString("-B%s/../lib/gcc/%s/%s" , binDir, base, version);
preArgv[3] = mkString("-B%s/../libexec/gcc/%s/%s", binDir, base, version);
run(exePath, 4, preArgv, argc - 1, argv + 1);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment