diff --git a/hadrian/src/Rules/Generate.hs b/hadrian/src/Rules/Generate.hs
index db220a98c431f7f69fc0817ed289c5bf32f7d8ac..3a1acb011c46b6306a0a2e8c8576cdc0331307e4 100644
--- a/hadrian/src/Rules/Generate.hs
+++ b/hadrian/src/Rules/Generate.hs
@@ -40,13 +40,15 @@ rtsDependencies :: Expr [FilePath]
 rtsDependencies = do
     stage   <- getStage
     rtsPath <- expr (rtsBuildPath stage)
+    useSystemFfi <- expr (flag UseSystemFfi)
+
     let headers =
             [ "ghcautoconf.h", "ghcplatform.h"
             , "DerivedConstants.h"
             , "rts" -/- "EventTypes.h"
             , "rts" -/- "EventLogConstants.h"
             ]
-            ++ libffiHeaderFiles
+            ++ (if useSystemFfi then [] else libffiHeaderFiles)
     pure $ ((rtsPath -/- "include") -/-) <$> headers
 
 genapplyDependencies :: Expr [FilePath]
diff --git a/hadrian/src/Rules/Rts.hs b/hadrian/src/Rules/Rts.hs
index 4e6b4f75321baa2b1637e11ddc65acc75531aa7c..abc9947f4a138b18b20ced37047d0615d74ec3ed 100644
--- a/hadrian/src/Rules/Rts.hs
+++ b/hadrian/src/Rules/Rts.hs
@@ -121,7 +121,7 @@ needRtsLibffiTargets stage = do
     let headers = fmap ((rtsPath -/- "include") -/-) libffiHeaderFiles
 
     if useSystemFfi
-    then return headers
+    then return []
     else do
         -- Need Libffi
         -- This returns the dynamic library files (in the Libffi build dir).
diff --git a/rts/rts.cabal.in b/rts/rts.cabal.in
index 5e53b38be22afedc65207b347bc95234b184945a..83badbe8b934c3a8c654a85bc0bc7f8e3225ca55 100644
--- a/rts/rts.cabal.in
+++ b/rts/rts.cabal.in
@@ -73,6 +73,9 @@ library
         extra-bundled-libraries: Cffi-6
       else
         extra-bundled-libraries: Cffi
+      install-includes: ffi.h ffitarget.h
+      -- ^ see Note [Packaging libffi headers] in
+      -- GHC.Driver.CodeOutput.
 
     -- The make build system does something special in config.mk.in
     -- for generating profiled, debugged, etc builds of those
@@ -163,7 +166,7 @@ library
     install-includes: Cmm.h HsFFI.h MachDeps.h Rts.h RtsAPI.h Stg.h
                       ghcautoconf.h ghcconfig.h ghcplatform.h ghcversion.h
                       -- ^ from include
-                      DerivedConstants.h ffi.h ffitarget.h
+                      DerivedConstants.h
                       rts/EventLogConstants.h
                       rts/EventTypes.h
                       -- ^ generated