Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cabal run & install broken #7325

Closed
adityagupta1089 opened this issue Mar 11, 2021 · 10 comments
Closed

Cabal run & install broken #7325

adityagupta1089 opened this issue Mar 11, 2021 · 10 comments

Comments

@adityagupta1089
Copy link

adityagupta1089 commented Mar 11, 2021

Describe the bug
I have a project with 1 library + multiple executables. I have defined ghc-options in .cabal file such as -O2 and -fllvm. These are not being picked up by cabal run --enable-profiling or cabal install, but those are being picked up when I do just cabal run or cabal build. I checked this using -v3 flag. Also it is building all the executables even though I specififed using cabal install exe:<executable1>

To Reproduce
Steps to reproduce the behavior: mentioned above

$ cabal run executable1 # uses flags from .cabal file
$ cabal install executable1 # doesn't use flags from .cabal file and starts building all executables
$ cabal run --enable-profiling executable1 -- +RTS -p # doesn't use flags from .cabal file 

Please use version-prefixed commands (e.g. v2-build or v1-build) to avoid ambiguity.

Expected behavior
mentioned above

System information

  • Operating system: Arch
  • cabal, ghc versions: 3.4, 8.10.4

Additional context
NA

@fgaz
Copy link
Member

fgaz commented Mar 11, 2021

Cannot reproduce. Could you attach / link to a minimal project that reproduces this?

Also it is building all the executables even though I specififed using cabal install exe:

What is the build-type? That's a limitation of the Custom build-type iirc

@adityagupta1089
Copy link
Author

will attach a MWE asap

@adityagupta1089
Copy link
Author

adityagupta1089 commented Mar 14, 2021

Hi I created a MWE project: https://github.com/adityagupta1089/cabal-test

  • cabal -v3 run problem1 | grep "\-O2" working
  • Install (not using cabal flags and installing all executables)
❯ cabal install problem1 --installdir=./bin --install-method=copy --overwrite-policy=always
Wrote tarball sdist to
/home/aditya/cabal-test/dist-newstyle/sdist/euler-0.1.0.0.tar.gz
Resolving dependencies...
Build profile: -w ghc-8.10.4 -O1
In order, the following will be built (use -v for more details):
 - euler-0.1.0.0 (lib) (requires build)
 - euler-0.1.0.0 (exe:problem3) (requires build)
 - euler-0.1.0.0 (exe:problem2) (requires build)
 - euler-0.1.0.0 (exe:problem1) (requires build)
Starting     euler-0.1.0.0 (lib)
Building     euler-0.1.0.0 (lib)
Installing   euler-0.1.0.0 (lib)
Completed    euler-0.1.0.0 (lib)
Starting     euler-0.1.0.0 (exe:problem3)
Starting     euler-0.1.0.0 (exe:problem2)
Starting     euler-0.1.0.0 (exe:problem1)
Building     euler-0.1.0.0 (exe:problem3)
Building     euler-0.1.0.0 (exe:problem2)
Building     euler-0.1.0.0 (exe:problem1)
  • Running with profiling: (not using cabal flags)
❯ cabal run --enable-profiling problem1 -- +RTS -p
Build profile: -w ghc-8.10.4 -O1
In order, the following will be built (use -v for more details):
 - euler-0.1.0.0 (lib)  --enable-profiling (configuration changed)
 - euler-0.1.0.0 (exe:problem1)  --enable-profiling (configuration changed)
Configuring library for euler-0.1.0.0..
Preprocessing library for euler-0.1.0.0..
Building library for euler-0.1.0.0..

Also I get this weird warning while running/building, etc.

Warning: The package has an extraneous version range for a dependency on an
internal library: euler >=0 && ==0.1.0.0, euler >=0 && ==0.1.0.0, euler >=0 &&
==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.

@fgaz
Copy link
Member

fgaz commented Mar 14, 2021

The warning is #5119

@adityagupta1089
Copy link
Author

@fgaz any idea about the other bugs? any workarounds?

@fgaz
Copy link
Member

fgaz commented Mar 20, 2021

Still cannot reproduce. I see the ghc options in the output of all three commands when running with -v3.

I see you're on arch, perhaps something in your ~/.cabal/config is interfering?

@fgaz
Copy link
Member

fgaz commented Mar 20, 2021

Ah wait, maybe you're referring to the "Build profile: -w ghc-8.8.4 -O1" output? The meaning of that is that optimizations are set at 1 at the project level, but you're still overriding to 2 at the component (executable) level. It agree it's a bit confusing (#6221)

@adityagupta1089
Copy link
Author

adityagupta1089 commented Apr 2, 2021

@fgaz Thanks. Seems like then the problem with flags is spurious. Only difficulty I am facing are then:

  • Can't install only a single binary (it installs all of them)
  • Maintaining a project with 100-200s of executables (writing executable blocks for all of them, I've tried a generation script)

So I'm currently using a makefile to glob the executable source files (Problem{1,2,3} in the MWE) and build using stack ghc (I wanted to use ghc but required some dependencies too)
But this method suffers from the problem when I need to profile a single binary (and I need profiling libraries), it's difficult if I haven't defined an executable (in which case both cabal & stack do this for me). and defining 100-200s of executables in .cabal or .yaml (hpack) are troublesome.

Can you give some advice how to structure or which build-tools to use for my project?

@fgaz
Copy link
Member

fgaz commented Apr 2, 2021

Can't install only a single binary (it installs all of them)

weird, I thought that was fixed. I'll have to check.
If that's the case you can still hack around it with build, run, and list-bin (all of them are granular enough)

Maintaining a project with 100-200s of executables (writing executable blocks for all of them, I've tried a generation script)

Common stanzas should make this less verbose, but you still have to at least enumerate the executables. Obtaining a list of exes from the file system will not be possible (cabal files are required to be self-contained in that sense). So generating the file looks like the best solution.

I wanted to use ghc but required some dependencies too

There are some ways to do that with cabal too. Either:

  • use --write-ghc-environment-files=always or set write-ghc-environment-files to always in your ~/.cabal/config, and then build the package. ghc will pick up the generated .ghc.environment file. Or...
  • use cabal exec ghc. Or...
  • use the cabal-env prototype mentioned in Separate cabal install --lib into own command (cabal env) #6481 to generate an environment file (this solution does not even need a .cabal file)

@adityagupta1089
Copy link
Author

adityagupta1089 commented Apr 6, 2021

@fgaz Thanks for the suggestions, I ran into cabal hell so using stack exec ghc for now with a makefile to build binaries. Also stack ghc -profile also works for me when I need to profile. make -j<num> is really fast compared to cabal or stack.

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

No branches or pull requests

3 participants