Open mouse07410 opened 4 years ago
I noted the same behaviour with various libraries using a .cabal/config
file where any related to shared/static/dynamic is commented out. For example:
$ cabal get splitmix
$ cd splitmix-0.1
$ cabal install --lib --disable-shared -v2
...
Building library for splitmix-0.1..
creating dist/build
/usr/local/bin/ghc --make -fbuilding-cabal-package -O -static -dynamic-too...
Note that ghc
is called with the option -dynamic-too
.
Versions: GHC 8.10.1 and cabal-install
3.2.0.0.
Blocking https://github.com/agda/agda/issues/4796.
Related to #7236.
@mouse07410 do we know if global config is overridden by cabal project config, top level or package specific? thanks!
@asr thanks for the info, however the command you tried is install and I am afraid the behaviour can be different for build, for better or worse the install case is being covered in #7236
in fact I am tempted to close this in favour the more general #7236, do you agree @mouse07410 ?
do we know if global config is overridden by cabal project config, top level or package specific?
I've no idea, and don't fully understand the question. It appears that the global config settings take precedence over the CLI switches passed to Cabal invocation - which is the problem this issue points at.
in fact I am tempted to close this in favour the more general https://github.com/haskell/cabal/issues/7236, do you agree @mouse07410 ?
Decision is yours - but I don't think #7236 is more general, on the contrary: #7236 is about failure to strip the built executable when the build is static. This issue is about failing to build static regardless of the CLI flags, when the global config says otherwise.
I've no idea, and don't fully understand the question. It appears that the global config settings take precedence over the CLI switches passed to Cabal invocation - which is the problem this issue points at.
I wanted to mean if you add to your cabal project:
static: true
or
package mypackage
static: true
do they override the global cabal config?
his issue is about facing to build static regardless of the CLI flags, when the global config says otherwise.
yeah i misunderstood the linked issue, sorry
I wanted to mean if you add to your cabal project . . .
Honestly, I haven't tried that (yet? ;) ).
But the goal was to make something like cabal build --enable-static
work, as opposed to modifying the project (or even global config) to accomplish it.
Also, it is unclear whether this problem extends to cabal install xyz --enable-static
. For example, I may want most (all?) of my installed packages - both local and from Hackage - to be dynamically linked. But for some I may need to build/install them static...
well so a workaround could be to have dynamic in the global config and set static for the few exceptions in their cabal.project(.local), you exchange write or update a config file for avoid the flag in each invocation
but a workaround, the cli flag should override any previous config for sure
well so a workaround could be to have dynamic in the global config and set static for the few exceptions in their cabal.project(.local),
Alas, no.
Same result - it still links dynamically after putting static: true
into either one of those files (BTW, what's the purpose and the differences between cabal.project
and cabal.project.local
?):
$ otool -L /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe
/Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe:
@rpath/libHSStr2Split-0.1.0.0-inplace-ghc9.0.2.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libHSbase-4.15.1.0-ghc9.0.2.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libHSghc-prim-0.7.0-ghc9.0.2.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libHSrts-1.0.2_thr-ghc9.0.2.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)
$ rm cabal.project.local
$
BTW, this is with Cabal-3.6.2.0, and GHC-9.0.2.
Same result - it still links dynamically after putting static: true into either one of those files (BTW, what's the purpose and the differences between cabal.project and cabal.project.local?):
cabal.project.local
is automatically merged with the main cabal.project
, the idea is to have local specific and/or temporal options in the .local
one and no upload it to cvs
Same result - it still links dynamically after putting static: true into either one of those files
ugh, not sure if i will have time but i would like to reproduce in linux with -v3
, just in case the verbose output give us a clue
would like to reproduce in linux with
-v3
, just in case the verbose output give us a clue
Explain please. First, I might be able to reproduce it in Linux, as I have a couple of Linux VMs. Second - what do you mean by -v3
? How exactly would you like to generate "verbose output"?
sorry didn't want to bother you with more testing so I was thinking in reproduce the error setting the -v3
cabal cli option to make it produce full verbose output and try to gather some insight from, but if you have time to attach such output, it would be great
Here's the output of cabal -v3 build --enable-shared --disable-static
on Mac:
cabal-static1.log.txt
Then I started experimenting with adding stuff to cabal.project.local
, and got this:
$ cabal clean
$ cat cabal.project.local
static: true
shared: false
executable-dynamic: false
$ cat cabal.project
packages: ./
-- repository ll-skete
-- url: http://g53blumenthal.llan.ll.mit.edu:12344/packages/archive/
-- secure: True
-- root-keys:
-- key-threshold: 3
$ cabal -v3 build
File monitor 'config' changed: first run
Project settings changed, reconfiguring...
creating /Users/ur20980/src/Str2Split/dist-newstyle
creating /Users/ur20980/src/Str2Split/dist-newstyle/cache
this build was affected by the following (project) config files:
- /Users/ur20980/src/Str2Split/cabal.project
- /Users/ur20980/src/Str2Split/cabal.project.local
File monitor 'improved-plan' changed: first run
File monitor 'elaborated-plan' changed: first run
File monitor 'compiler' changed: first run
Compiler settings changed, reconfiguring...
Searching for ghc in path.
Found ghc at /Users/ur20980/.ghcup/bin/ghc
/Users/ur20980/.ghcup/bin/ghc --numeric-version
/Users/ur20980/.ghcup/bin/ghc is version 9.0.2
looking for tool ghc-pkg near compiler in /Users/ur20980/.ghcup/bin
candidate locations:
["/Users/ur20980/.ghcup/ghc/9.0.2/bin/ghc-pkg-ghc-9.0.2","/Users/ur20980/.ghcup/ghc/9.0.2/bin/ghc-pkg-9.0.2","/Users/ur20980/.ghcup/ghc/9.0.2/bin/ghc-pkg","/Users/ur20980/.ghcup/bin/ghc-pkg"]
found ghc-pkg in /Users/ur20980/.ghcup/ghc/9.0.2/bin/ghc-pkg-9.0.2
/Users/ur20980/.ghcup/ghc/9.0.2/bin/ghc-pkg-9.0.2 --version
/Users/ur20980/.ghcup/ghc/9.0.2/bin/ghc-pkg-9.0.2 is version 9.0.2
/Users/ur20980/.ghcup/bin/ghc --supported-languages
/Users/ur20980/.ghcup/bin/ghc --info
File monitor 'solver-plan' changed: first run
/Users/ur20980/.ghcup/bin/ghc --print-global-package-db
Reading installed packages...
/Users/ur20980/.ghcup/ghc/9.0.2/bin/ghc-pkg-9.0.2 dump --global -v0
/Users/ur20980/.ghcup/bin/ghc --print-libdir
Reading available packages of hackage.haskell.org...
. . . . .
/Users/ur20980/.ghcup/bin/ghc --make -fbuilding-cabal-package -O -static -outputdir /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe-tmp -odir /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe-tmp -hidir /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe-tmp -stubdir /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe-tmp -i -i/Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe-tmp -iapp -i/Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/autogen -i/Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/global-autogen -I/Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/autogen -I/Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/global-autogen -I/Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe-tmp -I/opt/local/include -I/usr/local/include -optP-include -optP/Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/autogen/cabal_macros.h -L/opt/local/lib/liconv -L/opt/local/lib -L/usr/local/lib -L/usr/lib -hide-all-packages -Wmissing-home-modules -no-user-package-db -package-db /Users/ur20980/.cabal/store/ghc-9.0.2/package.db -package-db /Users/ur20980/src/Str2Split/dist-newstyle/packagedb/ghc-9.0.2 -package-db /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/package.conf.inplace -package-id Str2Split-0.1.0.0-inplace -package-id base-4.15.1.0 -XHaskell2010 app/Main.hs Paths_Str2Split -o /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe -threaded -rtsopts '-with-rtsopts=-N' -hide-all-packages
Linking /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe ...
packages definitely up to date: Str2Split-0.1.0.0-inplace, Str2Split-0.1.0.0-inplace-Str2Split-exe
packages previously probably up to date:
packages now probably up to date: Str2Split-0.1.0.0-inplace, Str2Split-0.1.0.0-inplace-Str2Split-exe
packages newly up to date: Str2Split-0.1.0.0-inplace, Str2Split-0.1.0.0-inplace-Str2Split-exe
packages out to date: Str2Split-0.1.0.0-inplace-Str2Split-test
packages invalid due to dep change: Str2Split-0.1.0.0-inplace-Str2Split-test
packages invalid due to build failure:
$ otool -L /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe
/Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe:
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)
/opt/local/lib/libffi.8.dylib (compatibility version 10.0.0, current version 10.0.0)
$
As you see, the above executable is static "enough" - as static as you can expect on MacOS, because system libraries are dynamic only.
Finally, I tried adding --disable-executable-dynamic
to CLI options:
$ cabal clean
$ cabal build --disable-shared --enable-static --disable-executable-dynamic
Resolving dependencies...
Build profile: -w ghc-9.0.2 -O1
In order, the following will be built (use -v for more details):
- Str2Split-0.1.0.0 (lib) (first run)
- Str2Split-0.1.0.0 (exe:Str2Split-exe) (first run)
Configuring library for Str2Split-0.1.0.0..
Preprocessing library for Str2Split-0.1.0.0..
Building library for Str2Split-0.1.0.0..
[1 of 2] Compiling Lib ( src/Lib.hs, /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/build/Lib.o )
[2 of 2] Compiling Paths_Str2Split ( /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/build/autogen/Paths_Str2Split.hs, /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/build/Paths_Str2Split.o )
. . . . .
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc9.0.2.a(Sanity.o) has no symbols
Preprocessing library for Str2Split-0.1.0.0..
Running Haddock on library for Str2Split-0.1.0.0..
0% ( 0 / 5) in 'Lib'
Missing documentation for:
Module header
splitStr (src/Lib.hs:7)
chunker (src/Lib.hs:15)
splitMore (src/Lib.hs:18)
splitLess (src/Lib.hs:21)
Documentation created:
/Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/doc/html/Str2Split/Str2Split.txt
Configuring executable 'Str2Split-exe' for Str2Split-0.1.0.0..
Preprocessing executable 'Str2Split-exe' for Str2Split-0.1.0.0..
Building executable 'Str2Split-exe' for Str2Split-0.1.0.0..
[1 of 2] Compiling Main ( app/Main.hs, /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe-tmp/Main.o )
[2 of 2] Compiling Paths_Str2Split ( /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/autogen/Paths_Str2Split.hs, /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe-tmp/Paths_Str2Split.o )
Linking /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe ...
$ otool -L /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe
/Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe:
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)
/opt/local/lib/libffi.8.dylib (compatibility version 10.0.0, current version 10.0.0)
$
Not even sure what this all means. It appears that to statically link an executable, the only CLI flag I need is --disable-executable-dynamic
?!
$ cabal build --disable-executable-dynamic
Resolving dependencies...
Build profile: -w ghc-9.0.2 -O1
In order, the following will be built (use -v for more details):
- Str2Split-0.1.0.0 (lib) (first run)
- Str2Split-0.1.0.0 (exe:Str2Split-exe) (first run)
Configuring library for Str2Split-0.1.0.0..
Preprocessing library for Str2Split-0.1.0.0..
Building library for Str2Split-0.1.0.0..
[1 of 2] Compiling Lib ( src/Lib.hs, /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/build/Lib.o )
[2 of 2] Compiling Paths_Str2Split ( /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/build/autogen/Paths_Str2Split.hs, /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/build/Paths_Str2Split.o )
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc9.0.2.a(mp_clz_tab.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc9.0.2.a(obprintf.o) has no symbols
. . . . .
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc9.0.2.a(Sanity.o) has no symbols
Preprocessing library for Str2Split-0.1.0.0..
Running Haddock on library for Str2Split-0.1.0.0..
0% ( 0 / 5) in 'Lib'
Missing documentation for:
Module header
splitStr (src/Lib.hs:7)
chunker (src/Lib.hs:15)
splitMore (src/Lib.hs:18)
splitLess (src/Lib.hs:21)
Documentation created:
/Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/doc/html/Str2Split/Str2Split.txt
Configuring executable 'Str2Split-exe' for Str2Split-0.1.0.0..
Preprocessing executable 'Str2Split-exe' for Str2Split-0.1.0.0..
Building executable 'Str2Split-exe' for Str2Split-0.1.0.0..
[1 of 2] Compiling Main ( app/Main.hs, /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe-tmp/Main.o )
[2 of 2] Compiling Paths_Str2Split ( /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/autogen/Paths_Str2Split.hs, /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe-tmp/Paths_Str2Split.o )
Linking /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe ...
$ otool -L /Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe
/Users/ur20980/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-9.0.2/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe:
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)
/opt/local/lib/libffi.8.dylib (compatibility version 10.0.0, current version 10.0.0)
$
Size difference (for this extremely trivial app):
P.S. Did not even need to get to Linux. ;-)
Describe the bug Cabal ignores
--enable-static --disable-shared
given in the command line, and follows the settings in~/.cabal/config
.To Reproduce Steps to reproduce the behavior:
Set the values in the
~/.cabal/config
for shared libraries and dynamic executables Here's the~/.cabal/config
I use: cabal-config.txtExpected behavior Executable linked with static Haskell libraries.
System information
cabal-3.2.0.0
,ghc
8.8.3, 8.6.5.Additional context
Here's my small test-project https://github.com/mouse07410/Str2Split.git
Attempts to build anything (demonstrating on this fairly simple reproducer project) with
--enable-executable-static
fails with:With
--enable-executable-static --disable-executable-dynamic
fail because of the OS constraints.