Cabal injects RUNPATHs into binaries in seemingly random order
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
It's a forward of upstream https://bugs.gentoo.org/746275 report where many packages when being built and installed with Cabal have `RUNPATH` to temporary directory they were built.
**To Reproduce**
```haskell
-- cat Main.hs
module Main (main) where
main :: IO ()
main = return ()
```
```haskell
-- cat SFF.hs
module SFF where
```
```
-- cat biosff.cabal
Cabal-version: 3.0
Name: biosff
Version: 0.3.7.1
Build-type: Simple
Library
Default-Language: Haskell2010
Exposed-modules: SFF
Build-depends: base
Executable x
Default-Language: Haskell2010
Main-Is: Main.hs
Build-Depends: base, array
Executable y
Default-Language: Haskell2010
Main-Is: Main.hs
Build-Depends: base
Executable z
Default-Language: Haskell2010
Main-Is: Main.hs
Build-Depends: base
```
```haskell
#cat Setup.hs
#!/usr/bin/env runhaskell
import Distribution.Simple
main = defaultMain
```
```
$ ghc --make Setup -o setup -dynamic
$ ./setup clean
cleaning...
$ ./setup configure --enable-executable-dynamic
Configuring biosff-0.3.7.1...
$ ./setup build
Preprocessing executable 'y' for biosff-0.3.7.1..
Building executable 'y' for biosff-0.3.7.1..
[1 of 1] Compiling Main ( Main.hs, dist/build/y/y-tmp/Main.dyn_o )
Linking dist/build/y/y ...
Preprocessing library for biosff-0.3.7.1..
Building library for biosff-0.3.7.1..
[1 of 1] Compiling SFF ( SFF.hs, dist/build/SFF.o )
Preprocessing executable 'x' for biosff-0.3.7.1..
Building executable 'x' for biosff-0.3.7.1..
[1 of 1] Compiling Main ( Main.hs, dist/build/x/x-tmp/Main.dyn_o )
Linking dist/build/x/x ...
Preprocessing executable 'z' for biosff-0.3.7.1..
Building executable 'z' for biosff-0.3.7.1..
[1 of 1] Compiling Main ( Main.hs, dist/build/z/z-tmp/Main.dyn_o )
Linking dist/build/z/z ...
```
Note: `y` binary was built before `biosff` library. As a result `x` and `z` binaries contain unexpected `RUNPATH`:
```
$ for b in x y z; do
echo $b
LANG=C readelf -a ./dist/build/$b/$b | fgrep RUNPATH | tr ':[]' $'\n\n\n' | grep -v ^/usr/lib64
done
x
0x000000000000001d (RUNPATH) Library runpath
/home/slyfox/dev/bugs/ghc-cabal-rpath/dist/build
y
0x000000000000001d (RUNPATH) Library runpath
z
0x000000000000001d (RUNPATH) Library runpath
/home/slyfox/dev/bugs/ghc-cabal-rpath/dist/build
```
**Expected behavior**
1. `RUNPATH` to temporary directory should not be injected into `x` and `z` binaries as the do not depend on `biosff` library.
**System information**
- OS: x86_64-linux
- `cabal`: current `git` version and `3.0.1.0`
- `ghc`: `8.8.4`
Contributor guide
Assessment
This issue has not been assessed yet.