Link the link to your local library

Allows MyLib be my local Haskell library. I can build it with cabal build and install it with cabal install , but can I use it in other projects without the installation step?

I develop several libraries and install them after each change is not a good solution.

+4
source share
2 answers

Let's say you have two completely separate projects, one of which is called my-library , and the other is my-project . And my-project depends on my-library .

The way to create my-library and make it available to other cabal install my-library projects. After that, any other project can use the library.

You are now ready to build my-project with the cabal install my-project command. It will not rebuild or reinstall my-library , but it will link your project to the library.

Now, if you make changes to my-library , be sure to update the version number before running cabal install my-library . If you forget to specify the version number, you will be warned that my-project will be deprecated. Now the old versions and the new version of your library are available for other projects.

You can continue to carry out your projects. They will gladly continue to use the previous version of my-library until they make another cabal install my-project . Therefore, there is no need to reinstall everything after each change.

If you want to rebuild your projects, but continue to work with the old version of your library, you can specify this in the build-depends section of your cabal file. For example, if you have installed versions 1.0 and 2.0 from my-library , you can create your project against an older version as follows:

 build-depends: my-library==1.0, ... 
+2
source

There is no great solution to your problem, but you can use sandboxes to maintain the development environment a little cleaner.

With cabal-1.18 or later, you can create a sandbox with cabal sandbox init , and then you can install it in this sandbox or add it ( cabal sandbox add-source <path to library> ).

This helps preserve the unstable libraries (and their potentially unstable dependencies) from your user package database, which can help prevent hellish hell (unresolvable conflicts between dependencies). However, this does not directly help reduce the number of commands that you need to issue each time you want to make a top-level assembly.

What you can , however, is set up a simple script that executes add-source commands and creates your top-level package. eg:

 #!/bin/bash cabal sandbox init # a no-op if the sandbox exists. cabal sandbox add-source ../MyLib cabal install --dependencies-only cabal build 

Of course, you could have done this earlier, but this time you can also easily clear (remove all installed artifacts) by clearing the sandbox:

 cabal sandbox delete 
+2
source

Source: https://habr.com/ru/post/1495571/


All Articles