Packages (roadmap #35)

A package is a directory with a lib.tr (its public definitions, as for any module) and, if it has dependencies of its own, a trine.toml. A project lists the packages it uses in [dependencies] of its trine.toml, and imports each one by its bare name:

# trine.toml
[package]
name = "app"

[dependencies]
geometry = { path = "../geometry" }                                    # a directory on disk (35a)
shapes = { git = "https://github.com/me/shapes", rev = "v1.2" }         # a git repository (35b)
# main.tr
import "shapes"

fn main():
  print(shapes.area(3, 4))

Git dependencies and trine.lock (35b)

rev is a tag, a branch or a commit (default: HEAD). The first build:

  1. fetches the repository into a mirror in the shared cache (below);
  2. resolves rev to a commit and checks that commit out, without .git and without line-ending conversion, into the cache under the hash of its files;
  3. writes trine.lock beside the project's trine.toml:
[[package]]
name = "shapes"
git = "https://github.com/me/shapes"
rev = "v1.2"
commit = "9e819af4457a4c260b495f27e73c8b8eae872cc2"
hash = "sha256:45f95f9eda8b…"

**Commit trine.lock.** Every later build, on any machine, uses exactly that commit, even if the tag has since moved, and checks the files against the hash: if a repository's history was rewritten (the same commit id, other files), the build stops and says so. Packages a package depends on are pinned in the same lock file: one lock file per project.

The shared cache (35c)

$TRINE_HOME, else %LOCALAPPDATA%\trine on Windows, $XDG_CACHE_HOME/trine or ~/.cache/trine elsewhere:

Everything in the cache can be deleted at any time; it is fetched or built again.

Reproducible builds

The executable depends only on the sources (the project's and the locked packages'), the compiler and the flags. A clean checkout with an empty cache builds a byte-identical executable when built the same way (the main file named by the same relative path: it is the program's name in its error messages). A test does exactly this: two git packages and an app, locked, the upstream tag moved, a fresh clone built --locked with a fresh cache.

Not yet: version ranges and a registry (packages are pinned commits); trine add.