Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

27 changed files:

Changes:

  • .gitlab/ci.sh
    ... ... @@ -341,11 +341,27 @@ function fetch_ghc() {
    341 341
     }
    
    342 342
     
    
    343 343
     function fetch_cabal() {
    
    344
    +  local should_fetch=false
    
    345
    +
    
    344 346
       if [ ! -e "$CABAL" ]; then
    
    345
    -      local v="$CABAL_INSTALL_VERSION"
    
    346
    -      if [[ -z "$v" ]]; then
    
    347
    -          fail "neither CABAL nor CABAL_INSTALL_VERSION are not set"
    
    347
    +    if [ -z "${CABAL_INSTALL_VERSION:-}" ]; then
    
    348
    +      fail "cabal not found at '$CABAL' and CABAL_INSTALL_VERSION is not set"
    
    349
    +    fi
    
    350
    +    should_fetch=true
    
    351
    +  fi
    
    352
    +
    
    353
    +  if  [ -e "$CABAL" ] && [ -n "${CABAL_INSTALL_VERSION:-}" ]; then
    
    354
    +    local current_version
    
    355
    +    if current_version=$($CABAL --numeric-version 2>/dev/null); then
    
    356
    +      if [ "$current_version" != "$CABAL_INSTALL_VERSION" ]; then
    
    357
    +        info "cabal version mismatch: found $current_version, expected $CABAL_INSTALL_VERSION"
    
    358
    +        should_fetch=true
    
    348 359
           fi
    
    360
    +    fi
    
    361
    +  fi
    
    362
    +
    
    363
    +  if [ "$should_fetch" = true ]; then
    
    364
    +      local v="$CABAL_INSTALL_VERSION"
    
    349 365
     
    
    350 366
           start_section fetch-cabal "Fetch Cabal"
    
    351 367
           case "$(uname)" in
    
    ... ... @@ -355,7 +371,7 @@ function fetch_cabal() {
    355 371
                 CLANG64) cabal_arch="x86_64" ;;
    
    356 372
                 *) fail "unknown MSYSTEM $MSYSTEM" ;;
    
    357 373
               esac
    
    358
    -          url="https://downloads.haskell.org/~cabal/cabal-install-$v/cabal-install-$v-$cabal_arch-windows.zip"
    
    374
    +          local url="https://downloads.haskell.org/~cabal/cabal-install-$v/cabal-install-$v-$cabal_arch-windows.zip"
    
    359 375
               info "Fetching cabal binary distribution from $url..."
    
    360 376
               curl "$url" > "$TMP/cabal.zip"
    
    361 377
               unzip "$TMP/cabal.zip"
    
    ... ... @@ -365,19 +381,21 @@ function fetch_cabal() {
    365 381
               local base_url="https://downloads.haskell.org/~cabal/cabal-install-$v/"
    
    366 382
               case "$(uname)" in
    
    367 383
                 Darwin) cabal_url="$base_url/cabal-install-$v-x86_64-apple-darwin17.7.0.tar.xz" ;;
    
    368
    -            FreeBSD) cabal_url="$base_url/cabal-install-$v-x86_64-freebsd14.tar.xz" ;;
    
    384
    +            FreeBSD) cabal_url="https://downloads.haskell.org/ghcup/unofficial-bindists/cabal/$v/cabal-install-$v-x86_64-portbld-freebsd.tar.xz" ;;
    
    369 385
                 *) fail "don't know where to fetch cabal-install for $(uname)"
    
    370 386
               esac
    
    371 387
               echo "Fetching cabal-install from $cabal_url"
    
    372 388
               curl "$cabal_url" > cabal.tar.xz
    
    373
    -          tmp="$(tar -tJf cabal.tar.xz | head -n1)"
    
    374
    -          $TAR -xJf cabal.tar.xz
    
    389
    +          local path="$(tar -tJf cabal.tar.xz | head -n1)"
    
    390
    +          local tmp_dir=$(mktemp -d XXXX-cabal)
    
    391
    +          $TAR -xJf cabal.tar.xz -C "${tmp_dir}"
    
    375 392
               # Check if the bindist has directory structure
    
    376
    -          if [[ "$tmp" = "cabal" ]]; then
    
    377
    -              mv cabal "$toolchain/bin"
    
    393
    +          if [[ "$path" = "cabal" ]]; then
    
    394
    +              mv "${tmp_dir}"/cabal "$toolchain/bin"
    
    378 395
               else
    
    379
    -              mv "$tmp/cabal" "$toolchain/bin"
    
    396
    +              mv "${tmp_dir}/$path/cabal" "$toolchain/bin"
    
    380 397
               fi
    
    398
    +          rmdir "${tmp_dir}"
    
    381 399
               ;;
    
    382 400
           esac
    
    383 401
           end_section fetch-cabal
    

  • .gitlab/generate-ci/gen_ci.hs
    ... ... @@ -451,7 +451,7 @@ opsysVariables _ FreeBSD14 = mconcat
    451 451
       , "CC" =: "cc"
    
    452 452
       , "CXX" =: "c++"
    
    453 453
       , "FETCH_GHC_VERSION" =: "9.10.1"
    
    454
    -  , "CABAL_INSTALL_VERSION" =: "3.10.3.0"
    
    454
    +  , "CABAL_INSTALL_VERSION" =: "3.14.2.0"
    
    455 455
       ]
    
    456 456
     opsysVariables arch (Linux distro) = distroVariables arch distro
    
    457 457
     opsysVariables AArch64 (Darwin {}) = mconcat
    
    ... ... @@ -480,9 +480,9 @@ opsysVariables Amd64 (Darwin {}) = mconcat
    480 480
     opsysVariables _ (Windows {}) = mconcat
    
    481 481
       [ "MSYSTEM" =: "CLANG64"
    
    482 482
       , "LANG" =: "en_US.UTF-8"
    
    483
    -  , "CABAL_INSTALL_VERSION" =: "3.10.2.0"
    
    483
    +  , "CABAL_INSTALL_VERSION" =: "3.14.2.0"
    
    484 484
       , "HADRIAN_ARGS" =: "--docs=no-sphinx-pdfs"
    
    485
    -  , "FETCH_GHC_VERSION" =: "9.10.1"
    
    485
    +  , "FETCH_GHC_VERSION" =: "9.10.3"
    
    486 486
       ]
    
    487 487
     opsysVariables _ _ = mempty
    
    488 488
     
    

  • .gitlab/jobs.yaml
    ... ... @@ -1463,7 +1463,7 @@
    1463 1463
           "BIGNUM_BACKEND": "gmp",
    
    1464 1464
           "BIN_DIST_NAME": "ghc-x86_64-freebsd14-validate",
    
    1465 1465
           "BUILD_FLAVOUR": "validate",
    
    1466
    -      "CABAL_INSTALL_VERSION": "3.10.3.0",
    
    1466
    +      "CABAL_INSTALL_VERSION": "3.14.2.0",
    
    1467 1467
           "CC": "cc",
    
    1468 1468
           "CONFIGURE_ARGS": "--with-iconv-includes=/usr/local/include --with-iconv-libraries=/usr/local/lib --with-system-libffi --with-ffi-includes=/usr/local/include --with-ffi-libraries=/usr/local/lib --with-gmp-includes=/usr/local/include --with-gmp-libraries=/usr/local/lib --enable-strict-ghc-toolchain-check",
    
    1469 1469
           "CXX": "c++",
    
    ... ... @@ -3691,9 +3691,9 @@
    3691 3691
           "BIGNUM_BACKEND": "native",
    
    3692 3692
           "BIN_DIST_NAME": "ghc-x86_64-windows-int_native-validate",
    
    3693 3693
           "BUILD_FLAVOUR": "validate",
    
    3694
    -      "CABAL_INSTALL_VERSION": "3.10.2.0",
    
    3694
    +      "CABAL_INSTALL_VERSION": "3.14.2.0",
    
    3695 3695
           "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    3696
    -      "FETCH_GHC_VERSION": "9.10.1",
    
    3696
    +      "FETCH_GHC_VERSION": "9.10.3",
    
    3697 3697
           "HADRIAN_ARGS": "--docs=no-sphinx-pdfs",
    
    3698 3698
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    3699 3699
           "LANG": "en_US.UTF-8",
    
    ... ... @@ -3754,9 +3754,9 @@
    3754 3754
           "BIGNUM_BACKEND": "gmp",
    
    3755 3755
           "BIN_DIST_NAME": "ghc-x86_64-windows-validate",
    
    3756 3756
           "BUILD_FLAVOUR": "validate",
    
    3757
    -      "CABAL_INSTALL_VERSION": "3.10.2.0",
    
    3757
    +      "CABAL_INSTALL_VERSION": "3.14.2.0",
    
    3758 3758
           "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    3759
    -      "FETCH_GHC_VERSION": "9.10.1",
    
    3759
    +      "FETCH_GHC_VERSION": "9.10.3",
    
    3760 3760
           "HADRIAN_ARGS": "--docs=no-sphinx-pdfs",
    
    3761 3761
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    3762 3762
           "LANG": "en_US.UTF-8",
    
    ... ... @@ -4346,7 +4346,7 @@
    4346 4346
           "BIGNUM_BACKEND": "gmp",
    
    4347 4347
           "BIN_DIST_NAME": "ghc-x86_64-freebsd14-release+no_split_sections",
    
    4348 4348
           "BUILD_FLAVOUR": "release+no_split_sections",
    
    4349
    -      "CABAL_INSTALL_VERSION": "3.10.3.0",
    
    4349
    +      "CABAL_INSTALL_VERSION": "3.14.2.0",
    
    4350 4350
           "CC": "cc",
    
    4351 4351
           "CONFIGURE_ARGS": "--with-iconv-includes=/usr/local/include --with-iconv-libraries=/usr/local/lib --with-system-libffi --with-ffi-includes=/usr/local/include --with-ffi-libraries=/usr/local/lib --with-gmp-includes=/usr/local/include --with-gmp-libraries=/usr/local/lib --enable-strict-ghc-toolchain-check",
    
    4352 4352
           "CXX": "c++",
    
    ... ... @@ -5437,9 +5437,9 @@
    5437 5437
           "BIGNUM_BACKEND": "native",
    
    5438 5438
           "BIN_DIST_NAME": "ghc-x86_64-windows-int_native-release",
    
    5439 5439
           "BUILD_FLAVOUR": "release",
    
    5440
    -      "CABAL_INSTALL_VERSION": "3.10.2.0",
    
    5440
    +      "CABAL_INSTALL_VERSION": "3.14.2.0",
    
    5441 5441
           "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    5442
    -      "FETCH_GHC_VERSION": "9.10.1",
    
    5442
    +      "FETCH_GHC_VERSION": "9.10.3",
    
    5443 5443
           "HADRIAN_ARGS": "--docs=no-sphinx-pdfs",
    
    5444 5444
           "IGNORE_PERF_FAILURES": "all",
    
    5445 5445
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    ... ... @@ -5501,9 +5501,9 @@
    5501 5501
           "BIGNUM_BACKEND": "gmp",
    
    5502 5502
           "BIN_DIST_NAME": "ghc-x86_64-windows-release",
    
    5503 5503
           "BUILD_FLAVOUR": "release",
    
    5504
    -      "CABAL_INSTALL_VERSION": "3.10.2.0",
    
    5504
    +      "CABAL_INSTALL_VERSION": "3.14.2.0",
    
    5505 5505
           "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    5506
    -      "FETCH_GHC_VERSION": "9.10.1",
    
    5506
    +      "FETCH_GHC_VERSION": "9.10.3",
    
    5507 5507
           "HADRIAN_ARGS": "--docs=no-sphinx-pdfs",
    
    5508 5508
           "IGNORE_PERF_FAILURES": "all",
    
    5509 5509
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    ... ... @@ -5638,7 +5638,7 @@
    5638 5638
           "BIGNUM_BACKEND": "gmp",
    
    5639 5639
           "BIN_DIST_NAME": "ghc-x86_64-freebsd14-validate",
    
    5640 5640
           "BUILD_FLAVOUR": "validate",
    
    5641
    -      "CABAL_INSTALL_VERSION": "3.10.3.0",
    
    5641
    +      "CABAL_INSTALL_VERSION": "3.14.2.0",
    
    5642 5642
           "CC": "cc",
    
    5643 5643
           "CONFIGURE_ARGS": "--with-iconv-includes=/usr/local/include --with-iconv-libraries=/usr/local/lib --with-system-libffi --with-ffi-includes=/usr/local/include --with-ffi-libraries=/usr/local/lib --with-gmp-includes=/usr/local/include --with-gmp-libraries=/usr/local/lib --enable-strict-ghc-toolchain-check",
    
    5644 5644
           "CXX": "c++",
    
    ... ... @@ -7835,9 +7835,9 @@
    7835 7835
           "BIGNUM_BACKEND": "native",
    
    7836 7836
           "BIN_DIST_NAME": "ghc-x86_64-windows-int_native-validate",
    
    7837 7837
           "BUILD_FLAVOUR": "validate",
    
    7838
    -      "CABAL_INSTALL_VERSION": "3.10.2.0",
    
    7838
    +      "CABAL_INSTALL_VERSION": "3.14.2.0",
    
    7839 7839
           "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    7840
    -      "FETCH_GHC_VERSION": "9.10.1",
    
    7840
    +      "FETCH_GHC_VERSION": "9.10.3",
    
    7841 7841
           "HADRIAN_ARGS": "--docs=no-sphinx-pdfs",
    
    7842 7842
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    7843 7843
           "LANG": "en_US.UTF-8",
    
    ... ... @@ -7897,9 +7897,9 @@
    7897 7897
           "BIGNUM_BACKEND": "gmp",
    
    7898 7898
           "BIN_DIST_NAME": "ghc-x86_64-windows-validate",
    
    7899 7899
           "BUILD_FLAVOUR": "validate",
    
    7900
    -      "CABAL_INSTALL_VERSION": "3.10.2.0",
    
    7900
    +      "CABAL_INSTALL_VERSION": "3.14.2.0",
    
    7901 7901
           "CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    7902
    -      "FETCH_GHC_VERSION": "9.10.1",
    
    7902
    +      "FETCH_GHC_VERSION": "9.10.3",
    
    7903 7903
           "HADRIAN_ARGS": "--docs=no-sphinx-pdfs",
    
    7904 7904
           "INSTALL_CONFIGURE_ARGS": "--enable-strict-ghc-toolchain-check",
    
    7905 7905
           "LANG": "en_US.UTF-8",
    

  • .gitmodules
    ... ... @@ -99,10 +99,6 @@
    99 99
     	path = utils/hsc2hs
    
    100 100
     	url = https://gitlab.haskell.org/ghc/hsc2hs.git
    
    101 101
     	ignore = untracked
    
    102
    -[submodule "libffi-tarballs"]
    
    103
    -	path = libffi-tarballs
    
    104
    -	url = https://gitlab.haskell.org/ghc/libffi-tarballs.git
    
    105
    -	ignore = untracked
    
    106 102
     [submodule "gmp-tarballs"]
    
    107 103
     	path = libraries/ghc-internal/gmp/gmp-tarballs
    
    108 104
     	url = https://gitlab.haskell.org/ghc/gmp-tarballs.git
    
    ... ... @@ -124,3 +120,6 @@
    124 120
     [submodule "libraries/template-haskell-quasiquoter"]
    
    125 121
     	path = libraries/template-haskell-quasiquoter
    
    126 122
     	url = https://gitlab.haskell.org/ghc/template-haskell-quasiquoter.git
    
    123
    +[submodule "libraries/libffi-clib"]
    
    124
    +	path = libraries/libffi-clib
    
    125
    +	url = https://github.com/stable-haskell/libffi-clib.git

  • compiler/GHC/Linker/Loader.hs
    1 1
     {-# LANGUAGE CPP #-}
    
    2 2
     {-# LANGUAGE RecordWildCards #-}
    
    3
    +{-# LANGUAGE LambdaCase #-}
    
    3 4
     {-# LANGUAGE ViewPatterns #-}
    
    4 5
     
    
    5 6
     --
    
    ... ... @@ -67,6 +68,8 @@ import GHC.ByteCode.Linker
    67 68
     import GHC.ByteCode.Asm
    
    68 69
     import GHC.ByteCode.Types
    
    69 70
     
    
    71
    +import GHC.Linker.Unit (getUnitDepends)
    
    72
    +
    
    70 73
     import GHC.Stack.CCS
    
    71 74
     import GHC.SysTools
    
    72 75
     
    
    ... ... @@ -179,10 +182,10 @@ getLoaderState :: Interp -> IO (Maybe LoaderState)
    179 182
     getLoaderState interp = readMVar (loader_state (interpLoader interp))
    
    180 183
     
    
    181 184
     
    
    182
    -emptyLoaderState :: LoaderState
    
    183
    -emptyLoaderState = LoaderState
    
    185
    +emptyLoaderState :: UnitEnv -> LoaderState
    
    186
    +emptyLoaderState unit_env = LoaderState
    
    184 187
        { bco_loader_state = emptyBytecodeLoaderState
    
    185
    -   , pkgs_loaded = init_pkgs
    
    188
    +   , pkgs_loaded = init_pkgs deps
    
    186 189
        , bcos_loaded = emptyModuleEnv
    
    187 190
        , objs_loaded = emptyModuleEnv
    
    188 191
        , temp_sos = []
    
    ... ... @@ -192,7 +195,13 @@ emptyLoaderState = LoaderState
    192 195
       --
    
    193 196
       -- The linker's symbol table is populated with RTS symbols using an
    
    194 197
       -- explicit list.  See rts/Linker.c for details.
    
    195
    -  where init_pkgs = unitUDFM rtsUnitId (LoadedPkgInfo rtsUnitId [] [] [] emptyUniqDSet)
    
    198
    +  where
    
    199
    +    deps = getUnitDepends unit_env rtsUnitId
    
    200
    +    pkg_to_dfm unit_id = (unit_id, (LoadedPkgInfo unit_id [] [] [] emptyUniqDSet))
    
    201
    +    init_pkgs deps = let addToUDFM' (k, v) m = addToUDFM m k v
    
    202
    +                     in foldr addToUDFM' emptyUDFM $ [
    
    203
    +                       pkg_to_dfm rtsUnitId
    
    204
    +                     ] ++ fmap pkg_to_dfm deps
    
    196 205
     
    
    197 206
     extendLoadedEnv :: Interp -> BytecodeLoaderStateModifier -> [(Name,ForeignHValue)] -> IO ()
    
    198 207
     extendLoadedEnv interp modify_bytecode_loader_state new_bindings =
    
    ... ... @@ -341,7 +350,7 @@ initLoaderState interp hsc_env = do
    341 350
     reallyInitLoaderState :: Interp -> HscEnv -> IO LoaderState
    
    342 351
     reallyInitLoaderState interp hsc_env = do
    
    343 352
       -- Initialise the linker state
    
    344
    -  let pls0 = emptyLoaderState
    
    353
    +  let pls0 = emptyLoaderState (hsc_unit_env hsc_env)
    
    345 354
     
    
    346 355
       case platformArch (targetPlatform (hsc_dflags hsc_env)) of
    
    347 356
         -- FIXME: we don't initialize anything with the JS interpreter.
    
    ... ... @@ -1226,12 +1235,6 @@ loadPackage interp hsc_env pkgs pls
    1226 1235
                 bc_dirs = [map ST.unpack $ Packages.unitLibraryBytecodeDirs pkg | pkg <- pkgs]
    
    1227 1236
     
    
    1228 1237
             let hs_libs   = [map ST.unpack $ Packages.unitLibraries pkg | pkg <- pkgs]
    
    1229
    -            -- The FFI GHCi import lib isn't needed as
    
    1230
    -            -- GHC.Linker.Loader + rts/Linker.c link the
    
    1231
    -            -- interpreted references to FFI to the compiled FFI.
    
    1232
    -            -- We therefore filter it out so that we don't get
    
    1233
    -            -- duplicate symbol errors.
    
    1234
    -            hs_libs'  =  filter ("HSffi" /=) <$> hs_libs
    
    1235 1238
     
    
    1236 1239
             -- Because of slight differences between the GHC dynamic linker and
    
    1237 1240
             -- the native system linker some packages have to link with a
    
    ... ... @@ -1251,7 +1254,7 @@ loadPackage interp hsc_env pkgs pls
    1251 1254
             dirs_env <- traverse (addEnvPaths "LIBRARY_PATH") dirs
    
    1252 1255
     
    
    1253 1256
             hs_classifieds
    
    1254
    -           <- sequenceA [mapM (locateLib interp hsc_env True bc_dir_  dirs_env_ gcc_paths) hs_libs'_ | (bc_dir_, dirs_env_, hs_libs'_) <- zip3 bc_dirs dirs_env hs_libs' ]
    
    1257
    +           <- sequenceA [mapM (locateLib interp hsc_env True bc_dir_  dirs_env_ gcc_paths) hs_libs'_ | (bc_dir_, dirs_env_, hs_libs'_) <- zip3 bc_dirs dirs_env hs_libs ]
    
    1255 1258
             extra_classifieds
    
    1256 1259
                <- sequenceA [mapM (locateLib interp hsc_env False [] dirs_env_ gcc_paths) extra_libs_ | (dirs_env_, extra_libs_) <- zip dirs_env extra_libs]
    
    1257 1260
             let classifieds = zipWith (++) hs_classifieds extra_classifieds
    

  • compiler/GHC/Linker/Unit.hs
    ... ... @@ -6,6 +6,7 @@ module GHC.Linker.Unit
    6 6
        , collectArchives
    
    7 7
        , getUnitLinkOpts
    
    8 8
        , getLibs
    
    9
    +   , getUnitDepends
    
    9 10
        )
    
    10 11
     where
    
    11 12
     
    
    ... ... @@ -105,3 +106,9 @@ getLibs namever ways unit_env pkgs = do
    105 106
                                         , f <- (\n -> "lib" ++ n ++ ".a") <$> unitHsLibs namever ways p ]
    
    106 107
         filterM (doesFileExist . fst) candidates
    
    107 108
     
    
    109
    +getUnitDepends :: HasDebugCallStack => UnitEnv -> UnitId -> [UnitId]
    
    110
    +getUnitDepends unit_env pkg =
    
    111
    +    let unit_state = ue_homeUnitState unit_env
    
    112
    +        unit_info = unsafeLookupUnitId unit_state pkg
    
    113
    +    in (unitDepends unit_info)
    
    114
    +

  • compiler/GHC/Unit/State.hs
    ... ... @@ -372,7 +372,7 @@ initUnitConfig dflags cached_dbs home_units =
    372 372
              -- Since "base" is not wired in, then the unit-id is discovered
    
    373 373
              -- from the settings file by default, but can be overriden by power-users
    
    374 374
              -- by specifying `-base-unit-id` flag.
    
    375
    -         | otherwise = filter (hu_id /=) [baseUnitId dflags, ghcInternalUnitId, rtsUnitId]
    
    375
    +         | otherwise = filter (hu_id /=) (baseUnitId dflags:wiredInUnitIds)
    
    376 376
     
    
    377 377
            -- if the home unit is indefinite, it means we are type-checking it only
    
    378 378
            -- (not producing any code). Hence we can use virtual units instantiated
    

  • hadrian/hadrian.cabal
    ... ... @@ -86,7 +86,6 @@ executable hadrian
    86 86
                            , Rules.Documentation
    
    87 87
                            , Rules.Generate
    
    88 88
                            , Rules.Gmp
    
    89
    -                       , Rules.Libffi
    
    90 89
                            , Rules.Library
    
    91 90
                            , Rules.Lint
    
    92 91
                            , Rules.Nofib
    

  • hadrian/src/Builder.hs
    ... ... @@ -229,25 +229,16 @@ instance H.Builder Builder where
    229 229
               -- changes (#18001).
    
    230 230
               _bootGhcVersion <- setting GhcVersion
    
    231 231
               pure []
    
    232
    -        Ghc _ st -> do
    
    232
    +        Ghc _ _ -> do
    
    233 233
                 root <- buildRoot
    
    234 234
                 unlitPath  <- builderPath Unlit
    
    235 235
                 distro_mingw <- lookupSystemConfig "settings-use-distro-mingw"
    
    236
    -            libffi_adjustors <- useLibffiForAdjustors
    
    237
    -            use_system_ffi <- flag UseSystemFfi
    
    238 236
     
    
    239 237
                 return $ [ unlitPath ]
    
    240 238
                       ++ [ root -/- mingwStamp | windowsHost, distro_mingw == "NO" ]
    
    241 239
                          -- proxy for the entire mingw toolchain that
    
    242 240
                          -- we have in inplace/mingw initially, and then at
    
    243 241
                          -- root -/- mingw.
    
    244
    -                  -- ffi.h needed by the compiler when using libffi_adjustors (#24864)
    
    245
    -                  -- It would be nicer to not duplicate this logic between here
    
    246
    -                  -- and needRtsLibffiTargets and libffiHeaderFiles but this doesn't change
    
    247
    -                  -- very often.
    
    248
    -                  ++ [ root -/- buildDir (rtsContext st) -/- "include" -/- header
    
    249
    -                     | header <- ["ffi.h", "ffitarget.h"]
    
    250
    -                     , libffi_adjustors && not use_system_ffi ]
    
    251 242
     
    
    252 243
             Hsc2Hs stage -> (\p -> [p]) <$> templateHscPath stage
    
    253 244
             Make dir  -> return [dir -/- "Makefile"]
    

  • hadrian/src/Packages.hs
    ... ... @@ -110,7 +110,7 @@ hpc = lib "hpc"
    110 110
     hpcBin              = util "hpc-bin"         `setPath` "utils/hpc"
    
    111 111
     integerGmp          = lib  "integer-gmp"
    
    112 112
     iservProxy          = util "iserv-proxy"
    
    113
    -libffi              = top  "libffi"
    
    113
    +libffi              = lib  "libffi-clib"
    
    114 114
     mtl                 = lib  "mtl"
    
    115 115
     osString            = lib  "os-string"
    
    116 116
     parsec              = lib  "parsec"
    

  • hadrian/src/Rules.hs
    ... ... @@ -21,7 +21,6 @@ import qualified Rules.Dependencies
    21 21
     import qualified Rules.Documentation
    
    22 22
     import qualified Rules.Generate
    
    23 23
     import qualified Rules.Gmp
    
    24
    -import qualified Rules.Libffi
    
    25 24
     import qualified Rules.Library
    
    26 25
     import qualified Rules.Program
    
    27 26
     import qualified Rules.Register
    
    ... ... @@ -80,7 +79,7 @@ packageTargets stage pkg = do
    80 79
         then return [] -- Skip inactive packages.
    
    81 80
         else if isLibrary pkg
    
    82 81
             then do -- Collect all targets of a library package.
    
    83
    -            let pkgWays = if pkg == rts then getRtsWays else getLibraryWays
    
    82
    +            let pkgWays = if pkg `elem` [rts, libffi] then getRtsWays else getLibraryWays
    
    84 83
                 ways  <- interpretInContext context pkgWays
    
    85 84
                 libs  <- mapM (\w -> pkgLibraryFile (Context stage pkg w (error "unused"))) (Set.toList ways)
    
    86 85
                 more  <- Rules.Library.libraryTargets context
    
    ... ... @@ -126,7 +125,6 @@ buildRules = do
    126 125
         Rules.Generate.generateRules
    
    127 126
         Rules.Generate.templateRules
    
    128 127
         Rules.Gmp.gmpRules
    
    129
    -    Rules.Libffi.libffiRules
    
    130 128
         Rules.Library.libraryRules
    
    131 129
         Rules.Rts.rtsRules
    
    132 130
         packageRules
    

  • hadrian/src/Rules/Documentation.hs
    ... ... @@ -232,6 +232,9 @@ buildSphinxHtml path = do
    232 232
     
    
    233 233
     ------------------------------------ Haddock -----------------------------------
    
    234 234
     
    
    235
    +haddockExclude :: [FilePath]
    
    236
    +haddockExclude = ["rts", "libffi-clib"]
    
    237
    +
    
    235 238
     -- | Build the haddocks for GHC's libraries.
    
    236 239
     buildLibraryDocumentation :: Rules ()
    
    237 240
     buildLibraryDocumentation = do
    
    ... ... @@ -241,11 +244,11 @@ buildLibraryDocumentation = do
    241 244
         root -/- htmlRoot -/- "libraries/index.html" %> \file -> do
    
    242 245
             need [ "libraries/prologue.txt" ]
    
    243 246
     
    
    244
    -        -- We want Haddocks for everything except `rts` to be built, but we
    
    247
    +        -- We want Haddocks for everything except `rts` and `libffi-clib` to be built, but we
    
    245 248
             -- don't want the index to be polluted by stuff from `ghc`-the-library
    
    246 249
             -- (there will be a separate top-level link to those Haddocks).
    
    247 250
             haddocks <- allHaddocks
    
    248
    -        let neededDocs = filter (\x -> takeFileName x /= "rts.haddock") haddocks
    
    251
    +        let neededDocs = filter (\x -> takeFileName x `notElem` ((<.> "haddock") <$> haddockExclude)) haddocks
    
    249 252
                 libDocs = filter (\x -> takeFileName x /= "ghc.haddock") neededDocs
    
    250 253
     
    
    251 254
             need neededDocs
    
    ... ... @@ -255,7 +258,7 @@ allHaddocks :: Action [FilePath]
    255 258
     allHaddocks = do
    
    256 259
         pkgs <- stagePackages Stage1
    
    257 260
         sequence [ pkgHaddockFile $ vanillaContext Stage1 pkg
    
    258
    -             | pkg <- pkgs, isLibrary pkg, pkgName pkg /= "rts" ]
    
    261
    +             | pkg <- pkgs, isLibrary pkg, pkgName pkg `notElem` haddockExclude ]
    
    259 262
     
    
    260 263
     -- Note: this build rule creates plenty of files, not just the .haddock one.
    
    261 264
     -- All of them go into the 'docRoot' subdirectory. Pedantically tracking all
    
    ... ... @@ -427,4 +430,4 @@ haddockDependencies :: Context -> Action [(Package, FilePath)]
    427 430
     haddockDependencies context = do
    
    428 431
         depNames <- interpretInContext context (getContextData depNames)
    
    429 432
         sequence [ (,) <$> pure depPkg <*> (pkgHaddockFile $ vanillaContext Stage1 depPkg)
    
    430
    -             | Just depPkg <- map findPackageByName depNames, depPkg /= rts ]
    433
    +             | Just depPkg <- map findPackageByName depNames, (pkgName depPkg) `notElem` haddockExclude ]

  • hadrian/src/Rules/Generate.hs
    ... ... @@ -18,7 +18,6 @@ import Hadrian.Haskell.Cabal.Type (PackageData(version))
    18 18
     import Hadrian.Haskell.Cabal
    
    19 19
     import Hadrian.Oracles.Cabal (readPackageData)
    
    20 20
     import Packages
    
    21
    -import Rules.Libffi
    
    22 21
     import Settings
    
    23 22
     import Target
    
    24 23
     import Utilities
    
    ... ... @@ -57,7 +56,6 @@ rtsDependencies = do
    57 56
         stage   <- getStage
    
    58 57
         rtsPath <- expr (rtsBuildPath stage)
    
    59 58
         jsTarget <- expr isJsTarget
    
    60
    -    useSystemFfi <- expr (flag UseSystemFfi)
    
    61 59
     
    
    62 60
         let -- headers common to native and JS RTS
    
    63 61
             common_headers =
    
    ... ... @@ -69,7 +67,6 @@ rtsDependencies = do
    69 67
                 [ "rts" -/- "EventTypes.h"
    
    70 68
                 , "rts" -/- "EventLogConstants.h"
    
    71 69
                 ]
    
    72
    -            ++ (if useSystemFfi then [] else libffiHeaderFiles)
    
    73 70
             headers
    
    74 71
               | jsTarget  = common_headers
    
    75 72
               | otherwise = common_headers ++ native_headers
    

  • hadrian/src/Rules/Libffi.hs deleted
    1
    -{-# LANGUAGE TypeFamilies #-}
    
    2
    -
    
    3
    -module Rules.Libffi (
    
    4
    -    LibffiDynLibs(..),
    
    5
    -    needLibffi, askLibffilDynLibs, libffiRules, libffiLibrary, libffiHeaderFiles,
    
    6
    -    libffiHeaderDir, libffiSystemHeaderDir, libffiName
    
    7
    -    ) where
    
    8
    -
    
    9
    -import Hadrian.Utilities
    
    10
    -
    
    11
    -import Packages
    
    12
    -import Settings.Builders.Common
    
    13
    -import Target
    
    14
    -import Utilities
    
    15
    -import GHC.Toolchain (targetPlatformTriple)
    
    16
    -
    
    17
    -{- Note [Libffi indicating inputs]
    
    18
    -   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    19
    -First see https://gitlab.haskell.org/ghc/ghc/wikis/Developing-Hadrian for an
    
    20
    -explanation of "indicating input". Part of the definition is copied here for
    
    21
    -your convenience:
    
    22
    -
    
    23
    -    change in the vital output -> change in the indicating inputs
    
    24
    -
    
    25
    -In the case of building libffi `vital output = built libffi library files` and
    
    26
    -we can consider the libffi archive file (i.e. the "libffi-tarballs/libffi*.tar.gz"
    
    27
    -file) to be the only indicating input besides the build tools (e.g. make).
    
    28
    -Note building libffi is split into a few rules, but we also expect that:
    
    29
    -
    
    30
    -    no change in the archive file -> no change in the intermediate build artifacts
    
    31
    -
    
    32
    -and so the archive file is still a valid choice of indicating input for
    
    33
    -all libffi rules. Hence we can get away with `need`ing only the archive file and
    
    34
    -don't have to `need` intermediate build artifacts (besides those to trigger
    
    35
    -dependant libffi rules i.e. to generate vital inputs as is noted on the wiki).
    
    36
    -It is then safe to `trackAllow` the libffi build directory as is done in
    
    37
    -`needLibfffiArchive`.
    
    38
    -
    
    39
    -A disadvantage to this approach is that changing the archive file forces a clean
    
    40
    -build of libffi i.e. we cannot incrementally build libffi. This seems like a
    
    41
    -performance issue, but is justified as building libffi is fast and the archive
    
    42
    -file is rarely changed.
    
    43
    -
    
    44
    --}
    
    45
    -
    
    46
    --- | Oracle question type. The oracle returns the list of dynamic
    
    47
    --- libffi library file paths (all but one of which should be symlinks).
    
    48
    -newtype LibffiDynLibs = LibffiDynLibs Stage
    
    49
    -        deriving (Eq, Show, Hashable, Binary, NFData)
    
    50
    -type instance RuleResult LibffiDynLibs = [FilePath]
    
    51
    -
    
    52
    -askLibffilDynLibs :: Stage -> Action [FilePath]
    
    53
    -askLibffilDynLibs stage = askOracle (LibffiDynLibs stage)
    
    54
    -
    
    55
    --- | The path to the dynamic library manifest file. The file contains all file
    
    56
    --- paths to libffi dynamic library file paths.
    
    57
    --- The path is calculated but not `need`ed.
    
    58
    -dynLibManifest' :: Monad m => m FilePath -> Stage -> m FilePath
    
    59
    -dynLibManifest' getRoot stage = do
    
    60
    -    root <- getRoot
    
    61
    -    return $ root -/- stageString stage -/- pkgName libffi -/- ".dynamiclibs"
    
    62
    -
    
    63
    -dynLibManifestRules :: Stage -> Rules FilePath
    
    64
    -dynLibManifestRules = dynLibManifest' buildRootRules
    
    65
    -
    
    66
    -dynLibManifest :: Stage -> Action FilePath
    
    67
    -dynLibManifest = dynLibManifest' buildRoot
    
    68
    -
    
    69
    --- | Need the (locally built) libffi library.
    
    70
    -needLibffi :: Stage -> Action ()
    
    71
    -needLibffi stage = do
    
    72
    -    jsTarget <- isJsTarget
    
    73
    -    unless jsTarget $ do
    
    74
    -        manifest <- dynLibManifest stage
    
    75
    -        need [manifest]
    
    76
    -
    
    77
    --- | Context for @libffi@.
    
    78
    -libffiContext :: Stage -> Action Context
    
    79
    -libffiContext stage = do
    
    80
    -    ways <- interpretInContext
    
    81
    -            (Context stage libffi (error "libffiContext: way not set") (error "libffiContext: iplace not set"))
    
    82
    -            getLibraryWays
    
    83
    -    return $ (\w -> Context stage libffi w Final) (if any (wayUnit Dynamic) ways
    
    84
    -        then dynamic
    
    85
    -        else vanilla)
    
    86
    -
    
    87
    --- | The name of the library
    
    88
    -libffiName :: Expr String
    
    89
    -libffiName = do
    
    90
    -    useSystemFfi <- expr (flag UseSystemFfi)
    
    91
    -    if useSystemFfi
    
    92
    -      then pure "ffi"
    
    93
    -      else libffiLocalName Nothing
    
    94
    -
    
    95
    --- | The name of the (locally built) library
    
    96
    -libffiLocalName :: Maybe Bool -> Expr String
    
    97
    -libffiLocalName force_dynamic = do
    
    98
    -  way <- getWay
    
    99
    -  winTarget <- expr isWinTarget
    
    100
    -  let dynamic = fromMaybe (Dynamic `wayUnit` way) force_dynamic
    
    101
    -  pure $ mconcat
    
    102
    -      [ if dynamic   then ""      else "C"
    
    103
    -      , if winTarget then "ffi-6" else "ffi"
    
    104
    -      ]
    
    105
    -
    
    106
    -libffiLibrary :: FilePath
    
    107
    -libffiLibrary = "inst/lib/libffi.a"
    
    108
    -
    
    109
    --- | These are the headers that we must package with GHC since foreign export
    
    110
    --- adjustor code produced by GHC depends upon them.
    
    111
    --- See Note [Packaging libffi headers] in GHC.Driver.CodeOutput.
    
    112
    -libffiHeaderFiles :: [FilePath]
    
    113
    -libffiHeaderFiles = ["ffi.h", "ffitarget.h"]
    
    114
    -
    
    115
    -libffiHeaderDir :: Stage -> Action FilePath
    
    116
    -libffiHeaderDir stage = do
    
    117
    -    path <- libffiBuildPath stage
    
    118
    -    return $ path -/- "inst/include"
    
    119
    -
    
    120
    -libffiSystemHeaderDir :: Action FilePath
    
    121
    -libffiSystemHeaderDir = setting FfiIncludeDir
    
    122
    -
    
    123
    -fixLibffiMakefile :: FilePath -> String -> String
    
    124
    -fixLibffiMakefile top =
    
    125
    -      replace "-MD" "-MMD"
    
    126
    -    . replace "@toolexeclibdir@" "$(libdir)"
    
    127
    -    . replace "@INSTALL@" ("$(subst ../install-sh," ++ top ++ "/install-sh,@INSTALL@)")
    
    128
    -
    
    129
    --- TODO: check code duplication w.r.t. ConfCcArgs
    
    130
    -configureEnvironment :: Stage -> Action [CmdOption]
    
    131
    -configureEnvironment stage = do
    
    132
    -    context <- libffiContext stage
    
    133
    -    cFlags  <- interpretInContext context getStagedCCFlags
    
    134
    -    sequence [ builderEnvironment "CC" $ Cc CompileC stage
    
    135
    -             , builderEnvironment "CXX" $ Cc CompileC stage
    
    136
    -             , builderEnvironment "AR" $ Ar Unpack stage
    
    137
    -             , builderEnvironment "NM" Nm
    
    138
    -             , builderEnvironment "RANLIB" Ranlib
    
    139
    -             , return . AddEnv  "CFLAGS" $ unwords  cFlags ++ " -w"
    
    140
    -             , return . AddEnv "LDFLAGS" $ "-w" ]
    
    141
    -
    
    142
    --- Need the libffi archive and `trackAllow` all files in the build directory.
    
    143
    --- See [Libffi indicating inputs].
    
    144
    -needLibfffiArchive :: FilePath -> Action FilePath
    
    145
    -needLibfffiArchive buildPath = do
    
    146
    -    top <- topDirectory
    
    147
    -    tarball <- unifyPath
    
    148
    -                . fromSingleton "Exactly one LibFFI tarball is expected"
    
    149
    -                <$> getDirectoryFiles top ["libffi-tarballs/libffi*.tar.gz"]
    
    150
    -    need [top -/- tarball]
    
    151
    -    trackAllow [buildPath -/- "**"]
    
    152
    -    return tarball
    
    153
    -
    
    154
    -libffiRules :: Rules ()
    
    155
    -libffiRules = do
    
    156
    -  _ <- addOracleCache $ \ (LibffiDynLibs stage)
    
    157
    -                         -> do
    
    158
    -                              jsTarget <- isJsTarget
    
    159
    -                              if jsTarget
    
    160
    -                                then return []
    
    161
    -                                else readFileLines =<< dynLibManifest stage
    
    162
    -  forM_ [Stage1, Stage2, Stage3] $ \stage -> do
    
    163
    -    root <- buildRootRules
    
    164
    -    let path       = root -/- stageString stage
    
    165
    -        libffiPath = path -/- pkgName libffi -/- "build"
    
    166
    -
    
    167
    -    -- We set a higher priority because this rule overlaps with the build rule
    
    168
    -    -- for static libraries 'Rules.Library.libraryRules'.
    
    169
    -    dynLibMan <- dynLibManifestRules stage
    
    170
    -    let topLevelTargets =  [ libffiPath -/- libffiLibrary
    
    171
    -                           , dynLibMan
    
    172
    -                           ]
    
    173
    -    priority 2 $ topLevelTargets &%> \_ -> do
    
    174
    -        _ <- needLibfffiArchive libffiPath
    
    175
    -        context <- libffiContext stage
    
    176
    -
    
    177
    -        -- Note this build needs the Makefile, triggering the rules bellow.
    
    178
    -        build $ target context (Make libffiPath) [] []
    
    179
    -        libffiName' <- interpretInContext context (libffiLocalName (Just True))
    
    180
    -
    
    181
    -        -- Produces all install files.
    
    182
    -        produces =<< (\\ topLevelTargets)
    
    183
    -                 <$> liftIO (getDirectoryFilesIO "." [libffiPath -/- "inst//*"])
    
    184
    -
    
    185
    -        -- Find dynamic libraries.
    
    186
    -        osxTarget <- isOsxTarget
    
    187
    -        winTarget <- isWinTarget
    
    188
    -
    
    189
    -        dynLibFiles <- do
    
    190
    -            let libfilesDir = libffiPath -/-
    
    191
    -                    (if winTarget then "inst" -/- "bin" else "inst" -/- "lib")
    
    192
    -                dynlibext
    
    193
    -                    | winTarget = "dll"
    
    194
    -                    | osxTarget = "dylib"
    
    195
    -                    | otherwise = "so"
    
    196
    -                filepat = "lib" ++ libffiName' ++ "." ++ dynlibext ++ "*"
    
    197
    -            liftIO $ getDirectoryFilesIO "." [libfilesDir -/- filepat]
    
    198
    -
    
    199
    -        writeFileLines dynLibMan dynLibFiles
    
    200
    -        putSuccess "| Successfully build libffi."
    
    201
    -
    
    202
    -    fmap (libffiPath -/-) ( "Makefile.in" :& "configure" :& Nil ) &%>
    
    203
    -      \ ( mkIn :& _ ) -> do
    
    204
    -        -- Extract libffi tar file
    
    205
    -        context <- libffiContext stage
    
    206
    -        removeDirectory libffiPath
    
    207
    -        tarball <- needLibfffiArchive libffiPath
    
    208
    -        -- Go from 'libffi-3.99999+git20171002+77e130c.tar.gz' to 'libffi-3.99999'
    
    209
    -        let libname = takeWhile (/= '+') $ fromJust $ stripExtension "tar.gz" $ takeFileName tarball
    
    210
    -
    
    211
    -        -- Move extracted directory to libffiPath.
    
    212
    -        root <- buildRoot
    
    213
    -        removeDirectory (root -/- libname)
    
    214
    -        actionFinally (do
    
    215
    -            build $ target context (Tar Extract) [tarball] [path]
    
    216
    -            moveDirectory (path -/- libname) libffiPath) $
    
    217
    -            -- And finally:
    
    218
    -            removeFiles (path) [libname -/- "**"]
    
    219
    -
    
    220
    -        top <- topDirectory
    
    221
    -        fixFile mkIn (fixLibffiMakefile top)
    
    222
    -
    
    223
    -        files <- liftIO $ getDirectoryFilesIO "." [libffiPath -/- "**"]
    
    224
    -        produces files
    
    225
    -
    
    226
    -    fmap (libffiPath -/-) ("Makefile" :& "config.guess" :& "config.sub" :& Nil)
    
    227
    -      &%> \( mk :& _ ) -> do
    
    228
    -        _ <- needLibfffiArchive libffiPath
    
    229
    -        context <- libffiContext stage
    
    230
    -
    
    231
    -        -- This need rule extracts the libffi tar file to libffiPath.
    
    232
    -        need [mk <.> "in"]
    
    233
    -
    
    234
    -        -- Configure.
    
    235
    -        forM_ ["config.guess", "config.sub"] $ \file -> do
    
    236
    -            copyFile file (libffiPath -/- file)
    
    237
    -        env <- configureEnvironment stage
    
    238
    -        buildWithCmdOptions env $
    
    239
    -            target context (Configure libffiPath) [mk <.> "in"] [mk]
    
    240
    -
    
    241
    -        dir   <- queryBuildTarget targetPlatformTriple
    
    242
    -        files <- liftIO $ getDirectoryFilesIO "." [libffiPath -/- dir -/- "**"]
    
    243
    -        produces files

  • hadrian/src/Rules/Register.hs
    ... ... @@ -147,7 +147,7 @@ buildConfFinal :: [(Resource, Int)] -> Context -> FilePath -> Action ()
    147 147
     buildConfFinal rs context@Context {..} _conf = do
    
    148 148
         depPkgIds <- cabalDependencies context
    
    149 149
         ensureConfigured context
    
    150
    -    ways <- interpretInContext context (getLibraryWays <> if package == rts then getRtsWays else mempty)
    
    150
    +    ways <- interpretInContext context (getLibraryWays <> if package `elem` [rts, libffi] then getRtsWays else mempty)
    
    151 151
         stamps <- mapM pkgStampFile [ context { way = w } | w <- Set.toList ways ]
    
    152 152
         confs <- mapM (\pkgId -> packageDbPath (PackageDbLoc stage Final) <&> (-/- pkgId <.> "conf")) depPkgIds
    
    153 153
         -- Important to need these together to avoid introducing a linearisation. This is not the most critical place
    
    ... ... @@ -295,20 +295,10 @@ parseCabalName s = bimap show id (Cabal.runParsecParser parser "<parseCabalName>
    295 295
           where
    
    296 296
             component = CabalCharParsing.munch1 (\c ->  Char.isAlphaNum c || c == '.')
    
    297 297
     
    
    298
    -
    
    299
    -
    
    300
    --- | Return extra library targets.
    
    301
    -extraTargets :: Context -> Action [FilePath]
    
    302
    -extraTargets context
    
    303
    -    | package context == rts  = needRtsLibffiTargets (Context.stage context)
    
    304
    -    | otherwise               = return []
    
    305
    -
    
    306 298
     -- | Given a library 'Package' this action computes all of its targets. Needing
    
    307 299
     -- all the targets should build the library such that it is ready to be
    
    308 300
     -- registered into the package database.
    
    309 301
     libraryTargets :: Context -> Action [FilePath]
    
    310 302
     libraryTargets context = do
    
    311 303
         libFile  <- pkgLibraryFile     context
    
    312
    -    extra    <- extraTargets context
    
    313
    -    return $ [ libFile ]
    
    314
    -          ++ extra
    304
    +    return [ libFile ]

  • hadrian/src/Rules/Rts.hs
    1 1
     {-# LANGUAGE MultiWayIf #-}
    
    2 2
     
    
    3
    -module Rules.Rts (rtsRules, needRtsLibffiTargets, needRtsSymLinks) where
    
    3
    +module Rules.Rts (rtsRules, needRtsSymLinks) where
    
    4 4
     
    
    5 5
     import qualified Data.Set as Set
    
    6 6
     
    
    7 7
     import Packages (rts)
    
    8
    -import Rules.Libffi
    
    9 8
     import Hadrian.Utilities
    
    10 9
     import Settings.Builders.Common
    
    11
    -import Context.Type
    
    12 10
     
    
    13 11
     -- | This rule has priority 3 to override the general rule for generating shared
    
    14 12
     -- library files (see Rules.Library.libraryRules).
    
    ... ... @@ -26,134 +24,6 @@ rtsRules = priority 3 $ do
    26 24
                 (addRtsDummyVersion $ takeFileName rtsLibFilePath')
    
    27 25
                 rtsLibFilePath'
    
    28 26
     
    
    29
    -    -- Libffi
    
    30
    -    forM_ [Stage1, Stage2, Stage3 ] $ \ stage -> do
    
    31
    -        let buildPath = root -/- buildDir (rtsContext stage)
    
    32
    -
    
    33
    -        -- Header files
    
    34
    -        -- See Note [Packaging libffi headers] in GHC.Driver.CodeOutput.
    
    35
    -        forM_ libffiHeaderFiles $ \header ->
    
    36
    -            buildPath -/- "include" -/- header %> copyLibffiHeader stage
    
    37
    -
    
    38
    -        -- Static libraries.
    
    39
    -        buildPath -/- "libCffi*.a"     %> copyLibffiStatic stage
    
    40
    -
    
    41
    -        -- Dynamic libraries
    
    42
    -        buildPath -/- "libffi*.dylib*" %> copyLibffiDynamicUnix stage ".dylib"
    
    43
    -        buildPath -/- "libffi*.so*"    %> copyLibffiDynamicUnix stage ".so"
    
    44
    -        buildPath -/- "libffi*.dll*"   %> copyLibffiDynamicWin  stage
    
    45
    -
    
    46
    -withLibffi :: Stage -> (FilePath -> FilePath -> Action a) -> Action a
    
    47
    -withLibffi stage action = needLibffi stage
    
    48
    -                        >> (join $ action <$> libffiBuildPath stage
    
    49
    -                                          <*> rtsBuildPath    stage)
    
    50
    -
    
    51
    --- | Copy a header files wither from the system libffi or from the libffi
    
    52
    --- build dir to the rts build dir.
    
    53
    ---
    
    54
    --- See Note [Packaging libffi headers] in GHC.Driver.CodeOutput.
    
    55
    -copyLibffiHeader :: Stage -> FilePath -> Action ()
    
    56
    -copyLibffiHeader stage header = do
    
    57
    -    useSystemFfi <- flag UseSystemFfi
    
    58
    -    (fromStr, headerDir) <- if useSystemFfi
    
    59
    -        then ("system",) <$> libffiSystemHeaderDir
    
    60
    -        else needLibffi stage
    
    61
    -          >> ("custom",) <$> libffiHeaderDir stage
    
    62
    -    copyFile
    
    63
    -        (headerDir -/- takeFileName header)
    
    64
    -        header
    
    65
    -    putSuccess $ "| Successfully copied " ++ fromStr ++ " FFI library header "
    
    66
    -                ++ "files to RTS build directory."
    
    67
    -
    
    68
    --- | Copy a static library file from the libffi build dir to the rts build dir.
    
    69
    -copyLibffiStatic :: Stage -> FilePath -> Action ()
    
    70
    -copyLibffiStatic stage target = withLibffi stage $ \ libffiPath _ -> do
    
    71
    -    -- Copy the vanilla library, and symlink the rest to it.
    
    72
    -    vanillaLibFile <- rtsLibffiLibrary stage vanilla
    
    73
    -    if target == vanillaLibFile
    
    74
    -    then copyFile' (libffiPath -/- libffiLibrary) target
    
    75
    -    else createFileLink (takeFileName vanillaLibFile) target
    
    76
    -
    
    77
    -
    
    78
    --- | Copy a dynamic library file from the libffi build dir to the rts build dir.
    
    79
    -copyLibffiDynamicUnix :: Stage -> String -> FilePath -> Action ()
    
    80
    -copyLibffiDynamicUnix stage libSuf target = do
    
    81
    -    needLibffi stage
    
    82
    -    dynLibs <- askLibffilDynLibs stage
    
    83
    -
    
    84
    -    -- If no version number suffix, then copy else just symlink.
    
    85
    -    let versionlessSourceFilePath = fromMaybe
    
    86
    -                (error $ "Needed " ++ show target ++ " which is not any of " ++
    
    87
    -                    "libffi's built shared libraries: " ++ show dynLibs)
    
    88
    -                (find (libSuf `isSuffixOf`) dynLibs)
    
    89
    -    let versionlessSourceFileName = takeFileName versionlessSourceFilePath
    
    90
    -    if versionlessSourceFileName == takeFileName target
    
    91
    -    then do
    
    92
    -        copyFile' versionlessSourceFilePath target
    
    93
    -
    
    94
    -        -- On OSX the dylib's id must be updated to a relative path.
    
    95
    -        when osxHost $ cmd
    
    96
    -            [ "install_name_tool"
    
    97
    -            , "-id", "@rpath/" ++ takeFileName target
    
    98
    -            , target
    
    99
    -            ]
    
    100
    -    else createFileLink versionlessSourceFileName target
    
    101
    -
    
    102
    --- | Copy a dynamic library file from the libffi build dir to the rts build dir.
    
    103
    -copyLibffiDynamicWin :: Stage -> FilePath -> Action ()
    
    104
    -copyLibffiDynamicWin stage target = do
    
    105
    -    needLibffi stage
    
    106
    -    dynLibs <- askLibffilDynLibs stage
    
    107
    -    let source = fromMaybe
    
    108
    -            (error $ "Needed " ++ show target ++ " which is not any of " ++
    
    109
    -                "libffi's built shared libraries: " ++ show dynLibs)
    
    110
    -            (find (\ lib -> takeFileName target == takeFileName lib) dynLibs)
    
    111
    -    copyFile' source target
    
    112
    -
    
    113
    -rtsLibffiLibrary :: Stage -> Way -> Action FilePath
    
    114
    -rtsLibffiLibrary stage way = do
    
    115
    -    name    <- interpretInContext ((rtsContext stage) { way = way }) libffiName
    
    116
    -    suf <- if wayUnit Dynamic way
    
    117
    -                then do
    
    118
    -                  extension <- setting DynamicExtension -- e.g., .dll or .so
    
    119
    -                  let suffix = waySuffix (removeWayUnit Dynamic way)
    
    120
    -                  return (suffix ++ extension)
    
    121
    -                -- Static suffix
    
    122
    -                else return (waySuffix way ++ ".a") -- e.g., _p.a
    
    123
    -    rtsPath <- rtsBuildPath stage
    
    124
    -    return $ rtsPath -/- "lib" ++ name ++ suf
    
    125
    -
    
    126
    --- | Get the libffi files bundled with the rts (header and library files).
    
    127
    --- Unless using the system libffi, this needs the libffi library. It must be
    
    128
    --- built before the targets can be calculated.
    
    129
    -needRtsLibffiTargets :: Stage -> Action [FilePath]
    
    130
    -needRtsLibffiTargets stage = do
    
    131
    -    rtsPath      <- rtsBuildPath stage
    
    132
    -    useSystemFfi <- flag UseSystemFfi
    
    133
    -    jsTarget     <- isJsTarget
    
    134
    -
    
    135
    -    -- Header files (in the rts build dir).
    
    136
    -    let headers = fmap ((rtsPath -/- "include") -/-) libffiHeaderFiles
    
    137
    -
    
    138
    -    if | jsTarget     -> return []
    
    139
    -       | useSystemFfi -> return []
    
    140
    -       | otherwise    -> do
    
    141
    -        -- Need Libffi
    
    142
    -        -- This returns the dynamic library files (in the Libffi build dir).
    
    143
    -        needLibffi stage
    
    144
    -        dynLibffSource <- askLibffilDynLibs stage
    
    145
    -
    
    146
    -        -- Dynamic library files (in the rts build dir).
    
    147
    -        let dynLibffis = fmap (\ lib -> rtsPath -/- takeFileName lib)
    
    148
    -                                  dynLibffSource
    
    149
    -
    
    150
    -        -- Libffi files (in the rts build dir).
    
    151
    -        libffis_libs <- do
    
    152
    -            ways <- interpretInContext (stageContext stage)
    
    153
    -                                       (getLibraryWays <> getRtsWays)
    
    154
    -            mapM (rtsLibffiLibrary stage) (Set.toList ways)
    
    155
    -        return $ concat [ headers, dynLibffis, libffis_libs ]
    
    156
    -
    
    157 27
     -- Need symlinks generated by rtsRules.
    
    158 28
     needRtsSymLinks :: Stage -> Set.Set Way -> Action ()
    
    159 29
     needRtsSymLinks stage rtsWays
    

  • hadrian/src/Rules/SourceDist.hs
    ... ... @@ -155,6 +155,9 @@ prepareTree dest = do
    155 155
           , pkgPath time -/- "lib" -/- "include" -/- "HsTimeConfig.h.in"
    
    156 156
           , pkgPath unix -/- "configure"
    
    157 157
           , pkgPath unix -/- "include" -/- "HsUnixConfig.h.in"
    
    158
    +      , pkgPath libffi -/- "configure"
    
    159
    +      , pkgPath libffi -/- "fficonfig.h.in"
    
    160
    +      , pkgPath libffi -/- "include" -/- "ffi.h.in"
    
    158 161
           , pkgPath terminfo -/- "configure"
    
    159 162
           , "configure"
    
    160 163
           , "aclocal.m4"
    

  • hadrian/src/Settings/Builders/Cabal.hs
    ... ... @@ -184,7 +184,8 @@ configureArgs cFlags' ldFlags' = do
    184 184
                                , arg $ top -/- pkgPath pkg
    
    185 185
                                , cFlags'
    
    186 186
                                ]
    
    187
    -    mconcat
    
    187
    +    useSystemFfi <- getFlag UseSystemFfi
    
    188
    +    mconcat $
    
    188 189
             [ conf "CFLAGS"   cFlags
    
    189 190
             , conf "LDFLAGS"  ldFlags'
    
    190 191
             , conf "--with-iconv-includes"    $ arg =<< getSetting IconvIncludeDir
    
    ... ... @@ -198,7 +199,7 @@ configureArgs cFlags' ldFlags' = do
    198 199
             , conf "--host"                   $ arg =<< getSetting TargetPlatformFull
    
    199 200
             , conf "--with-cc" $ arg =<< getBuilderPath . (Cc CompileC) =<< getStage
    
    200 201
             , ghcVersionH
    
    201
    -        ]
    
    202
    +        ] ++ if useSystemFfi then [arg "--configure-option=--with-system-libffi"] else []
    
    202 203
     
    
    203 204
     bootPackageConstraints :: Args
    
    204 205
     bootPackageConstraints = (stage0InTree ==) <$> getStage ? do
    

  • hadrian/src/Settings/Builders/Ghc.hs
    ... ... @@ -10,7 +10,6 @@ import Packages
    10 10
     import Settings.Builders.Common
    
    11 11
     import Settings.Warnings
    
    12 12
     import qualified Context as Context
    
    13
    -import Rules.Libffi (libffiName)
    
    14 13
     import qualified Data.Set as Set
    
    15 14
     import Data.Version.Extra
    
    16 15
     
    
    ... ... @@ -106,9 +105,6 @@ ghcLinkArgs = builder (Ghc LinkHs) ? do
    106 105
         context <- getContext
    
    107 106
         distPath <- expr (Context.distDynDir context)
    
    108 107
     
    
    109
    -    useSystemFfi <- expr (flag UseSystemFfi)
    
    110
    -    buildPath <- getBuildPath
    
    111
    -    libffiName' <- libffiName
    
    112 108
         debugged <- buildingCompilerStage' . ghcDebugged =<< expr flavour
    
    113 109
     
    
    114 110
         osxTarget <- expr isOsxTarget
    
    ... ... @@ -127,17 +123,6 @@ ghcLinkArgs = builder (Ghc LinkHs) ? do
    127 123
                     metaOrigin | osxTarget = "@loader_path"
    
    128 124
                                | otherwise = "$ORIGIN"
    
    129 125
     
    
    130
    -        -- TODO: an alternative would be to generalize by linking with extra
    
    131
    -        -- bundled libraries, but currently the rts is the only use case. It is
    
    132
    -        -- a special case when `useSystemFfi == True`: the ffi library files
    
    133
    -        -- are not actually bundled with the rts. Perhaps ffi should be part of
    
    134
    -        -- rts's extra libraries instead of extra bundled libraries in that
    
    135
    -        -- case. Care should be take as to not break the make build.
    
    136
    -        rtsFfiArg = package rts ? not useSystemFfi ? mconcat
    
    137
    -            [ arg ("-L" ++ buildPath)
    
    138
    -            , arg ("-l" ++ libffiName')
    
    139
    -            ]
    
    140
    -
    
    141 126
             -- This is the -rpath argument that is required for the bindist scenario
    
    142 127
             -- to work. Indeed, when you install a bindist, the actual executables
    
    143 128
             -- end up nested somewhere under $libdir, with the wrapper scripts
    
    ... ... @@ -166,7 +151,6 @@ ghcLinkArgs = builder (Ghc LinkHs) ? do
    166 151
                 , (not (nonHsMainPackage pkg) && not (isLibrary pkg)) ? arg "-rtsopts"
    
    167 152
                 , pure [ "-l" ++ lib    | lib    <- libs    ]
    
    168 153
                 , pure [ "-L" ++ libDir | libDir <- libDirs ]
    
    169
    -            , rtsFfiArg
    
    170 154
                 , osxTarget ? pure (concat [ ["-framework", fmwk] | fmwk <- fmwks ])
    
    171 155
                 , debugged ? packageOneOf [ghc, iservProxy, remoteIserv] ?
    
    172 156
                   arg "-debug"
    

  • hadrian/src/Settings/Default.hs
    ... ... @@ -141,7 +141,9 @@ stage1Packages = do
    141 141
         libraries0 <- filter good_stage0_package <$> stage0Packages
    
    142 142
         cross      <- flag CrossCompiling
    
    143 143
         winTarget  <- isWinTarget
    
    144
    +    jsTarget   <- isJsTarget
    
    144 145
         haveCurses <- any (/= "") <$> traverse setting [ CursesIncludeDir, CursesLibDir ]
    
    146
    +    useSystemFfi <- flag UseSystemFfi
    
    145 147
     
    
    146 148
         let when c xs = if c then xs else mempty
    
    147 149
     
    
    ... ... @@ -194,6 +196,10 @@ stage1Packages = do
    194 196
             [
    
    195 197
               terminfo
    
    196 198
             ]
    
    199
    +      , when (not jsTarget && not useSystemFfi)
    
    200
    +        [
    
    201
    +          libffi
    
    202
    +        ]
    
    197 203
           ]
    
    198 204
     
    
    199 205
     -- | Packages built in 'Stage2' by default. You can change this in "UserSettings".
    

  • hadrian/src/Settings/Packages.hs
    ... ... @@ -215,6 +215,7 @@ packageArgs = do
    215 215
     
    
    216 216
             ---------------------------------- rts ---------------------------------
    
    217 217
             , package rts ? rtsPackageArgs -- RTS deserves a separate function
    
    218
    +        , package libffi ? libffiPackageArgs
    
    218 219
     
    
    219 220
             -------------------------------- runGhc --------------------------------
    
    220 221
             , package runGhc ?
    
    ... ... @@ -275,6 +276,19 @@ ghcInternalArgs = package ghcInternal ? do
    275 276
     
    
    276 277
               ]
    
    277 278
     
    
    279
    +-- libffi and rts have to have the same flavour configuration
    
    280
    +libffiPackageArgs :: Args
    
    281
    +libffiPackageArgs = package libffi ? do
    
    282
    +    rtsWays <- getRtsWays
    
    283
    +    mconcat
    
    284
    +        [ builder (Cabal Flags) ? mconcat
    
    285
    +          [ any (wayUnit Profiling) rtsWays `cabalFlag` "profiling"
    
    286
    +          , any (wayUnit Debug) rtsWays     `cabalFlag` "debug"
    
    287
    +          , any (wayUnit Dynamic) rtsWays   `cabalFlag` "dynamic"
    
    288
    +          , any (wayUnit Threaded) rtsWays  `cabalFlag` "threaded"
    
    289
    +          ]
    
    290
    +        ]
    
    291
    +
    
    278 292
     -- | RTS-specific command line arguments.
    
    279 293
     rtsPackageArgs :: Args
    
    280 294
     rtsPackageArgs = package rts ? do
    
    ... ... @@ -285,8 +299,6 @@ rtsPackageArgs = package rts ? do
    285 299
         path           <- getBuildPath
    
    286 300
         top            <- expr topDirectory
    
    287 301
         useSystemFfi   <- getFlag UseSystemFfi
    
    288
    -    ffiIncludeDir  <- getSetting FfiIncludeDir
    
    289
    -    ffiLibraryDir  <- getSetting FfiLibDir
    
    290 302
         libdwIncludeDir   <- queryTarget (Lib.includePath <=< tgtRTSWithLibdw)
    
    291 303
         libdwLibraryDir   <- queryTarget (Lib.libraryPath <=< tgtRTSWithLibdw)
    
    292 304
         libnumaIncludeDir <- getSetting LibnumaIncludeDir
    
    ... ... @@ -428,7 +440,6 @@ rtsPackageArgs = package rts ? do
    428 440
                   [ useLibdw ? cabalExtraDirs (fromMaybe "" libdwIncludeDir) (fromMaybe "" libdwLibraryDir)
    
    429 441
                   , cabalExtraDirs libnumaIncludeDir libnumaLibraryDir
    
    430 442
                   , cabalExtraDirs libzstdIncludeDir libzstdLibraryDir
    
    431
    -              , useSystemFfi ? cabalExtraDirs ffiIncludeDir ffiLibraryDir
    
    432 443
                   ]
    
    433 444
             , builder (Cc (FindCDependencies CDep)) ? cArgs
    
    434 445
             , builder (Cc (FindCDependencies  CxxDep)) ? cArgs
    

  • libffi-tarballs deleted
    1
    -Subproject commit 7c51059557b68d29820a0a87cebfa6fe73c8adf5

  • libraries/libffi-clib
    1
    +Subproject commit 5323bdcc5229191884edb186709b7b91fe5117ee

  • packages
    ... ... @@ -37,7 +37,6 @@
    37 37
     # localpath                  tag         remotepath                      upstreamurl
    
    38 38
     # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    39 39
     ghc-tarballs                 windows     ghc-tarballs.git                -
    
    40
    -libffi-tarballs              -           -                               -
    
    41 40
     utils/hsc2hs                 -           -                               ssh://git@github.com/haskell/hsc2hs.git
    
    42 41
     libraries/array              -           -                               -
    
    43 42
     libraries/binary             -           -                               https://github.com/kolmodin/binary.git
    

  • rts/include/rts/ghc_ffi.h
    ... ... @@ -25,4 +25,4 @@
    25 25
     #endif
    
    26 26
     #endif
    
    27 27
     
    
    28
    -#include "ffi.h"
    28
    +#include <ffi.h>

  • rts/rts.buildinfo.in
    1 1
     extra-libraries: @EXTRA_LIBS@
    
    2 2
     extra-libraries-static: @EXTRA_LIBS@
    
    3 3
     include-dirs: @FFIIncludeDir@
    
    4
    -library-dirs: @FFILibDir@
    
    5
    -library-dirs-static: @FFILibDir@
    
    6
    -dynamic-library-dirs: @FFILibDir@
    4
    +extra-lib-dirs: @FFILibDir@
    
    5
    +extra-lib-dirs-static: @FFILibDir@

  • rts/rts.cabal
    ... ... @@ -163,18 +163,6 @@ library
    163 163
                             stg/Types.h
    
    164 164
     
    
    165 165
         else
    
    166
    -      -- If we are using an in-tree libffi then we must declare it as a bundled
    
    167
    -      -- library to ensure that Cabal installs it.
    
    168
    -      if !flag(use-system-libffi)
    
    169
    -        if os(windows)
    
    170
    -          extra-bundled-libraries: Cffi-6
    
    171
    -        else
    
    172
    -          extra-bundled-libraries: Cffi
    
    173
    -
    
    174
    -        install-includes: ffi.h ffitarget.h
    
    175
    -        -- ^ see Note [Packaging libffi headers] in
    
    176
    -        -- GHC.Driver.CodeOutput.
    
    177
    -
    
    178 166
           -- Here we declare several flavours to be available when passing the
    
    179 167
           -- suitable (combination of) flag(s) when configuring the RTS from hadrian,
    
    180 168
           -- using Cabal.
    
    ... ... @@ -232,6 +220,8 @@ library
    232 220
           if flag(use-system-libffi)
    
    233 221
              extra-libraries: ffi
    
    234 222
              extra-libraries-static: ffi
    
    223
    +      else
    
    224
    +         build-depends: libffi-clib
    
    235 225
           if os(windows)
    
    236 226
              extra-libraries:
    
    237 227
                 -- for the linker