Skip to content

cabal v2-build fails to override global config with --enable-static --disable-shared #6688

Open

Description

@mouse07410

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:

  1. Set the values in the ~/.cabal/config for shared libraries and dynamic executables
    Here's the ~/.cabal/config I use: cabal-config.txt

$ cabal v2-build --enable-static --disable-shared
Resolving dependencies...
Build profile: -w ghc-8.6.5 -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/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/Lib.o )
[2 of 2] Compiling Paths_Str2Split  ( /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/autogen/Paths_Str2Split.hs, /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/Paths_Str2Split.o )
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(Win32Utils.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(consUtils.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(mp_clz_tab.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(obprintf.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(obprntffuns.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(obvprintf.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(repl-vsnprintf.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(longlong.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(Disassembler.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(LdvProfile.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(OldARMAtomic.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(ProfilerReport.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(ProfilerReportJson.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(Profiling.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(RetainerProfile.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(RetainerSet.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(RtsDllMain.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(Evac_thr.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(Sanity.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(Scav_thr.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(EventLog.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(Elf.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(PEi386.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(elf_got.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(elf_plt.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(elf_plt_aarch64.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(elf_plt_arm.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(elf_reloc.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(elf_reloc_aarch64.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/build/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.a(elf_util.o) has no symbols
Preprocessing library for Str2Split-0.1.0.0..
Running Haddock on library for Str2Split-0.1.0.0..
Haddock coverage:
   0% (  0 /  5) in 'Lib'
  Missing documentation for:
    Module header
    splitStr (src/Lib.hs:12)
    chunker (src/Lib.hs:26)
    splitMore (src/Lib.hs:29)
    splitLess (src/Lib.hs:32)
Documentation created:
/Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/doc/html/Str2Split/index.html
Configuring executable 'Str2Split-exe' for Str2Split-0.1.0.0..
Warning: The package has an extraneous version range for a dependency on an
internal library: Str2Split -any && ==0.1.0.0, Str2Split -any && ==0.1.0.0.
This version range includes the current package but isn't needed as the
current package's library will always be used.
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/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe-tmp/Main.dyn_o )
[2 of 2] Compiling Paths_Str2Split  ( /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/autogen/Paths_Str2Split.hs, /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe-tmp/Paths_Str2Split.dyn_o )
Linking /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe ...
$ otool -L /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe
/Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe:
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)
	@rpath/libHSStr2Split-0.1.0.0-inplace-ghc8.6.5.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libHSbase-4.12.0.0-ghc8.6.5.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libHSghc-prim-0.5.3-ghc8.6.5.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/libHSrts_thr-ghc8.6.5.dylib (compatibility version 0.0.0, current version 0.0.0)

Expected behavior
Executable linked with static Haskell libraries.

System information

  • MacOS Catalina 10.15.4, Xcode-11.4.
  • 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:

$ cabal build --enable-static --disable-shared --enable-executable-static
Build profile: -w ghc-8.6.5 -O1
In order, the following will be built (use -v for more details):
 - Str2Split-0.1.0.0 (lib) (configuration changed)
 - Str2Split-0.1.0.0 (exe:Str2Split-exe) (configuration changed)
Configuring library for Str2Split-0.1.0.0..
cabal: --enable-executable-dynamic and --enable-executable-static are
incompatible with each other.

cabal: Failed to build Str2Split-0.1.0.0 (which is required by
exe:Str2Split-exe from Str2Split-0.1.0.0). The failure occurred during the
configure step.

With --enable-executable-static --disable-executable-dynamic fail because of the OS constraints.

$ cabal build --enable-static --disable-shared --enable-executable-static --disable-executable-dynamic
. . . . .
Linking /Users/uri/src/Str2Split/dist-newstyle/build/x86_64-osx/ghc-8.6.5/Str2Split-0.1.0.0/x/Str2Split-exe/build/Str2Split-exe/Str2Split-exe ...
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`clang' failed in phase `Linker'. (Exit code: 1)

Activity

  1. asr commented on Jul 10, 2020

    @asr
    Contributor

    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 agda/agda#4796.

  2. Mikolaj commented on Jul 16, 2021

    @Mikolaj
    Member

    Related to #7236.

  3. changed the title [-]Cabal fails to respect build flags --enable-static[/-] [+]`cabal v2-build` fails to overwrite global config with `--enable-static` [/+] on Mar 25, 2022
  4. jneira commented on Mar 25, 2022

    @jneira
    Member

    @mouse07410 do we know if global config is overridden by cabal
    project config, top level or package specific? thanks!

  5. jneira commented on Mar 25, 2022

    @jneira
    Member

    @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

  6. jneira commented on Mar 25, 2022

    @jneira
    Member

    in fact I am tempted to close this in favour the more general #7236, do you agree @mouse07410 ?

  7. changed the title [-]`cabal v2-build` fails to overwrite global config with `--enable-static` [/-] [+]`cabal v2-build` fails to overridee global config with `--enable-static --disable-shared`[/+] on Mar 25, 2022
  8. changed the title [-]`cabal v2-build` fails to overridee global config with `--enable-static --disable-shared`[/-] [+]`cabal v2-build` fails to override global config with `--enable-static --disable-shared`[/+] on Mar 25, 2022
  9. mouse07410 commented on Mar 25, 2022

    @mouse07410
    CollaboratorAuthor

    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 #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.

  10. jneira commented on Mar 25, 2022

    @jneira
    Member

    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

  11. mouse07410 commented on Mar 25, 2022

    @mouse07410
    CollaboratorAuthor

    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...

  12. jneira commented on Mar 26, 2022

    @jneira
    Member

    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

  13. mouse07410 commented on Mar 27, 2022

    @mouse07410
    CollaboratorAuthor

    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.

  14. jneira commented on Mar 27, 2022

    @jneira
    Member

    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

  15. mouse07410 commented on Mar 27, 2022

    @mouse07410
    CollaboratorAuthor

    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"?

  16. jneira commented on Mar 27, 2022

    @jneira
    Member

    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

  17. mouse07410 commented on Mar 27, 2022

    @mouse07410
    CollaboratorAuthor

    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):

    • 92KB for dynamically-linked executable;
    • 1.4MB for statically-linked.

    P.S. Did not even need to get to Linux. ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions