Skip to content

Commit

Permalink
Merge pull request #810 from reflex-frp/dylang/fix-macos
Browse files Browse the repository at this point in the history
Add patches to fix GHC 8.6.5 on MacOS Big Sur and up
  • Loading branch information
mankyKitty authored Feb 15, 2023
2 parents 12ab0ad + 9f7c52d commit ae41504
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
3 changes: 3 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ let iosSupport = system == "x86_64-darwin";
# nixpkgs-21.05 ships with a version of autoreconf that is incompatible with ghc 8.6.5,
# Cf. https://gitlab.haskell.org/ghc/ghc/-/commit/ad2ef3a13f1eb000eab8e3d64592373b91a52806
./haskell-overlays/splices-load-save/ghc-8.6-autoreconf.patch
] ++ super.lib.optionals (super.stdenv.targetPlatform.isDarwin) [
./haskell-overlays/patches/ghc865/fix-big-sur.patch
];
})).override {
bootPkgs = super.haskell.packages.ghc865Binary // {
Expand Down Expand Up @@ -128,6 +130,7 @@ let iosSupport = system == "x86_64-darwin";
binutils-unwrapped = super.binutils-unwrapped.override {
autoreconfHook = lib.optional self.stdenv.buildPlatform.isDarwin super.autoreconfHook269;
};

# Bump ios-deploy
# - for faster deployments
# - fixes debug deploy with iOS 16/macos 12.3/ xcode 13.4.1
Expand Down
80 changes: 80 additions & 0 deletions haskell-overlays/patches/ghc865/fix-big-sur.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
diff --git a/compiler/ghci/Linker.hs b/compiler/ghci/Linker.hs
index dbe71cd9ab048bd5cc9b2774dd30faeecbdd84fb..da18c019461bdffd62e06bd0441742786109c08c 100644
--- a/compiler/ghci/Linker.hs
+++ b/compiler/ghci/Linker.hs
@@ -1676,6 +1676,38 @@ addEnvPaths name list
-- ----------------------------------------------------------------------------
-- Loading a dynamic library (dlopen()-ish on Unix, LoadLibrary-ish on Win32)

+{-
+Note [macOS Big Sur dynamic libraries]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+macOS Big Sur makes the following change to how frameworks are shipped
+with the OS:
+
+> New in macOS Big Sur 11 beta, the system ships with a built-in
+> dynamic linker cache of all system-provided libraries. As part of
+> this change, copies of dynamic libraries are no longer present on
+> the filesystem. Code that attempts to check for dynamic library
+> presence by looking for a file at a path or enumerating a directory
+> will fail. Instead, check for library presence by attempting to
+> dlopen() the path, which will correctly check for the library in the
+> cache. (62986286)
+
+(https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-release-notes/)
+
+Therefore, the previous method of checking whether a library exists
+before attempting to load it makes GHC.Runtime.Linker.loadFramework
+fail to find frameworks installed at /System/Library/Frameworks.
+Instead, any attempt to load a framework at runtime, such as by
+passing -framework OpenGL to runghc or running code loading such a
+framework with GHCi, fails with a 'not found' message.
+
+GHC.Runtime.Linker.loadFramework now opportunistically loads the
+framework libraries without checking for their existence first,
+failing only if all attempts to load a given framework from any of the
+various possible locations fail. See also #18446, which this change
+addresses.
+-}
+
-- Darwin / MacOS X only: load a framework
-- a framework is a dynamic library packaged inside a directory of the same
-- name. They are searched for in different paths than normal libraries.
@@ -1686,17 +1718,29 @@ loadFramework hsc_env extraPaths rootname
Left _ -> []
Right dir -> [dir </> "Library/Frameworks"]
ps = extraPaths ++ homeFrameworkPath ++ defaultFrameworkPaths
- ; mb_fwk <- findFile ps fwk_file
- ; case mb_fwk of
- Just fwk_path -> loadDLL hsc_env fwk_path
- Nothing -> return (Just "not found") }
- -- Tried all our known library paths, but dlopen()
- -- has no built-in paths for frameworks: give up
+ ; errs <- findLoadDLL ps []
+ ; return $ fmap (intercalate ", ") errs
+ }
where
fwk_file = rootname <.> "framework" </> rootname
- -- sorry for the hardcoded paths, I hope they won't change anytime soon:
+
+ -- sorry for the hardcoded paths, I hope they won't change anytime soon:
defaultFrameworkPaths = ["/Library/Frameworks", "/System/Library/Frameworks"]

+ -- Try to call loadDLL for each candidate path.
+ --
+ -- See Note [macOS Big Sur dynamic libraries]
+ findLoadDLL [] errs =
+ -- Tried all our known library paths, but dlopen()
+ -- has no built-in paths for frameworks: give up
+ return $ Just errs
+ findLoadDLL (p:ps) errs =
+ do { dll <- loadDLL hsc_env (p </> fwk_file)
+ ; case dll of
+ Nothing -> return Nothing
+ Just err -> findLoadDLL ps ((p ++ ": " ++ err):errs)
+ }
+
{- **********************************************************************

Helper functions

0 comments on commit ae41504

Please sign in to comment.