Jonathan Prieto-Cubides
Jonathan Prieto-Cubides

Reputation: 2847

Stack using binaries of other package

I have two projects in my user directory ~, the project A and B. I run stack init and later stack build on the project A. Then, I have the binaries of the A package in a folder ~/.stack-work/install/x86_64-linux/lts-6.0/7.10.3/bin. The issue is B needs this version of the binaries from A package, and then try the same build with stack on the B project directory. I tried on ~/B run the following command without success.

stack build ~/.stack-work/install/x86_64-linux/lts-6.0/7.10.3/bin

How can I do that? What if I create a third package C, and need something similar?

Excerpts:

The A.cabal content.

name: A
version: 1.1

And the B.cabal.

name: B
version: 1.0
build-depends: A>= 1.1

Then,

$ stack init
Looking for .cabal or package.yaml files to use to init the project.
Using cabal packages:
- B.cabal

Selecting the best among 8 snapshots...

* Partially matches lts-6.0
    A version 1.0 found
        - A requires ==1.1

This may be resolved by: - Using '--omit-packages to exclude mismatching package(s). - Using '--resolver' to specify a matching snapshot/resolver

But I actually have the version 1.1 of A build.

Upvotes: 0

Views: 156

Answers (3)

ErikR
ErikR

Reputation: 52029

You don't need to include the project A's bin directory - that was a red herring.

Organize your files like this:

.
├── stack.yaml
├── project-A
│   ├── LICENSE.txt
│   ├── Setup.hs
│   ├── project-A.cabal
│   └── src
│       └── ...
│
└── project-B
    ├── Setup.hs
    ├── project-B.cabal
    └── src
        └── ...

Your top-level stack.yaml file will look like:

resolver: lts-5.13
packages:
- project-A/
- project-B/

Then in the top-level directory run stack build.

Upvotes: 1

Jonathan Prieto-Cubides
Jonathan Prieto-Cubides

Reputation: 2847

I found an answer after digging into the FAQ of stack. Create a file stack.yaml into B folder. At first the content could be:

resolver: lts-6.0
packages:
- '.'
- '/home/jonaprieto/A'

extra-deps: []

Then, it runs:

$ stack build

Upvotes: 0

ErikR
ErikR

Reputation: 52029

I'll take a stab at answering your question...

How about putting

~/.stack-work/install/x86_64-linux/lts-6.0/7.10.3/bin

in your PATH? If the other project really needs binaries (i.e. programs) built by another project, this would be the way to do it.

Or, copy the built programs to some directory in your current PATH - i.e. /usr/local/bin or ~/bin.

If this doesn't answer your question, please post the cabal files for both projects.

Upvotes: 0

Related Questions