Behaviour of relative paths in `source:` in multi-dar projects

Maybe a bit of history helps understand the current behavior:

There are two concepts here which are orthogonal in the current implementation but from a user pov probably shouldn’t be.

The first is the list of roots modules that are included in the DAR produced by daml build. Initially, you could only have a single file. We later extended that to support a directory which means all files in that directory are considered root modules. This list of root modules is only used by daml build. Daml studio does not care about this at all.

The second concept is that of import paths: When we see an import, we need to locate that file somehow. For that, we search for that file in all import paths and take the first match. If it is not found, we search in dependencies and if it doesn’t exist, we fail. So what are the import paths? It is the list of paths specified via -I but there is one special case: For module A.B.C located in file path/to/A/B/C.daml we add path/to to the front of the import path.

So the first important take away from that is that the source directory has no influence on import paths and thereby where modules are found.
The second important take away is that trying to point source somewhere inside your module tree is usually a bad idea since you’ll add path/to into the import path and might include more than you expect.

Instead, if you want to be on the safe side, separate them at the top-level directories so something like

src/implementation/daml/Daml/Finance/Implementation/Token.daml
src/interface/daml/Daml/Finance/Interface/Transferable.daml
src/interface/daml/Daml/Finance/Interface/Issuable.daml
src/types/daml/Daml/Finance/Types.daml
src/test/daml/Daml/Finance/Test/Token.daml

And then point source at those directories. That way path/to will never pull in other files. If you want to pull them in explicitly you can do so via -I just remember that they are only pulled in if they are referenced rather than considered roots in daml build.

1 Like