-
Notifications
You must be signed in to change notification settings - Fork 697
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
How to correctly install a locally-built library in Cabal 3? #6478
Comments
I've had a similar issue, where I want to write "scripts" that make use of the Pandoc API. I have not been able to find a set of new-style commands that will let me use The only thing I've found that works is to go back to the It would be nice if there were a way to use the new-style subcommands, otherwise I guess I'll just not be updating past the point where the |
@elliottslaughter there is |
@phadej If you see jgm/pandoc#6066, I did try this, with the result:
I also tried Is this a bug? Should I open a new issue? |
is wrong, If you instead look into So, I'm really sorry that documentation is not up to date, if you find something missing the documentation PRs are more than welcome. Arguably the |
Ok, that works, though I had to also run I agree that modifying the output of I'm not honestly sure what to suggest for the documentation. It seems the new-style subcommands introduce a new abstraction (the environment), but this is something shared between Cabal and GHC. Presumably the Cabal documentation wouldn't be the place to find out that I need to run |
Hmm, I'm still not able to get it working with
|
I see now that
Also, I couldn't pick this out from the conversation, so I reproduced @elliottslaughter 's secondary issue by installing the dependent package twice, i.e. two versions end up in ~/.cabal. This isn't solved by |
I'm getting a similar problem when installing the upstream versions of shellac and lambda-shell. Cabal and GHC versions:
First, I install the
And the
Now, I try to install
and the installation fails because Any ideas? |
@asr Interesting, it also seems then that |
I could reproduce the installation using the global package db. However the installation failed installing
No. Using |
@asr Sorry yes, I understand now: the second package must also be built with v1 commands to find the first installed by v1-install. |
It would be v good to have some common use scenarios drawn out in the documentation. (I'd offer to help, but don't have enough knowledge to do so reliably.) For example:
This task-based documentation would complement the reference material in the manual. I'm sure that this would not be an arduous task and would significantly reduce the cost of entry to building robust cabal configurations. Perhaps this already exists somewhere, but I wasn't able to find it in a way that I could grok. |
cabal install --lib puts the packages in an environment so that they are visible to ghc, but cabal still cannot refer to them from another project unless you have a way to unambiguously specify that package's hash, so I think op's problem can be solved with a cabal.project that refers to both packages:
then
I also think the docs could benefit a lot from a cookbook if there isn't one already. Maybe you could open an issue with a list of common scenarios, then we can start filling out the "how"s? |
@fgaz This is a pretty good solution. Somehow I had never seen this usage, although searching for similar topics I'm finally starting to notice it, albeit usually buried under some sandbox-related solution. I also see that it won't work for more than one level of local dependency (see #5060). Also seen in that issue are some further difficulties of truly installing then depending on packages as opposed to building in every package the cabal.project way. But for my little project ecosystem the latter usually works out okay. |
@acrylic-origami is this solved? There's also https://github.com/phadej/cabal-extras/tree/master/cabal-env , a prototype of what a future install --lib sould be (#6481) |
@fgaz Yes! Thanks for linking the discussion around |
I came here googling for solutions how to depend on a unreleased package. With v1-cabal, I would simply have typed
in the root of my git working copy of Agda (development version, 2.6.2) and then Agda-2.6.2 would have been picked up when building agda-bench. I am looking for a v2-cabal drop-in replacement for this workflow. This does not seem to scale. Imagine a scenario where you have M projects each depending on N local packages, each of which takes half an hour to build. Say the build time for the M projects alone (with the N packages already built) is negligible. Your total v2-build time for these M projects is then MN/2 hours, as opposed to just N/2 hours in v1-style. Even just 1 additional build of Agda hurts badly... |
I tried putting Agda as one of the
It doesn't say anything about
(Note the whole build attempt took 1h 0min 36sec.) What am I missing? Why isn't GHC finding the package Agda-2.6.2 it just spend >40 min to compile? The environment file does contain an "inplace" version of Agda:
|
Not the package, the module:
That is, the module is listed in |
@andreasabel As for trying to install Agda as a proper global package, I've had success (caveat: for packages with far fewer dependencies) with the Setup.hs-based install outlined in my first post. To elaborate on step "2" of registering all the package dependencies globally (which should really be the first step), this is my workflow:
Then run the remaining steps, which will build and install the package globally. In the dependents, so long as your local version is versioned beyond the one on Hackage, constraining that package appropriately should convince Cabal to use your local version. You may want to do this on a clean/sandboxed GHC+Cabal as updating those global registrations of all the transitive dependencies can be a big pain. |
@andreasabel re artifact sharing:
No, v2- is fundamentally different. that's why it had a prefix and everything.
I'd say the principles are just different, less imperative and more functional/declarative. There are a few different ways you could declare dependencies in your scenario, with different artifact sharing properties.
As for the N*M problem, apart from putting them all in a big project, it looks like the best solution would be to treat the N packages as remote packages by adding them to a global file:// or file+noindex:// repository. As @acrylic-origami wrote, there is one single exception to all this: system packages, which are installed in the global package db. At the moment, only the global package db has this property. Also, for @andreasabel use case I'd avoid messing with package dbs |
And then it didn't.. and old commands silently stopped working, with old use cases no longer supported, and the new behaviour undocumented. |
This is such a fundamental operation. To me it borders on the insane that it isn't properly documented and/or working. I'm just throwing up my hands on Haskell. Brilliant language, amazing compiler, unusable toolset. There are other good choices for software development that don't inflict this level of pain. |
@donaldcallen: I thoroughly sympathise. Would you like to help improving the situation? Trying out the outlined solutions or solution prototypes and submitting documentation PRs are the ways in which you can have impact immediately. |
I found this thread when I was searching why running |
@kaol: thank you for sharing the tips. Just to make sure: you really do need to manually install libraries? Normally it's not necessary and actually causes problems. |
I want to audit all my dependencies before even building them. I don't see that there's the option to download only with |
I'm sure there are many ways to do that more conveniently. How about |
Yes, it would fit my purpose. But it's not yet available in the Cabal version I'm using. |
Well, in that case, |
After reading all of the above, I am more confused than before. Perhaps someone could help me with a summary for dummies of how to actually install a local library now. What I tried:
This worked fine. Then I go to another project on the same machine. In the
However, if I do not include
which means that the GHC does know of |
@l8l: are you sure you need to install the library? It shouldn't be needed except for some rare cases and even there mostly for repl usage convenience. |
@Mikolaj Thanks for the reply. I would like to use the functions in that library in other projects without copying them into those other projects. Is that possible without installing a library? Otherwise I do not undertand the question. |
Oh, yes, it's absolutely possible. cabal does that for you. Just mention this library in |
@Mikolaj Perhaps I misunderstand the answer. But how is cabal supposed to find this library if it is not installed? It is just a local library which is not on hackage. |
That's a good question. Either take it from a local directory or directly from a git repo. Both are declared in a |
@Mikolaj Thanks. With your hint, I now created a
and now the project builds correctly. However, this procedure requires me to specify a new relative path, or to copy an absolute path to my library around everytime I want to use it. Originally, I had hoped that running |
Again when the majority of your work is in the REPL, this is not just about 'convenience'. I agree that having to think ahead to manually make a text file containing all the libraries you are going to use in a session really gets in the way of getting things done. It's often just not possible - you might not know what libraries you will need until halfway through the day. |
I'm sure you are both right about your use cases. I don't have any similar workflows so can't advise. @l8l: Does the first ticket or any ticket at https://github.com/haskell/cabal/projects/10 offer any help? E.g., would |
|
Using globally installed packages is possible, with v1- or a combination of the new Instead, I think there are alternatives suitable to all your use cases:
|
I have a dream: the current cabal leadership convenes and decides where to put the marvelous text above in the user manual. Also, I whole-heartedly support suggestion to avoid |
As above, cabal.project doesn't work well for my use case, and package environments constantly break. Until there is something that works better than v1-install, please don't remove it. |
I confess to not having read this thread in detail, but I would like to
mention that I solved my confusion about dealing with local libraries with
a cabal.project file. It really took me a while -- too long -- to dig this
out of
what passes for documentation of cabal (I got a big assist from searching,
which turned up good advice from people who had been down this road). I
hope this is helpful.
…On Wed, Aug 24, 2022 at 11:09 AM Artem Pelenitsyn ***@***.***> wrote:
I have a dream: the current cabal leadership convenes and decides where to
put the marvelous text above in the user manual.
Also, I whole-heartedly support suggestion to avoid v1-install at all
costs. Even if this requires you to learn a field or two of cabal.project
or how GHC environments work. This is easier than it sounds. v1 is legacy
and should be expelled imo.
—
Reply to this email directly, view it on GitHub
<#6478 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABGOGJYPLONK53F47AUF7T3V2Y3MFANCNFSM4KFT234A>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Yes this sounds good! Not only useful for experiments and debugging, but also using the libraries interactively, e.g. in live music performance. |
Would somebody please volunteer a PR to put @fgaz list into the https://cabal.readthedocs.io/en/stable manual? We can then work on the text together in the PR, not to miss anybody's perspective. |
Thanks @fgaz for the detailed reply. Could you elaborate on your third option in your post? What does "sdist the package and put it in a local noindex repository" mean? And wouldn't it also be nice to have a very simple command that does that or provides some way to register a local library globally? I am not deep enough into the matter to understand why this is so complicated but I am somehow surprised that it is. Anyways, thanks again. |
Is that actually true? v1 installation (ie using Setup) is what Linux distros still do for Haskell libraries and I think it actually plays nicely with v2 - best of both worlds in my opinion. But I am interested in hearing counter-examples and may be forgetting something. |
@ulysses4ever wrote:
|
I think Debian uses Setup.hs, not v1. @andreasabel is |
Personally, I never use the |
Thank you. Let's hope v2 gets enough functionality at some point to retire v1. |
Note that this means we need to teach cabal and GHC environments to newcomers, including people who only intend to use an eDSL that happens to be embedded in Haskell. Since DSLs are one of the main use cases of Haskell, I think we really need to support using
I use |
I'm having difficulties installing and using a library built from source. It's likely just a documentation/my understanding issue, but to do the following:
I could only find one working method that I cannot believe is the Right Way:
runhaskell Setup.hs configure --global
; must be global. User installs aren't found by other projects (which I don't understand).ghc-pkg register --global /path/to/user/package.db/package-name.conf
./usr/local/bin/ghc-pkg dump --global -v0
, where the package (installed bycabal install --lib
) was missing. Trying to install withcabal install --global --lib package-name
still doesn't show up inghc-pkg dump --global
.runhaskell Setup.hs build
sudo runhaskell Setup.hs install
build-depends
as usual.This is with Setup as
Distribution.Simple.defaultMain
on GHC 8.6.5 and Cabal 3.0.0.0. GHC 8.4.2 + Cabal 2.4.0.0 surprisingly works with a simplecabal build; cabal install;
, so maybe it's a version thing?Any other combinations seem to fail. In particular, the intuitive
cabal new-install --lib
: the package isn't found inghc-pkg list
norcabal list --installed
and is an "unknown package" to other libraries. Interestingly, trying to use the package via-fplugin
withoutbuild-depends
will instead say that it's a hidden module of our library.In case this is rare workflow, at least to develop source plugins it's a vital one. This way, I don't have to specify a
source-repository-package
and build it again and again in every codebase I analyze, or upload it to Hackage for every edit I want to test.The text was updated successfully, but these errors were encountered: