-
Notifications
You must be signed in to change notification settings - Fork 733
Fix --host= triple mangling during cross-compilation #11718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
fb2cc4c
5910bf0
5629641
eb68627
c5b0ca3
7b1a466
8c5d401
5aa5349
6617792
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,8 +56,11 @@ runConfigureScript | |
| -> ProgramDb | ||
| -> Platform | ||
| -- ^ host platform | ||
| -> Maybe String | ||
| -- ^ original target triple from compiler info (e.g. @"x86_64-w64-mingw32"@), | ||
| -- used for the @--host=@ flag instead of the pretty-printed 'Platform' | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There needs to be an explanation (or a reference to an explanation) about how the GHC target platform corresponds to the autoconf notion of host. Otherwise it looks very confusing at a first glance, i.e. it appears like we are mixing up host and target. |
||
| -> IO () | ||
| runConfigureScript verbHandles cfg flags programDb hp = do | ||
| runConfigureScript verbHandles cfg flags programDb hp targetTriple = do | ||
| let commonCfg = configCommonFlags cfg | ||
| verbosity = mkVerbosity verbHandles (fromFlag $ setupVerbosity commonCfg) | ||
| dist_dir <- findDistPrefOrDefault $ setupDistPref commonCfg | ||
|
|
@@ -183,7 +186,7 @@ runConfigureScript verbHandles cfg flags programDb hp = do | |
| : [("CXXFLAGS", Just (mkFlagsEnv cxxFlags "CXXFLAGS")) | Just cxxFlags <- [mcxxFlags]] | ||
| ++ [("PATH", Just pathEnv) | not (null extraPath)] | ||
| ++ cabalFlagEnv | ||
| maybeHostFlag = ["--host=" ++ show (pretty hp) | hp /= buildPlatform] | ||
| maybeHostFlag = ["--host=" ++ fromMaybe (show (pretty hp)) targetTriple | hp /= buildPlatform] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why use the original This also needs a very loud comment that the |
||
| args' = | ||
| configureFile' | ||
| : args | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| module A where |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module Main (main) where | ||
|
|
||
| import Distribution.Simple | ||
|
|
||
| main :: IO () | ||
| main = defaultMainWithHooks autoconfUserHooks |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/bin/sh | ||
| # Minimal configure script that records its arguments. | ||
| # We write all args to configure-args.txt so the test can inspect them. | ||
| echo "$@" > configure-args.txt |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/bin/sh | ||
|
|
||
| # A fake GHC that proxies the real GHC but overrides | ||
| # "Target platform" to simulate cross-compilation | ||
| # to x86_64-w64-mingw32. | ||
|
|
||
| case "$*" in | ||
| *--info*) | ||
| ghc "$@" | sed 's/("Target platform","[^"]*")/("Target platform","x86_64-w64-mingw32")/' | ||
| ;; | ||
| *) | ||
| exec ghc "$@" | ||
| ;; | ||
| esac |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import Test.Cabal.Prelude | ||
| import Test.Cabal.Script (runghc) | ||
| import Control.Monad.IO.Class | ||
| import Data.List (isInfixOf) | ||
|
|
||
| -- When cross-compiling, Cabal passes a --host= flag to configure scripts. | ||
| -- The value should be the original GNU triple (e.g. x86_64-w64-mingw32), | ||
| -- not Cabal's canonical platform string (e.g. x86_64-windows). | ||
| -- | ||
| -- This test uses a fake GHC wrapper that reports "x86_64-w64-mingw32" | ||
| -- as its Target platform (simulating a cross-compiler), then checks | ||
| -- that the configure script receives --host=x86_64-w64-mingw32 | ||
| -- rather than the mangled --host=x86_64-windows. | ||
| main = do | ||
| skipIfWindows "uses sh script as fake ghc" | ||
| setupTest $ recordMode DoNotRecord $ do | ||
| env <- getTestEnv | ||
| let cwd = testCurrentDir env | ||
| fakeGhc = cwd </> "scripts" </> "fake-ghc.sh" | ||
| -- Run Setup.hs configure with our fake cross-compiler. | ||
| -- We call runghc ourselves to bypass the test framework's | ||
| -- --with-ghc which would override ours. | ||
| _ <- liftIO $ runghc | ||
| (testScriptEnv env) | ||
| (Just $ testTmpDir env) | ||
| (testEnvironment env) | ||
| ("." </> "Setup.hs") | ||
| [ "configure" | ||
| , "--distdir", testDistDir env | ||
| , "--with-compiler", fakeGhc | ||
| ] | ||
| -- The configure script writes its arguments to configure-args.txt | ||
| -- in its working directory (dist/build/). | ||
| let argsFile = testDistDir env </> "build" </> "configure-args.txt" | ||
| args <- liftIO $ readFile argsFile | ||
| -- The configure script should receive --host=x86_64-w64-mingw32 | ||
| -- (the original GNU triple), not --host=x86_64-windows. | ||
| unless ("--host=x86_64-w64-mingw32" `isInfixOf` args) $ | ||
| error $ unlines | ||
| [ "Expected --host=x86_64-w64-mingw32 in configure arguments" | ||
| , "but got: " ++ args | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| cabal-version: 2.2 | ||
| name: test | ||
| version: 0 | ||
| build-type: Configure | ||
|
|
||
| library | ||
| exposed-modules: A | ||
| build-depends: base | ||
| default-language: Haskell2010 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| synopsis: Fix --host= triple mangling during cross-compilation#11718 | ||
|
jappeace marked this conversation as resolved.
Outdated
|
||
| packages: [cabal-install] | ||
| prs: 11718 | ||
|
jappeace marked this conversation as resolved.
|
||
| --- | ||
|
|
||
| repairs (hopefully): https://github.com/haskell/cabal/issues/5887 | ||
|
|
||
| Adds an integration test which fails | ||
| on master and now succeeds. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cabal now passes the unchanged GHC target platform triple as the autoconf For example, Cabal now passes the full |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would call this (here and below) compilerTargetTriple just to be explicit.