You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
--extra-lib-dirs and --extra-include-dirs ignored? #2997
I tried compiling hackage-server with new-build, and hackage-server relies on text-icu, which in my case is installed in the brew Cellar and hence needs additional lib and include paths. However, doing
(which arguably is the most logical way to configure this anyway, so perhaps this is merely a matter of warning the user that global lib/include flags are not taken into account for subpackages?).
This is a question about what packages do top level options apply to? All packages all the way down, all packages local to the project or what?
The current answer is all packages local to the project. So in this example since text-icu is not local to the project then the top level options do not apply to it.
What if we give a warning if these options are passed in from command line? They could be legitimate, but I think in most cases they won't be, and a user can always stick it in cabal.project.local to suppress it.
Sorry -- dumb and slightly off-topic question here -- but I just want to make sure that the options set in the ~/.cabal/configure file for these two are always respected even under new-build?
So, let's assume that I want all Cabal build to find header files in /usr/local/include -- regardless of whether it's a local package or an external package I'm building. How would I configure that? Listing that location as an extra-include-dir in ~/.cabal/config used to work, but with new-build it no longer does. What solution exists to there to handle this use-case?
Reacted by Joshua Grosso, Nadeem Bitar and Артур Файзрахманов
@peti btw, one problem I recently realised is that such a global setting would force every package, including GHC boot libraries to be recompiled, as it would force a new nix-hash (as those flags enter the hash computation). And for non-reinstallable packages such as base cabal would likely end up having to give up, as it couldn't satisfy the request. So I'm not sure we can even provide what you want in a principled truly "global" way. The reason it worked in the past was that Cabal applied flags in ~/.cabal/config only to newly compiled packages, which was maybe convenient but also quite hacky/fragile at the same time, as it introduced statefulness.
I am basically happy specifying those extra-include-dirs paths for specific packages only, i.e. not globally for everything. However, those paths are specific to the system I'm building on, so I want to configure them in ~/.cabal/config (or something like that). But new-build won't honor such things in the global config file; it honors package-specific configuration options only in the per-project cabal.project file. But system paths don't belong there. They belong to the system.
to ~/.cabal/config and have new-build use that information every time it compiles hopenssl for any of my projects, then I would be happy. Is that feasible?
Reacted by Herbert Valerio Riedel and Joshua Grosso
@peti Personally, I think that'd quite reasonable to have in ~/.cabal/config (or nearby).
I do wonder though how to be able to locally override the global setting. Especially with openssl, I've sometimes needed temporarily to use a newer local versions rather than the system-wide installed one (e.g. hookup for example needs a more recent OpenSSL version than is installed systemwide in Debian 8; however I want every other project that doesn't need hookup to use the system-wide openssl version; now imagine if the system-wide was installed in a non-standard location requiring extra-includes), and cabal traditionally considers settings to be of the free monoid kind, and thus appends settings rather than replacing them.
On the other hand, I guess a local package hopenssl configuration could simply override all of the global package hopenssl stanza (as if there never was a global one).
I think we have enough here to turn this into a specification for a feature-request ticket... :-)
@hvr, I see what you mean. extra-xxx-dirs are difficult to treat as Moniods. I can think of the following strategies to deal with this issue:
Just mconcat all extra paths into one large list and make it the user's responsibility to write a sensible configuration. If the global config file sets an extra include dir for any package foo, then that directory will be part of the search path for all builds of foo, regardless of what more local configuration files say. Therefore, if I want a search path included in some builds of foo but not all, then I cannot set one in the global configuration file.
In addition to (1), but we could guarantee that more locally configured search paths occur in that final list before the moreddition to (1), but w globally configured ones. Therefore, if I configure /tmp/foo/include globally and /tmp/bar/include locally, then my project will compile with -I/tmp/bar/include -I/tmp/foo/include. This is dangerous, of course, but it's a pretty common strategy to use. After all, all compilers have /usr/include and their search path, yet we re-direct the compiler elsewhere just by pre-pending another location to that list so that the files in /usr/include are no longer found.
We could introduce another kind of search path, say default-extra-include-dirs, which is cleared whenever a extra-include-dirs directive appears anywhere else. That way, I could specify a search path that is used for "almost all builds", i.e. all builds that don't specify something else. Multiple occurrences of default-extra-include-dirs would be mappended, of course.
Provide an explicit clear-<option-name> directive that throws away all occurrences of that configuration option that occur in a less local place. So, when I run cabal configure --clear-extra-include-dirs, then that search path will be empty -- regardless of what ~/.cabal/config, cabal.project, or cabal.project.local say. I'm not quite sure how the syntax would work in configuration files, but I suppose there is some sensible way to express that there, too.
If anyone is looking for a workaround: I found that setting the C_INCLUDE_PATH environment variable works (LIBRARY_PATH may also work). This doesn't seem to be documented anywhere, but I saw it mentioned here: #2705 (comment)
For example, I have a project that has a dependency on the lzma package. When running regular cabal new-build it would give an error that it can't find the header file "lzma.h". Using --extra-include-dirs did not help.
Note that search paths configured via environment variables like C_INCLUDE_PATH and others will not be recorded in the package configuration file for the generated library, which means that the build result might be unusable in shell environments that don't have these variables. In case of header files, this is probably not going to pose a problem, but when shared libraries need to be found at link-time, then it certainly will.
I was compiling GHC and it errored out because it could not find gmp.h. I found that GHC scripts were invoking cabal configure but I did not know where in the ghc make scripts I can specify something like --extra-include-dirs. I knew gmp.h was in `/opt/local/include' but there was no way I could tell cabal about it. I knew there was some environment variable to tell cabal about where to look for c headers, but could not find it anywhere in the documentation. After a lot of search, the comment above about C_INCLUDE_PATH helped. Why is this not documented? This is the second time I ran into this problem and every time I find this at some obscure place.
The main reason I can't go that route is that I'm trying to get a configuration that will work across multiple environments. So I wouldn't want to embed that configuration into something I'd check into source control. And also, the actual lib is dynamically created (through Nix). So, a command line argument is really what I need here, as opposed to a config value. (I guess I could dynamically generate the project file, but, I really don't want to do that.)
I'm currently trying a different approach in Nix. Although it seems like I should be able to do this, somehow, maybe I can avoid the problem entirely.
You can add that configuration to cabal.project.local and hence not place it in what is put it in source control, fwiw.
I can't think of a good way to specify this in command line options. We would need a full design to have subpackage options stanzas specifiable on the command line, which feels pretty awkward compared to creating a file.
or maybe we could play with the explicit target, the counterintuitive thing arise when you do a cabal command my-package --whatever and such option is not applied to my-package
The --extra-lib-dirs= command line argument, just like the extra-lib-dirs: cabal.project option, only applies to local packages and will not apply to dependencies.
This is due to the fact that cabal includes fields like extra-lib-dirs: and extra-include-dirs: in the hash it uses to reuse already build dependencies. Applying that option globally will cause recompiling everything.
In a project setting, there is a syntax to apply these options to any arbitrary package, whether local or not:
package [package name or * for all packages]
extra-lib-dirs: ...
While in a project, both cabal build and cabal install will read and use those options. The options are now scoped in a project so any recompilation is intentional.
If you are developing a project, it is best practice to add these paths to cabal.project.local and not include that into source version control, since those options are most likely specific to your system.
Users of cabal install outside a project do not have a simple equivalent. One could argue that the use case of using cabal install as a non-project/global command was left out of the transition to v2/nix-style commands. This includes the use case of "installing" packages from Hackage, which was and seems to be still quite common.
If you try to cabal install a Hackage package that needs a system library that cannot be found in the default search paths, you don't have a way to fix that with a command line option.
My understanding is that adding/changing extra-lib-dirs in the global cabal config works (but be aware you will recompile all dependencies everytime you change it). Edit: I tested this and it does work.
It seem impossible at the moment to use the above per-package syntax in the global cabal config. This is due to techinical debts that have not been solved (:heart: @jgotoh for working on Migrate cabal.project parsing to parsec #7748). I am under the impression this would give an good solution, since you would be able to scope the extra options to specific packages, avoding mass recompilations.
The other solution is influencing gcc library search paths. In the end, all cabal does is passing extra-libraries to gcc, which has its own library search mechanism. In particular you can provide gcc with extra paths to look for libraries in, using the LIBRARY_PATH environment variable. The same applies with extra-include-path and C_INCLUDE_PATH, see gcc manual page.
Notice this will be invisible to cabal's hashing mechanism, so changes in LIBRARY_PATH and C_INCLUDE_PATH will not trigger recompilation.
This all I know and can understand, please correct me if I made mistakes or missed something important.
Reacted by Bruno Dias, Artem Pelenitsyn, Rodrigo Mesquita and Francesco Gazzetta
I investigated and discussed this issue in yesterday's Cabal dev meeting.
As has been noted in this ticket's discussion, and summarised by @andreabedini and the commit message of 652a77c (this is a commit that took the wrong approach, but describes what packages do each flags apply to), flags given in the command line to build, such as --extra-lib-dirs and --extra-include-dirs, are local flags, just like flags at the top-level of the cabal.project file.
Local flags apply to local packages, such as those in your local project for which you have a .cabal file.
However, local flags do not apply to non-local packages (such as those pulled from hackage and installed in the store). Therefore, specifying --extra-lib-dirs in the command line will not apply those options to the packages you depend on such as HsOpenSSL. They are not ignored, they /only/ apply to the /local/ packages you are building!
To apply flags to a package you depend on, such as HsOpenSSL, you need to use either global configuration (~/.cabal/config) or per-package configuration, such as:
or e.g. using an * instead of the package name to apply those options to all non-local dependencies of the project you are building.
In the meeting we agreed that, ultimately, the behaviour of local flags applying to local packages only is the correct one, and that we shouldn't change that behaviour.
Instead, we agree the solution to this ticket is to improve documentation and be very clear in cabal configure/build about the scope of configuration flags, add explicit examples of these use cases such as configuring the extra-lib-dirs of a specific package, and perhaps even add a small note to the documentation of --extra-lib-dirs saying something like "Note that this flag only applies to the packages local to the project, but not its dependencies. Read X documentation for more details."
Reacted by Francesco Gazzetta, Bit Connor, Siyuan Chen, Léana and George Thomas
Activity
hvr commentedon Aug 24, 2016
It appears the same problem exists with global
flagsnot being honoreddcoutts commentedon Aug 24, 2016
This is a question about what packages do top level options apply to? All packages all the way down, all packages local to the project or what?
The current answer is all packages local to the project. So in this example since text-icu is not local to the project then the top level options do not apply to it.
hvr commentedon Sep 2, 2016
Btw, here's a quite common use-case I heard from an OSX user w/ homebrew:
ezyang commentedon Sep 2, 2016
What if we give a warning if these options are passed in from command line? They could be legitimate, but I think in most cases they won't be, and a user can always stick it in
cabal.project.localto suppress it.gbaz commentedon Sep 2, 2016
Sorry -- dumb and slightly off-topic question here -- but I just want to make sure that the options set in the ~/.cabal/configure file for these two are always respected even under new-build?
ezyang commentedon Sep 2, 2016
.cabal/config is respected by new-build. See also http://ezyang.com/nix-local-build.html#configuring-builds-with-cabal.project for all the config that is used in this determination.
peti commentedon May 15, 2017
So, let's assume that I want all Cabal build to find header files in
/usr/local/include-- regardless of whether it's a local package or an external package I'm building. How would I configure that? Listing that location as anextra-include-dirin~/.cabal/configused to work, but withnew-buildit no longer does. What solution exists to there to handle this use-case?hvr commentedon May 16, 2017
@peti btw, one problem I recently realised is that such a global setting would force every package, including GHC boot libraries to be recompiled, as it would force a new nix-hash (as those flags enter the hash computation). And for non-reinstallable packages such as
basecabal would likely end up having to give up, as it couldn't satisfy the request. So I'm not sure we can even provide what you want in a principled truly "global" way. The reason it worked in the past was that Cabal applied flags in ~/.cabal/config only to newly compiled packages, which was maybe convenient but also quite hacky/fragile at the same time, as it introduced statefulness.peti commentedon May 16, 2017
I see. Yes, that makes sense.
I am basically happy specifying those
extra-include-dirspaths for specific packages only, i.e. not globally for everything. However, those paths are specific to the system I'm building on, so I want to configure them in~/.cabal/config(or something like that). Butnew-buildwon't honor such things in the global config file; it honors package-specific configuration options only in the per-projectcabal.projectfile. But system paths don't belong there. They belong to the system.Now, if I could add
to
~/.cabal/configand havenew-builduse that information every time it compileshopensslfor any of my projects, then I would be happy. Is that feasible?hvr commentedon May 16, 2017
@peti Personally, I think that'd quite reasonable to have in ~/.cabal/config (or nearby).
I do wonder though how to be able to locally override the global setting. Especially with openssl, I've sometimes needed temporarily to use a newer local versions rather than the system-wide installed one (e.g.
hookupfor example needs a more recent OpenSSL version than is installed systemwide in Debian 8; however I want every other project that doesn't needhookupto use the system-wide openssl version; now imagine if the system-wide was installed in a non-standard location requiring extra-includes), and cabal traditionally considers settings to be of the free monoid kind, and thus appends settings rather than replacing them.On the other hand, I guess a local
package hopensslconfiguration could simply override all of the globalpackage hopensslstanza (as if there never was a global one).I think we have enough here to turn this into a specification for a feature-request ticket... :-)
peti commentedon May 17, 2017
@hvr, I see what you mean.
extra-xxx-dirsare difficult to treat as Moniods. I can think of the following strategies to deal with this issue:Just
mconcatall extra paths into one large list and make it the user's responsibility to write a sensible configuration. If the global config file sets an extra include dir for any packagefoo, then that directory will be part of the search path for all builds offoo, regardless of what more local configuration files say. Therefore, if I want a search path included in some builds offoobut not all, then I cannot set one in the global configuration file.In addition to (1), but we could guarantee that more locally configured search paths occur in that final list before the moreddition to (1), but w globally configured ones. Therefore, if I configure
/tmp/foo/includeglobally and/tmp/bar/includelocally, then my project will compile with-I/tmp/bar/include -I/tmp/foo/include. This is dangerous, of course, but it's a pretty common strategy to use. After all, all compilers have/usr/includeand their search path, yet we re-direct the compiler elsewhere just by pre-pending another location to that list so that the files in/usr/includeare no longer found.We could introduce another kind of search path, say
default-extra-include-dirs, which is cleared whenever aextra-include-dirsdirective appears anywhere else. That way, I could specify a search path that is used for "almost all builds", i.e. all builds that don't specify something else. Multiple occurrences ofdefault-extra-include-dirswould bemappended, of course.Provide an explicit
clear-<option-name>directive that throws away all occurrences of that configuration option that occur in a less local place. So, when I runcabal configure --clear-extra-include-dirs, then that search path will be empty -- regardless of what~/.cabal/config,cabal.project, orcabal.project.localsay. I'm not quite sure how the syntax would work in configuration files, but I suppose there is some sensible way to express that there, too.bitc commentedon Dec 15, 2017
If anyone is looking for a workaround: I found that setting the
C_INCLUDE_PATHenvironment variable works (LIBRARY_PATHmay also work). This doesn't seem to be documented anywhere, but I saw it mentioned here: #2705 (comment)For example, I have a project that has a dependency on the lzma package. When running regular
cabal new-buildit would give an error that it can't find the header file "lzma.h". Using--extra-include-dirsdid not help.But this did work:
peti commentedon Dec 15, 2017
Note that search paths configured via environment variables like
C_INCLUDE_PATHand others will not be recorded in the package configuration file for the generated library, which means that the build result might be unusable in shell environments that don't have these variables. In case of header files, this is probably not going to pose a problem, but when shared libraries need to be found at link-time, then it certainly will.harendra-kumar commentedon Aug 20, 2019
I was compiling GHC and it errored out because it could not find
gmp.h. I found that GHC scripts were invoking cabal configure but I did not know where in the ghc make scripts I can specify something like --extra-include-dirs. I knewgmp.hwas in `/opt/local/include' but there was no way I could tell cabal about it. I knew there was some environment variable to tell cabal about where to look for c headers, but could not find it anywhere in the documentation. After a lot of search, the comment above about C_INCLUDE_PATH helped. Why is this not documented? This is the second time I ran into this problem and every time I find this at some obscure place.28 remaining items
asivitz commentedon May 6, 2022
The main reason I can't go that route is that I'm trying to get a configuration that will work across multiple environments. So I wouldn't want to embed that configuration into something I'd check into source control. And also, the actual lib is dynamically created (through Nix). So, a command line argument is really what I need here, as opposed to a config value. (I guess I could dynamically generate the project file, but, I really don't want to do that.)
I'm currently trying a different approach in Nix. Although it seems like I should be able to do this, somehow, maybe I can avoid the problem entirely.
gbaz commentedon May 9, 2022
You can add that configuration to cabal.project.local and hence not place it in what is put it in source control, fwiw.
I can't think of a good way to specify this in command line options. We would need a full design to have subpackage options stanzas specifiable on the command line, which feels pretty awkward compared to creating a file.
jneira commentedon May 10, 2022
or maybe we could play with the explicit target, the counterintuitive thing arise when you do a
cabal command my-package --whateverand such option is not applied to my-packageasivitz commentedon May 10, 2022
That would certainly address my use case. It makes intuitive sense to me as well
andreabedini commentedon Aug 31, 2023
Trying to summarise:
The
--extra-lib-dirs=command line argument, just like theextra-lib-dirs:cabal.project option, only applies to local packages and will not apply to dependencies.This is due to the fact that cabal includes fields like
extra-lib-dirs:andextra-include-dirs:in the hash it uses to reuse already build dependencies. Applying that option globally will cause recompiling everything.In a project setting, there is a syntax to apply these options to any arbitrary package, whether local or not:
While in a project, both
cabal buildandcabal installwill read and use those options. The options are now scoped in a project so any recompilation is intentional.If you are developing a project, it is best practice to add these paths to
cabal.project.localand not include that into source version control, since those options are most likely specific to your system.Users of
cabal installoutside a project do not have a simple equivalent. One could argue that the use case of usingcabal installas a non-project/global command was left out of the transition to v2/nix-style commands. This includes the use case of "installing" packages from Hackage, which was and seems to be still quite common.If you try to
cabal installa Hackage package that needs a system library that cannot be found in the default search paths, you don't have a way to fix that with a command line option.My understanding is that adding/changing
extra-lib-dirsin the global cabal config works (but be aware you will recompile all dependencies everytime you change it). Edit: I tested this and it does work.It seem impossible at the moment to use the above per-package syntax in the global cabal config. This is due to techinical debts that have not been solved (:heart: @jgotoh for working on Migrate cabal.project parsing to parsec #7748). I am under the impression this would give an good solution, since you would be able to scope the extra options to specific packages, avoding mass recompilations.
The other solution is influencing
gcclibrary search paths. In the end, all cabal does is passingextra-librariestogcc, which has its own library search mechanism. In particular you can providegccwith extra paths to look for libraries in, using theLIBRARY_PATHenvironment variable. The same applies withextra-include-pathandC_INCLUDE_PATH, seegccmanual page.Notice this will be invisible to cabal's hashing mechanism, so changes in
LIBRARY_PATHandC_INCLUDE_PATHwill not trigger recompilation.This all I know and can understand, please correct me if I made mistakes or missed something important.
Apply project local options on install
Apply project local options on install
alt-romes commentedon Feb 2, 2024
I investigated and discussed this issue in yesterday's Cabal dev meeting.
As has been noted in this ticket's discussion, and summarised by @andreabedini and the commit message of 652a77c (this is a commit that took the wrong approach, but describes what packages do each flags apply to), flags given in the command line to
build, such as--extra-lib-dirsand--extra-include-dirs, are local flags, just like flags at the top-level of thecabal.projectfile.Local flags apply to local packages, such as those in your local project for which you have a
.cabalfile.However, local flags do not apply to non-local packages (such as those pulled from hackage and installed in the store). Therefore, specifying
--extra-lib-dirsin the command line will not apply those options to the packages you depend on such asHsOpenSSL. They are not ignored, they /only/ apply to the /local/ packages you are building!To apply flags to a package you depend on, such as
HsOpenSSL, you need to use either global configuration (~/.cabal/config) or per-package configuration, such as:package HsOpenSSL extra-lib-dirs: ... extra-include-dirs: ...or e.g. using an
*instead of the package name to apply those options to all non-local dependencies of the project you are building.In the meeting we agreed that, ultimately, the behaviour of local flags applying to local packages only is the correct one, and that we shouldn't change that behaviour.
Instead, we agree the solution to this ticket is to improve documentation and be very clear in cabal configure/build about the scope of configuration flags, add explicit examples of these use cases such as configuring the extra-lib-dirs of a specific package, and perhaps even add a small note to the documentation of
--extra-lib-dirssaying something like "Note that this flag only applies to the packages local to the project, but not its dependencies. Read X documentation for more details."