[darwin] GHC will try to inject rpaths based on dependencies, this fails if -optl-Wl,-rpath is provided
Due to cabal being a bit stupid and insisting on replicating linking logic, and rpath logic, cabal may insist on passing -optl-Wl,-rpath to ghc, which ghc will pass verbatim to the linker. We should not change this in GHC. We do not want to prevent linker flags from being injected. However cabal needs to change.
We currently fail if we try to inject an rpath via install_name_tool, with -add_rpath, that is already in the build product. This failure is due to install_name_tool failing in that case.
A relevant cabal issue is here: https://github.com/haskell/cabal/pull/7094
We can't easily detect pre-existing rpath entries in library. otool -l
provides only some hard to parse output. And we surely don't want to write a mach-o header parser just to extract pre-existing rpaths, nor do we want to parse the command line arguments for occurences of -optl-Wl,-rpath or any other ways of passing arguments to the linker.
PS: Ideally we wouldn't have to do this whole rpath dance at all, but due to restrictions on the load command size on macOS, we do.